Allow creating WinCompositorWidgetProxy without an nsWindow. (bug 1281998 part 1, r=jimm)
authorDavid Anderson <danderson@mozilla.com>
Fri, 01 Jul 2016 01:15:15 -0700
changeset 383182 456f9b45d6d6529974864253973a2fcf1be41cdd
parent 383181 7c72118d085a5cd547f83371435aad8fc7a96335
child 383183 0cbb330c02c75657c3f4f9265d705217bb005c5b
push id21963
push userdmitchell@mozilla.com
push dateFri, 01 Jul 2016 19:54:18 +0000
reviewersjimm
bugs1281998
milestone50.0a1
Allow creating WinCompositorWidgetProxy without an nsWindow. (bug 1281998 part 1, r=jimm)
widget/windows/WinCompositorWidgetProxy.cpp
widget/windows/WinCompositorWidgetProxy.h
widget/windows/nsWindow.cpp
--- a/widget/windows/WinCompositorWidgetProxy.cpp
+++ b/widget/windows/WinCompositorWidgetProxy.cpp
@@ -8,27 +8,28 @@
 #include "VsyncDispatcher.h"
 #include "mozilla/gfx/Point.h"
 
 namespace mozilla {
 namespace widget {
 
 using namespace mozilla::gfx;
 
-WinCompositorWidgetProxy::WinCompositorWidgetProxy(nsWindow* aWindow)
+WinCompositorWidgetProxy::WinCompositorWidgetProxy(HWND aWnd,
+                                                   uintptr_t aWidgetKey,
+                                                   nsTransparencyMode aMode,
+                                                   nsWindow* aWindow)
  : mWindow(aWindow),
-   mWidgetKey(reinterpret_cast<uintptr_t>(aWindow)),
-   mWnd(reinterpret_cast<HWND>(aWindow->GetNativeData(NS_NATIVE_WINDOW))),
-   mTransparencyMode(aWindow->GetTransparencyMode()),
+   mWidgetKey(aWidgetKey),
+   mWnd(aWnd),
+   mTransparencyMode(aMode),
    mMemoryDC(nullptr),
    mCompositeDC(nullptr),
    mLockedBackBufferData(nullptr)
 {
-  MOZ_ASSERT(aWindow);
-  MOZ_ASSERT(!aWindow->Destroyed());
   MOZ_ASSERT(mWnd && ::IsWindow(mWnd));
 }
 
 void
 WinCompositorWidgetProxy::OnDestroyWindow()
 {
   mTransparentSurface = nullptr;
   mMemoryDC = nullptr;
@@ -49,16 +50,17 @@ void
 WinCompositorWidgetProxy::PostRender(layers::LayerManagerComposite* aManager)
 {
   mPresentLock.Leave();
 }
 
 nsIWidget*
 WinCompositorWidgetProxy::RealWidget()
 {
+  MOZ_ASSERT(mWindow);
   return mWindow;
 }
 
 LayoutDeviceIntSize
 WinCompositorWidgetProxy::GetClientSize()
 {
   RECT r;
   if (!::GetClientRect(mWnd, &r)) {
--- a/widget/windows/WinCompositorWidgetProxy.h
+++ b/widget/windows/WinCompositorWidgetProxy.h
@@ -16,17 +16,20 @@ namespace widget {
  
 // This is the Windows-specific implementation of CompositorWidgetProxy. For
 // the most part it only requires an HWND, however it maintains extra state
 // for transparent windows, as well as for synchronizing WM_SETTEXT messages
 // with the compositor.
 class WinCompositorWidgetProxy : public CompositorWidgetProxy
 {
 public:
-  WinCompositorWidgetProxy(nsWindow* aWindow);
+  WinCompositorWidgetProxy(HWND aWnd,
+                           uintptr_t aWidgetKey,
+                           nsTransparencyMode aMode,
+                           nsWindow* aWindow = nullptr);
 
   bool PreRender(layers::LayerManagerComposite*) override;
   void PostRender(layers::LayerManagerComposite*) override;
   already_AddRefed<gfx::DrawTarget> StartRemoteDrawing() override;
   void EndRemoteDrawing() override;
   LayoutDeviceIntSize GetClientSize() override;
   already_AddRefed<gfx::DrawTarget> GetBackBufferDrawTarget(gfx::DrawTarget* aScreenTarget,
                                                             const LayoutDeviceIntRect& aRect,
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -3616,17 +3616,17 @@ nsWindow::GetLayerManager(PLayerTransact
   }
 
   if (!mLayerManager) {
     MOZ_ASSERT(!mCompositorSession && !mCompositorBridgeChild);
 
     // Ensure we have a widget proxy even if we're not using the compositor,
     // since that's where we handle transparent windows.
     if (!mCompositorWidgetProxy) {
-      mCompositorWidgetProxy = new WinCompositorWidgetProxy(this);
+      mCompositorWidgetProxy = NewCompositorWidgetProxy();
     }
 
     mLayerManager = CreateBasicLayerManager();
   }
 
   NS_ASSERTION(mLayerManager, "Couldn't provide a valid layer manager.");
 
   return mLayerManager;
@@ -3682,17 +3682,21 @@ nsWindow::OnDefaultButtonLoaded(const La
     return NS_ERROR_FAILURE;
   }
   return NS_OK;
 }
 
 mozilla::widget::CompositorWidgetProxy*
 nsWindow::NewCompositorWidgetProxy()
 {
-  return new WinCompositorWidgetProxy(this);
+  return new WinCompositorWidgetProxy(
+    mWnd,
+    reinterpret_cast<uintptr_t>(this),
+    mTransparencyMode,
+    this);
 }
 
 mozilla::widget::WinCompositorWidgetProxy*
 nsWindow::GetCompositorWidgetProxy()
 {
   return mCompositorWidgetProxy ? mCompositorWidgetProxy->AsWindowsProxy() : nullptr;
 }