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_InProcessWinCompositorWidget_h 7 #define widget_windows_InProcessWinCompositorWidget_h 8 9 #include "WinCompositorWidget.h" 10 11 class nsWindow; 12 13 namespace mozilla { 14 namespace widget { 15 16 // This is the Windows-specific implementation of CompositorWidget. For 17 // the most part it only requires an HWND, however it maintains extra state 18 // for transparent windows, as well as for synchronizing WM_SETTEXT messages 19 // with the compositor. 20 class InProcessWinCompositorWidget final 21 : public WinCompositorWidget, 22 public PlatformCompositorWidgetDelegate { 23 public: 24 InProcessWinCompositorWidget(const WinCompositorWidgetInitData& aInitData, 25 const layers::CompositorOptions& aOptions, 26 nsWindow* aWindow); 27 28 bool PreRender(WidgetRenderingContext*) override; 29 void PostRender(WidgetRenderingContext*) override; 30 already_AddRefed<gfx::DrawTarget> StartRemoteDrawing() override; 31 void EndRemoteDrawing() override; 32 bool NeedsToDeferEndRemoteDrawing() override; 33 LayoutDeviceIntSize GetClientSize() override; 34 already_AddRefed<gfx::DrawTarget> GetBackBufferDrawTarget( 35 gfx::DrawTarget* aScreenTarget, const gfx::IntRect& aRect, 36 bool* aOutIsCleared) override; 37 already_AddRefed<gfx::SourceSurface> EndBackBufferDrawing() override; 38 bool InitCompositor(layers::Compositor* aCompositor) override; AsDelegate()39 CompositorWidgetDelegate* AsDelegate() override { return this; } 40 bool IsHidden() const override; 41 42 // PlatformCompositorWidgetDelegate Overrides 43 44 void EnterPresentLock() override; 45 void LeavePresentLock() override; 46 void OnDestroyWindow() override; 47 bool OnWindowResize(const LayoutDeviceIntSize& aSize) override; 48 void OnWindowModeChange(nsSizeMode aSizeMode) override; 49 void UpdateTransparency(nsTransparencyMode aMode) override; 50 void ClearTransparentWindow() override; 51 52 bool RedrawTransparentWindow(); 53 54 // Ensure that a transparent surface exists, then return it. 55 RefPtr<gfxASurface> EnsureTransparentSurface(); 56 GetTransparentDC()57 HDC GetTransparentDC() const { return mMemoryDC; } 58 GetTransparentSurfaceLock()59 mozilla::Mutex& GetTransparentSurfaceLock() { 60 return mTransparentSurfaceLock; 61 } 62 63 bool HasGlass() const override; 64 65 void ObserveVsync(VsyncObserver* aObserver) override; 66 nsIWidget* RealWidget() override; 67 UpdateCompositorWnd(const HWND aCompositorWnd,const HWND aParentWnd)68 void UpdateCompositorWnd(const HWND aCompositorWnd, 69 const HWND aParentWnd) override {} SetRootLayerTreeID(const layers::LayersId & aRootLayerTreeId)70 void SetRootLayerTreeID(const layers::LayersId& aRootLayerTreeId) override {} 71 72 private: 73 HDC GetWindowSurface(); 74 void FreeWindowSurface(HDC dc); 75 76 void CreateTransparentSurface(const gfx::IntSize& aSize); 77 78 nsWindow* mWindow; 79 80 HWND mWnd; 81 82 gfx::CriticalSection mPresentLock; 83 84 // Transparency handling. 85 mozilla::Mutex mTransparentSurfaceLock; 86 mozilla::Atomic<nsTransparencyMode, MemoryOrdering::Relaxed> 87 mTransparencyMode; 88 RefPtr<gfxASurface> mTransparentSurface; 89 HDC mMemoryDC; 90 HDC mCompositeDC; 91 92 // Locked back buffer of BasicCompositor 93 uint8_t* mLockedBackBufferData; 94 95 bool mNotDeferEndRemoteDrawing; 96 }; 97 98 } // namespace widget 99 } // namespace mozilla 100 101 #endif // widget_windows_InProcessWinCompositorWidget_h 102