From b1c632ce7465484c2d0e9d07c02ed71cbc2047a9 Mon Sep 17 00:00:00 2001 From: Tor Arvid Lund Date: Wed, 12 Feb 2014 10:07:47 -0500 Subject: [PATCH] Bug 948765 - Simplify (and fix issue) with CanvasLayerD3D9. r=nical There seemed to be some duplication of code in the UpdateSurface method, as well as an issue with updating that caused some reftests to fail. In this patch, I remove the mSurface member variable from CanvasLayerD3D9.h, and instead call mDrawTarget->Snapshot() as needed. I also reuse the code to draw into the D3DLOCKED_RECT so that we don't duplicate that portion anymore. It seems now to be more similar to the way CanvasLayerD3D10 works. The reftests now pass. --- gfx/layers/d3d9/CanvasLayerD3D9.cpp | 85 +++++++++-------------------- gfx/layers/d3d9/CanvasLayerD3D9.h | 1 - 2 files changed, 25 insertions(+), 61 deletions(-) diff --git a/gfx/layers/d3d9/CanvasLayerD3D9.cpp b/gfx/layers/d3d9/CanvasLayerD3D9.cpp index 193243abb85..d0fe7cb867b 100644 --- a/gfx/layers/d3d9/CanvasLayerD3D9.cpp +++ b/gfx/layers/d3d9/CanvasLayerD3D9.cpp @@ -42,11 +42,10 @@ CanvasLayerD3D9::~CanvasLayerD3D9() void CanvasLayerD3D9::Initialize(const Data& aData) { - NS_ASSERTION(mSurface == nullptr, "BasicCanvasLayer::Initialize called twice!"); + NS_ASSERTION(mDrawTarget == nullptr, "BasicCanvasLayer::Initialize called twice!"); if (aData.mDrawTarget) { mDrawTarget = aData.mDrawTarget; - mSurface = mDrawTarget->Snapshot(); mNeedsYFlip = false; mDataIsPremultiplied = true; } else if (aData.mGLContext) { @@ -55,7 +54,7 @@ CanvasLayerD3D9::Initialize(const Data& aData) mDataIsPremultiplied = aData.mIsGLAlphaPremult; mNeedsYFlip = true; } else { - NS_ERROR("CanvasLayer created without mSurface, mGLContext or mDrawTarget?"); + NS_ERROR("CanvasLayer created without mGLContext or mDrawTarget?"); } mBounds.SetRect(0, 0, aData.mSize.width, aData.mSize.height); @@ -79,71 +78,37 @@ CanvasLayerD3D9::UpdateSurface() } } + RefPtr surface; + if (mGLContext) { SharedSurface* surf = mGLContext->RequestFrame(); if (!surf) return; SharedSurface_Basic* shareSurf = SharedSurface_Basic::Cast(surf); - - // WebGL reads entire surface. - LockTextureRectD3D9 textureLock(mTexture); - if (!textureLock.HasLock()) { - NS_WARNING("Failed to lock CanvasLayer texture."); - return; - } - - D3DLOCKED_RECT rect = textureLock.GetLockRect(); - - DataSourceSurface* frameData = shareSurf->GetData(); - // Scope for DrawTarget, so it's destroyed early. - { - RefPtr rectDt = Factory::CreateDrawTargetForData(BackendType::CAIRO, - (uint8_t*)rect.pBits, - frameData->GetSize(), - rect.Pitch, - SurfaceFormat::B8G8R8A8); - - Rect drawRect(0, 0, frameData->GetSize().width, frameData->GetSize().height); - rectDt->DrawSurface(frameData, drawRect, drawRect, - DrawSurfaceOptions(), DrawOptions(1.0F, CompositionOp::OP_SOURCE)); - rectDt->Flush(); - } + surface = shareSurf->GetData(); } else { - RECT r; - r.left = mBounds.x; - r.top = mBounds.y; - r.right = mBounds.XMost(); - r.bottom = mBounds.YMost(); - - LockTextureRectD3D9 textureLock(mTexture); - if (!textureLock.HasLock()) { - NS_WARNING("Failed to lock CanvasLayer texture."); - return; - } - - D3DLOCKED_RECT lockedRect = textureLock.GetLockRect(); - - RefPtr dataSourceSurf = mSurface->GetDataSurface(); - - if (dataSourceSurf->GetFormat() != SurfaceFormat::B8G8R8A8 && - dataSourceSurf->GetFormat() != SurfaceFormat::B8G8R8X8 && - dataSourceSurf->GetFormat() != SurfaceFormat::R8G8B8A8 && - dataSourceSurf->GetFormat() != SurfaceFormat::R8G8B8X8) - { - return; - } - mHasAlpha = (dataSourceSurf->GetFormat() == SurfaceFormat::B8G8R8A8 || - dataSourceSurf->GetFormat() == SurfaceFormat::R8G8B8A8); - - DataSourceSurface::MappedSurface ms; - dataSourceSurf->Map(DataSourceSurface::MapType::READ, &ms); - for (int y = 0; y < mBounds.height; y++) { - memcpy((uint8_t*)lockedRect.pBits + lockedRect.Pitch * y, - ms.mData + ms.mStride * y, - mBounds.width * 4); - } + surface = mDrawTarget->Snapshot(); } + + // WebGL reads entire surface. + LockTextureRectD3D9 textureLock(mTexture); + if (!textureLock.HasLock()) { + NS_WARNING("Failed to lock CanvasLayer texture."); + return; + } + + D3DLOCKED_RECT rect = textureLock.GetLockRect(); + RefPtr rectDt = Factory::CreateDrawTargetForData(BackendType::CAIRO, + (uint8_t*)rect.pBits, + surface->GetSize(), + rect.Pitch, + SurfaceFormat::B8G8R8A8); + + Rect drawRect(0, 0, surface->GetSize().width, surface->GetSize().height); + rectDt->DrawSurface(surface, drawRect, drawRect, + DrawSurfaceOptions(), DrawOptions(1.0F, CompositionOp::OP_SOURCE)); + rectDt->Flush(); } Layer* diff --git a/gfx/layers/d3d9/CanvasLayerD3D9.h b/gfx/layers/d3d9/CanvasLayerD3D9.h index 67ca3b8b524..931103f8b55 100644 --- a/gfx/layers/d3d9/CanvasLayerD3D9.h +++ b/gfx/layers/d3d9/CanvasLayerD3D9.h @@ -39,7 +39,6 @@ protected: void UpdateSurface(); - RefPtr mSurface; nsRefPtr mGLContext; nsRefPtr mTexture; RefPtr mDrawTarget;