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 #include "CompositorWidgetChild.h"
7 #include "mozilla/Unused.h"
8 #include "mozilla/gfx/Logging.h"
9 #include "mozilla/widget/CompositorWidgetVsyncObserver.h"
10 #include "mozilla/widget/PlatformWidgetTypes.h"
11 #include "nsBaseWidget.h"
12 #include "VsyncDispatcher.h"
13 #include "gfxPlatform.h"
14 #include "RemoteBackbuffer.h"
19 CompositorWidgetChild::CompositorWidgetChild(
20 RefPtr
<CompositorVsyncDispatcher
> aVsyncDispatcher
,
21 RefPtr
<CompositorWidgetVsyncObserver
> aVsyncObserver
,
22 const CompositorWidgetInitData
& aInitData
)
23 : mVsyncDispatcher(aVsyncDispatcher
),
24 mVsyncObserver(aVsyncObserver
),
25 mCompositorWnd(nullptr),
26 mWnd(reinterpret_cast<HWND
>(
27 aInitData
.get_WinCompositorWidgetInitData().hWnd())),
29 aInitData
.get_WinCompositorWidgetInitData().transparencyMode()),
30 mRemoteBackbufferProvider() {
31 MOZ_ASSERT(XRE_IsParentProcess());
32 MOZ_ASSERT(!gfxPlatform::IsHeadless());
33 MOZ_ASSERT(mWnd
&& ::IsWindow(mWnd
));
36 CompositorWidgetChild::~CompositorWidgetChild() {}
38 bool CompositorWidgetChild::Initialize() {
39 mRemoteBackbufferProvider
= std::make_unique
<remote_backbuffer::Provider
>();
40 if (!mRemoteBackbufferProvider
->Initialize(mWnd
, OtherPid(),
45 auto maybeRemoteHandles
= mRemoteBackbufferProvider
->CreateRemoteHandles();
46 if (!maybeRemoteHandles
) {
50 Unused
<< SendInitialize(*maybeRemoteHandles
);
55 void CompositorWidgetChild::EnterPresentLock() {
56 Unused
<< SendEnterPresentLock();
59 void CompositorWidgetChild::LeavePresentLock() {
60 Unused
<< SendLeavePresentLock();
63 void CompositorWidgetChild::OnDestroyWindow() {}
65 bool CompositorWidgetChild::OnWindowResize(const LayoutDeviceIntSize
& aSize
) {
69 void CompositorWidgetChild::OnWindowModeChange(nsSizeMode aSizeMode
) {}
71 void CompositorWidgetChild::UpdateTransparency(TransparencyMode aMode
) {
72 mTransparencyMode
= aMode
;
73 mRemoteBackbufferProvider
->UpdateTransparencyMode(aMode
);
74 Unused
<< SendUpdateTransparency(aMode
);
77 void CompositorWidgetChild::NotifyVisibilityUpdated(nsSizeMode aSizeMode
,
78 bool aIsFullyOccluded
) {
79 Unused
<< SendNotifyVisibilityUpdated(aSizeMode
, aIsFullyOccluded
);
82 void CompositorWidgetChild::ClearTransparentWindow() {
83 Unused
<< SendClearTransparentWindow();
86 mozilla::ipc::IPCResult
CompositorWidgetChild::RecvObserveVsync() {
87 mVsyncDispatcher
->SetCompositorVsyncObserver(mVsyncObserver
);
91 mozilla::ipc::IPCResult
CompositorWidgetChild::RecvUnobserveVsync() {
92 mVsyncDispatcher
->SetCompositorVsyncObserver(nullptr);
96 mozilla::ipc::IPCResult
CompositorWidgetChild::RecvUpdateCompositorWnd(
97 const WindowsHandle
& aCompositorWnd
, const WindowsHandle
& aParentWnd
,
98 UpdateCompositorWndResolver
&& aResolve
) {
99 HWND parentWnd
= reinterpret_cast<HWND
>(aParentWnd
);
100 if (mWnd
== parentWnd
) {
101 mCompositorWnd
= reinterpret_cast<HWND
>(aCompositorWnd
);
102 ::SetParent(mCompositorWnd
, mWnd
);
106 gfxCriticalNote
<< "Parent winow does not match";
107 MOZ_ASSERT_UNREACHABLE("unexpected to happen");
113 } // namespace widget
114 } // namespace mozilla