From b7a705dcefe0e7aa4437b8dd720bd3b1d324c22b Mon Sep 17 00:00:00 2001 From: sotaro Date: Wed, 18 Mar 2020 10:38:32 +0000 Subject: [PATCH] Bug 1623254 - Re-create DrawTarget of CanvasRenderingContext2D when the DrawTarget becomes invalid r=nical Differential Revision: https://phabricator.services.mozilla.com/D67274 --HG-- extra : moz-landing-system : lando --- dom/canvas/CanvasRenderingContext2D.cpp | 2 +- gfx/2d/DrawTargetD2D1.cpp | 5 ++++- gfx/2d/DrawTargetD2D1.h | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/dom/canvas/CanvasRenderingContext2D.cpp b/dom/canvas/CanvasRenderingContext2D.cpp index 48f6bdb3b1a8..b1377577b4b4 100644 --- a/dom/canvas/CanvasRenderingContext2D.cpp +++ b/dom/canvas/CanvasRenderingContext2D.cpp @@ -1296,7 +1296,7 @@ bool CanvasRenderingContext2D::EnsureTarget(const gfx::Rect* aCoveredRect, RestoreClipsAndTransformToTarget(); } - if (mTarget) { + if (mTarget && mTarget->IsValid()) { return true; } } diff --git a/gfx/2d/DrawTargetD2D1.cpp b/gfx/2d/DrawTargetD2D1.cpp index d86bd5b34b39..bdbcb4217c0c 100644 --- a/gfx/2d/DrawTargetD2D1.cpp +++ b/gfx/2d/DrawTargetD2D1.cpp @@ -90,6 +90,9 @@ DrawTargetD2D1::~DrawTargetD2D1() { } bool DrawTargetD2D1::IsValid() const { + if (mInitState != InitState::Uninitialized && !IsDeviceContextValid()) { + return false; + } if (NS_IsMainThread()) { // Uninitialized DTs are considered valid. return mInitState != InitState::Failure; @@ -2274,7 +2277,7 @@ void DrawTargetD2D1::PushD2DLayer(ID2D1DeviceContext* aDC, nullptr); } -bool DrawTargetD2D1::IsDeviceContextValid() { +bool DrawTargetD2D1::IsDeviceContextValid() const { uint32_t seqNo; return mDC && Factory::GetD2D1Device(&seqNo) && seqNo == mDeviceSeq; } diff --git a/gfx/2d/DrawTargetD2D1.h b/gfx/2d/DrawTargetD2D1.h index 972e5a6c265d..74b06fdeb800 100644 --- a/gfx/2d/DrawTargetD2D1.h +++ b/gfx/2d/DrawTargetD2D1.h @@ -244,7 +244,7 @@ class DrawTargetD2D1 : public DrawTarget { // This function is used to determine if the mDC is still valid; if it is // stale, we should avoid using it to execute any draw commands. - bool IsDeviceContextValid(); + bool IsDeviceContextValid() const; IntSize mSize;