Bug 1604412 - Give CompositorWidgetChild more window info r=sotaro

CompositorWidgetChild is about to be responsible for creating,
destroying, and presenting a shared buffer that CompositorWidgetParent
will draw into. To do this, it will need the window handle,
transparency mode changes, window size changes, and window size mode
changes.

Its creation is also about to become fallible, so it needs a separate
initialization routine.

Differential Revision: https://phabricator.services.mozilla.com/D57430

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Chris Martin 2020-01-08 18:37:38 +00:00
parent f88303ae72
commit 795cf400a0
11 changed files with 64 additions and 14 deletions

View File

@ -799,6 +799,9 @@ RefPtr<CompositorSession> GPUProcessManager::CreateRemoteSession(
if (!child->SendPCompositorWidgetConstructor(widget, initData)) {
return nullptr;
}
if (!widget->Initialize()) {
return nullptr;
}
if (!child->SendInitialize(aRootLayerTreeId)) {
return nullptr;
}

View File

@ -21,6 +21,8 @@ CompositorWidgetChild::CompositorWidgetChild(
CompositorWidgetChild::~CompositorWidgetChild() {}
bool CompositorWidgetChild::Initialize() { return true; }
mozilla::ipc::IPCResult CompositorWidgetChild::RecvObserveVsync() {
mVsyncDispatcher->SetCompositorVsyncObserver(mVsyncObserver);
return IPC_OK();

View File

@ -21,6 +21,8 @@ class CompositorWidgetChild final : public PCompositorWidgetChild,
const CompositorWidgetInitData&);
~CompositorWidgetChild() override;
bool Initialize();
mozilla::ipc::IPCResult RecvObserveVsync() override;
mozilla::ipc::IPCResult RecvUnobserveVsync() override;

View File

@ -21,15 +21,19 @@ CompositorWidgetChild::CompositorWidgetChild(
: mVsyncDispatcher(aVsyncDispatcher),
mVsyncObserver(aVsyncObserver),
mCompositorWnd(nullptr),
mParentWnd(reinterpret_cast<HWND>(
aInitData.get_WinCompositorWidgetInitData().hWnd())) {
mWnd(reinterpret_cast<HWND>(
aInitData.get_WinCompositorWidgetInitData().hWnd())),
mTransparencyMode(
aInitData.get_WinCompositorWidgetInitData().transparencyMode()) {
MOZ_ASSERT(XRE_IsParentProcess());
MOZ_ASSERT(!gfxPlatform::IsHeadless());
MOZ_ASSERT(mParentWnd && ::IsWindow(mParentWnd));
MOZ_ASSERT(mWnd && ::IsWindow(mWnd));
}
CompositorWidgetChild::~CompositorWidgetChild() {}
bool CompositorWidgetChild::Initialize() { return true; }
void CompositorWidgetChild::EnterPresentLock() {
Unused << SendEnterPresentLock();
}
@ -40,6 +44,12 @@ void CompositorWidgetChild::LeavePresentLock() {
void CompositorWidgetChild::OnDestroyWindow() {}
bool CompositorWidgetChild::OnWindowResize(const LayoutDeviceIntSize& aSize) {
return true;
}
void CompositorWidgetChild::OnWindowModeChange(nsSizeMode aSizeMode) {}
void CompositorWidgetChild::UpdateTransparency(nsTransparencyMode aMode) {
Unused << SendUpdateTransparency(aMode);
}
@ -61,12 +71,10 @@ mozilla::ipc::IPCResult CompositorWidgetChild::RecvUnobserveVsync() {
mozilla::ipc::IPCResult CompositorWidgetChild::RecvUpdateCompositorWnd(
const WindowsHandle& aCompositorWnd, const WindowsHandle& aParentWnd,
UpdateCompositorWndResolver&& aResolve) {
MOZ_ASSERT(mParentWnd);
HWND parentWnd = reinterpret_cast<HWND>(aParentWnd);
if (mParentWnd == parentWnd) {
if (mWnd == parentWnd) {
mCompositorWnd = reinterpret_cast<HWND>(aCompositorWnd);
::SetParent(mCompositorWnd, mParentWnd);
::SetParent(mCompositorWnd, mWnd);
aResolve(true);
} else {
aResolve(false);

View File

@ -23,9 +23,13 @@ class CompositorWidgetChild final : public PCompositorWidgetChild,
const CompositorWidgetInitData& aInitData);
~CompositorWidgetChild() override;
bool Initialize();
void EnterPresentLock() override;
void LeavePresentLock() override;
void OnDestroyWindow() override;
bool OnWindowResize(const LayoutDeviceIntSize& aSize) override;
void OnWindowModeChange(nsSizeMode aSizeMode) override;
void UpdateTransparency(nsTransparencyMode aMode) override;
void ClearTransparentWindow() override;
@ -39,7 +43,9 @@ class CompositorWidgetChild final : public PCompositorWidgetChild,
RefPtr<CompositorVsyncDispatcher> mVsyncDispatcher;
RefPtr<CompositorWidgetVsyncObserver> mVsyncObserver;
HWND mCompositorWnd;
HWND mParentWnd;
HWND mWnd;
nsTransparencyMode mTransparencyMode;
};
} // namespace widget

View File

@ -73,6 +73,13 @@ void InProcessWinCompositorWidget::OnDestroyWindow() {
LeavePresentLock();
}
bool InProcessWinCompositorWidget::OnWindowResize(
const LayoutDeviceIntSize& aSize) {
return true;
}
void InProcessWinCompositorWidget::OnWindowModeChange(nsSizeMode aSizeMode) {}
bool InProcessWinCompositorWidget::PreRender(WidgetRenderingContext* aContext) {
// This can block waiting for WM_SETTEXT to finish
// Using PreRender is unnecessarily pessimistic because

View File

@ -44,6 +44,8 @@ class InProcessWinCompositorWidget final
void EnterPresentLock() override;
void LeavePresentLock() override;
void OnDestroyWindow() override;
bool OnWindowResize(const LayoutDeviceIntSize& aSize) override;
void OnWindowModeChange(nsSizeMode aSizeMode) override;
void UpdateTransparency(nsTransparencyMode aMode) override;
void ClearTransparentWindow() override;

View File

@ -7,6 +7,7 @@
include HeadlessWidgetTypes;
using mozilla::WindowsHandle from "ipc/IPCMessageUtils.h";
using nsSizeMode from "nsIWidgetListener.h";
using nsTransparencyMode from "mozilla/widget/WidgetMessageUtils.h";
namespace mozilla {
@ -17,6 +18,7 @@ struct WinCompositorWidgetInitData
WindowsHandle hWnd;
uintptr_t widgetKey;
nsTransparencyMode transparencyMode;
nsSizeMode sizeMode;
};
union CompositorWidgetInitData

View File

@ -28,6 +28,8 @@ class PlatformCompositorWidgetDelegate : public CompositorWidgetDelegate {
virtual void EnterPresentLock() = 0;
virtual void LeavePresentLock() = 0;
virtual void OnDestroyWindow() = 0;
virtual bool OnWindowResize(const LayoutDeviceIntSize& aSize) = 0;
virtual void OnWindowModeChange(nsSizeMode aSizeMode) = 0;
// Transparency handling.
virtual void UpdateTransparency(nsTransparencyMode aMode) = 0;

View File

@ -3357,8 +3357,9 @@ nsresult nsWindow::MakeFullScreen(bool aFullScreen, nsIScreen* aTargetScreen) {
taskbarInfo->PrepareFullScreenHWND(mWnd, FALSE);
}
OnSizeModeChange(mSizeMode);
if (mWidgetListener) {
mWidgetListener->SizeModeChanged(mSizeMode);
mWidgetListener->FullscreenChanged(aFullScreen);
}
@ -3771,7 +3772,7 @@ LayerManager* nsWindow::GetLayerManager(PLayerTransactionChild* aShadowManager,
WinCompositorWidgetInitData initData(
reinterpret_cast<uintptr_t>(mWnd),
reinterpret_cast<uintptr_t>(static_cast<nsIWidget*>(this)),
mTransparencyMode);
mTransparencyMode, mSizeMode);
// If we're not using the compositor, the options don't actually matter.
CompositorOptions options(false, false);
mBasicLayersSurface =
@ -6535,8 +6536,7 @@ void nsWindow::OnWindowPosChanged(WINDOWPOS* wp) {
}
#endif
if (mWidgetListener && mSizeMode != previousSizeMode)
mWidgetListener->SizeModeChanged(mSizeMode);
if (mSizeMode != previousSizeMode) OnSizeModeChange(mSizeMode);
// If window was restored, window activation was bypassed during the
// SetSizeMode call originating from OnWindowPosChanging to avoid saving
@ -6674,7 +6674,7 @@ void nsWindow::OnWindowPosChanging(LPWINDOWPOS& info) {
else
sizeMode = nsSizeMode_Normal;
if (mWidgetListener) mWidgetListener->SizeModeChanged(sizeMode);
OnSizeModeChange(sizeMode);
UpdateNonClientMargins(sizeMode, false);
}
@ -7247,6 +7247,11 @@ void nsWindow::OnDestroy() {
// Send a resize message to the listener
bool nsWindow::OnResize(const LayoutDeviceIntSize& aSize) {
if (mCompositorWidgetDelegate &&
!mCompositorWidgetDelegate->OnWindowResize(aSize)) {
return false;
}
bool result = false;
if (mWidgetListener) {
result = mWidgetListener->WindowResized(this, aSize.width, aSize.height);
@ -7262,6 +7267,16 @@ bool nsWindow::OnResize(const LayoutDeviceIntSize& aSize) {
return result;
}
void nsWindow::OnSizeModeChange(nsSizeMode aSizeMode) {
if (mCompositorWidgetDelegate) {
mCompositorWidgetDelegate->OnWindowModeChange(aSizeMode);
}
if (mWidgetListener) {
mWidgetListener->SizeModeChanged(aSizeMode);
}
}
bool nsWindow::OnHotKey(WPARAM wParam, LPARAM lParam) { return true; }
// Can be overriden. Controls auto-erase of background.
@ -8475,7 +8490,7 @@ void nsWindow::GetCompositorWidgetInitData(
*aInitData = WinCompositorWidgetInitData(
reinterpret_cast<uintptr_t>(mWnd),
reinterpret_cast<uintptr_t>(static_cast<nsIWidget*>(this)),
mTransparencyMode);
mTransparencyMode, mSizeMode);
}
bool nsWindow::SynchronouslyRepaintOnResize() {

View File

@ -438,6 +438,7 @@ class nsWindow final : public nsWindowBase {
*/
virtual void OnDestroy() override;
bool OnResize(const LayoutDeviceIntSize& aSize);
void OnSizeModeChange(nsSizeMode aSizeMode);
bool OnGesture(WPARAM wParam, LPARAM lParam);
bool OnTouch(WPARAM wParam, LPARAM lParam);
bool OnHotKey(WPARAM wParam, LPARAM lParam);