b=374262, fix win32 chromeless window opacity, r=stuart
authorvladimir@pobox.com
Mon, 02 Apr 2007 11:53:43 -0700
changeset 268 b1c0a468cbc80b6e34aaac5ba2c90ff6eef8e160
parent 267 ff68b34b6a9d25e0a4bb9989cf346505598f1c93
child 269 c09efaa121af4408b89f06ebc7b77f1919ad0c90
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstuart
bugs374262
milestone1.9a4pre
b=374262, fix win32 chromeless window opacity, r=stuart
widget/src/windows/nsWindow.cpp
widget/src/windows/nsWindow.h
--- a/widget/src/windows/nsWindow.cpp
+++ b/widget/src/windows/nsWindow.cpp
@@ -794,16 +794,19 @@ nsWindow::nsWindow() : nsBaseWidget()
   mPreferredWidth     = 0;
   mPreferredHeight    = 0;
   mFont               = nsnull;
   mIsVisible          = PR_FALSE;
   mHas3DBorder        = PR_FALSE;
 #ifdef MOZ_XUL
   mIsTranslucent      = PR_FALSE;
   mIsTopTranslucent   = PR_FALSE;
+#ifdef MOZ_CAIRO_GFX
+  mTranslucentSurface = nsnull;
+#endif
   mMemoryDC           = NULL;
   mMemoryBitmap       = NULL;
   mMemoryBits         = NULL;
   mAlphaMask          = nsnull;
 #endif
   mWindowType         = eWindowType_child;
   mBorderStyle        = eBorderStyle_default;
   mUnicodeWidget      = PR_TRUE;
@@ -5912,17 +5915,27 @@ PRBool nsWindow::OnPaint(HDC aDC)
       debug_DumpPaintEvent(stdout,
                            this,
                            &event,
                            nsCAutoString("noname"),
                            (PRInt32) mWnd);
 #endif // NS_DEBUG
 
 #ifdef MOZ_CAIRO_GFX
+#ifdef MOZ_XUL
+      nsRefPtr<gfxASurface> targetSurface;
+      if (mIsTranslucent) {
+        targetSurface = mTranslucentSurface;
+      } else {
+        targetSurface = new gfxWindowsSurface(hDC);
+      }
+#else
       nsRefPtr<gfxASurface> targetSurface = new gfxWindowsSurface(hDC);
+#endif
+
       nsRefPtr<gfxContext> thebesContext = new gfxContext(targetSurface);
 
 #ifdef MOZ_XUL
       if (mIsTranslucent) {
         // If we're rendering with translucency, we're going to be
         // rendering the whole window; make sure we clear it first
         thebesContext->SetOperator(gfxContext::OPERATOR_CLEAR);
         thebesContext->Paint();
@@ -8176,17 +8189,21 @@ gfxASurface *nsWindow::GetThebesSurface(
 }
 #endif
 
 void nsWindow::ResizeTranslucentWindow(PRInt32 aNewWidth, PRInt32 aNewHeight, PRBool force)
 {
   if (!force && aNewWidth == mBounds.width && aNewHeight == mBounds.height)
     return;
 
-#ifndef MOZ_CAIRO_GFX
+#ifdef MOZ_CAIRO_GFX
+  mTranslucentSurface = new gfxWindowsSurface(gfxIntSize(aNewWidth, aNewHeight), gfxASurface::ImageFormatARGB32);
+  mMemoryDC = mTranslucentSurface->GetDC();
+  mMemoryBitmap = NULL;
+#else
   // resize the alpha mask
   PRUint8* pBits;
 
   if (aNewWidth > 0 && aNewHeight > 0)
   {
     pBits = new PRUint8 [aNewWidth * aNewHeight];
 
     if (pBits && mAlphaMask)
@@ -8231,30 +8248,24 @@ void nsWindow::ResizeTranslucentWindow(P
         pDest += aNewWidth;
       }
     }
   } else
     pBits = nsnull;
 
   delete [] mAlphaMask;
   mAlphaMask = pBits;
-#endif
 
   if (!mMemoryDC)
     mMemoryDC = ::CreateCompatibleDC(NULL);
 
-  // Always use at least 24-bit (32 with cairo) bitmaps regardless of the device context.
+  // Always use at least 24-bit bitmaps regardless of the device context.
   int depth = ::GetDeviceCaps(mMemoryDC, BITSPIXEL);
-#ifdef MOZ_CAIRO_GFX
-  if (depth < 32)
-    depth = 32;
-#else
   if (depth < 24)
     depth = 24;
-#endif
 
   // resize the memory bitmap
   BITMAPINFO bi = { 0 };
   bi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
   bi.bmiHeader.biWidth = aNewWidth;
   bi.bmiHeader.biHeight = -aNewHeight;
   bi.bmiHeader.biPlanes = 1;
   bi.bmiHeader.biBitCount = depth;
@@ -8262,16 +8273,17 @@ void nsWindow::ResizeTranslucentWindow(P
 
   mMemoryBitmap = ::CreateDIBSection(mMemoryDC, &bi, DIB_RGB_COLORS, (void**)&mMemoryBits, NULL, 0);
 
   if (mMemoryBitmap)
   {
     HGDIOBJ oldBitmap = ::SelectObject(mMemoryDC, mMemoryBitmap);
     ::DeleteObject(oldBitmap);
   }
+#endif
 }
 
 NS_IMETHODIMP nsWindow::GetWindowTranslucency(PRBool& aTranslucent)
 {
   aTranslucent = GetTopLevelWindow()->GetWindowTranslucencyInner();
 
   return NS_OK;
 }
@@ -8351,20 +8363,24 @@ nsresult nsWindow::SetWindowTranslucency
   return rv;
 }
 
 nsresult nsWindow::SetupTranslucentWindowMemoryBitmap(PRBool aTranslucent)
 {
   if (aTranslucent) {
     ResizeTranslucentWindow(mBounds.width, mBounds.height, PR_TRUE);
   } else {
+#ifdef MOZ_CAIRO_GFX
+    mTranslucentSurface = nsnull;
+#else
     if (mMemoryDC)
       ::DeleteDC(mMemoryDC);
     if (mMemoryBitmap)
       ::DeleteObject(mMemoryBitmap);
+#endif
 
     mMemoryDC = NULL;
     mMemoryBitmap = NULL;
   }
 
   return NS_OK;
 }
 
