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_windows_InProcessWinCompositorWidget_h
7 #define widget_windows_InProcessWinCompositorWidget_h
9 #include "WinCompositorWidget.h"
14 namespace mozilla::widget
{
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
{
24 InProcessWinCompositorWidget(const WinCompositorWidgetInitData
& aInitData
,
25 const layers::CompositorOptions
& aOptions
,
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
;
39 CompositorWidgetDelegate
* AsDelegate() override
{ return this; }
40 bool IsHidden() const override
;
42 // PlatformCompositorWidgetDelegate Overrides
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(TransparencyMode aMode
) override
;
50 void NotifyVisibilityUpdated(nsSizeMode aSizeMode
,
51 bool aIsFullyOccluded
) override
;
52 void ClearTransparentWindow() override
;
54 bool RedrawTransparentWindow();
56 // Ensure that a transparent surface exists, then return it.
57 RefPtr
<gfxASurface
> EnsureTransparentSurface();
59 HDC
GetTransparentDC() const { return mMemoryDC
; }
61 mozilla::Mutex
& GetTransparentSurfaceLock() {
62 return mTransparentSurfaceLock
;
65 nsSizeMode
GetWindowSizeMode() const override
;
66 bool GetWindowIsFullyOccluded() const override
;
68 void ObserveVsync(VsyncObserver
* aObserver
) override
;
69 nsIWidget
* RealWidget() override
;
71 void UpdateCompositorWnd(const HWND aCompositorWnd
,
72 const HWND aParentWnd
) override
;
73 void SetRootLayerTreeID(const layers::LayersId
& aRootLayerTreeId
) override
{}
76 HDC
GetWindowSurface();
77 void FreeWindowSurface(HDC dc
);
79 void CreateTransparentSurface(const gfx::IntSize
& aSize
);
85 gfx::CriticalSection mPresentLock
;
87 // Transparency handling.
88 mozilla::Mutex mTransparentSurfaceLock MOZ_UNANNOTATED
;
89 mozilla::Atomic
<uint32_t, MemoryOrdering::Relaxed
> mTransparencyMode
;
91 bool TransparencyModeIs(TransparencyMode aMode
) const {
92 return TransparencyMode(uint32_t(mTransparencyMode
)) == aMode
;
95 // Visibility handling.
96 mozilla::Atomic
<nsSizeMode
, MemoryOrdering::Relaxed
> mSizeMode
;
97 mozilla::Atomic
<bool, MemoryOrdering::Relaxed
> mIsFullyOccluded
;
99 RefPtr
<gfxASurface
> mTransparentSurface
;
103 // Locked back buffer of BasicCompositor
104 uint8_t* mLockedBackBufferData
;
106 bool mNotDeferEndRemoteDrawing
;
109 } // namespace mozilla::widget
111 #endif // widget_windows_InProcessWinCompositorWidget_h