diff --git a/layout/svg/nsFilterInstance.cpp b/layout/svg/nsFilterInstance.cpp index 53f9e34b2d0c..bed18301edb5 100644 --- a/layout/svg/nsFilterInstance.cpp +++ b/layout/svg/nsFilterInstance.cpp @@ -298,30 +298,18 @@ nsFilterInstance::ComputeNeededBoxes() nsresult nsFilterInstance::BuildSourcePaint(SourceInfo *aSource, - gfxASurface* aTargetSurface, DrawTarget* aTargetDT) { nsIntRect neededRect = aSource->mNeededBounds; - RefPtr offscreenDT; - nsRefPtr offscreenSurface; - nsRefPtr ctx; - if (aTargetSurface) { - offscreenSurface = gfxPlatform::GetPlatform()->CreateOffscreenSurface( - neededRect.Size().ToIntSize(), gfxContentType::COLOR_ALPHA); - if (!offscreenSurface || offscreenSurface->CairoStatus()) { - return NS_ERROR_OUT_OF_MEMORY; - } - ctx = new gfxContext(offscreenSurface); - } else { - offscreenDT = gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget( + RefPtr offscreenDT = + gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget( ToIntSize(neededRect.Size()), SurfaceFormat::B8G8R8A8); - if (!offscreenDT) { - return NS_ERROR_OUT_OF_MEMORY; - } - ctx = new gfxContext(offscreenDT); + if (!offscreenDT) { + return NS_ERROR_OUT_OF_MEMORY; } + nsRefPtr ctx = new gfxContext(offscreenDT); ctx->Translate(-neededRect.TopLeft()); nsRefPtr tmpCtx(new nsRenderingContext()); @@ -348,63 +336,46 @@ nsFilterInstance::BuildSourcePaint(SourceInfo *aSource, } gfx->Restore(); - if (offscreenSurface) { - aSource->mSourceSurface = - gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(aTargetDT, offscreenSurface); - } else { - aSource->mSourceSurface = offscreenDT->Snapshot(); - } + + aSource->mSourceSurface = offscreenDT->Snapshot(); aSource->mSurfaceRect = ToIntRect(neededRect); return NS_OK; } nsresult -nsFilterInstance::BuildSourcePaints(gfxASurface* aTargetSurface, - DrawTarget* aTargetDT) +nsFilterInstance::BuildSourcePaints(DrawTarget* aTargetDT) { nsresult rv = NS_OK; if (!mFillPaint.mNeededBounds.IsEmpty()) { - rv = BuildSourcePaint(&mFillPaint, aTargetSurface, aTargetDT); + rv = BuildSourcePaint(&mFillPaint, aTargetDT); NS_ENSURE_SUCCESS(rv, rv); } if (!mStrokePaint.mNeededBounds.IsEmpty()) { - rv = BuildSourcePaint(&mStrokePaint, aTargetSurface, aTargetDT); + rv = BuildSourcePaint(&mStrokePaint, aTargetDT); NS_ENSURE_SUCCESS(rv, rv); } return rv; } nsresult -nsFilterInstance::BuildSourceImage(gfxASurface* aTargetSurface, - DrawTarget* aTargetDT) +nsFilterInstance::BuildSourceImage(DrawTarget* aTargetDT) { nsIntRect neededRect = mSourceGraphic.mNeededBounds; if (neededRect.IsEmpty()) { return NS_OK; } - RefPtr offscreenDT; - nsRefPtr offscreenSurface; - nsRefPtr ctx; - if (aTargetSurface) { - offscreenSurface = gfxPlatform::GetPlatform()->CreateOffscreenSurface( - neededRect.Size().ToIntSize(), gfxContentType::COLOR_ALPHA); - if (!offscreenSurface || offscreenSurface->CairoStatus()) { - return NS_ERROR_OUT_OF_MEMORY; - } - ctx = new gfxContext(offscreenSurface); - } else { - offscreenDT = gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget( + RefPtr offscreenDT = + gfxPlatform::GetPlatform()->CreateOffscreenContentDrawTarget( ToIntSize(neededRect.Size()), SurfaceFormat::B8G8R8A8); - if (!offscreenDT) { - return NS_ERROR_OUT_OF_MEMORY; - } - ctx = new gfxContext(offscreenDT); + if (!offscreenDT) { + return NS_ERROR_OUT_OF_MEMORY; } + nsRefPtr ctx = new gfxContext(offscreenDT); ctx->Translate(-neededRect.TopLeft()); nsRefPtr tmpCtx(new nsRenderingContext()); @@ -431,16 +402,7 @@ nsFilterInstance::BuildSourceImage(gfxASurface* aTargetSurface, tmpCtx->ThebesContext()->Multiply(deviceToFilterSpace); mPaintCallback->Paint(tmpCtx, mTargetFrame, &dirty, mTransformRoot); - RefPtr sourceGraphicSource; - - if (offscreenSurface) { - sourceGraphicSource = - gfxPlatform::GetPlatform()->GetSourceSurfaceForSurface(aTargetDT, offscreenSurface); - } else { - sourceGraphicSource = offscreenDT->Snapshot(); - } - - mSourceGraphic.mSourceSurface = sourceGraphicSource; + mSourceGraphic.mSourceSurface = offscreenDT->Snapshot(); mSourceGraphic.mSurfaceRect = ToIntRect(neededRect); return NS_OK; @@ -457,34 +419,18 @@ nsFilterInstance::Render(gfxContext* aContext) } Matrix oldDTMatrix; - nsRefPtr resultImage; - RefPtr dt; - if (aContext->IsCairo()) { - resultImage = - gfxPlatform::GetPlatform()->CreateOffscreenSurface(filterRect.Size().ToIntSize(), - gfxContentType::COLOR_ALPHA); - if (!resultImage || resultImage->CairoStatus()) - return NS_ERROR_OUT_OF_MEMORY; - - // Create a Cairo DrawTarget around resultImage. - dt = gfxPlatform::GetPlatform()->CreateDrawTargetForSurface( - resultImage, ToIntSize(filterRect.Size())); - } else { - // When we have a DrawTarget-backed context, we can call DrawFilter - // directly on the target DrawTarget and don't need a temporary DT. - dt = aContext->GetDrawTarget(); - oldDTMatrix = dt->GetTransform(); - Matrix matrix = ToMatrix(ctm); - matrix.Translate(filterRect.x, filterRect.y); - dt->SetTransform(matrix * oldDTMatrix); - } + RefPtr dt = aContext->GetDrawTarget(); + oldDTMatrix = dt->GetTransform(); + Matrix matrix = ToMatrix(ctm); + matrix.Translate(filterRect.x, filterRect.y); + dt->SetTransform(matrix * oldDTMatrix); ComputeNeededBoxes(); - nsresult rv = BuildSourceImage(resultImage, dt); + nsresult rv = BuildSourceImage(dt); if (NS_FAILED(rv)) return rv; - rv = BuildSourcePaints(resultImage, dt); + rv = BuildSourcePaints(dt); if (NS_FAILED(rv)) return rv; @@ -498,16 +444,7 @@ nsFilterInstance::Render(gfxContext* aContext) mStrokePaint.mSourceSurface, mStrokePaint.mSurfaceRect, mInputImages); - if (resultImage) { - aContext->Save(); - aContext->Multiply(ctm); - aContext->Translate(filterRect.TopLeft()); - aContext->SetSource(resultImage); - aContext->Paint(); - aContext->Restore(); - } else { - dt->SetTransform(oldDTMatrix); - } + dt->SetTransform(oldDTMatrix); return NS_OK; } diff --git a/layout/svg/nsFilterInstance.h b/layout/svg/nsFilterInstance.h index bf5679f79789..2932908f7f55 100644 --- a/layout/svg/nsFilterInstance.h +++ b/layout/svg/nsFilterInstance.h @@ -183,7 +183,6 @@ private: * nodes */ nsresult BuildSourcePaint(SourceInfo *aPrimitive, - gfxASurface* aTargetSurface, DrawTarget* aTargetDT); /** @@ -191,15 +190,13 @@ private: * nodes, fills its contents and assigns it to mFillPaint.mSourceSurface and * mStrokePaint.mSourceSurface respectively. */ - nsresult BuildSourcePaints(gfxASurface* aTargetSurface, - DrawTarget* aTargetDT); + nsresult BuildSourcePaints(DrawTarget* aTargetDT); /** * Creates the SourceSurface for the SourceGraphic graph node, paints its * contents, and assigns it to mSourceGraphic.mSourceSurface. */ - nsresult BuildSourceImage(gfxASurface* aTargetSurface, - DrawTarget* aTargetDT); + nsresult BuildSourceImage(DrawTarget* aTargetDT); /** * Build the list of FilterPrimitiveDescriptions that describes the filter's