Bug 1751217 Part 3: Make HDR-capable macOS screens report 30 pixelDepth. r=mstange
[gecko.git] / widget / gtk / GtkCompositorWidget.h
blobbbf00d34a226740b4e47e329e6e4afe0ff93bdbc
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 defined(MOZ_X11)
83 Window XWindow() const { return mXWindow; }
84 #endif
85 #if defined(MOZ_WAYLAND)
86 void SetEGLNativeWindowSize(const LayoutDeviceIntSize& aEGLWindowSize);
87 RefPtr<mozilla::layers::NativeLayerRoot> GetNativeLayerRoot() override;
88 #endif
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; }
100 private:
101 #if defined(MOZ_WAYLAND)
102 bool ConfigureWaylandBackend(RefPtr<nsWindow> aWindow);
103 #endif
104 #if defined(MOZ_X11)
105 bool ConfigureX11Backend(Window aXWindow, bool aShaped);
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 WindowSurfaceProvider mProvider;
125 #if defined(MOZ_X11)
126 Window mXWindow = {};
127 #endif
128 #ifdef MOZ_WAYLAND
129 RefPtr<mozilla::layers::NativeLayerRootWayland> mNativeLayerRoot;
130 #endif
131 Atomic<bool> mIsRenderingSuspended;
134 } // namespace widget
135 } // namespace mozilla
137 #endif // widget_gtk_GtkCompositorWidget_h