@@ -8406,30 +8422,28 @@ nsresult nsWindow::UpdateTranslucentWind
   if (mBounds.IsEmpty())
     return NS_OK;
 
   nsresult rv = NS_ERROR_FAILURE;
 
   ::GdiFlush();
 
   HDC hMemoryDC;
-#ifndef MOZ_CAIRO_GFX
-  HBITMAP hAlphaBitmap;
-#endif
   PRBool needConversion;
 
 #ifdef MOZ_CAIRO_GFX
 
   hMemoryDC = mMemoryDC;
   needConversion = PR_FALSE;
 
   rv = NS_OK;
 
 #else
 
+  HBITMAP hAlphaBitmap;
   int depth = ::GetDeviceCaps(mMemoryDC, BITSPIXEL);
   if (depth < 24)
     depth = 24;
 
   needConversion = (depth == 24);
 
   if (needConversion)
   {
--- a/widget/src/windows/nsWindow.h
+++ b/widget/src/windows/nsWindow.h
@@ -65,16 +65,20 @@ class nsIFile;
 
 class imgIContainer;
 
 #ifdef ACCESSIBILITY
 #include "OLEACC.H"
 #include "nsIAccessible.h"
 #endif
 
+#ifdef MOZ_CAIRO_GFX
+#include "gfxWindowsSurface.h"
+#endif
+
 #define IME_MAX_CHAR_POS       64
 
 #define NSRGB_2_COLOREF(color) \
             RGB(NS_GET_R(color),NS_GET_G(color),NS_GET_B(color))
 #define COLOREF_2_NSRGB(color) \
             NS_RGB(GetRValue(color), GetGValue(color), GetBValue(color))
 
 /*
@@ -401,16 +405,19 @@ protected:
 #if 0
   HPALETTE      mPalette;
 #endif
   WNDPROC       mPrevWndProc;
   HBRUSH        mBrush;
 
 #ifdef MOZ_XUL
   // use layered windows to support full 256 level alpha translucency
+#ifdef MOZ_CAIRO_GFX
+  nsRefPtr<gfxWindowsSurface> mTranslucentSurface;
+#endif
   HDC           mMemoryDC;
   HBITMAP       mMemoryBitmap;
   PRUint8*      mMemoryBits;
   PRUint8*      mAlphaMask;
   PRPackedBool  mIsTranslucent;
   PRPackedBool  mIsTopTranslucent;     // Topmost window itself or any of it's child windows has tranlucency enabled
 #endif
   PRPackedBool  mIsTopWidgetWindow;