Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/Canvas2DLayerBridgeTest.cpp

Issue 2653933003: Make stream captures work on canvases that are not in the DOM. (Closed)
Patch Set: rebase Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 233
234 void prepareMailboxWhenContextIsLost() { 234 void prepareMailboxWhenContextIsLost() {
235 FakeGLES2Interface gl; 235 FakeGLES2Interface gl;
236 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = 236 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider =
237 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 237 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
238 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( 238 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(
239 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, 239 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque,
240 Canvas2DLayerBridge::ForceAccelerationForTesting, 240 Canvas2DLayerBridge::ForceAccelerationForTesting,
241 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType))); 241 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType)));
242 242
243 // TODO(junov): The PrepareTextureMailbox() method will fail a DCHECK if we 243 EXPECT_TRUE(bridge->isAccelerated());
244 // don't do this before calling it the first time when the context is lost.
245 bridge->prepareSurfaceForPaintingIfNeeded();
246 244
247 // When the context is lost we are not sure if we should still be producing 245 // When the context is lost we are not sure if we should still be producing
248 // GL frames for the compositor or not, so fail to generate frames. 246 // GL frames for the compositor or not, so fail to generate frames.
249 gl.setIsContextLost(true); 247 gl.setIsContextLost(true);
250 248
251 cc::TextureMailbox textureMailbox; 249 cc::TextureMailbox textureMailbox;
252 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback; 250 std::unique_ptr<cc::SingleReleaseCallback> releaseCallback;
253 EXPECT_FALSE( 251 EXPECT_FALSE(
254 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback)); 252 bridge->PrepareTextureMailbox(&textureMailbox, &releaseCallback));
255 } 253 }
256 254
257 void prepareMailboxWhenContextIsLostWithFailedRestore() { 255 void prepareMailboxWhenContextIsLostWithFailedRestore() {
258 FakeGLES2Interface gl; 256 FakeGLES2Interface gl;
259 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = 257 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider =
260 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl)); 258 WTF::wrapUnique(new FakeWebGraphicsContext3DProvider(&gl));
261 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge( 259 Canvas2DLayerBridgePtr bridge(adoptRef(new Canvas2DLayerBridge(
262 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque, 260 std::move(contextProvider), IntSize(300, 150), 0, NonOpaque,
263 Canvas2DLayerBridge::ForceAccelerationForTesting, 261 Canvas2DLayerBridge::ForceAccelerationForTesting,
264 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType))); 262 gfx::ColorSpace::CreateSRGB(), false, kN32_SkColorType)));
265 263
266 // TODO(junov): The PrepareTextureMailbox() method will fail a DCHECK if we 264 bridge->getOrCreateSurface();
267 // don't do this before calling it the first time when the context is lost. 265 EXPECT_TRUE(bridge->checkSurfaceValid());
268 bridge->prepareSurfaceForPaintingIfNeeded();
269
270 // When the context is lost we are not sure if we should still be producing 266 // When the context is lost we are not sure if we should still be producing
271 // GL frames for the compositor or not, so fail to generate frames. 267 // GL frames for the compositor or not, so fail to generate frames.
272 gl.setIsContextLost(true); 268 gl.setIsContextLost(true);
273 EXPECT_FALSE(bridge->checkSurfaceValid()); 269 EXPECT_FALSE(bridge->checkSurfaceValid());
274 270
275 // Restoration will fail because 271 // Restoration will fail because
276 // Platform::createSharedOffscreenGraphicsContext3DProvider() is stubbed 272 // Platform::createSharedOffscreenGraphicsContext3DProvider() is stubbed
277 // in unit tests. This simulates what would happen when attempting to 273 // in unit tests. This simulates what would happen when attempting to
278 // restore while the GPU process is down. 274 // restore while the GPU process is down.
279 bridge->restoreSurface(); 275 bridge->restoreSurface();
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 gpu::gles2::GLES2Interface* gl, 409 gpu::gles2::GLES2Interface* gl,
414 Canvas2DLayerBridgeTest* testHost, 410 Canvas2DLayerBridgeTest* testHost,
415 WaitableEvent* doneEvent) { 411 WaitableEvent* doneEvent) {
416 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider = 412 std::unique_ptr<FakeWebGraphicsContext3DProvider> contextProvider =
417 WTF::makeUnique<FakeWebGraphicsContext3DProvider>(gl); 413 WTF::makeUnique<FakeWebGraphicsContext3DProvider>(gl);
418 *bridgePtr = 414 *bridgePtr =
419 testHost->makeBridge(std::move(contextProvider), IntSize(300, 300), 415 testHost->makeBridge(std::move(contextProvider), IntSize(300, 300),
420 Canvas2DLayerBridge::EnableAcceleration); 416 Canvas2DLayerBridge::EnableAcceleration);
421 // draw+flush to trigger the creation of a GPU surface 417 // draw+flush to trigger the creation of a GPU surface
422 (*bridgePtr)->didDraw(FloatRect(0, 0, 1, 1)); 418 (*bridgePtr)->didDraw(FloatRect(0, 0, 1, 1));
423 (*bridgePtr)->finalizeFrame(FloatRect(0, 0, 1, 1)); 419 (*bridgePtr)->finalizeFrame();
424 (*bridgePtr)->flush(); 420 (*bridgePtr)->flush();
425 doneEvent->signal(); 421 doneEvent->signal();
426 } 422 }
427 423
428 void postAndWaitCreateBridgeTask(const WebTraceLocation& location, 424 void postAndWaitCreateBridgeTask(const WebTraceLocation& location,
429 WebThread* testThread, 425 WebThread* testThread,
430 Canvas2DLayerBridgePtr* bridgePtr, 426 Canvas2DLayerBridgePtr* bridgePtr,
431 gpu::gles2::GLES2Interface* gl, 427 gpu::gles2::GLES2Interface* gl,
432 Canvas2DLayerBridgeTest* testHost) { 428 Canvas2DLayerBridgeTest* testHost) {
433 std::unique_ptr<WaitableEvent> bridgeCreatedEvent = 429 std::unique_ptr<WaitableEvent> bridgeCreatedEvent =
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 EXPECT_FALSE(bridge->isHibernating()); 668 EXPECT_FALSE(bridge->isHibernating());
673 EXPECT_TRUE(bridge->checkSurfaceValid()); 669 EXPECT_TRUE(bridge->checkSurfaceValid());
674 670
675 // Tear down the bridge on the thread so that 'bridge' can go out of scope 671 // Tear down the bridge on the thread so that 'bridge' can go out of scope
676 // without crashing due to thread checks 672 // without crashing due to thread checks
677 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge); 673 postAndWaitDestroyBridgeTask(BLINK_FROM_HERE, testThread.get(), &bridge);
678 } 674 }
679 675
680 void runRenderingTask(Canvas2DLayerBridge* bridge, WaitableEvent* doneEvent) { 676 void runRenderingTask(Canvas2DLayerBridge* bridge, WaitableEvent* doneEvent) {
681 bridge->didDraw(FloatRect(0, 0, 1, 1)); 677 bridge->didDraw(FloatRect(0, 0, 1, 1));
682 bridge->finalizeFrame(FloatRect(0, 0, 1, 1)); 678 bridge->finalizeFrame();
683 bridge->flush(); 679 bridge->flush();
684 doneEvent->signal(); 680 doneEvent->signal();
685 } 681 }
686 682
687 void postAndWaitRenderingTask(const WebTraceLocation& location, 683 void postAndWaitRenderingTask(const WebTraceLocation& location,
688 WebThread* testThread, 684 WebThread* testThread,
689 Canvas2DLayerBridge* bridge) { 685 Canvas2DLayerBridge* bridge) {
690 std::unique_ptr<WaitableEvent> doneEvent = WTF::makeUnique<WaitableEvent>(); 686 std::unique_ptr<WaitableEvent> doneEvent = WTF::makeUnique<WaitableEvent>();
691 testThread->getWebTaskRunner()->postTask( 687 testThread->getWebTaskRunner()->postTask(
692 location, 688 location,
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after
1372 EXPECT_FALSE(bridge->hasRecordedDrawCommands()); 1368 EXPECT_FALSE(bridge->hasRecordedDrawCommands());
1373 ::testing::Mock::VerifyAndClearExpectations(&gl); 1369 ::testing::Mock::VerifyAndClearExpectations(&gl);
1374 1370
1375 EXPECT_CALL(gl, Flush()).Times(1); 1371 EXPECT_CALL(gl, Flush()).Times(1);
1376 bridge->flushGpu(); 1372 bridge->flushGpu();
1377 EXPECT_FALSE(bridge->hasRecordedDrawCommands()); 1373 EXPECT_FALSE(bridge->hasRecordedDrawCommands());
1378 ::testing::Mock::VerifyAndClearExpectations(&gl); 1374 ::testing::Mock::VerifyAndClearExpectations(&gl);
1379 } 1375 }
1380 1376
1381 } // namespace blink 1377 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698