Bug 1869043 assert that graph set access is main thread only r=padenot
[gecko.git] / widget / gtk / GtkCompositorWidget.h
blob5bf89835d74772f01c5b0395c28f247b122b5e41
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"
14 class nsIWidget;
15 class nsWindow;
17 namespace mozilla {
19 namespace layers {
20 class NativeLayerRootWayland;
21 } // namespace layers
23 namespace widget {
25 class PlatformCompositorWidgetDelegate : public CompositorWidgetDelegate {
26 public:
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 {
38 return this;
42 class GtkCompositorWidgetInitData;
44 class GtkCompositorWidget : public CompositorWidget,
45 public PlatformCompositorWidgetDelegate {
46 public:
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;
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 mXWindow; }
88 #endif
89 #if defined(MOZ_WAYLAND)
90 RefPtr<mozilla::layers::NativeLayerRoot> GetNativeLayerRoot() override;
91 #endif
93 bool PreRender(WidgetRenderingContext* aContext) override {
94 return !mIsRenderingSuspended;
96 bool IsHidden() const override { return mIsRenderingSuspended; }
98 // PlatformCompositorWidgetDelegate Overrides
100 void NotifyClientSizeChanged(const LayoutDeviceIntSize& aClientSize) override;
101 GtkCompositorWidget* AsGtkCompositorWidget() override { return this; }
103 private:
104 #if defined(MOZ_WAYLAND)
105 bool ConfigureWaylandBackend();
106 #endif
107 #if defined(MOZ_X11)
108 bool ConfigureX11Backend(Window aXWindow, bool aShaped);
109 #endif
110 #ifdef MOZ_LOGGING
111 bool IsPopup();
112 #endif
114 protected:
115 RefPtr<nsWindow> mWidget;
117 private:
118 // This field is written to on the main thread and read from on the compositor
119 // or renderer thread. During window resizing, this is subject to a (largely
120 // benign) read/write race, see bug 1665726. The DataMutex doesn't prevent the
121 // read/write race, but it does make it Not Undefined Behaviour, and also
122 // ensures we only ever use the old or new size, and not some weird synthesis
123 // of the two.
124 DataMutex<LayoutDeviceIntSize> mClientSize;
126 WindowSurfaceProvider mProvider;
128 #if defined(MOZ_X11)
129 Window mXWindow = {};
130 #endif
131 #ifdef MOZ_WAYLAND
132 RefPtr<mozilla::layers::NativeLayerRootWayland> mNativeLayerRoot;
133 #endif
134 Atomic<bool> mIsRenderingSuspended{true};
137 } // namespace widget
138 } // namespace mozilla
140 #endif // widget_gtk_GtkCompositorWidget_h