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"
13 #include "mozilla/UniquePtr.h"
14 #include "WaylandSurfaceLock.h"
22 class NativeLayerRootWayland
;
27 class PlatformCompositorWidgetDelegate
: public CompositorWidgetDelegate
{
29 virtual void NotifyClientSizeChanged(
30 const LayoutDeviceIntSize
& aClientSize
) = 0;
31 virtual GtkCompositorWidget
* AsGtkCompositorWidget() { return nullptr; };
33 virtual void CleanupResources() = 0;
34 virtual void SetRenderingSurface(const uintptr_t aXWindow
) = 0;
36 // CompositorWidgetDelegate Overrides
38 PlatformCompositorWidgetDelegate
* AsPlatformSpecificDelegate() override
{
43 class GtkCompositorWidgetInitData
;
45 class GtkCompositorWidget
: public CompositorWidget
,
46 public PlatformCompositorWidgetDelegate
{
48 GtkCompositorWidget(const GtkCompositorWidgetInitData
& aInitData
,
49 const layers::CompositorOptions
& aOptions
,
50 RefPtr
<nsWindow
> aWindow
/* = nullptr*/);
51 ~GtkCompositorWidget();
53 // CompositorWidget Overrides
55 already_AddRefed
<gfx::DrawTarget
> StartRemoteDrawing() override
;
56 void EndRemoteDrawing() override
;
58 already_AddRefed
<gfx::DrawTarget
> StartRemoteDrawingInRegion(
59 const LayoutDeviceIntRegion
& aInvalidRegion
,
60 layers::BufferMode
* aBufferMode
) override
;
61 void EndRemoteDrawingInRegion(
62 gfx::DrawTarget
* aDrawTarget
,
63 const LayoutDeviceIntRegion
& aInvalidRegion
) override
;
65 LayoutDeviceIntSize
GetClientSize() override
;
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 CleanupResources() override
;
79 // Resume rendering with to given aXWindow (X11) or nsWindow (Wayland).
80 void SetRenderingSurface(const uintptr_t aXWindow
) override
;
82 // If we fail to set window size (due to different screen scale or so)
83 // we can't paint the frame by compositor.
84 bool SetEGLNativeWindowSize(const LayoutDeviceIntSize
& aEGLWindowSize
);
87 Window
XWindow() const { return mProvider
.GetXWindow(); }
89 #if defined(MOZ_WAYLAND)
90 RefPtr
<mozilla::layers::NativeLayerRoot
> GetNativeLayerRoot() override
;
93 // PlatformCompositorWidgetDelegate Overrides
95 void NotifyClientSizeChanged(const LayoutDeviceIntSize
& aClientSize
) override
;
96 GtkCompositorWidget
* AsGtkCompositorWidget() override
{ return this; }
98 UniquePtr
<WaylandSurfaceLock
> LockSurface();
101 #if defined(MOZ_WAYLAND)
102 void ConfigureWaylandBackend();
105 void ConfigureX11Backend(Window aXWindow
);
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 // Holds rendering resources
124 WindowSurfaceProvider mProvider
;
127 RefPtr
<mozilla::layers::NativeLayerRootWayland
> mNativeLayerRoot
;
131 } // namespace widget
132 } // namespace mozilla
134 #endif // widget_gtk_GtkCompositorWidget_h