Merge mozilla-central to autoland on a CLOSED TREE
[gecko.git] / widget / windows / CompositorWidgetChild.cpp
blobb294efef5162311d0feec21acf13874f4e150866
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"
16 namespace mozilla {
17 namespace widget {
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())),
28 mTransparencyMode(
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(),
41 mTransparencyMode)) {
42 return false;
45 auto maybeRemoteHandles = mRemoteBackbufferProvider->CreateRemoteHandles();
46 if (!maybeRemoteHandles) {
47 return false;
50 Unused << SendInitialize(*maybeRemoteHandles);
52 return true;
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) {
66 return true;
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);
88 return IPC_OK();
91 mozilla::ipc::IPCResult CompositorWidgetChild::RecvUnobserveVsync() {
92 mVsyncDispatcher->SetCompositorVsyncObserver(nullptr);
93 return IPC_OK();
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);
103 aResolve(true);
104 } else {
105 aResolve(false);
106 gfxCriticalNote << "Parent winow does not match";
107 MOZ_ASSERT_UNREACHABLE("unexpected to happen");
110 return IPC_OK();
113 } // namespace widget
114 } // namespace mozilla