2016-04-30 02:20:40 +03: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 11:15:16 +03:00
|
|
|
#ifndef mozilla_widget_CompositorWidget_h__
|
|
|
|
#define mozilla_widget_CompositorWidget_h__
|
2016-04-30 02:20:40 +03:00
|
|
|
|
|
|
|
#include "nsISupports.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
#include "Units.h"
|
2016-04-30 02:23:17 +03:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2017-01-13 01:29:42 +03:00
|
|
|
#include "mozilla/layers/CompositorOptions.h"
|
2016-04-30 02:23:17 +03:00
|
|
|
#include "mozilla/layers/LayersTypes.h"
|
|
|
|
|
|
|
|
class nsIWidget;
|
|
|
|
class nsBaseWidget;
|
2016-04-30 02:20:40 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
2016-07-19 21:56:07 +03:00
|
|
|
class VsyncObserver;
|
2016-11-16 16:54:51 +03:00
|
|
|
namespace gl {
|
|
|
|
class GLContext;
|
|
|
|
} // namespace gl
|
2016-04-30 02:20:40 +03:00
|
|
|
namespace layers {
|
2016-04-30 02:20:41 +03:00
|
|
|
class Compositor;
|
2016-11-16 16:54:51 +03:00
|
|
|
class LayerManager;
|
2016-04-30 02:20:40 +03:00
|
|
|
class LayerManagerComposite;
|
|
|
|
class Compositor;
|
|
|
|
} // namespace layers
|
|
|
|
namespace gfx {
|
|
|
|
class DrawTarget;
|
2016-05-12 17:23:11 +03:00
|
|
|
class SourceSurface;
|
2016-04-30 02:20:40 +03:00
|
|
|
} // namespace gfx
|
|
|
|
namespace widget {
|
|
|
|
|
2016-07-01 11:15:16 +03:00
|
|
|
class WinCompositorWidget;
|
2017-12-18 22:20:02 +03:00
|
|
|
class GtkCompositorWidget;
|
2016-10-03 19:26:00 +03:00
|
|
|
class AndroidCompositorWidget;
|
2016-07-01 11:15:16 +03:00
|
|
|
class CompositorWidgetInitData;
|
2016-06-29 23:47:23 +03:00
|
|
|
|
2016-07-01 11:15:16 +03: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 03:45:34 +03:00
|
|
|
class PlatformCompositorWidgetDelegate;
|
|
|
|
|
|
|
|
// Headless mode uses its own, singular CompositorWidget implementation.
|
|
|
|
class HeadlessCompositorWidget;
|
|
|
|
|
|
|
|
class CompositorWidgetDelegate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual PlatformCompositorWidgetDelegate* AsPlatformSpecificDelegate() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual HeadlessCompositorWidget* AsHeadlessCompositorWidget() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
};
|
2016-07-01 11:15:16 +03:00
|
|
|
|
2016-07-01 11:15:16 +03:00
|
|
|
// Platforms that support out-of-process widgets.
|
2016-07-22 20:23:07 +03:00
|
|
|
#if defined(XP_WIN) || defined(MOZ_X11)
|
2016-07-01 11:15:16 +03:00
|
|
|
// CompositorWidgetParent should implement CompositorWidget and
|
|
|
|
// PCompositorWidgetParent.
|
|
|
|
class CompositorWidgetParent;
|
|
|
|
|
|
|
|
// CompositorWidgetChild should implement CompositorWidgetDelegate and
|
|
|
|
// PCompositorWidgetChild.
|
|
|
|
class CompositorWidgetChild;
|
|
|
|
|
|
|
|
# define MOZ_WIDGET_SUPPORTS_OOP_COMPOSITING
|
|
|
|
#endif
|
|
|
|
|
2016-11-08 05:16:52 +03:00
|
|
|
class WidgetRenderingContext
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
#if defined(XP_MACOSX)
|
2016-11-16 16:54:51 +03:00
|
|
|
WidgetRenderingContext()
|
|
|
|
: mLayerManager(nullptr)
|
|
|
|
, mGL(nullptr) {}
|
2016-11-08 05:16:52 +03:00
|
|
|
layers::LayerManagerComposite* mLayerManager;
|
2016-11-16 16:54:51 +03:00
|
|
|
gl::GLContext* mGL;
|
2016-11-08 05:16:52 +03:00
|
|
|
#elif defined(MOZ_WIDGET_ANDROID)
|
|
|
|
WidgetRenderingContext() : mCompositor(nullptr) {}
|
|
|
|
layers::Compositor* mCompositor;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2016-04-30 02:20:40 +03:00
|
|
|
/**
|
|
|
|
* Access to a widget from the compositor is restricted to these methods.
|
|
|
|
*/
|
2016-07-01 11:15:16 +03:00
|
|
|
class CompositorWidget
|
2016-04-30 02:20:40 +03:00
|
|
|
{
|
|
|
|
public:
|
2016-11-16 16:54:51 +03:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(mozilla::widget::CompositorWidget)
|
2016-06-29 23:47:22 +03:00
|
|
|
|
2016-07-01 11:15:16 +03:00
|
|
|
/**
|
|
|
|
* Create an in-process compositor widget. aWidget may be ignored if the
|
|
|
|
* platform does not require it.
|
|
|
|
*/
|
2017-01-13 01:29:42 +03:00
|
|
|
static RefPtr<CompositorWidget> CreateLocal(const CompositorWidgetInitData& aInitData,
|
|
|
|
const layers::CompositorOptions& aOptions,
|
|
|
|
nsIWidget* aWidget);
|
2016-07-01 11:15:16 +03:00
|
|
|
|
2016-04-30 02:20:40 +03: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.
|
|
|
|
*/
|
2016-11-08 05:16:52 +03:00
|
|
|
virtual bool PreRender(WidgetRenderingContext* aContext) {
|
2016-04-30 02:20:40 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2016-11-08 05:16:52 +03:00
|
|
|
virtual void PostRender(WidgetRenderingContext* aContext)
|
2016-04-30 02:20:40 +03:00
|
|
|
{}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called before the LayerManager draws the layer tree.
|
|
|
|
*
|
|
|
|
* Always called from the compositing thread.
|
|
|
|
*/
|
2016-11-08 05:16:52 +03:00
|
|
|
virtual void DrawWindowUnderlay(WidgetRenderingContext* aContext,
|
2016-04-30 02:20:40 +03:00
|
|
|
LayoutDeviceIntRect aRect)
|
|
|
|
{}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called after the LayerManager draws the layer tree
|
|
|
|
*
|
|
|
|
* Always called from the compositing thread.
|
|
|
|
*/
|
2016-11-08 05:16:52 +03:00
|
|
|
virtual void DrawWindowOverlay(WidgetRenderingContext* aContext,
|
2016-04-30 02:20:40 +03:00
|
|
|
LayoutDeviceIntRect aRect)
|
|
|
|
{}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a DrawTarget for the window which can be composited into.
|
|
|
|
*
|
|
|
|
* Called by BasicCompositor on the compositor thread for OMTC drawing
|
|
|
|
* before each composition.
|
|
|
|
*
|
|
|
|
* The window may specify its buffer mode. If unspecified, it is assumed
|
|
|
|
* to require double-buffering.
|
|
|
|
*/
|
2016-04-30 02:23:17 +03:00
|
|
|
virtual already_AddRefed<gfx::DrawTarget> StartRemoteDrawing();
|
2016-04-30 02:20:40 +03:00
|
|
|
virtual already_AddRefed<gfx::DrawTarget>
|
|
|
|
StartRemoteDrawingInRegion(LayoutDeviceIntRegion& aInvalidRegion,
|
|
|
|
layers::BufferMode* aBufferMode)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
* after each composition.
|
|
|
|
*/
|
|
|
|
virtual void EndRemoteDrawing()
|
|
|
|
{}
|
|
|
|
virtual void EndRemoteDrawingInRegion(gfx::DrawTarget* aDrawTarget,
|
|
|
|
LayoutDeviceIntRegion& aInvalidRegion)
|
|
|
|
{
|
|
|
|
EndRemoteDrawing();
|
|
|
|
}
|
|
|
|
|
2016-08-24 01:18:55 +03:00
|
|
|
/**
|
|
|
|
* Return true when it is better to defer EndRemoteDrawing().
|
|
|
|
*
|
|
|
|
* Called by BasicCompositor on the compositor thread for OMTC drawing
|
|
|
|
* after each composition.
|
|
|
|
*/
|
|
|
|
virtual bool NeedsToDeferEndRemoteDrawing() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-04-30 02:20:40 +03:00
|
|
|
/**
|
|
|
|
* Called when shutting down the LayerManager to clean-up any cached resources.
|
|
|
|
*
|
|
|
|
* Always called from the compositing thread.
|
|
|
|
*/
|
|
|
|
virtual void CleanupWindowEffects()
|
|
|
|
{}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A hook for the widget to prepare a Compositor, during the latter's initialization.
|
|
|
|
*
|
|
|
|
* 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).
|
|
|
|
*/
|
|
|
|
virtual bool InitCompositor(layers::Compositor* aCompositor) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-30 02:23:17 +03:00
|
|
|
virtual uint32_t GetGLFrameBufferFormat();
|
2016-04-30 02:20:40 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Access the underlying nsIWidget. This method will be removed when the compositor no longer
|
|
|
|
* depends on nsIWidget on any platform.
|
|
|
|
*/
|
|
|
|
virtual nsIWidget* RealWidget() = 0;
|
2016-04-30 02:23:17 +03: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 08:00:14 +03: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.
|
|
|
|
*/
|
|
|
|
virtual uintptr_t GetWidgetKey() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-04-30 02:23:17 +03:00
|
|
|
/**
|
|
|
|
* Create a backbuffer for the software compositor.
|
|
|
|
*/
|
|
|
|
virtual already_AddRefed<gfx::DrawTarget>
|
2016-05-12 17:23:11 +03:00
|
|
|
GetBackBufferDrawTarget(gfx::DrawTarget* aScreenTarget,
|
|
|
|
const LayoutDeviceIntRect& aRect,
|
|
|
|
const LayoutDeviceIntRect& aClearRect);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-30 02:23:17 +03:00
|
|
|
|
2016-05-04 03:39:23 +03:00
|
|
|
/**
|
2016-07-19 21:56:07 +03:00
|
|
|
* Observe or unobserve vsync.
|
2016-05-04 03:39:23 +03:00
|
|
|
*/
|
2016-07-19 21:56:07 +03:00
|
|
|
virtual void ObserveVsync(VsyncObserver* aObserver) = 0;
|
2016-05-04 03:39:23 +03:00
|
|
|
|
2017-01-13 01:29:42 +03:00
|
|
|
/**
|
|
|
|
* Get the compositor options for the compositor associated with this
|
|
|
|
* CompositorWidget.
|
|
|
|
*/
|
|
|
|
const layers::CompositorOptions& GetCompositorOptions() {
|
|
|
|
return mOptions;
|
|
|
|
}
|
|
|
|
|
2017-06-20 11:17:19 +03:00
|
|
|
/**
|
|
|
|
* Return true if the window is hidden and should not be composited.
|
|
|
|
*/
|
|
|
|
virtual bool IsHidden() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-07-19 21:56:07 +03:00
|
|
|
/**
|
|
|
|
* This is only used by out-of-process compositors.
|
|
|
|
*/
|
|
|
|
virtual RefPtr<VsyncObserver> GetVsyncObserver() const;
|
|
|
|
|
2016-07-01 11:15:16 +03:00
|
|
|
virtual WinCompositorWidget* AsWindows() {
|
2016-06-29 23:47:23 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
2017-12-18 22:20:02 +03:00
|
|
|
virtual GtkCompositorWidget* AsX11() {
|
2016-07-22 20:23:07 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
2016-10-03 19:26:00 +03:00
|
|
|
virtual AndroidCompositorWidget* AsAndroid() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2016-06-29 23:47:23 +03:00
|
|
|
|
2016-07-01 11:15:16 +03:00
|
|
|
/**
|
|
|
|
* Return the platform-specific delegate for the widget, if any.
|
|
|
|
*/
|
|
|
|
virtual CompositorWidgetDelegate* AsDelegate() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-04-30 02:23:17 +03:00
|
|
|
protected:
|
2017-01-13 01:29:42 +03:00
|
|
|
explicit CompositorWidget(const layers::CompositorOptions& aOptions);
|
2016-07-01 11:15:16 +03:00
|
|
|
virtual ~CompositorWidget();
|
2016-04-30 02:23:17 +03:00
|
|
|
|
|
|
|
// Back buffer of BasicCompositor
|
|
|
|
RefPtr<gfx::DrawTarget> mLastBackBuffer;
|
2017-01-13 01:29:42 +03:00
|
|
|
|
|
|
|
layers::CompositorOptions mOptions;
|
2016-04-30 02:20:40 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif
|