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_windows_CompositorWidgetParent_h 7 #define widget_windows_CompositorWidgetParent_h 8 9 #include "CompositorWidget.h" 10 #include "gfxASurface.h" 11 #include "mozilla/gfx/CriticalSection.h" 12 #include "mozilla/gfx/Point.h" 13 #include "mozilla/Mutex.h" 14 #include "nsIWidget.h" 15 16 class nsWindow; 17 18 namespace mozilla { 19 namespace widget { 20 21 class PlatformCompositorWidgetDelegate : public CompositorWidgetDelegate { 22 public: 23 // Callbacks for nsWindow. 24 virtual void EnterPresentLock() = 0; 25 virtual void LeavePresentLock() = 0; 26 virtual void OnDestroyWindow() = 0; 27 28 // Transparency handling. 29 virtual void UpdateTransparency(nsTransparencyMode aMode) = 0; 30 virtual void ClearTransparentWindow() = 0; 31 32 // If in-process and using software rendering, return the backing transparent 33 // DC. 34 virtual HDC GetTransparentDC() const = 0; 35 36 // CompositorWidgetDelegate Overrides 37 AsPlatformSpecificDelegate()38 PlatformCompositorWidgetDelegate* AsPlatformSpecificDelegate() override { 39 return this; 40 } 41 }; 42 43 class WinCompositorWidgetInitData; 44 45 // This is the Windows-specific implementation of CompositorWidget. For 46 // the most part it only requires an HWND, however it maintains extra state 47 // for transparent windows, as well as for synchronizing WM_SETTEXT messages 48 // with the compositor. 49 class WinCompositorWidget : public CompositorWidget, 50 public PlatformCompositorWidgetDelegate { 51 public: 52 WinCompositorWidget(const WinCompositorWidgetInitData& aInitData, 53 const layers::CompositorOptions& aOptions); 54 55 // CompositorWidget Overrides 56 57 bool PreRender(WidgetRenderingContext*) override; 58 void PostRender(WidgetRenderingContext*) override; 59 already_AddRefed<gfx::DrawTarget> StartRemoteDrawing() override; 60 void EndRemoteDrawing() override; 61 bool NeedsToDeferEndRemoteDrawing() override; 62 LayoutDeviceIntSize GetClientSize() override; 63 already_AddRefed<gfx::DrawTarget> GetBackBufferDrawTarget( 64 gfx::DrawTarget* aScreenTarget, const LayoutDeviceIntRect& aRect, 65 const LayoutDeviceIntRect& aClearRect) override; 66 already_AddRefed<gfx::SourceSurface> EndBackBufferDrawing() override; 67 bool InitCompositor(layers::Compositor* aCompositor) override; 68 uintptr_t GetWidgetKey() override; AsWindows()69 WinCompositorWidget* AsWindows() override { return this; } AsDelegate()70 CompositorWidgetDelegate* AsDelegate() override { return this; } 71 bool IsHidden() const override; 72 73 // PlatformCompositorWidgetDelegate Overrides 74 75 void EnterPresentLock() override; 76 void LeavePresentLock() override; 77 void OnDestroyWindow() override; 78 void UpdateTransparency(nsTransparencyMode aMode) override; 79 void ClearTransparentWindow() override; 80 81 bool RedrawTransparentWindow(); 82 83 // Ensure that a transparent surface exists, then return it. 84 RefPtr<gfxASurface> EnsureTransparentSurface(); 85 GetTransparentDC()86 HDC GetTransparentDC() const override { return mMemoryDC; } GetHwnd()87 HWND GetHwnd() const { return mWnd; } 88 GetTransparentSurfaceLock()89 mozilla::Mutex& GetTransparentSurfaceLock() { 90 return mTransparentSurfaceLock; 91 } 92 93 private: 94 HDC GetWindowSurface(); 95 void FreeWindowSurface(HDC dc); 96 97 void CreateTransparentSurface(const gfx::IntSize& aSize); 98 99 private: 100 uintptr_t mWidgetKey; 101 HWND mWnd; 102 gfx::CriticalSection mPresentLock; 103 104 // Transparency handling. 105 mozilla::Mutex mTransparentSurfaceLock; 106 nsTransparencyMode mTransparencyMode; 107 RefPtr<gfxASurface> mTransparentSurface; 108 HDC mMemoryDC; 109 HDC mCompositeDC; 110 111 // Locked back buffer of BasicCompositor 112 uint8_t* mLockedBackBufferData; 113 114 bool mNotDeferEndRemoteDrawing; 115 }; 116 117 } // namespace widget 118 } // namespace mozilla 119 120 #endif // widget_windows_CompositorWidgetParent_h 121