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/. */ 5 6 #ifndef widget_gtk_GtkCompositorWidget_h 7 #define widget_gtk_GtkCompositorWidget_h 8 9 #include "GLDefs.h" 10 #include "mozilla/DataMutex.h" 11 #include "mozilla/widget/CompositorWidget.h" 12 #include "WindowSurfaceProvider.h" 13 14 class nsIWidget; 15 class nsWindow; 16 17 namespace mozilla { 18 19 namespace layers { 20 class NativeLayerRootWayland; 21 } // namespace layers 22 23 namespace widget { 24 25 class PlatformCompositorWidgetDelegate : public CompositorWidgetDelegate { 26 public: 27 virtual void NotifyClientSizeChanged( 28 const LayoutDeviceIntSize& aClientSize) = 0; AsGtkCompositorWidget()29 virtual GtkCompositorWidget* AsGtkCompositorWidget() { return nullptr; }; 30 31 // CompositorWidgetDelegate Overrides 32 AsPlatformSpecificDelegate()33 PlatformCompositorWidgetDelegate* AsPlatformSpecificDelegate() override { 34 return this; 35 } 36 }; 37 38 class GtkCompositorWidgetInitData; 39 40 class GtkCompositorWidget : public CompositorWidget, 41 public PlatformCompositorWidgetDelegate { 42 public: 43 GtkCompositorWidget(const GtkCompositorWidgetInitData& aInitData, 44 const layers::CompositorOptions& aOptions, 45 nsWindow* aWindow /* = nullptr*/); 46 ~GtkCompositorWidget(); 47 48 // CompositorWidget Overrides 49 50 already_AddRefed<gfx::DrawTarget> StartRemoteDrawing() override; 51 void EndRemoteDrawing() override; 52 53 already_AddRefed<gfx::DrawTarget> StartRemoteDrawingInRegion( 54 const LayoutDeviceIntRegion& aInvalidRegion, 55 layers::BufferMode* aBufferMode) override; 56 void EndRemoteDrawingInRegion( 57 gfx::DrawTarget* aDrawTarget, 58 const LayoutDeviceIntRegion& aInvalidRegion) override; 59 uintptr_t GetWidgetKey() override; 60 61 LayoutDeviceIntSize GetClientSize() override; 62 63 nsIWidget* RealWidget() override; AsGTK()64 GtkCompositorWidget* AsGTK() override { return this; } AsDelegate()65 CompositorWidgetDelegate* AsDelegate() override { return this; } 66 67 EGLNativeWindowType GetEGLNativeWindow(); 68 69 LayoutDeviceIntRegion GetTransparentRegion() override; 70 71 #if defined(MOZ_X11) XWindow()72 Window XWindow() const { return mXWindow; } 73 #endif 74 #if defined(MOZ_WAYLAND) 75 void SetEGLNativeWindowSize(const LayoutDeviceIntSize& aEGLWindowSize); 76 RefPtr<mozilla::layers::NativeLayerRoot> GetNativeLayerRoot() override; 77 #endif 78 79 // PlatformCompositorWidgetDelegate Overrides 80 81 void NotifyClientSizeChanged(const LayoutDeviceIntSize& aClientSize) override; AsGtkCompositorWidget()82 GtkCompositorWidget* AsGtkCompositorWidget() override { return this; } 83 84 protected: 85 nsWindow* mWidget; 86 87 private: 88 // This field is written to on the main thread and read from on the compositor 89 // or renderer thread. During window resizing, this is subject to a (largely 90 // benign) read/write race, see bug 1665726. The DataMutex doesn't prevent the 91 // read/write race, but it does make it Not Undefined Behaviour, and also 92 // ensures we only ever use the old or new size, and not some weird synthesis 93 // of the two. 94 DataMutex<LayoutDeviceIntSize> mClientSize; 95 96 WindowSurfaceProvider mProvider; 97 98 #if defined(MOZ_X11) 99 Window mXWindow = {}; 100 #endif 101 #ifdef MOZ_WAYLAND 102 RefPtr<mozilla::layers::NativeLayerRootWayland> mNativeLayerRoot; 103 #endif 104 }; 105 106 } // namespace widget 107 } // namespace mozilla 108 109 #endif // widget_gtk_GtkCompositorWidget_h 110