2016-04-29 23:20:40 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2016-07-01 08:15:16 +00:00
|
|
|
#ifndef mozilla_widget_CompositorWidget_h__
|
|
|
|
#define mozilla_widget_CompositorWidget_h__
|
2016-04-29 23:20:40 +00:00
|
|
|
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
#include "Units.h"
|
2016-04-29 23:23:17 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2017-01-12 22:29:42 +00:00
|
|
|
#include "mozilla/layers/CompositorOptions.h"
|
2016-04-29 23:23:17 +00:00
|
|
|
#include "mozilla/layers/LayersTypes.h"
|
2019-08-25 17:10:52 +00:00
|
|
|
#include "mozilla/layers/NativeLayer.h"
|
2016-04-29 23:23:17 +00:00
|
|
|
|
|
|
|
class nsIWidget;
|
|
|
|
class nsBaseWidget;
|
2016-04-29 23:20:40 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
2016-07-19 18:56:07 +00:00
|
|
|
class VsyncObserver;
|
2016-11-16 13:54:51 +00:00
|
|
|
namespace gl {
|
|
|
|
class GLContext;
|
2018-11-30 10:46:48 +00:00
|
|
|
} // namespace gl
|
2016-04-29 23:20:40 +00:00
|
|
|
namespace layers {
|
2016-04-29 23:20:41 +00:00
|
|
|
class Compositor;
|
2016-11-16 13:54:51 +00:00
|
|
|
class LayerManager;
|
2016-04-29 23:20:40 +00:00
|
|
|
class LayerManagerComposite;
|
|
|
|
class Compositor;
|
2018-11-30 10:46:48 +00:00
|
|
|
} // namespace layers
|
2016-04-29 23:20:40 +00:00
|
|
|
namespace gfx {
|
|
|
|
class DrawTarget;
|
2016-05-12 14:23:11 +00:00
|
|
|
class SourceSurface;
|
2018-11-30 10:46:48 +00:00
|
|
|
} // namespace gfx
|
2016-04-29 23:20:40 +00:00
|
|
|
namespace widget {
|
|
|
|
|
2016-07-01 08:15:16 +00:00
|
|
|
class WinCompositorWidget;
|
2017-12-18 19:20:02 +00:00
|
|
|
class GtkCompositorWidget;
|
2016-10-03 16:26:00 +00:00
|
|
|
class AndroidCompositorWidget;
|
2016-07-01 08:15:16 +00:00
|
|
|
class CompositorWidgetInitData;
|
2016-06-29 20:47:23 +00:00
|
|
|
|
2016-07-01 08:15:16 +00:00
|
|
|
// Gecko widgets usually need to communicate with the CompositorWidget with
|
|
|
|
// platform-specific messages (for example to update the window size or
|
|
|
|
// transparency). This functionality is controlled through a "host". Since
|
|
|
|
// this functionality is platform-dependent, it is only forward declared
|
|
|
|
// here.
|
Bug 1373739 - Make headless compositing Windows-compatible, in addition to Linux. r=dvander
To make the HeadlessCompositorWidget work under Windows as well as Linux, I had
to change the way that I hooked it into the existing CompositorWidget system.
Under GTK, the CompositorWidgetInitData and CompositorWidgetDelegate types
provided the information needed by the headless compositor widget already (the
widget client size). On Windows, however, the definitions of these types
differ, and the client size information is simply retrieved from the platform
APIs when needed.
After this patch, CompositorWidgetDelegate is renamed to
PlatformCompositorWidgetDelegate, and a new base class called
CompositorWidgetDelegate is added with "AsPlatformSpecificDelegate()" and
"AsHeadlessCompositorWidget()" methods. In non-headless mode, widgets use
AsPlatformSpecificDelegate() to access the Windows- and GTK-specific delegate
APIs. In headless mode, AsHeadlessCompositorWidget() is used to access the
singular CompositorWidget implementation for headless. Meanwhile, the
CompositorWidgetInitData IPDL type is made into a union which always contains a
headless-specific HeadlessCompositorWidgetInitData struct and under GTK and
Windows also contains an {X11,Win}CompositorWidgetInitData struct.
This also includes a small patch to ensure that the GPU process and
hardware-accelerated compositing are always disabled under headless mode. These
features weren't activated by default in the Linux environments I tested in, but
did end up activating (and then promptly crashing Firefox) when I tested on
Windows.
MozReview-Commit-ID: CocPoHBDV7H
--HG--
extra : rebase_source : 4581fa63aa3a9f32a8dc2672015a35b9be01b20f
2017-07-07 00:45:34 +00:00
|
|
|
class PlatformCompositorWidgetDelegate;
|
|
|
|
|
|
|
|
// Headless mode uses its own, singular CompositorWidget implementation.
|
|
|
|
class HeadlessCompositorWidget;
|
|
|
|
|
2018-11-30 10:46:48 +00:00
|
|
|
class CompositorWidgetDelegate {
|
|
|
|
public:
|
Bug 1373739 - Make headless compositing Windows-compatible, in addition to Linux. r=dvander
To make the HeadlessCompositorWidget work under Windows as well as Linux, I had
to change the way that I hooked it into the existing CompositorWidget system.
Under GTK, the CompositorWidgetInitData and CompositorWidgetDelegate types
provided the information needed by the headless compositor widget already (the
widget client size). On Windows, however, the definitions of these types
differ, and the client size information is simply retrieved from the platform
APIs when needed.
After this patch, CompositorWidgetDelegate is renamed to
PlatformCompositorWidgetDelegate, and a new base class called
CompositorWidgetDelegate is added with "AsPlatformSpecificDelegate()" and
"AsHeadlessCompositorWidget()" methods. In non-headless mode, widgets use
AsPlatformSpecificDelegate() to access the Windows- and GTK-specific delegate
APIs. In headless mode, AsHeadlessCompositorWidget() is used to access the
singular CompositorWidget implementation for headless. Meanwhile, the
CompositorWidgetInitData IPDL type is made into a union which always contains a
headless-specific HeadlessCompositorWidgetInitData struct and under GTK and
Windows also contains an {X11,Win}CompositorWidgetInitData struct.
This also includes a small patch to ensure that the GPU process and
hardware-accelerated compositing are always disabled under headless mode. These
features weren't activated by default in the Linux environments I tested in, but
did end up activating (and then promptly crashing Firefox) when I tested on
Windows.
MozReview-Commit-ID: CocPoHBDV7H
--HG--
extra : rebase_source : 4581fa63aa3a9f32a8dc2672015a35b9be01b20f
2017-07-07 00:45:34 +00:00
|
|
|
virtual PlatformCompositorWidgetDelegate* AsPlatformSpecificDelegate() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual HeadlessCompositorWidget* AsHeadlessCompositorWidget() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
};
|
2016-07-01 08:15:16 +00:00
|
|
|
|
2016-07-01 08:15:16 +00:00
|
|
|
// Platforms that support out-of-process widgets.
|
2016-07-22 17:23:07 +00:00
|
|
|
#if defined(XP_WIN) || defined(MOZ_X11)
|
2016-07-01 08:15:16 +00:00
|
|
|
// CompositorWidgetParent should implement CompositorWidget and
|
|
|
|
// PCompositorWidgetParent.
|
|
|
|
class CompositorWidgetParent;
|
|
|
|
|
|
|
|
// CompositorWidgetChild should implement CompositorWidgetDelegate and
|
|
|
|
// PCompositorWidgetChild.
|
|
|
|
class CompositorWidgetChild;
|
|
|
|
|
2019-01-18 09:16:18 +00:00
|
|
|
# define MOZ_WIDGET_SUPPORTS_OOP_COMPOSITING
|
2016-07-01 08:15:16 +00:00
|
|
|
#endif
|
|
|
|
|
2018-11-30 10:46:48 +00:00
|
|
|
class WidgetRenderingContext {
|
|
|
|
public:
|
2016-11-08 02:16:52 +00:00
|
|
|
#if defined(XP_MACOSX)
|
2019-11-20 23:22:58 +00:00
|
|
|
gl::GLContext* mGL = nullptr;
|
2016-11-08 02:16:52 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2016-04-29 23:20:40 +00:00
|
|
|
/**
|
|
|
|
* Access to a widget from the compositor is restricted to these methods.
|
|
|
|
*/
|
2018-11-30 10:46:48 +00:00
|
|
|
class CompositorWidget {
|
|
|
|
public:
|
2016-11-16 13:54:51 +00:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(mozilla::widget::CompositorWidget)
|
2016-06-29 20:47:22 +00:00
|
|
|
|
2016-07-01 08:15:16 +00:00
|
|
|
/**
|
|
|
|
* Create an in-process compositor widget. aWidget may be ignored if the
|
|
|
|
* platform does not require it.
|
|
|
|
*/
|
2018-11-30 10:46:48 +00:00
|
|
|
static RefPtr<CompositorWidget> CreateLocal(
|
|
|
|
const CompositorWidgetInitData& aInitData,
|
|
|
|
const layers::CompositorOptions& aOptions, nsIWidget* aWidget);
|
2016-07-01 08:15:16 +00:00
|
|
|
|
2016-04-29 23:20:40 +00:00
|
|
|
/**
|
|
|
|
* Called before rendering using OMTC. Returns false when the widget is
|
|
|
|
* not ready to be rendered (for example while the window is closed).
|
|
|
|
*
|
|
|
|
* Always called from the compositing thread, which may be the main-thread if
|
|
|
|
* OMTC is not enabled.
|
|
|
|
*/
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual bool PreRender(WidgetRenderingContext* aContext) { return true; }
|
2016-04-29 23:20:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Called after rendering using OMTC. Not called when rendering was
|
|
|
|
* cancelled by a negative return value from PreRender.
|
|
|
|
*
|
|
|
|
* Always called from the compositing thread, which may be the main-thread if
|
|
|
|
* OMTC is not enabled.
|
|
|
|
*/
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual void PostRender(WidgetRenderingContext* aContext) {}
|
2016-04-29 23:20:40 +00:00
|
|
|
|
2019-08-25 17:43:42 +00:00
|
|
|
/**
|
|
|
|
* Called before the first composite. If the result is non-null, one or more
|
|
|
|
* native layers will be placed on the window and used for compositing.
|
|
|
|
* When native layers are used, StartRemoteDrawing(InRegion) and
|
|
|
|
* EndRemoteDrawing(InRegion) will not be called.
|
|
|
|
*/
|
2019-08-25 17:10:52 +00:00
|
|
|
virtual RefPtr<layers::NativeLayerRoot> GetNativeLayerRoot() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-04-29 23:20:40 +00:00
|
|
|
/**
|
|
|
|
* Return a DrawTarget for the window which can be composited into.
|
|
|
|
*
|
2019-08-25 17:43:42 +00:00
|
|
|
* Only called if GetNativeLayerRoot() returns nullptr.
|
2016-04-29 23:20:40 +00:00
|
|
|
* Called by BasicCompositor on the compositor thread for OMTC drawing
|
2019-08-25 17:43:42 +00:00
|
|
|
* before each composition (unless there's a native layer root).
|
2016-04-29 23:20:40 +00:00
|
|
|
*
|
|
|
|
* The window may specify its buffer mode. If unspecified, it is assumed
|
|
|
|
* to require double-buffering.
|
|
|
|
*/
|
2016-04-29 23:23:17 +00:00
|
|
|
virtual already_AddRefed<gfx::DrawTarget> StartRemoteDrawing();
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual already_AddRefed<gfx::DrawTarget> StartRemoteDrawingInRegion(
|
|
|
|
LayoutDeviceIntRegion& aInvalidRegion, layers::BufferMode* aBufferMode) {
|
2016-04-29 23:20:40 +00:00
|
|
|
return StartRemoteDrawing();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure that what was painted into the DrawTarget returned from
|
|
|
|
* StartRemoteDrawing reaches the screen.
|
|
|
|
*
|
|
|
|
* Called by BasicCompositor on the compositor thread for OMTC drawing
|
2019-08-25 17:43:42 +00:00
|
|
|
* after each composition for which StartRemoteDrawing(InRegion) was called.
|
2016-04-29 23:20:40 +00:00
|
|
|
*/
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual void EndRemoteDrawing() {}
|
2019-08-19 22:40:39 +00:00
|
|
|
virtual void EndRemoteDrawingInRegion(
|
|
|
|
gfx::DrawTarget* aDrawTarget,
|
|
|
|
const LayoutDeviceIntRegion& aInvalidRegion) {
|
2016-04-29 23:20:40 +00:00
|
|
|
EndRemoteDrawing();
|
|
|
|
}
|
|
|
|
|
2016-08-23 22:18:55 +00:00
|
|
|
/**
|
|
|
|
* Return true when it is better to defer EndRemoteDrawing().
|
|
|
|
*
|
|
|
|
* Called by BasicCompositor on the compositor thread for OMTC drawing
|
|
|
|
* after each composition.
|
|
|
|
*/
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual bool NeedsToDeferEndRemoteDrawing() { return false; }
|
2016-08-23 22:18:55 +00:00
|
|
|
|
2016-04-29 23:20:40 +00:00
|
|
|
/**
|
2018-11-30 10:46:48 +00:00
|
|
|
* Called when shutting down the LayerManager to clean-up any cached
|
|
|
|
* resources.
|
2016-04-29 23:20:40 +00:00
|
|
|
*
|
|
|
|
* Always called from the compositing thread.
|
|
|
|
*/
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual void CleanupWindowEffects() {}
|
2016-04-29 23:20:40 +00:00
|
|
|
|
|
|
|
/**
|
2018-11-30 10:46:48 +00:00
|
|
|
* A hook for the widget to prepare a Compositor, during the latter's
|
|
|
|
* initialization.
|
2016-04-29 23:20:40 +00:00
|
|
|
*
|
|
|
|
* If this method returns true, it means that the widget will be able to
|
|
|
|
* present frames from the compoositor.
|
|
|
|
*
|
|
|
|
* Returning false will cause the compositor's initialization to fail, and
|
|
|
|
* a different compositor backend will be used (if any).
|
|
|
|
*/
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual bool InitCompositor(layers::Compositor* aCompositor) { return true; }
|
2016-04-29 23:20:40 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the size of the drawable area of the widget.
|
|
|
|
*/
|
|
|
|
virtual LayoutDeviceIntSize GetClientSize() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the internal format of the default framebuffer for this
|
|
|
|
* widget.
|
|
|
|
*/
|
2016-04-29 23:23:17 +00:00
|
|
|
virtual uint32_t GetGLFrameBufferFormat();
|
2016-04-29 23:20:40 +00:00
|
|
|
|
|
|
|
/*
|
2018-11-30 10:46:48 +00:00
|
|
|
* Access the underlying nsIWidget. This method will be removed when the
|
|
|
|
* compositor no longer depends on nsIWidget on any platform.
|
2016-04-29 23:20:40 +00:00
|
|
|
*/
|
|
|
|
virtual nsIWidget* RealWidget() = 0;
|
2016-04-29 23:23:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean up any resources used by Start/EndRemoteDrawing.
|
|
|
|
*
|
|
|
|
* Called by BasicCompositor on the compositor thread for OMTC drawing
|
|
|
|
* when the compositor is destroyed.
|
|
|
|
*/
|
|
|
|
virtual void CleanupRemoteDrawing();
|
|
|
|
|
2016-05-05 05:00:14 +00:00
|
|
|
/**
|
|
|
|
* Return a key that can represent the widget object round-trip across the
|
|
|
|
* CompositorBridge channel. This only needs to be implemented on GTK and
|
|
|
|
* Windows.
|
|
|
|
*
|
|
|
|
* The key must be the nsIWidget pointer cast to a uintptr_t. See
|
|
|
|
* CompositorBridgeChild::RecvHideAllPlugins and
|
|
|
|
* CompositorBridgeParent::SendHideAllPlugins.
|
|
|
|
*/
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual uintptr_t GetWidgetKey() { return 0; }
|
2016-05-05 05:00:14 +00:00
|
|
|
|
2016-04-29 23:23:17 +00:00
|
|
|
/**
|
|
|
|
* Create a backbuffer for the software compositor.
|
|
|
|
*/
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual already_AddRefed<gfx::DrawTarget> GetBackBufferDrawTarget(
|
2019-08-19 22:40:55 +00:00
|
|
|
gfx::DrawTarget* aScreenTarget, const gfx::IntRect& aRect,
|
2019-08-19 22:39:00 +00:00
|
|
|
bool* aOutIsCleared);
|
2016-05-12 14:23:11 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Ensure end of composition to back buffer.
|
|
|
|
*
|
|
|
|
* Called by BasicCompositor on the compositor thread for OMTC drawing
|
|
|
|
* after each composition to back buffer.
|
|
|
|
*/
|
|
|
|
virtual already_AddRefed<gfx::SourceSurface> EndBackBufferDrawing();
|
2016-04-29 23:23:17 +00:00
|
|
|
|
2016-05-04 00:39:23 +00:00
|
|
|
/**
|
2016-07-19 18:56:07 +00:00
|
|
|
* Observe or unobserve vsync.
|
2016-05-04 00:39:23 +00:00
|
|
|
*/
|
2016-07-19 18:56:07 +00:00
|
|
|
virtual void ObserveVsync(VsyncObserver* aObserver) = 0;
|
2016-05-04 00:39:23 +00:00
|
|
|
|
2017-01-12 22:29:42 +00:00
|
|
|
/**
|
|
|
|
* Get the compositor options for the compositor associated with this
|
|
|
|
* CompositorWidget.
|
|
|
|
*/
|
2018-11-30 10:46:48 +00:00
|
|
|
const layers::CompositorOptions& GetCompositorOptions() { return mOptions; }
|
2017-01-12 22:29:42 +00:00
|
|
|
|
2017-06-20 08:17:19 +00:00
|
|
|
/**
|
|
|
|
* Return true if the window is hidden and should not be composited.
|
|
|
|
*/
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual bool IsHidden() const { return false; }
|
2017-06-20 08:17:19 +00:00
|
|
|
|
2016-07-19 18:56:07 +00:00
|
|
|
/**
|
|
|
|
* This is only used by out-of-process compositors.
|
|
|
|
*/
|
|
|
|
virtual RefPtr<VsyncObserver> GetVsyncObserver() const;
|
|
|
|
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual WinCompositorWidget* AsWindows() { return nullptr; }
|
|
|
|
virtual GtkCompositorWidget* AsX11() { return nullptr; }
|
|
|
|
virtual AndroidCompositorWidget* AsAndroid() { return nullptr; }
|
2016-06-29 20:47:23 +00:00
|
|
|
|
2016-07-01 08:15:16 +00:00
|
|
|
/**
|
|
|
|
* Return the platform-specific delegate for the widget, if any.
|
|
|
|
*/
|
2018-11-30 10:46:48 +00:00
|
|
|
virtual CompositorWidgetDelegate* AsDelegate() { return nullptr; }
|
2016-07-01 08:15:16 +00:00
|
|
|
|
2018-11-30 10:46:48 +00:00
|
|
|
protected:
|
2017-01-12 22:29:42 +00:00
|
|
|
explicit CompositorWidget(const layers::CompositorOptions& aOptions);
|
2016-07-01 08:15:16 +00:00
|
|
|
virtual ~CompositorWidget();
|
2016-04-29 23:23:17 +00:00
|
|
|
|
|
|
|
// Back buffer of BasicCompositor
|
|
|
|
RefPtr<gfx::DrawTarget> mLastBackBuffer;
|
2017-01-12 22:29:42 +00:00
|
|
|
|
|
|
|
layers::CompositorOptions mOptions;
|
2016-04-29 23:20:40 +00:00
|
|
|
};
|
|
|
|
|
2018-11-30 10:46:48 +00:00
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|
2016-04-29 23:20:40 +00:00
|
|
|
|
|
|
|
#endif
|