Bug 1521368: Forego drawing if our drawtarget is invalid, this can happen on a devicereset. r=rhunt

Differential Revision: https://phabricator.services.mozilla.com/D17224

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Bas Schouten 2019-01-22 23:09:28 +00:00
parent 6e5e033cec
commit 587e039c49
3 changed files with 21 additions and 5 deletions

View File

@ -87,6 +87,15 @@ DrawTargetD2D1::~DrawTargetD2D1() {
}
}
bool DrawTargetD2D1::IsValid() const {
if (NS_IsMainThread()) {
// Uninitialized DTs are considered valid.
return !mIsInitialized || mDC;
} else {
return const_cast<DrawTargetD2D1 *>(this)->EnsureInitialized();
}
}
already_AddRefed<SourceSurface> DrawTargetD2D1::Snapshot() {
if (!EnsureInitialized()) {
return nullptr;
@ -1307,9 +1316,12 @@ void DrawTargetD2D1::FlushInternal(bool aHasDependencyMutex /* = false */) {
bool DrawTargetD2D1::EnsureInitialized() {
if (mIsInitialized) {
return true;
return !!mDC;
}
// Don't retry.
mIsInitialized = true;
HRESULT hr;
RefPtr<ID2D1Device> device = Factory::GetD2D1Device(&mDeviceSeq);
@ -1388,8 +1400,6 @@ bool DrawTargetD2D1::EnsureInitialized() {
mDC->Clear();
}
mIsInitialized = true;
return true;
}

View File

@ -34,6 +34,7 @@ class DrawTargetD2D1 : public DrawTarget {
DrawTargetD2D1();
virtual ~DrawTargetD2D1();
virtual bool IsValid() const override;
virtual DrawTargetType GetType() const override {
return DrawTargetType::HARDWARE_RASTER;
}

View File

@ -196,8 +196,13 @@ void PaintThread::AsyncPaintTask(CompositorBridgeChild* aBridge,
gfx::DrawTargetCapture* capture = aTask->mCapture;
gfx::DrawTarget* target = aTask->mTarget;
target->DrawCapturedDT(capture, Matrix());
target->Flush();
if (target->IsValid()) {
// Do not replay to invalid targets. This can happen on device resets and
// the browser will ensure the graphics stack is reinitialized on the main
// thread.
target->DrawCapturedDT(capture, Matrix());
target->Flush();
}
if (gfxPrefs::LayersOMTPReleaseCaptureOnMainThread()) {
// This should ensure the capture drawtarget, which may hold on to