From 05a47f9aef8c0e62edf9b719f078f20bcad0a02a Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Tue, 13 Sep 2016 11:05:58 -0400 Subject: [PATCH] Bug 1298829. Move non-operator OVER handling to callback drawables. r=bas This cleans up the code and makes us use an extra surface less. --- gfx/thebes/gfxDrawable.cpp | 3 ++- layout/base/nsLayoutUtils.cpp | 36 +---------------------------------- 2 files changed, 3 insertions(+), 36 deletions(-) diff --git a/gfx/thebes/gfxDrawable.cpp b/gfx/thebes/gfxDrawable.cpp index 7da1fbb8ce83e..8e8e5d7880ea2 100644 --- a/gfx/thebes/gfxDrawable.cpp +++ b/gfx/thebes/gfxDrawable.cpp @@ -159,7 +159,8 @@ gfxCallbackDrawable::Draw(gfxContext* aContext, gfxFloat aOpacity, const gfxMatrix& aTransform) { - if ((IsRepeatingExtendMode(aExtendMode) || aOpacity != 1.0) && !mSurfaceDrawable) { + if ((IsRepeatingExtendMode(aExtendMode) || aOpacity != 1.0 || aContext->CurrentOp() != CompositionOp::OP_OVER) && + !mSurfaceDrawable) { mSurfaceDrawable = MakeSurfaceDrawable(aSamplingFilter); } diff --git a/layout/base/nsLayoutUtils.cpp b/layout/base/nsLayoutUtils.cpp index 86de31b0ed93a..9fa201e4f54c2 100644 --- a/layout/base/nsLayoutUtils.cpp +++ b/layout/base/nsLayoutUtils.cpp @@ -6702,30 +6702,7 @@ DrawImageInternal(gfxContext& aContext, RefPtr destCtx = &aContext; - IntRect tmpDTRect; - - if (destCtx->CurrentOp() == CompositionOp::OP_OVER) { - destCtx->SetMatrix(params.imageSpaceToDeviceSpace); - } else { - // We need a temporary DrawTarget to composite correctly - Rect imageRect = ToRect(params.imageSpaceToDeviceSpace.TransformBounds(params.region.Rect())); - imageRect.ToIntRect(&tmpDTRect); - - RefPtr tempDT = - destCtx->GetDrawTarget()->CreateSimilarDrawTarget(tmpDTRect.Size(), - SurfaceFormat::B8G8R8A8); - if (!tempDT || !tempDT->IsValid()) { - gfxDevCrash(LogReason::InvalidContext) << "NonOP_OVER context problem " << gfx::hexa(tempDT); - return DrawResult::TEMPORARY_ERROR; - } - tempDT->SetTransform(ToMatrix(params.imageSpaceToDeviceSpace). - PostTranslate(-tmpDTRect.TopLeft())); - destCtx = gfxContext::CreatePreservingTransformOrNull(tempDT); - if (!destCtx) { - gfxDevCrash(LogReason::InvalidContext) << "NonOP_OVER context problem " << gfx::hexa(tempDT); - return result; - } - } + destCtx->SetMatrix(params.imageSpaceToDeviceSpace); Maybe svgContext = ToMaybe(aSVGContext); if (!svgContext) { @@ -6737,17 +6714,6 @@ DrawImageInternal(gfxContext& aContext, imgIContainer::FRAME_CURRENT, aSamplingFilter, svgContext, aImageFlags); - if (!tmpDTRect.IsEmpty()) { - // Snapshot the temporary DrawTarget and composite the result - DrawTarget* dt = aContext.GetDrawTarget(); - RefPtr surf = destCtx->GetDrawTarget()->Snapshot(); - - dt->SetTransform(Matrix::Translation(-aContext.GetDeviceOffset())); - dt->DrawSurface(surf, Rect(tmpDTRect.x, tmpDTRect.y, tmpDTRect.width, tmpDTRect.height), - Rect(0, 0, tmpDTRect.width, tmpDTRect.height), - DrawSurfaceOptions(SamplingFilter::POINT), - DrawOptions(1.0f, aContext.CurrentOp())); - } } return result;