1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef widget_gtk_GtkCompositorWidget_h
7 #define widget_gtk_GtkCompositorWidget_h
10 #include "mozilla/DataMutex.h"
11 #include "mozilla/widget/CompositorWidget.h"
12 #include "WindowSurfaceProvider.h"
20 class NativeLayerRootWayland
;
25 class PlatformCompositorWidgetDelegate
: public CompositorWidgetDelegate
{
27 virtual void NotifyClientSizeChanged(
28 const LayoutDeviceIntSize
& aClientSize
) = 0;
29 virtual GtkCompositorWidget
* AsGtkCompositorWidget() { return nullptr; };
31 virtual void DisableRendering() = 0;
32 virtual void EnableRendering(const uintptr_t aXWindow
,
33 const bool aShaped
) = 0;
35 // CompositorWidgetDelegate Overrides
37 PlatformCompositorWidgetDelegate
* AsPlatformSpecificDelegate() override
{
42 class GtkCompositorWidgetInitData
;
44 class GtkCompositorWidget
: public CompositorWidget
,
45 public PlatformCompositorWidgetDelegate
{
47 GtkCompositorWidget(const GtkCompositorWidgetInitData
& aInitData
,
48 const layers::CompositorOptions
& aOptions
,
49 RefPtr
<nsWindow
> aWindow
/* = nullptr*/);
50 ~GtkCompositorWidget();
52 // CompositorWidget Overrides
54 already_AddRefed
<gfx::DrawTarget
> StartRemoteDrawing() override
;
55 void EndRemoteDrawing() override
;
57 already_AddRefed
<gfx::DrawTarget
> StartRemoteDrawingInRegion(
58 const LayoutDeviceIntRegion
& aInvalidRegion
,
59 layers::BufferMode
* aBufferMode
) override
;
60 void EndRemoteDrawingInRegion(
61 gfx::DrawTarget
* aDrawTarget
,
62 const LayoutDeviceIntRegion
& aInvalidRegion
) override
;
64 LayoutDeviceIntSize
GetClientSize() override
;
65 void RemoteLayoutSizeUpdated(const LayoutDeviceRect
& aSize
);
67 nsIWidget
* RealWidget() override
;
68 GtkCompositorWidget
* AsGTK() override
{ return this; }
69 CompositorWidgetDelegate
* AsDelegate() override
{ return this; }
71 EGLNativeWindowType
GetEGLNativeWindow();
73 LayoutDeviceIntRegion
GetTransparentRegion() override
;
75 // Suspend rendering of this remote widget and clear all resources.
76 // Can be used when underlying window is hidden/unmapped.
77 void DisableRendering() override
;
79 // Resume rendering with to given aXWindow (X11) or nsWindow (Wayland).
80 void EnableRendering(const uintptr_t aXWindow
, const bool aShaped
) override
;
83 Window
XWindow() const { return mXWindow
; }
85 #if defined(MOZ_WAYLAND)
86 void SetEGLNativeWindowSize(const LayoutDeviceIntSize
& aEGLWindowSize
);
87 RefPtr
<mozilla::layers::NativeLayerRoot
> GetNativeLayerRoot() override
;
90 bool PreRender(WidgetRenderingContext
* aContext
) override
{
91 return !mIsRenderingSuspended
;
93 bool IsHidden() const override
{ return mIsRenderingSuspended
; }
95 // PlatformCompositorWidgetDelegate Overrides
97 void NotifyClientSizeChanged(const LayoutDeviceIntSize
& aClientSize
) override
;
98 GtkCompositorWidget
* AsGtkCompositorWidget() override
{ return this; }
101 #if defined(MOZ_WAYLAND)
102 bool ConfigureWaylandBackend(RefPtr
<nsWindow
> aWindow
);
105 bool ConfigureX11Backend(Window aXWindow
, bool aShaped
);
112 RefPtr
<nsWindow
> mWidget
;
115 // This field is written to on the main thread and read from on the compositor
116 // or renderer thread. During window resizing, this is subject to a (largely
117 // benign) read/write race, see bug 1665726. The DataMutex doesn't prevent the
118 // read/write race, but it does make it Not Undefined Behaviour, and also
119 // ensures we only ever use the old or new size, and not some weird synthesis
121 DataMutex
<LayoutDeviceIntSize
> mClientSize
;
123 WindowSurfaceProvider mProvider
;
126 Window mXWindow
= {};
129 RefPtr
<mozilla::layers::NativeLayerRootWayland
> mNativeLayerRoot
;
131 Atomic
<bool> mIsRenderingSuspended
;
134 } // namespace widget
135 } // namespace mozilla
137 #endif // widget_gtk_GtkCompositorWidget_h