Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1522415: Properly track initialization state in case a device res…
Browse files Browse the repository at this point in the history
…et 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
  • Loading branch information
Bas-moz committed Jan 24, 2019
1 parent 2645451 commit 40ccfdd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 7 additions & 5 deletions gfx/2d/DrawTargetD2D1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ DrawTargetD2D1::DrawTargetD2D1()
mTransformedGlyphsSinceLastPurge(0),
mComplexBlendsWithListInList(0),
mDeviceSeq(0),
mIsInitialized(false) {}
mInitState(InitState::Uninitialized) {}

DrawTargetD2D1::~DrawTargetD2D1() {
PopAllClips();
Expand Down Expand Up @@ -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<DrawTargetD2D1 *>(this)->EnsureInitialized();
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -1400,6 +1400,8 @@ bool DrawTargetD2D1::EnsureInitialized() {
mDC->Clear();
}

mInitState = InitState::Success;

return true;
}

Expand Down
7 changes: 6 additions & 1 deletion gfx/2d/DrawTargetD2D1.h
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,12 @@ class DrawTargetD2D1 : public DrawTarget {
bool EnsureLuminanceEffect();
RefPtr<ID2D1Effect> mLuminanceEffect;

bool mIsInitialized;
enum class InitState {
Uninitialized,
Success,
Failure
};
InitState mInitState;
RefPtr<IDXGISurface> mSurface;
};

Expand Down

0 comments on commit 40ccfdd

Please sign in to comment.