Bug 946532. Setup translucent window drawing properly with OMTC. r=dvander, mattwoodrow
authorNicholas Cameron <ncameron@mozilla.com>
Mon, 09 Dec 2013 17:44:57 +1300
changeset 159471 396ef872cb8be37b6501e27b478d8b6116c72014
parent 159470 7713c80c1028137688900d06320e2c4885654186
child 159472 5d7adaa5e3e9c512d5f23144494d334ce0bd4427
child 159540 7e19e0662879c5a8c1b40a310b7dbf597bd80fe6
push id37316
push userncameron@mozilla.com
push dateMon, 09 Dec 2013 04:45:16 +0000
treeherdermozilla-inbound@396ef872cb8b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdvander, mattwoodrow
bugs946532
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 946532. Setup translucent window drawing properly with OMTC. r=dvander, mattwoodrow
widget/windows/nsWindow.cpp
widget/windows/nsWindow.h
widget/windows/nsWindowGfx.cpp
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -3508,44 +3508,66 @@ nsWindow::OverrideSystemMouseScrollSpeed
   }
   return NS_OK;
 }
 
 mozilla::TemporaryRef<mozilla::gfx::DrawTarget>
 nsWindow::StartRemoteDrawing()
 {
   MOZ_ASSERT(!mCompositeDC);
+  NS_ASSERTION(IsRenderMode(gfxWindowsPlatform::RENDER_DIRECT2D) ||
+               IsRenderMode(gfxWindowsPlatform::RENDER_GDI),
+               "Unexpected render mode for remote drawing");
 
   HDC dc = (HDC)GetNativeData(NS_NATIVE_GRAPHIC);
-  if (!dc) {
-    return nullptr;
-  }
-
-  uint32_t flags = (mTransparencyMode == eTransparencyOpaque) ? 0 :
-      gfxWindowsSurface::FLAG_IS_TRANSPARENT;
-  nsRefPtr<gfxASurface> surf = new gfxWindowsSurface(dc, flags);
+  nsRefPtr<gfxASurface> surf;
+
+  if (mTransparencyMode == eTransparencyTransparent) {
+    if (!mTransparentSurface) {
+      SetupTranslucentWindowMemoryBitmap(mTransparencyMode);
+    }
+    if (mTransparentSurface) {
+      surf = mTransparentSurface;
+    }
+  } 
+  
+  if (!surf) {
+    if (!dc) {
+      return nullptr;
+    }
+    uint32_t flags = (mTransparencyMode == eTransparencyOpaque) ? 0 :
+        gfxWindowsSurface::FLAG_IS_TRANSPARENT;
+    surf = new gfxWindowsSurface(dc, flags);
+  }
 
   mozilla::gfx::IntSize size(surf->GetSize().width, surf->GetSize().height);
   if (size.width <= 0 || size.height <= 0) {
-    FreeNativeData(dc, NS_NATIVE_GRAPHIC);
+    if (dc) {
+      FreeNativeData(dc, NS_NATIVE_GRAPHIC);
+    }
     return nullptr;
   }
 
   MOZ_ASSERT(!mCompositeDC);
   mCompositeDC = dc;
 
   return mozilla::gfx::Factory::CreateDrawTargetForCairoSurface(surf->CairoSurface(), size);
 }
 
 void
 nsWindow::EndRemoteDrawing()
 {
-  MOZ_ASSERT(mCompositeDC);
-  UpdateTranslucentWindow();
-  FreeNativeData(mCompositeDC, NS_NATIVE_GRAPHIC);
+  if (mTransparencyMode == eTransparencyTransparent) {
+    MOZ_ASSERT(IsRenderMode(gfxWindowsPlatform::RENDER_DIRECT2D)
+               || mTransparentSurface);
+    UpdateTranslucentWindow();
+  }
+  if (mCompositeDC) {
+    FreeNativeData(mCompositeDC, NS_NATIVE_GRAPHIC);
+  }
   mCompositeDC = nullptr;
 }
 
 /**************************************************************
  **************************************************************
  **
  ** BLOCK: Moz Events
  **
--- a/widget/windows/nsWindow.h
+++ b/widget/windows/nsWindow.h
@@ -13,16 +13,17 @@
 #include "nsAutoPtr.h"
 #include "nsBaseWidget.h"
 #include "nsWindowBase.h"
 #include "nsdefs.h"
 #include "nsIdleService.h"
 #include "nsToolkit.h"
 #include "nsString.h"
 #include "nsTArray.h"
+#include "gfxWindowsPlatform.h"
 #include "gfxWindowsSurface.h"
 #include "nsWindowDbg.h"
 #include "cairo.h"
 #include "nsITimer.h"
 #include "nsRegion.h"
 #include "mozilla/EventForwards.h"
 #include "mozilla/MouseEvents.h"
 #include "mozilla/TimeStamp.h"
@@ -431,16 +432,17 @@ protected:
   static bool             IsTopLevelMouseExit(HWND aWnd);
   nsresult                SetWindowClipRegion(const nsTArray<nsIntRect>& aRects,
                                               bool aIntersectWithExisting);
   nsIntRegion             GetRegionToPaint(bool aForceFullRepaint, 
                                            PAINTSTRUCT ps, HDC aDC);
   static void             ActivateOtherWindowHelper(HWND aWnd);
   void                    ClearCachedResources();
   nsIWidgetListener*      GetPaintListener();
+  static bool             IsRenderMode(gfxWindowsPlatform::RenderMode aMode);
 
 protected:
   nsCOMPtr<nsIWidget>   mParent;
   nsIntSize             mLastSize;
   nsIntPoint            mLastPoint;
   HWND                  mWnd;
   WNDPROC               mPrevWndProc;
   HBRUSH                mBrush;
--- a/widget/windows/nsWindowGfx.cpp
+++ b/widget/windows/nsWindowGfx.cpp
@@ -95,18 +95,18 @@ static IconMetrics sIconMetrics[] = {
  **
  ** BLOCK: nsWindowGfx impl.
  **
  ** Misc. graphics related utilities.
  **
  **************************************************************
  **************************************************************/
 
-static bool
-IsRenderMode(gfxWindowsPlatform::RenderMode rmode)
+/* static */ bool
+nsWindow::IsRenderMode(gfxWindowsPlatform::RenderMode rmode)
 {
   return gfxWindowsPlatform::GetPlatform()->GetRenderMode() == rmode;
 }
 
 /**************************************************************
  **************************************************************
  **
  ** BLOCK: nsWindow impl.