| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); | 175 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); |
| 176 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID()); | 176 EXPECT_EQ(genID, bridge->getOrCreateSurface()->generationID()); |
| 177 // This results in the internal surface being torn down in response to t
he context loss. | 177 // This results in the internal surface being torn down in response to t
he context loss. |
| 178 EXPECT_FALSE(bridge->checkSurfaceValid()); | 178 EXPECT_FALSE(bridge->checkSurfaceValid()); |
| 179 EXPECT_EQ(nullptr, bridge->getOrCreateSurface()); | 179 EXPECT_EQ(nullptr, bridge->getOrCreateSurface()); |
| 180 // The following passes by not crashing | 180 // The following passes by not crashing |
| 181 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); | 181 bridge->canvas()->drawRect(SkRect::MakeXYWH(0, 0, 1, 1), paint); |
| 182 bridge->flush(); | 182 bridge->flush(); |
| 183 } | 183 } |
| 184 | 184 |
| 185 void prepareMailboxSoftwareTest() | 185 void prepareMailboxWhenContextIsLost() |
| 186 { | 186 { |
| 187 FakeGLES2Interface gl; | 187 FakeGLES2Interface gl; |
| 188 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = wrap
Unique(new FakeWebGraphicsContext3DProvider(&gl)); | 188 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = wrap
Unique(new FakeWebGraphicsContext3DProvider(&gl)); |
| 189 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(std::move
(contextProvider), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge::ForceAc
celerationForTesting))); | 189 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(std::move
(contextProvider), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge::ForceAc
celerationForTesting))); |
| 190 | 190 |
| 191 // TODO(junov): The PrepareTextureMailbox() method will fail a DCHECK if
we don't |
| 192 // do this before calling it the first time when the context is lost. |
| 193 bridge->prepareSurfaceForPaintingIfNeeded(); |
| 194 |
| 195 // When the context is lost we are not sure if we should be producing GL
frames for the |
| 196 // compositor still or not, so fail to generate frames. |
| 197 gl.setIsContextLost(true); |
| 198 |
| 191 cc::TextureMailbox textureMailbox; | 199 cc::TextureMailbox textureMailbox; |
| 192 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; | 200 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; |
| 193 bool useSharedMemory = true; | 201 EXPECT_FALSE(bridge->PrepareTextureMailbox(&textureMailbox, &releaseCall
back)); |
| 194 EXPECT_FALSE(bridge->PrepareTextureMailbox(&textureMailbox, &releaseCall
back, useSharedMemory)); | |
| 195 } | 202 } |
| 196 | 203 |
| 197 void prepareMailboxAndLoseResourceTest() | 204 void prepareMailboxAndLoseResourceTest() |
| 198 { | 205 { |
| 199 // Prepare a mailbox, then report the resource as lost. | 206 // Prepare a mailbox, then report the resource as lost. |
| 200 // This test passes by not crashing and not triggering assertions. | 207 // This test passes by not crashing and not triggering assertions. |
| 201 { | 208 { |
| 202 FakeGLES2Interface gl; | 209 FakeGLES2Interface gl; |
| 203 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider =
wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); | 210 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider =
wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); |
| 204 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(std::
move(contextProvider), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge::For
ceAccelerationForTesting))); | 211 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(std::
move(contextProvider), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge::For
ceAccelerationForTesting))); |
| 205 | 212 |
| 206 cc::TextureMailbox textureMailbox; | 213 cc::TextureMailbox textureMailbox; |
| 207 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; | 214 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; |
| 208 bool useSharedMemory = false; | 215 EXPECT_TRUE(bridge->PrepareTextureMailbox(&textureMailbox, &releaseC
allback)); |
| 209 EXPECT_TRUE(bridge->PrepareTextureMailbox(&textureMailbox, &releaseC
allback, useSharedMemory)); | |
| 210 | 216 |
| 211 bool lostResource = true; | 217 bool lostResource = true; |
| 212 releaseCallback->Run(gpu::SyncToken(), lostResource); | 218 releaseCallback->Run(gpu::SyncToken(), lostResource); |
| 213 } | 219 } |
| 214 | 220 |
| 215 // Retry with mailbox released while bridge destruction is in progress. | 221 // Retry with mailbox released while bridge destruction is in progress. |
| 216 { | 222 { |
| 217 FakeGLES2Interface gl; | 223 FakeGLES2Interface gl; |
| 218 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider =
wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); | 224 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider =
wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); |
| 219 | 225 |
| 220 cc::TextureMailbox textureMailbox; | 226 cc::TextureMailbox textureMailbox; |
| 221 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; | 227 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; |
| 222 bool useSharedMemory = false; | |
| 223 | 228 |
| 224 { | 229 { |
| 225 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(s
td::move(contextProvider), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge:
:ForceAccelerationForTesting))); | 230 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(s
td::move(contextProvider), IntSize(300, 150), 0, NonOpaque, Canvas2DLayerBridge:
:ForceAccelerationForTesting))); |
| 226 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback,
useSharedMemory); | 231 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback)
; |
| 227 // |bridge| goes out of scope and would normally be destroyed, b
ut object is kept alive by self references. | 232 // |bridge| goes out of scope and would normally be destroyed, b
ut object is kept alive by self references. |
| 228 } | 233 } |
| 229 | 234 |
| 230 // Before fixing crbug.com/411864, the following line you cause a me
mory use after free | 235 // Before fixing crbug.com/411864, the following line you cause a me
mory use after free |
| 231 // that sometimes causes a crash in normal builds and crashes consis
tently with ASAN. | 236 // that sometimes causes a crash in normal builds and crashes consis
tently with ASAN. |
| 232 // This should cause the bridge to be destroyed. | 237 // This should cause the bridge to be destroyed. |
| 233 bool lostResource = true; | 238 bool lostResource = true; |
| 234 releaseCallback->Run(gpu::SyncToken(), lostResource); | 239 releaseCallback->Run(gpu::SyncToken(), lostResource); |
| 235 } | 240 } |
| 236 } | 241 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 264 TEST_F(Canvas2DLayerBridgeTest, FullLifecycleSingleThreaded) | 269 TEST_F(Canvas2DLayerBridgeTest, FullLifecycleSingleThreaded) |
| 265 { | 270 { |
| 266 fullLifecycleTest(); | 271 fullLifecycleTest(); |
| 267 } | 272 } |
| 268 | 273 |
| 269 TEST_F(Canvas2DLayerBridgeTest, NoDrawOnContextLost) | 274 TEST_F(Canvas2DLayerBridgeTest, NoDrawOnContextLost) |
| 270 { | 275 { |
| 271 noDrawOnContextLostTest(); | 276 noDrawOnContextLostTest(); |
| 272 } | 277 } |
| 273 | 278 |
| 274 TEST_F(Canvas2DLayerBridgeTest, PrepareMailboxSoftware) | 279 TEST_F(Canvas2DLayerBridgeTest, PrepareMailboxWhenContextIsLost) |
| 275 { | 280 { |
| 276 prepareMailboxSoftwareTest(); | 281 prepareMailboxWhenContextIsLost(); |
| 277 } | 282 } |
| 278 | 283 |
| 279 TEST_F(Canvas2DLayerBridgeTest, PrepareMailboxAndLoseResource) | 284 TEST_F(Canvas2DLayerBridgeTest, PrepareMailboxAndLoseResource) |
| 280 { | 285 { |
| 281 prepareMailboxAndLoseResourceTest(); | 286 prepareMailboxAndLoseResourceTest(); |
| 282 } | 287 } |
| 283 | 288 |
| 284 TEST_F(Canvas2DLayerBridgeTest, AccelerationHint) | 289 TEST_F(Canvas2DLayerBridgeTest, AccelerationHint) |
| 285 { | 290 { |
| 286 accelerationHintTest(); | 291 accelerationHintTest(); |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 998 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe
rnationScheduled)); | 1003 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe
rnationScheduled)); |
| 999 EXPECT_CALL(*mockLoggerPtr, didStartHibernating()) | 1004 EXPECT_CALL(*mockLoggerPtr, didStartHibernating()) |
| 1000 .WillOnce(testing::Invoke(hibernationStartedEvent.get(), &WaitableEvent:
:signal)); | 1005 .WillOnce(testing::Invoke(hibernationStartedEvent.get(), &WaitableEvent:
:signal)); |
| 1001 postSetIsHiddenTask(BLINK_FROM_HERE, testThread.get(), bridge.get(), true); | 1006 postSetIsHiddenTask(BLINK_FROM_HERE, testThread.get(), bridge.get(), true); |
| 1002 hibernationStartedEvent->wait(); | 1007 hibernationStartedEvent->wait(); |
| 1003 ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr); | 1008 ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr); |
| 1004 | 1009 |
| 1005 // Test prepareMailbox while hibernating | 1010 // Test prepareMailbox while hibernating |
| 1006 cc::TextureMailbox textureMailbox; | 1011 cc::TextureMailbox textureMailbox; |
| 1007 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; | 1012 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; |
| 1008 bool useSharedMemory = false; | 1013 EXPECT_FALSE(bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback
)); |
| 1009 EXPECT_FALSE(bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback
, useSharedMemory)); | |
| 1010 EXPECT_TRUE(bridge->checkSurfaceValid()); | 1014 EXPECT_TRUE(bridge->checkSurfaceValid()); |
| 1011 | 1015 |
| 1012 // Tear down the bridge on the thread so that 'bridge' can go out of scope | 1016 // Tear down the bridge on the thread so that 'bridge' can go out of scope |
| 1013 // without crashing due to thread checks | 1017 // without crashing due to thread checks |
| 1014 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe
rnationEndedWithTeardown)); | 1018 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe
rnationEndedWithTeardown)); |
| 1015 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); | 1019 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); |
| 1016 } | 1020 } |
| 1017 | 1021 |
| 1018 #if CANVAS2D_HIBERNATION_ENABLED && CANVAS2D_BACKGROUND_RENDER_SWITCH_TO_CPU | 1022 #if CANVAS2D_HIBERNATION_ENABLED && CANVAS2D_BACKGROUND_RENDER_SWITCH_TO_CPU |
| 1019 TEST_F(Canvas2DLayerBridgeTest, PrepareMailboxWhileBackgroundRendering) | 1023 TEST_F(Canvas2DLayerBridgeTest, PrepareMailboxWhileBackgroundRendering) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1047 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe
rnationEndedWithSwitchToBackgroundRendering)); | 1051 EXPECT_CALL(*mockLoggerPtr, reportHibernationEvent(Canvas2DLayerBridge::Hibe
rnationEndedWithSwitchToBackgroundRendering)); |
| 1048 postAndWaitRenderingTask(BLINK_FROM_HERE, testThread.get(), bridge.get()); | 1052 postAndWaitRenderingTask(BLINK_FROM_HERE, testThread.get(), bridge.get()); |
| 1049 ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr); | 1053 ::testing::Mock::VerifyAndClearExpectations(mockLoggerPtr); |
| 1050 EXPECT_FALSE(bridge->isAccelerated()); | 1054 EXPECT_FALSE(bridge->isAccelerated()); |
| 1051 EXPECT_FALSE(bridge->isHibernating()); | 1055 EXPECT_FALSE(bridge->isHibernating()); |
| 1052 EXPECT_TRUE(bridge->checkSurfaceValid()); | 1056 EXPECT_TRUE(bridge->checkSurfaceValid()); |
| 1053 | 1057 |
| 1054 // Test prepareMailbox while background rendering | 1058 // Test prepareMailbox while background rendering |
| 1055 cc::TextureMailbox textureMailbox; | 1059 cc::TextureMailbox textureMailbox; |
| 1056 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; | 1060 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; |
| 1057 bool useSharedMemory = false; | 1061 EXPECT_FALSE(bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback
)); |
| 1058 EXPECT_FALSE(bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback
, useSharedMemory)); | |
| 1059 EXPECT_TRUE(bridge->checkSurfaceValid()); | 1062 EXPECT_TRUE(bridge->checkSurfaceValid()); |
| 1060 | 1063 |
| 1061 // Tear down the bridge on the thread so that 'bridge' can go out of scope | 1064 // Tear down the bridge on the thread so that 'bridge' can go out of scope |
| 1062 // without crashing due to thread checks | 1065 // without crashing due to thread checks |
| 1063 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); | 1066 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); |
| 1064 } | 1067 } |
| 1065 | 1068 |
| 1066 } // namespace blink | 1069 } // namespace blink |
| OLD | NEW |