Skip to content

Commit

Permalink
Bug 1298829. Move non-operator OVER handling to callback drawables. r…
Browse files Browse the repository at this point in the history
…=bas

This cleans up the code and makes us use an extra surface less.
  • Loading branch information
jrmuizel committed Sep 13, 2016
1 parent 3423a0b commit 05a47f9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 36 deletions.
3 changes: 2 additions & 1 deletion gfx/thebes/gfxDrawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
36 changes: 1 addition & 35 deletions layout/base/nsLayoutUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6702,30 +6702,7 @@ DrawImageInternal(gfxContext& aContext,

RefPtr<gfxContext> 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<DrawTarget> 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<SVGImageContext> svgContext = ToMaybe(aSVGContext);
if (!svgContext) {
Expand All @@ -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<SourceSurface> 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;
Expand Down

0 comments on commit 05a47f9

Please sign in to comment.