From 71f949fbcc3523a2d6f906ff9eb61aa87abcc88e Mon Sep 17 00:00:00 2001 From: Nicholas Cameron Date: Mon, 9 Dec 2013 09:47:57 +1300 Subject: [PATCH] Bug 946532. Fix crash on startup with basic compositor and d2d. r= --- widget/windows/nsWindow.cpp | 42 ++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index ce319a62764..11f8bd38a81 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -3514,19 +3514,36 @@ mozilla::TemporaryRef 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; - } + nsRefPtr surf; - uint32_t flags = (mTransparencyMode == eTransparencyOpaque) ? 0 : - gfxWindowsSurface::FLAG_IS_TRANSPARENT; - nsRefPtr surf = new gfxWindowsSurface(dc, flags); + 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; } @@ -3539,9 +3556,14 @@ nsWindow::StartRemoteDrawing() 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; }