From 997c7019bc7259e3b6f87bdee9aab9cff3f96053 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 31 Oct 2017 12:02:32 -0700 Subject: [PATCH] Don't cache DrawTargetCaptures in nsCanvasFrame. (bug 1395478 part 10, r=mattwoodrow) --HG-- extra : rebase_source : fc0746099e910f1e46842f292f60b2f00ee25f38 --- gfx/2d/2D.h | 12 ++++++++++++ gfx/2d/DrawTargetCapture.cpp | 7 +++++++ gfx/2d/DrawTargetCapture.h | 2 ++ layout/generic/nsCanvasFrame.cpp | 6 +++--- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/gfx/2d/2D.h b/gfx/2d/2D.h index 6a02a30cc538..348526dee7a7 100644 --- a/gfx/2d/2D.h +++ b/gfx/2d/2D.h @@ -1273,6 +1273,18 @@ public: return CreateSimilarDrawTarget(aSize, aFormat); } + /** + * Create a similar draw target, but if the draw target is not backed by a + * raster backend (for example, it is capturing or recording), force it to + * create a raster target instead. This is intended for code that wants to + * cache pixels, and would have no effect if it were caching a recording. + */ + virtual RefPtr + CreateSimilarRasterTarget(const IntSize& aSize, SurfaceFormat aFormat) const + { + return CreateSimilarDrawTarget(aSize, aFormat); + } + /** * Create a path builder with the specified fillmode. * diff --git a/gfx/2d/DrawTargetCapture.cpp b/gfx/2d/DrawTargetCapture.cpp index a172b0e9495f..2e0b2171c86a 100644 --- a/gfx/2d/DrawTargetCapture.cpp +++ b/gfx/2d/DrawTargetCapture.cpp @@ -405,5 +405,12 @@ DrawTargetCaptureImpl::CreateSimilarDrawTarget(const IntSize &aSize, SurfaceForm return MakeAndAddRef(GetBackendType(), aSize, aFormat); } +RefPtr +DrawTargetCaptureImpl::CreateSimilarRasterTarget(const IntSize& aSize, SurfaceFormat aFormat) const +{ + MOZ_ASSERT(!mRefDT->IsCaptureDT()); + return mRefDT->CreateSimilarDrawTarget(aSize, aFormat); +} + } // namespace gfx } // namespace mozilla diff --git a/gfx/2d/DrawTargetCapture.h b/gfx/2d/DrawTargetCapture.h index 355031516acc..9880a1bd55dc 100644 --- a/gfx/2d/DrawTargetCapture.h +++ b/gfx/2d/DrawTargetCapture.h @@ -128,6 +128,8 @@ public: virtual already_AddRefed CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const override; + virtual RefPtr + CreateSimilarRasterTarget(const IntSize& aSize, SurfaceFormat aFormat) const override; virtual already_AddRefed CreatePathBuilder(FillRule aFillRule = FillRule::FILL_WINDING) const override { diff --git a/layout/generic/nsCanvasFrame.cpp b/layout/generic/nsCanvasFrame.cpp index a0c0b8132c17..bb835f00a9c8 100644 --- a/layout/generic/nsCanvasFrame.cpp +++ b/layout/generic/nsCanvasFrame.cpp @@ -383,9 +383,9 @@ nsDisplayCanvasBackgroundImage::Paint(nsDisplayListBuilder* aBuilder, return; } - dt = destDT->CreateSimilarDrawTarget(IntSize::Ceil(destRect.width, - destRect.height), - SurfaceFormat::B8G8R8A8); + dt = destDT->CreateSimilarRasterTarget(IntSize::Ceil(destRect.width, + destRect.height), + SurfaceFormat::B8G8R8A8); if (dt && dt->IsValid()) { RefPtr ctx = gfxContext::CreateOrNull(dt); MOZ_ASSERT(ctx); // already checked draw target above