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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 | 229 |
230 void prepareMailboxWhenContextIsLost() { | 230 void prepareMailboxWhenContextIsLost() { |
231 FakeGLES2Interface gl; | 231 FakeGLES2Interface gl; |
232 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = | 232 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = |
233 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); | 233 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); |
234 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( | 234 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( |
235 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, | 235 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, |
236 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr, | 236 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr, |
237 kN32_SkColorType))); | 237 kN32_SkColorType))); |
238 | 238 |
239 // TODO(junov): The PrepareTextureMailbox() method will fail a DCHECK if we | 239 EXPECT_TRUE(bridge->isAccelerated()); |
240 // don't do this before calling it the first time when the context is lost. | |
241 bridge->prepareSurfaceForPaintingIfNeeded(); | |
242 | 240 |
243 // When the context is lost we are not sure if we should still be producing | 241 // When the context is lost we are not sure if we should still be producing |
244 // GL frames for the compositor or not, so fail to generate frames. | 242 // GL frames for the compositor or not, so fail to generate frames. |
245 gl.setIsContextLost(true); | 243 gl.setIsContextLost(true); |
246 | 244 |
247 cc::TextureMailbox textureMailbox; | 245 cc::TextureMailbox textureMailbox; |
248 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; | 246 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; |
249 EXPECT_FALSE( | 247 EXPECT_FALSE( |
250 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback)); | 248 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback)); |
251 } | 249 } |
252 | 250 |
253 void prepareMailboxWhenContextIsLostWithFailedRestore() { | 251 void prepareMailboxWhenContextIsLostWithFailedRestore() { |
254 FakeGLES2Interface gl; | 252 FakeGLES2Interface gl; |
255 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = | 253 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = |
256 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); | 254 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); |
257 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( | 255 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( |
258 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, | 256 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, |
259 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr, | 257 Canvas2DLayerBridge::ForceAccelerationForTesting, nullptr, |
260 kN32_SkColorType))); | 258 kN32_SkColorType))); |
261 | 259 |
262 // TODO(junov): The PrepareTextureMailbox() method will fail a DCHECK if we | 260 bridge->getOrCreateSurface(); |
263 // don't do this before calling it the first time when the context is lost. | 261 EXPECT_TRUE(bridge->checkSurfaceValid()); |
264 bridge->prepareSurfaceForPaintingIfNeeded(); | |
265 | |
266 // When the context is lost we are not sure if we should still be producing | 262 // When the context is lost we are not sure if we should still be producing |
267 // GL frames for the compositor or not, so fail to generate frames. | 263 // GL frames for the compositor or not, so fail to generate frames. |
268 gl.setIsContextLost(true); | 264 gl.setIsContextLost(true); |
269 EXPECT_FALSE(bridge->checkSurfaceValid()); | 265 EXPECT_FALSE(bridge->checkSurfaceValid()); |
270 | 266 |
271 // Restoration will fail because | 267 // Restoration will fail because |
272 // Platform::createSharedOffscreenGraphicsContext3DProvider() is stubbed | 268 // Platform::createSharedOffscreenGraphicsContext3DProvider() is stubbed |
273 // in unit tests. This simulates what would happen when attempting to | 269 // in unit tests. This simulates what would happen when attempting to |
274 // restore while the GPU process is down. | 270 // restore while the GPU process is down. |
275 bridge->restoreSurface(); | 271 bridge->restoreSurface(); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 gpu::gles2::GLES2Interface* gl, | 403 gpu::gles2::GLES2Interface* gl, |
408 Canvas2DLayerBridgeTest* testHost, | 404 Canvas2DLayerBridgeTest* testHost, |
409 WaitableEvent* doneEvent) { | 405 WaitableEvent* doneEvent) { |
410 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = | 406 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = |
411 WTF::makeUnique<FakeWebGraphicsContext3DProvider>(gl); | 407 WTF::makeUnique<FakeWebGraphicsContext3DProvider>(gl); |
412 *bridgePtr = | 408 *bridgePtr = |
413 testHost->makeBridge(std::move(contextProvider), IntSize(300, 300), | 409 testHost->makeBridge(std::move(contextProvider), IntSize(300, 300), |
414 Canvas2DLayerBridge::EnableAcceleration); | 410 Canvas2DLayerBridge::EnableAcceleration); |
415 // draw+flush to trigger the creation of a GPU surface | 411 // draw+flush to trigger the creation of a GPU surface |
416 (*bridgePtr)->didDraw(FloatRect(0, 0, 1, 1)); | 412 (*bridgePtr)->didDraw(FloatRect(0, 0, 1, 1)); |
417 (*bridgePtr)->finalizeFrame(FloatRect(0, 0, 1, 1)); | 413 (*bridgePtr)->finalizeFrame(); |
418 (*bridgePtr)->flush(); | 414 (*bridgePtr)->flush(); |
419 doneEvent->signal(); | 415 doneEvent->signal(); |
420 } | 416 } |
421 | 417 |
422 void postAndWaitCreateBridgeTask(const WebTraceLocation& location, | 418 void postAndWaitCreateBridgeTask(const WebTraceLocation& location, |
423 WebThread* testThread, | 419 WebThread* testThread, |
424 Canvas2DLayerBridgePtr* bridgePtr, | 420 Canvas2DLayerBridgePtr* bridgePtr, |
425 gpu::gles2::GLES2Interface* gl, | 421 gpu::gles2::GLES2Interface* gl, |
426 Canvas2DLayerBridgeTest* testHost) { | 422 Canvas2DLayerBridgeTest* testHost) { |
427 std::unique_ptr<WaitableEvent> bridgeCreatedEvent = | 423 std::unique_ptr<WaitableEvent> bridgeCreatedEvent = |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 EXPECT_FALSE(bridge->isHibernating()); | 662 EXPECT_FALSE(bridge->isHibernating()); |
667 EXPECT_TRUE(bridge->checkSurfaceValid()); | 663 EXPECT_TRUE(bridge->checkSurfaceValid()); |
668 | 664 |
669 // Tear down the bridge on the thread so that 'bridge' can go out of scope | 665 // Tear down the bridge on the thread so that 'bridge' can go out of scope |
670 // without crashing due to thread checks | 666 // without crashing due to thread checks |
671 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); | 667 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); |
672 } | 668 } |
673 | 669 |
674 void runRenderingTask(Canvas2DLayerBridge* bridge, WaitableEvent* doneEvent) { | 670 void runRenderingTask(Canvas2DLayerBridge* bridge, WaitableEvent* doneEvent) { |
675 bridge->didDraw(FloatRect(0, 0, 1, 1)); | 671 bridge->didDraw(FloatRect(0, 0, 1, 1)); |
676 bridge->finalizeFrame(FloatRect(0, 0, 1, 1)); | 672 bridge->finalizeFrame(); |
677 bridge->flush(); | 673 bridge->flush(); |
678 doneEvent->signal(); | 674 doneEvent->signal(); |
679 } | 675 } |
680 | 676 |
681 void postAndWaitRenderingTask(const WebTraceLocation& location, | 677 void postAndWaitRenderingTask(const WebTraceLocation& location, |
682 WebThread* testThread, | 678 WebThread* testThread, |
683 Canvas2DLayerBridge* bridge) { | 679 Canvas2DLayerBridge* bridge) { |
684 std::unique_ptr<WaitableEvent> doneEvent = WTF::makeUnique<WaitableEvent>(); | 680 std::unique_ptr<WaitableEvent> doneEvent = WTF::makeUnique<WaitableEvent>(); |
685 testThread->getWebTaskRunner()->postTask( | 681 testThread->getWebTaskRunner()->postTask( |
686 location, | 682 location, |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1366 EXPECT_FALSE(bridge->hasRecordedDrawCommands()); | 1362 EXPECT_FALSE(bridge->hasRecordedDrawCommands()); |
1367 ::testing::Mock::VerifyAndClearExpectations(&gl); | 1363 ::testing::Mock::VerifyAndClearExpectations(&gl); |
1368 | 1364 |
1369 EXPECT_CALL(gl, Flush()).Times(1); | 1365 EXPECT_CALL(gl, Flush()).Times(1); |
1370 bridge->flushGpu(); | 1366 bridge->flushGpu(); |
1371 EXPECT_FALSE(bridge->hasRecordedDrawCommands()); | 1367 EXPECT_FALSE(bridge->hasRecordedDrawCommands()); |
1372 ::testing::Mock::VerifyAndClearExpectations(&gl); | 1368 ::testing::Mock::VerifyAndClearExpectations(&gl); |
1373 } | 1369 } |
1374 | 1370 |
1375 } // namespace blink | 1371 } // namespace blink |
OLD | NEW |