Commit 526a7f4c authored by junov's avatar junov Committed by Commit bot

Fix 2D canvas content loss while page is hidden

BUG=578963
R=senorblanco@chromium.org

Review URL: https://codereview.chromium.org/1618283006

Cr-Commit-Position: refs/heads/master@{#371095}
parent e0906ef8
......@@ -520,6 +520,8 @@ bool Canvas2DLayerBridge::checkSurfaceValid()
ASSERT(!m_destructionInProgress);
if (m_destructionInProgress)
return false;
if (isHibernating())
return true;
if (!m_layer)
return true;
if (!m_surface)
......
......@@ -482,6 +482,7 @@ TEST_F(Canvas2DLayerBridgeTest, HibernationLifeCycle)
::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr);
EXPECT_FALSE(bridge->isAccelerated());
EXPECT_TRUE(bridge->isHibernating());
EXPECT_TRUE(bridge->checkSurfaceValid());
// Test exiting hibernation
OwnPtr<WebWaitableEvent> hibernationEndedEvent = adoptPtr(Platform::current()->createWaitableEvent());
......@@ -491,6 +492,7 @@ TEST_F(Canvas2DLayerBridgeTest, HibernationLifeCycle)
::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr);
EXPECT_TRUE(bridge->isAccelerated());
EXPECT_FALSE(bridge->isHibernating());
EXPECT_TRUE(bridge->checkSurfaceValid());
// Tear down the bridge on the thread so that 'bridge' can go out of scope
// without crashing due to thread checks
......@@ -533,6 +535,7 @@ TEST_F(Canvas2DLayerBridgeTest, HibernationLifeCycleWithDeferredRenderingDisable
::testing::Mock::VerifyAndClearExpectations(&mockImageBuffer);
EXPECT_FALSE(bridge->isAccelerated());
EXPECT_TRUE(bridge->isHibernating());
EXPECT_TRUE(bridge->checkSurfaceValid());
// Test exiting hibernation
OwnPtr<WebWaitableEvent> hibernationEndedEvent = adoptPtr(Platform::current()->createWaitableEvent());
......@@ -544,6 +547,7 @@ TEST_F(Canvas2DLayerBridgeTest, HibernationLifeCycleWithDeferredRenderingDisable
::testing::Mock::VerifyAndClearExpectations(&mockImageBuffer);
EXPECT_TRUE(bridge->isAccelerated());
EXPECT_FALSE(bridge->isHibernating());
EXPECT_TRUE(bridge->checkSurfaceValid());
// Tear down the bridge on the thread so that 'bridge' can go out of scope
// without crashing due to thread checks
......@@ -603,6 +607,7 @@ TEST_F(Canvas2DLayerBridgeTest, BackgroundRenderingWhileHibernating)
::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr);
EXPECT_FALSE(bridge->isAccelerated());
EXPECT_TRUE(bridge->isHibernating());
EXPECT_TRUE(bridge->checkSurfaceValid());
// Rendering in the background -> temp switch to SW
EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::HibernationEndedWithSwitchToBackgroundRendering));
......@@ -612,6 +617,7 @@ TEST_F(Canvas2DLayerBridgeTest, BackgroundRenderingWhileHibernating)
::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr);
EXPECT_FALSE(bridge->isAccelerated());
EXPECT_FALSE(bridge->isHibernating());
EXPECT_TRUE(bridge->checkSurfaceValid());
// Unhide
OwnPtr<WebWaitableEvent> unhideEvent = adoptPtr(Platform::current()->createWaitableEvent());
......@@ -620,6 +626,7 @@ TEST_F(Canvas2DLayerBridgeTest, BackgroundRenderingWhileHibernating)
::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr);
EXPECT_TRUE(bridge->isAccelerated()); // Becoming visible causes switch back to GPU
EXPECT_FALSE(bridge->isHibernating());
EXPECT_TRUE(bridge->checkSurfaceValid());
// Tear down the bridge on the thread so that 'bridge' can go out of scope
// without crashing due to thread checks
......@@ -662,6 +669,7 @@ TEST_F(Canvas2DLayerBridgeTest, BackgroundRenderingWhileHibernatingWithDeferredR
::testing::Mock::VerifyAndClearExpectations(&mockImageBuffer);
EXPECT_FALSE(bridge->isAccelerated());
EXPECT_TRUE(bridge->isHibernating());
EXPECT_TRUE(bridge->checkSurfaceValid());
// Rendering in the background -> temp switch to SW
EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::HibernationEndedWithSwitchToBackgroundRendering));
......@@ -673,6 +681,7 @@ TEST_F(Canvas2DLayerBridgeTest, BackgroundRenderingWhileHibernatingWithDeferredR
::testing::Mock::VerifyAndClearExpectations(&mockImageBuffer);
EXPECT_FALSE(bridge->isAccelerated());
EXPECT_FALSE(bridge->isHibernating());
EXPECT_TRUE(bridge->checkSurfaceValid());
// Unhide
EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AtLeast(1));
......@@ -683,6 +692,7 @@ TEST_F(Canvas2DLayerBridgeTest, BackgroundRenderingWhileHibernatingWithDeferredR
::testing::Mock::VerifyAndClearExpectations(&mockImageBuffer);
EXPECT_TRUE(bridge->isAccelerated()); // Becoming visible causes switch back to GPU
EXPECT_FALSE(bridge->isHibernating());
EXPECT_TRUE(bridge->checkSurfaceValid());
// Tear down the bridge on the thread so that 'bridge' can go out of scope
// without crashing due to thread checks
......@@ -723,6 +733,7 @@ TEST_F(Canvas2DLayerBridgeTest, DisableDeferredRenderingWhileHibernating)
::testing::Mock::VerifyAndClearExpectations(&mockImageBuffer);
EXPECT_FALSE(bridge->isAccelerated());
EXPECT_TRUE(bridge->isHibernating());
EXPECT_TRUE(bridge->checkSurfaceValid());
// Disable deferral while background rendering
EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::HibernationEndedWithSwitchToBackgroundRendering));
......@@ -732,6 +743,7 @@ TEST_F(Canvas2DLayerBridgeTest, DisableDeferredRenderingWhileHibernating)
::testing::Mock::VerifyAndClearExpectations(&mockImageBuffer);
EXPECT_FALSE(bridge->isAccelerated());
EXPECT_FALSE(bridge->isHibernating());
EXPECT_TRUE(bridge->checkSurfaceValid());
// Unhide
EXPECT_CALL(mockImageBuffer, resetCanvas(_)).Times(AtLeast(1));
......@@ -742,6 +754,7 @@ TEST_F(Canvas2DLayerBridgeTest, DisableDeferredRenderingWhileHibernating)
::testing::Mock::VerifyAndClearExpectations(&mockImageBuffer);
EXPECT_TRUE(bridge->isAccelerated()); // Becoming visible causes switch back to GPU
EXPECT_FALSE(bridge->isHibernating());
EXPECT_TRUE(bridge->checkSurfaceValid());
// Tear down the bridge on the thread so that 'bridge' can go out of scope
// without crashing due to thread checks
......@@ -926,6 +939,7 @@ TEST_F(Canvas2DLayerBridgeTest, HibernationAbortedDueToVisibilityChange)
::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr);
EXPECT_TRUE(bridge->isAccelerated());
EXPECT_FALSE(bridge->isHibernating());
EXPECT_TRUE(bridge->checkSurfaceValid());
// Tear down the bridge on the thread so that 'bridge' can go out of scope
// without crashing due to thread checks
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment