From 6f9594cf0a2e3a2cae6830dfd664783f8c6d8620 Mon Sep 17 00:00:00 2001 From: sotaro Date: Tue, 23 Mar 2021 01:17:19 +0000 Subject: [PATCH] Bug 1699352 - Fix DrawTargetD2D1::mVRAMUsageSS handling r=jrmuizel Implementation is borrowed from SourceSurfaceD2DTarget::mOwnsCopy that existed in the past. Differential Revision: https://phabricator.services.mozilla.com/D108906 --- gfx/2d/SourceSurfaceD2D1.cpp | 16 +++++++++++----- gfx/2d/SourceSurfaceD2D1.h | 5 +++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/gfx/2d/SourceSurfaceD2D1.cpp b/gfx/2d/SourceSurfaceD2D1.cpp index 659b500c59bb..2be9f9289de3 100644 --- a/gfx/2d/SourceSurfaceD2D1.cpp +++ b/gfx/2d/SourceSurfaceD2D1.cpp @@ -17,17 +17,22 @@ SourceSurfaceD2D1::SourceSurfaceD2D1(ID2D1Image* aImage, : mImage(aImage), mDC(aDC), mDevice(Factory::GetD2D1Device()), - mDrawTarget(aDT) { + mFormat(aFormat), + mSize(aSize), + mDrawTarget(aDT), + mOwnsCopy(false) { aImage->QueryInterface((ID2D1Bitmap1**)getter_AddRefs(mRealizedBitmap)); - - mFormat = aFormat; - mSize = aSize; if (aDT) { mSnapshotLock = aDT->mSnapshotLock; } } -SourceSurfaceD2D1::~SourceSurfaceD2D1() {} +SourceSurfaceD2D1::~SourceSurfaceD2D1() { + if (mOwnsCopy) { + DrawTargetD2D1::mVRAMUsageSS -= + mSize.width * mSize.height * BytesPerPixel(mFormat); + } +} bool SourceSurfaceD2D1::IsValid() const { return mDevice == Factory::GetD2D1Device(); @@ -145,6 +150,7 @@ void SourceSurfaceD2D1::DrawTargetWillChange() { DrawTargetD2D1::mVRAMUsageSS += mSize.width * mSize.height * BytesPerPixel(mFormat); + mOwnsCopy = true; // Ensure the object stays alive for the duration of MarkIndependent. RefPtr deathGrip = this; diff --git a/gfx/2d/SourceSurfaceD2D1.h b/gfx/2d/SourceSurfaceD2D1.h index 7d2ce10805aa..cfc6dd6b86a8 100644 --- a/gfx/2d/SourceSurfaceD2D1.h +++ b/gfx/2d/SourceSurfaceD2D1.h @@ -62,10 +62,11 @@ class SourceSurfaceD2D1 : public SourceSurface { // Keep this around to verify whether out image is still valid in the future. RefPtr mDevice; - SurfaceFormat mFormat; - IntSize mSize; + const SurfaceFormat mFormat; + const IntSize mSize; DrawTargetD2D1* mDrawTarget; std::shared_ptr mSnapshotLock; + bool mOwnsCopy; }; class DataSourceSurfaceD2D1 : public DataSourceSurface {