From d8a0c1497052e0f58f1c8f28fc0cf8ebb61f9aa1 Mon Sep 17 00:00:00 2001 From: Bas Schouten Date: Thu, 24 Jan 2019 12:37:28 +0100 Subject: [PATCH] Bug 1522415: Properly track initialization state in case a device reset occurs during initialization. r=rhunt This fixes a situation where a Device Reset occurs during initialization, after mDC has already been created but before mBitmap is created. In this case IsValid and EnsureInitialized would previously return 'true' in subsequent calls, since they were only checking for the DC. This patch makes us properly store the full result of initialization for checking with IsValid and re-runs of EnsureInitialized. Differential Revision: https://phabricator.services.mozilla.com/D17486 --HG-- extra : rebase_source : a20480486c094e14c3a2f67e5f39b1efbece5c69 --- gfx/2d/DrawTargetD2D1.cpp | 12 +++++++----- gfx/2d/DrawTargetD2D1.h | 7 ++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/gfx/2d/DrawTargetD2D1.cpp b/gfx/2d/DrawTargetD2D1.cpp index 98d22643ad91..b7b8d62bb6e9 100644 --- a/gfx/2d/DrawTargetD2D1.cpp +++ b/gfx/2d/DrawTargetD2D1.cpp @@ -45,7 +45,7 @@ DrawTargetD2D1::DrawTargetD2D1() mTransformedGlyphsSinceLastPurge(0), mComplexBlendsWithListInList(0), mDeviceSeq(0), - mIsInitialized(false) {} + mInitState(InitState::Uninitialized) {} DrawTargetD2D1::~DrawTargetD2D1() { PopAllClips(); @@ -90,7 +90,7 @@ DrawTargetD2D1::~DrawTargetD2D1() { bool DrawTargetD2D1::IsValid() const { if (NS_IsMainThread()) { // Uninitialized DTs are considered valid. - return !mIsInitialized || mDC; + return mInitState != InitState::Failure; } else { return const_cast(this)->EnsureInitialized(); } @@ -1315,12 +1315,12 @@ void DrawTargetD2D1::FlushInternal(bool aHasDependencyMutex /* = false */) { } bool DrawTargetD2D1::EnsureInitialized() { - if (mIsInitialized) { - return !!mDC; + if (mInitState != InitState::Uninitialized) { + return mInitState == InitState::Success; } // Don't retry. - mIsInitialized = true; + mInitState = InitState::Failure; HRESULT hr; @@ -1400,6 +1400,8 @@ bool DrawTargetD2D1::EnsureInitialized() { mDC->Clear(); } + mInitState = InitState::Success; + return true; } diff --git a/gfx/2d/DrawTargetD2D1.h b/gfx/2d/DrawTargetD2D1.h index dd731c12aba4..a7b669b1945d 100644 --- a/gfx/2d/DrawTargetD2D1.h +++ b/gfx/2d/DrawTargetD2D1.h @@ -318,7 +318,12 @@ class DrawTargetD2D1 : public DrawTarget { bool EnsureLuminanceEffect(); RefPtr mLuminanceEffect; - bool mIsInitialized; + enum class InitState { + Uninitialized, + Success, + Failure + }; + InitState mInitState; RefPtr mSurface; };