Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / widget / gtk / GtkCompositorWidget.h
blobaf4dcd536ea9fc6499c7dbc4c2e46668e3d8eab7
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
9 #include "GLDefs.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"
16 class nsIWidget;
17 class nsWindow;
19 namespace mozilla {
21 namespace layers {
22 class NativeLayerRootWayland;
23 } // namespace layers
25 namespace widget {
27 class PlatformCompositorWidgetDelegate : public CompositorWidgetDelegate {
28 public:
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 {
39 return this;
43 class GtkCompositorWidgetInitData;
45 class GtkCompositorWidget : public CompositorWidget,
46 public PlatformCompositorWidgetDelegate {
47 public:
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);
86 #if defined(MOZ_X11)
87 Window XWindow() const { return mProvider.GetXWindow(); }
88 #endif
89 #if defined(MOZ_WAYLAND)
90 RefPtr<mozilla::layers::NativeLayerRoot> GetNativeLayerRoot() override;
91 #endif
93 // PlatformCompositorWidgetDelegate Overrides
95 void NotifyClientSizeChanged(const LayoutDeviceIntSize& aClientSize) override;
96 GtkCompositorWidget* AsGtkCompositorWidget() override { return this; }
98 UniquePtr<WaylandSurfaceLock> LockSurface();
100 private:
101 #if defined(MOZ_WAYLAND)
102 void ConfigureWaylandBackend();
103 #endif
104 #if defined(MOZ_X11)
105 void ConfigureX11Backend(Window aXWindow);
106 #endif
107 #ifdef MOZ_LOGGING
108 bool IsPopup();
109 #endif
111 protected:
112 RefPtr<nsWindow> mWidget;
114 private:
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
120 // of the two.
121 DataMutex<LayoutDeviceIntSize> mClientSize;
123 // Holds rendering resources
124 WindowSurfaceProvider mProvider;
126 #ifdef MOZ_WAYLAND
127 RefPtr<mozilla::layers::NativeLayerRootWayland> mNativeLayerRoot;
128 #endif
131 } // namespace widget
132 } // namespace mozilla
134 #endif // widget_gtk_GtkCompositorWidget_h