| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/layer_tree_host_impl.h" | 5 #include "cc/layer_tree_host_impl.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/hash_tables.h" | 11 #include "base/hash_tables.h" |
| 12 #include "cc/compositor_frame_metadata.h" | 12 #include "cc/compositor_frame_metadata.h" |
| 13 #include "cc/delegated_renderer_layer_impl.h" | 13 #include "cc/delegated_renderer_layer_impl.h" |
| 14 #include "cc/gl_renderer.h" | 14 #include "cc/gl_renderer.h" |
| 15 #include "cc/heads_up_display_layer_impl.h" | 15 #include "cc/heads_up_display_layer_impl.h" |
| 16 #include "cc/io_surface_layer_impl.h" | 16 #include "cc/io_surface_layer_impl.h" |
| 17 #include "cc/layer_impl.h" | 17 #include "cc/layer_impl.h" |
| 18 #include "cc/layer_tiling_data.h" | 18 #include "cc/layer_tiling_data.h" |
| 19 #include "cc/layer_tree_impl.h" | 19 #include "cc/layer_tree_impl.h" |
| 20 #include "cc/math_util.h" | 20 #include "cc/math_util.h" |
| 21 #include "cc/quad_sink.h" | 21 #include "cc/quad_sink.h" |
| 22 #include "cc/render_pass_draw_quad.h" | 22 #include "cc/render_pass_draw_quad.h" |
| 23 #include "cc/scrollbar_geometry_fixed_thumb.h" | 23 #include "cc/scrollbar_geometry_fixed_thumb.h" |
| 24 #include "cc/scrollbar_layer_impl.h" | 24 #include "cc/scrollbar_layer_impl.h" |
| 25 #include "cc/single_thread_proxy.h" | 25 #include "cc/single_thread_proxy.h" |
| 26 #include "cc/solid_color_draw_quad.h" | 26 #include "cc/solid_color_draw_quad.h" |
| 27 #include "cc/test/animation_test_common.h" | 27 #include "cc/test/animation_test_common.h" |
| 28 #include "cc/test/fake_output_surface.h" | 28 #include "cc/test/fake_output_surface.h" |
| 29 #include "cc/test/fake_proxy.h" | 29 #include "cc/test/fake_proxy.h" |
| 30 #include "cc/test/fake_video_frame.h" |
| 31 #include "cc/test/fake_video_frame_provider.h" |
| 30 #include "cc/test/fake_web_graphics_context_3d.h" | 32 #include "cc/test/fake_web_graphics_context_3d.h" |
| 31 #include "cc/test/fake_web_scrollbar_theme_geometry.h" | 33 #include "cc/test/fake_web_scrollbar_theme_geometry.h" |
| 32 #include "cc/test/geometry_test_utils.h" | 34 #include "cc/test/geometry_test_utils.h" |
| 33 #include "cc/test/layer_test_common.h" | 35 #include "cc/test/layer_test_common.h" |
| 34 #include "cc/test/render_pass_test_common.h" | 36 #include "cc/test/render_pass_test_common.h" |
| 35 #include "cc/texture_draw_quad.h" | 37 #include "cc/texture_draw_quad.h" |
| 36 #include "cc/texture_layer_impl.h" | 38 #include "cc/texture_layer_impl.h" |
| 37 #include "cc/tile_draw_quad.h" | 39 #include "cc/tile_draw_quad.h" |
| 38 #include "cc/tiled_layer_impl.h" | 40 #include "cc/tiled_layer_impl.h" |
| 39 #include "cc/video_layer_impl.h" | 41 #include "cc/video_layer_impl.h" |
| 40 #include "media/base/media.h" | 42 #include "media/base/media.h" |
| 41 #include "media/base/video_frame.h" | |
| 42 #include "testing/gmock/include/gmock/gmock.h" | 43 #include "testing/gmock/include/gmock/gmock.h" |
| 43 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
| 44 #include "third_party/WebKit/Source/Platform/chromium/public/WebVideoFrame.h" | |
| 45 #include "third_party/WebKit/Source/Platform/chromium/public/WebVideoFrameProvid
er.h" | |
| 46 #include "ui/gfx/size_conversions.h" | 45 #include "ui/gfx/size_conversions.h" |
| 47 #include "ui/gfx/vector2d_conversions.h" | 46 #include "ui/gfx/vector2d_conversions.h" |
| 48 | 47 |
| 49 using media::VideoFrame; | |
| 50 using ::testing::Mock; | 48 using ::testing::Mock; |
| 51 using ::testing::Return; | 49 using ::testing::Return; |
| 52 using ::testing::AnyNumber; | 50 using ::testing::AnyNumber; |
| 53 using ::testing::AtLeast; | 51 using ::testing::AtLeast; |
| 54 using ::testing::_; | 52 using ::testing::_; |
| 55 | 53 |
| 56 namespace cc { | 54 namespace cc { |
| 57 namespace { | 55 namespace { |
| 58 | 56 |
| 59 // This test is parametrized to run all tests with the | 57 // This test is parametrized to run all tests with the |
| (...skipping 2158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2218 EXPECT_CALL(*m_context, disable(_)) | 2216 EXPECT_CALL(*m_context, disable(_)) |
| 2219 .WillRepeatedly(Return()); | 2217 .WillRepeatedly(Return()); |
| 2220 } | 2218 } |
| 2221 | 2219 |
| 2222 void mustDrawSolidQuad() | 2220 void mustDrawSolidQuad() |
| 2223 { | 2221 { |
| 2224 EXPECT_CALL(*m_context, drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT,
0)) | 2222 EXPECT_CALL(*m_context, drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT,
0)) |
| 2225 .WillOnce(Return()) | 2223 .WillOnce(Return()) |
| 2226 .RetiresOnSaturation(); | 2224 .RetiresOnSaturation(); |
| 2227 | 2225 |
| 2228 // 1 is hardcoded return value of fake createProgram() | 2226 EXPECT_CALL(*m_context, useProgram(_)) |
| 2229 EXPECT_CALL(*m_context, useProgram(1)) | |
| 2230 .WillOnce(Return()) | 2227 .WillOnce(Return()) |
| 2231 .RetiresOnSaturation(); | 2228 .RetiresOnSaturation(); |
| 2232 | 2229 |
| 2233 } | 2230 } |
| 2234 | 2231 |
| 2235 void mustSetScissor(int x, int y, int width, int height) | 2232 void mustSetScissor(int x, int y, int width, int height) |
| 2236 { | 2233 { |
| 2237 EXPECT_CALL(*m_context, enable(GL_SCISSOR_TEST)) | 2234 EXPECT_CALL(*m_context, enable(GL_SCISSOR_TEST)) |
| 2238 .WillRepeatedly(Return()); | 2235 .WillRepeatedly(Return()); |
| 2239 | 2236 |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2447 ASSERT_EQ(1U, frame.renderPasses[0]->quad_list.size()); | 2444 ASSERT_EQ(1U, frame.renderPasses[0]->quad_list.size()); |
| 2448 ASSERT_EQ(1U, frame.renderPasses[1]->quad_list.size()); | 2445 ASSERT_EQ(1U, frame.renderPasses[1]->quad_list.size()); |
| 2449 EXPECT_EQ(DrawQuad::SOLID_COLOR, frame.renderPasses[0]->quad_list[0]->ma
terial); | 2446 EXPECT_EQ(DrawQuad::SOLID_COLOR, frame.renderPasses[0]->quad_list[0]->ma
terial); |
| 2450 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[1]->quad_list[0]->ma
terial); | 2447 EXPECT_EQ(DrawQuad::RENDER_PASS, frame.renderPasses[1]->quad_list[0]->ma
terial); |
| 2451 | 2448 |
| 2452 myHostImpl->drawLayers(frame); | 2449 myHostImpl->drawLayers(frame); |
| 2453 myHostImpl->didDrawAllLayers(frame); | 2450 myHostImpl->didDrawAllLayers(frame); |
| 2454 } | 2451 } |
| 2455 } | 2452 } |
| 2456 | 2453 |
| 2457 // Make sure that output surface lost notifications are propagated through the t
ree. | |
| 2458 class OutputSurfaceLostNotificationCheckLayer : public LayerImpl { | |
| 2459 public: | |
| 2460 static scoped_ptr<LayerImpl> create(LayerTreeImpl* treeImpl, int id) { retur
n scoped_ptr<LayerImpl>(new OutputSurfaceLostNotificationCheckLayer(treeImpl, id
)); } | |
| 2461 | |
| 2462 virtual void didLoseOutputSurface() OVERRIDE | |
| 2463 { | |
| 2464 m_didLoseOutputSurfaceCalled = true; | |
| 2465 } | |
| 2466 | |
| 2467 bool didLoseOutputSurfaceCalled() const { return m_didLoseOutputSurfaceCalle
d; } | |
| 2468 | |
| 2469 private: | |
| 2470 OutputSurfaceLostNotificationCheckLayer(LayerTreeImpl* treeImpl, int id) | |
| 2471 : LayerImpl(treeImpl, id) | |
| 2472 , m_didLoseOutputSurfaceCalled(false) | |
| 2473 { | |
| 2474 } | |
| 2475 | |
| 2476 bool m_didLoseOutputSurfaceCalled; | |
| 2477 }; | |
| 2478 | |
| 2479 TEST_P(LayerTreeHostImplTest, outputSurfaceLostAndRestoredNotificationSentToAllL
ayers) | |
| 2480 { | |
| 2481 m_hostImpl->setRootLayer(OutputSurfaceLostNotificationCheckLayer::create(m_h
ostImpl->activeTree(), 1)); | |
| 2482 OutputSurfaceLostNotificationCheckLayer* root = static_cast<OutputSurfaceLos
tNotificationCheckLayer*>(m_hostImpl->rootLayer()); | |
| 2483 | |
| 2484 root->addChild(OutputSurfaceLostNotificationCheckLayer::create(m_hostImpl->a
ctiveTree(), 2)); | |
| 2485 OutputSurfaceLostNotificationCheckLayer* layer1 = static_cast<OutputSurfaceL
ostNotificationCheckLayer*>(root->children()[0]); | |
| 2486 | |
| 2487 layer1->addChild(OutputSurfaceLostNotificationCheckLayer::create(m_hostImpl-
>activeTree(), 3)); | |
| 2488 OutputSurfaceLostNotificationCheckLayer* layer2 = static_cast<OutputSurfaceL
ostNotificationCheckLayer*>(layer1->children()[0]); | |
| 2489 | |
| 2490 EXPECT_FALSE(root->didLoseOutputSurfaceCalled()); | |
| 2491 EXPECT_FALSE(layer1->didLoseOutputSurfaceCalled()); | |
| 2492 EXPECT_FALSE(layer2->didLoseOutputSurfaceCalled()); | |
| 2493 | |
| 2494 m_hostImpl->initializeRenderer(createOutputSurface()); | |
| 2495 | |
| 2496 EXPECT_TRUE(root->didLoseOutputSurfaceCalled()); | |
| 2497 EXPECT_TRUE(layer1->didLoseOutputSurfaceCalled()); | |
| 2498 EXPECT_TRUE(layer2->didLoseOutputSurfaceCalled()); | |
| 2499 } | |
| 2500 | |
| 2501 TEST_P(LayerTreeHostImplTest, finishAllRenderingAfterContextLost) | |
| 2502 { | |
| 2503 LayerTreeSettings settings; | |
| 2504 m_hostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); | |
| 2505 | |
| 2506 // The context initialization will fail, but we should still be able to call
finishAllRendering() without any ill effects. | |
| 2507 m_hostImpl->initializeRenderer(FakeOutputSurface::Create3d(scoped_ptr<WebKit
::WebGraphicsContext3D>(new FakeWebGraphicsContext3DMakeCurrentFails)).PassAs<Ou
tputSurface>()); | |
| 2508 m_hostImpl->finishAllRendering(); | |
| 2509 } | |
| 2510 | |
| 2511 class FakeWebGraphicsContext3DMakeCurrentFailsEventually : public FakeWebGraphic
sContext3D { | |
| 2512 public: | |
| 2513 explicit FakeWebGraphicsContext3DMakeCurrentFailsEventually(unsigned succeed
Count) : m_succeedCount(succeedCount) { } | |
| 2514 virtual bool makeContextCurrent() { | |
| 2515 if (!m_succeedCount) | |
| 2516 return false; | |
| 2517 --m_succeedCount; | |
| 2518 return true; | |
| 2519 } | |
| 2520 | |
| 2521 private: | |
| 2522 unsigned m_succeedCount; | |
| 2523 }; | |
| 2524 | |
| 2525 TEST_P(LayerTreeHostImplTest, context3DLostDuringInitialize) | |
| 2526 { | |
| 2527 LayerTreeSettings settings; | |
| 2528 m_hostImpl = LayerTreeHostImpl::create(settings, this, &m_proxy); | |
| 2529 | |
| 2530 // Initialize into a known successful state. | |
| 2531 EXPECT_TRUE(m_hostImpl->initializeRenderer(createOutputSurface())); | |
| 2532 EXPECT_TRUE(m_hostImpl->outputSurface()); | |
| 2533 EXPECT_TRUE(m_hostImpl->renderer()); | |
| 2534 EXPECT_TRUE(m_hostImpl->resourceProvider()); | |
| 2535 | |
| 2536 // We will make the context get lost after a numer of makeContextCurrent | |
| 2537 // calls. The exact number of calls to make it succeed is dependent on the | |
| 2538 // implementation and doesn't really matter (i.e. can be changed to make the | |
| 2539 // tests pass after some refactoring). | |
| 2540 const unsigned kMakeCurrentSuccessesNeededForSuccessfulInitialization = 3; | |
| 2541 | |
| 2542 for (unsigned i = 0; i < kMakeCurrentSuccessesNeededForSuccessfulInitializat
ion; ++i) { | |
| 2543 // The context will get lost during initialization, we shouldn't crash.
We | |
| 2544 // should also be in a consistent state. | |
| 2545 EXPECT_FALSE(m_hostImpl->initializeRenderer(FakeOutputSurface::Create3d(
scoped_ptr<WebKit::WebGraphicsContext3D>(new FakeWebGraphicsContext3DMakeCurrent
FailsEventually(i))).PassAs<OutputSurface>())); | |
| 2546 EXPECT_EQ(0, m_hostImpl->outputSurface()); | |
| 2547 EXPECT_EQ(0, m_hostImpl->renderer()); | |
| 2548 EXPECT_EQ(0, m_hostImpl->resourceProvider()); | |
| 2549 EXPECT_TRUE(m_hostImpl->initializeRenderer(createOutputSurface())); | |
| 2550 } | |
| 2551 | |
| 2552 EXPECT_TRUE(m_hostImpl->initializeRenderer(FakeOutputSurface::Create3d(scope
d_ptr<WebKit::WebGraphicsContext3D>(new FakeWebGraphicsContext3DMakeCurrentFails
Eventually(kMakeCurrentSuccessesNeededForSuccessfulInitialization))).PassAs<Outp
utSurface>())); | |
| 2553 EXPECT_TRUE(m_hostImpl->outputSurface()); | |
| 2554 EXPECT_TRUE(m_hostImpl->renderer()); | |
| 2555 EXPECT_TRUE(m_hostImpl->resourceProvider()); | |
| 2556 } | |
| 2557 | |
| 2558 // Fake WebKit::WebGraphicsContext3D that will cause a failure if trying to use
a | |
| 2559 // resource that wasn't created by it (resources created by | |
| 2560 // FakeWebGraphicsContext3D have an id of 1). | |
| 2561 class StrictWebGraphicsContext3D : public FakeWebGraphicsContext3D { | |
| 2562 public: | |
| 2563 StrictWebGraphicsContext3D() | |
| 2564 : FakeWebGraphicsContext3D() | |
| 2565 { | |
| 2566 next_texture_id_ = 8; // Start allocating texture ids larger than any ot
her resource IDs so we can tell if someone's mixing up their resource types. | |
| 2567 } | |
| 2568 | |
| 2569 virtual WebKit::WebGLId createBuffer() { return 2; } | |
| 2570 virtual WebKit::WebGLId createFramebuffer() { return 3; } | |
| 2571 virtual WebKit::WebGLId createProgram() { return 4; } | |
| 2572 virtual WebKit::WebGLId createRenderbuffer() { return 5; } | |
| 2573 virtual WebKit::WebGLId createShader(WebKit::WGC3Denum) { return 6; } | |
| 2574 | |
| 2575 static const WebKit::WebGLId kExternalTextureId = 7; | |
| 2576 | |
| 2577 virtual void deleteBuffer(WebKit::WebGLId id) | |
| 2578 { | |
| 2579 if (id != 2) | |
| 2580 ADD_FAILURE() << "Trying to delete buffer id " << id; | |
| 2581 } | |
| 2582 | |
| 2583 virtual void deleteFramebuffer(WebKit::WebGLId id) | |
| 2584 { | |
| 2585 if (id != 3) | |
| 2586 ADD_FAILURE() << "Trying to delete framebuffer id " << id; | |
| 2587 } | |
| 2588 | |
| 2589 virtual void deleteProgram(WebKit::WebGLId id) | |
| 2590 { | |
| 2591 if (id != 4) | |
| 2592 ADD_FAILURE() << "Trying to delete program id " << id; | |
| 2593 } | |
| 2594 | |
| 2595 virtual void deleteRenderbuffer(WebKit::WebGLId id) | |
| 2596 { | |
| 2597 if (id != 5) | |
| 2598 ADD_FAILURE() << "Trying to delete renderbuffer id " << id; | |
| 2599 } | |
| 2600 | |
| 2601 virtual void deleteShader(WebKit::WebGLId id) | |
| 2602 { | |
| 2603 if (id != 6) | |
| 2604 ADD_FAILURE() << "Trying to delete shader id " << id; | |
| 2605 } | |
| 2606 | |
| 2607 virtual WebKit::WebGLId createTexture() | |
| 2608 { | |
| 2609 unsigned textureId = FakeWebGraphicsContext3D::createTexture(); | |
| 2610 m_allocatedTextureIds.insert(textureId); | |
| 2611 return textureId; | |
| 2612 } | |
| 2613 virtual void deleteTexture(WebKit::WebGLId id) | |
| 2614 { | |
| 2615 if (id == kExternalTextureId) | |
| 2616 ADD_FAILURE() << "Trying to delete external texture"; | |
| 2617 if (!ContainsKey(m_allocatedTextureIds, id)) | |
| 2618 ADD_FAILURE() << "Trying to delete texture id " << id; | |
| 2619 m_allocatedTextureIds.erase(id); | |
| 2620 } | |
| 2621 | |
| 2622 virtual void bindBuffer(WebKit::WGC3Denum, WebKit::WebGLId id) | |
| 2623 { | |
| 2624 if (id != 2 && id) | |
| 2625 ADD_FAILURE() << "Trying to bind buffer id " << id; | |
| 2626 } | |
| 2627 | |
| 2628 virtual void bindFramebuffer(WebKit::WGC3Denum, WebKit::WebGLId id) | |
| 2629 { | |
| 2630 if (id != 3 && id) | |
| 2631 ADD_FAILURE() << "Trying to bind framebuffer id " << id; | |
| 2632 } | |
| 2633 | |
| 2634 virtual void useProgram(WebKit::WebGLId id) | |
| 2635 { | |
| 2636 if (id != 4) | |
| 2637 ADD_FAILURE() << "Trying to use program id " << id; | |
| 2638 } | |
| 2639 | |
| 2640 virtual void bindRenderbuffer(WebKit::WGC3Denum, WebKit::WebGLId id) | |
| 2641 { | |
| 2642 if (id != 5 && id) | |
| 2643 ADD_FAILURE() << "Trying to bind renderbuffer id " << id; | |
| 2644 } | |
| 2645 | |
| 2646 virtual void attachShader(WebKit::WebGLId program, WebKit::WebGLId shader) | |
| 2647 { | |
| 2648 if ((program != 4) || (shader != 6)) | |
| 2649 ADD_FAILURE() << "Trying to attach shader id " << shader << " to pro
gram id " << program; | |
| 2650 } | |
| 2651 | |
| 2652 virtual void bindTexture(WebKit::WGC3Denum, WebKit::WebGLId id) | |
| 2653 { | |
| 2654 if (id && id != kExternalTextureId && !ContainsKey(m_allocatedTextureIds
, id)) | |
| 2655 ADD_FAILURE() << "Trying to bind texture id " << id; | |
| 2656 } | |
| 2657 | |
| 2658 private: | |
| 2659 base::hash_set<unsigned> m_allocatedTextureIds; | |
| 2660 }; | |
| 2661 | |
| 2662 // Fake WebKit::WebVideoFrame wrapper of media::VideoFrame. | |
| 2663 class FakeVideoFrame: public WebKit::WebVideoFrame { | |
| 2664 public: | |
| 2665 explicit FakeVideoFrame(const scoped_refptr<VideoFrame>& frame) : m_frame(fr
ame) { } | |
| 2666 virtual ~FakeVideoFrame() { } | |
| 2667 | |
| 2668 virtual Format format() const { NOTREACHED(); return FormatInvalid; } | |
| 2669 virtual unsigned width() const { NOTREACHED(); return 0; } | |
| 2670 virtual unsigned height() const { NOTREACHED(); return 0; } | |
| 2671 virtual unsigned planes() const { NOTREACHED(); return 0; } | |
| 2672 virtual int stride(unsigned plane) const { NOTREACHED(); return 0; } | |
| 2673 virtual const void* data(unsigned plane) const { NOTREACHED(); return NULL;
} | |
| 2674 virtual unsigned textureId() const { NOTREACHED(); return 0; } | |
| 2675 virtual unsigned textureTarget() const { NOTREACHED(); return 0; } | |
| 2676 virtual WebKit::WebRect visibleRect() const { NOTREACHED(); return WebKit::W
ebRect(0, 0, 0, 0); } | |
| 2677 virtual WebKit::WebSize textureSize() const { NOTREACHED(); return WebKit::W
ebSize(4, 4); } | |
| 2678 | |
| 2679 static VideoFrame* toVideoFrame(WebKit::WebVideoFrame* web_video_frame) { | |
| 2680 FakeVideoFrame* wrapped_frame = | |
| 2681 static_cast<FakeVideoFrame*>(web_video_frame); | |
| 2682 if (wrapped_frame) | |
| 2683 return wrapped_frame->m_frame.get(); | |
| 2684 return NULL; | |
| 2685 } | |
| 2686 | |
| 2687 private: | |
| 2688 scoped_refptr<VideoFrame> m_frame; | |
| 2689 }; | |
| 2690 | |
| 2691 // Fake video frame provider that always provides the same FakeVideoFrame. | |
| 2692 class FakeVideoFrameProvider: public WebKit::WebVideoFrameProvider { | |
| 2693 public: | |
| 2694 FakeVideoFrameProvider() : m_frame(0), m_client(0) { } | |
| 2695 virtual ~FakeVideoFrameProvider() | |
| 2696 { | |
| 2697 if (m_client) | |
| 2698 m_client->stopUsingProvider(); | |
| 2699 } | |
| 2700 | |
| 2701 virtual void setVideoFrameProviderClient(Client* client) { m_client = client
; } | |
| 2702 virtual WebKit::WebVideoFrame* getCurrentFrame() { return m_frame; } | |
| 2703 virtual void putCurrentFrame(WebKit::WebVideoFrame*) { } | |
| 2704 | |
| 2705 void setFrame(WebKit::WebVideoFrame* frame) { m_frame = frame; } | |
| 2706 | |
| 2707 private: | |
| 2708 WebKit::WebVideoFrame* m_frame; | |
| 2709 Client* m_client; | |
| 2710 }; | |
| 2711 | |
| 2712 class StrictWebGraphicsContext3DWithIOSurface : public StrictWebGraphicsContext3
D { | |
| 2713 public: | |
| 2714 virtual WebKit::WebString getString(WebKit::WGC3Denum name) OVERRIDE | |
| 2715 { | |
| 2716 if (name == GL_EXTENSIONS) | |
| 2717 return WebKit::WebString("GL_CHROMIUM_iosurface GL_ARB_texture_recta
ngle"); | |
| 2718 | |
| 2719 return WebKit::WebString(); | |
| 2720 } | |
| 2721 }; | |
| 2722 | |
| 2723 class FakeWebGraphicsContext3DWithIOSurface : public FakeWebGraphicsContext3D { | |
| 2724 public: | |
| 2725 virtual WebKit::WebString getString(WebKit::WGC3Denum name) OVERRIDE | |
| 2726 { | |
| 2727 if (name == GL_EXTENSIONS) | |
| 2728 return WebKit::WebString("GL_CHROMIUM_iosurface GL_ARB_texture_recta
ngle"); | |
| 2729 | |
| 2730 return WebKit::WebString(); | |
| 2731 } | |
| 2732 }; | |
| 2733 | |
| 2734 class FakeWebScrollbarThemeGeometryNonEmpty : public FakeWebScrollbarThemeGeomet
ry { | |
| 2735 virtual WebKit::WebRect trackRect(WebKit::WebScrollbar*) OVERRIDE { return W
ebKit::WebRect(0, 0, 10, 10); } | |
| 2736 virtual WebKit::WebRect thumbRect(WebKit::WebScrollbar*) OVERRIDE { return W
ebKit::WebRect(0, 5, 5, 2); } | |
| 2737 virtual void splitTrack(WebKit::WebScrollbar*, const WebKit::WebRect& track,
WebKit::WebRect& startTrack, WebKit::WebRect& thumb, WebKit::WebRect& endTrack)
OVERRIDE | |
| 2738 { | |
| 2739 thumb = WebKit::WebRect(0, 5, 5, 2); | |
| 2740 startTrack = WebKit::WebRect(0, 5, 0, 5); | |
| 2741 endTrack = WebKit::WebRect(0, 0, 0, 5); | |
| 2742 } | |
| 2743 }; | |
| 2744 | |
| 2745 class FakeScrollbarLayerImpl : public ScrollbarLayerImpl { | |
| 2746 public: | |
| 2747 static scoped_ptr<FakeScrollbarLayerImpl> create(LayerTreeImpl* treeImpl, in
t id) | |
| 2748 { | |
| 2749 return make_scoped_ptr(new FakeScrollbarLayerImpl(treeImpl, id)); | |
| 2750 } | |
| 2751 | |
| 2752 void createResources(ResourceProvider* provider) | |
| 2753 { | |
| 2754 DCHECK(provider); | |
| 2755 gfx::Size size(10, 10); | |
| 2756 GLenum format = GL_RGBA; | |
| 2757 ResourceProvider::TextureUsageHint hint = ResourceProvider::TextureUsage
Any; | |
| 2758 setScrollbarGeometry(ScrollbarGeometryFixedThumb::create(FakeWebScrollba
rThemeGeometryNonEmpty::create())); | |
| 2759 | |
| 2760 setBackTrackResourceId(provider->createResource(size, format, hint)); | |
| 2761 setForeTrackResourceId(provider->createResource(size, format, hint)); | |
| 2762 setThumbResourceId(provider->createResource(size, format, hint)); | |
| 2763 } | |
| 2764 | |
| 2765 protected: | |
| 2766 FakeScrollbarLayerImpl(LayerTreeImpl* treeImpl, int id) | |
| 2767 : ScrollbarLayerImpl(treeImpl, id) | |
| 2768 { | |
| 2769 } | |
| 2770 }; | |
| 2771 | |
| 2772 static inline scoped_ptr<RenderPass> createRenderPassWithResource(ResourceProvid
er* provider) | |
| 2773 { | |
| 2774 ResourceProvider::ResourceId resourceId = provider->createResource(gfx::Size
(1, 1), GL_RGBA, ResourceProvider::TextureUsageAny); | |
| 2775 | |
| 2776 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); | |
| 2777 pass->SetNew(RenderPass::Id(1, 1), gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1,
1), gfx::Transform()); | |
| 2778 scoped_ptr<SharedQuadState> sharedState = SharedQuadState::Create(); | |
| 2779 sharedState->SetAll(gfx::Transform(), gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0,
1, 1), gfx::Rect(0, 0, 1, 1), false, 1); | |
| 2780 const float vertex_opacity[] = {1.0f, 1.0f, 1.0f, 1.0f}; | |
| 2781 scoped_ptr<TextureDrawQuad> quad = TextureDrawQuad::Create(); | |
| 2782 quad->SetNew(sharedState.get(), gfx::Rect(0, 0, 1, 1), gfx::Rect(0, 0, 1, 1)
, resourceId, false, gfx::RectF(0, 0, 1, 1), vertex_opacity, false); | |
| 2783 | |
| 2784 pass->AppendSharedQuadState(sharedState.Pass()); | |
| 2785 pass->AppendQuad(quad.PassAs<DrawQuad>()); | |
| 2786 | |
| 2787 return pass.PassAs<RenderPass>(); | |
| 2788 } | |
| 2789 | |
| 2790 TEST_P(LayerTreeHostImplTest, dontUseOldResourcesAfterLostOutputSurface) | |
| 2791 { | |
| 2792 int layerId = 1; | |
| 2793 | |
| 2794 scoped_ptr<LayerImpl> rootLayer(LayerImpl::create(m_hostImpl->activeTree(),
layerId++)); | |
| 2795 rootLayer->setBounds(gfx::Size(10, 10)); | |
| 2796 rootLayer->setAnchorPoint(gfx::PointF(0, 0)); | |
| 2797 | |
| 2798 scoped_ptr<TiledLayerImpl> tileLayer = TiledLayerImpl::create(m_hostImpl->ac
tiveTree(), layerId++); | |
| 2799 tileLayer->setBounds(gfx::Size(10, 10)); | |
| 2800 tileLayer->setAnchorPoint(gfx::PointF(0, 0)); | |
| 2801 tileLayer->setContentBounds(gfx::Size(10, 10)); | |
| 2802 tileLayer->setDrawsContent(true); | |
| 2803 tileLayer->setSkipsDraw(false); | |
| 2804 scoped_ptr<LayerTilingData> tilingData(LayerTilingData::create(gfx::Size(10,
10), LayerTilingData::NoBorderTexels)); | |
| 2805 tilingData->setBounds(gfx::Size(10, 10)); | |
| 2806 tileLayer->setTilingData(*tilingData); | |
| 2807 tileLayer->pushTileProperties(0, 0, 1, gfx::Rect(0, 0, 10, 10), false); | |
| 2808 rootLayer->addChild(tileLayer.PassAs<LayerImpl>()); | |
| 2809 | |
| 2810 scoped_ptr<TextureLayerImpl> textureLayer = TextureLayerImpl::create(m_hostI
mpl->activeTree(), layerId++); | |
| 2811 textureLayer->setBounds(gfx::Size(10, 10)); | |
| 2812 textureLayer->setAnchorPoint(gfx::PointF(0, 0)); | |
| 2813 textureLayer->setContentBounds(gfx::Size(10, 10)); | |
| 2814 textureLayer->setDrawsContent(true); | |
| 2815 textureLayer->setTextureId(StrictWebGraphicsContext3D::kExternalTextureId); | |
| 2816 rootLayer->addChild(textureLayer.PassAs<LayerImpl>()); | |
| 2817 | |
| 2818 scoped_ptr<TiledLayerImpl> maskLayer = TiledLayerImpl::create(m_hostImpl->ac
tiveTree(), layerId++); | |
| 2819 maskLayer->setBounds(gfx::Size(10, 10)); | |
| 2820 maskLayer->setAnchorPoint(gfx::PointF(0, 0)); | |
| 2821 maskLayer->setContentBounds(gfx::Size(10, 10)); | |
| 2822 maskLayer->setDrawsContent(true); | |
| 2823 maskLayer->setSkipsDraw(false); | |
| 2824 maskLayer->setTilingData(*tilingData); | |
| 2825 maskLayer->pushTileProperties(0, 0, 1, gfx::Rect(0, 0, 10, 10), false); | |
| 2826 | |
| 2827 scoped_ptr<TextureLayerImpl> textureLayerWithMask = TextureLayerImpl::create
(m_hostImpl->activeTree(), layerId++); | |
| 2828 textureLayerWithMask->setBounds(gfx::Size(10, 10)); | |
| 2829 textureLayerWithMask->setAnchorPoint(gfx::PointF(0, 0)); | |
| 2830 textureLayerWithMask->setContentBounds(gfx::Size(10, 10)); | |
| 2831 textureLayerWithMask->setDrawsContent(true); | |
| 2832 textureLayerWithMask->setTextureId(StrictWebGraphicsContext3D::kExternalText
ureId); | |
| 2833 textureLayerWithMask->setMaskLayer(maskLayer.PassAs<LayerImpl>()); | |
| 2834 rootLayer->addChild(textureLayerWithMask.PassAs<LayerImpl>()); | |
| 2835 | |
| 2836 FakeVideoFrame videoFrame(VideoFrame::CreateColorFrame(gfx::Size(4, 4), | |
| 2837 0x80, 0x80, 0x80, | |
| 2838 base::TimeDelta())); | |
| 2839 VideoLayerImpl::FrameUnwrapper unwrapper = | |
| 2840 base::Bind(FakeVideoFrame::toVideoFrame); | |
| 2841 FakeVideoFrameProvider provider; | |
| 2842 provider.setFrame(&videoFrame); | |
| 2843 scoped_ptr<VideoLayerImpl> videoLayer = VideoLayerImpl::create(m_hostImpl->a
ctiveTree(), layerId++, &provider, unwrapper); | |
| 2844 videoLayer->setBounds(gfx::Size(10, 10)); | |
| 2845 videoLayer->setAnchorPoint(gfx::PointF(0, 0)); | |
| 2846 videoLayer->setContentBounds(gfx::Size(10, 10)); | |
| 2847 videoLayer->setDrawsContent(true); | |
| 2848 rootLayer->addChild(videoLayer.PassAs<LayerImpl>()); | |
| 2849 | |
| 2850 FakeVideoFrameProvider providerScaled; | |
| 2851 scoped_ptr<VideoLayerImpl> videoLayerScaled = VideoLayerImpl::create(m_hostI
mpl->activeTree(), layerId++, &providerScaled, unwrapper); | |
| 2852 videoLayerScaled->setBounds(gfx::Size(10, 10)); | |
| 2853 videoLayerScaled->setAnchorPoint(gfx::PointF(0, 0)); | |
| 2854 videoLayerScaled->setContentBounds(gfx::Size(10, 10)); | |
| 2855 videoLayerScaled->setDrawsContent(true); | |
| 2856 rootLayer->addChild(videoLayerScaled.PassAs<LayerImpl>()); | |
| 2857 | |
| 2858 FakeVideoFrameProvider hwProvider; | |
| 2859 scoped_ptr<VideoLayerImpl> hwVideoLayer = VideoLayerImpl::create(m_hostImpl-
>activeTree(), layerId++, &hwProvider, unwrapper); | |
| 2860 hwVideoLayer->setBounds(gfx::Size(10, 10)); | |
| 2861 hwVideoLayer->setAnchorPoint(gfx::PointF(0, 0)); | |
| 2862 hwVideoLayer->setContentBounds(gfx::Size(10, 10)); | |
| 2863 hwVideoLayer->setDrawsContent(true); | |
| 2864 rootLayer->addChild(hwVideoLayer.PassAs<LayerImpl>()); | |
| 2865 | |
| 2866 scoped_ptr<IOSurfaceLayerImpl> ioSurfaceLayer = IOSurfaceLayerImpl::create(m
_hostImpl->activeTree(), layerId++); | |
| 2867 ioSurfaceLayer->setBounds(gfx::Size(10, 10)); | |
| 2868 ioSurfaceLayer->setAnchorPoint(gfx::PointF(0, 0)); | |
| 2869 ioSurfaceLayer->setContentBounds(gfx::Size(10, 10)); | |
| 2870 ioSurfaceLayer->setDrawsContent(true); | |
| 2871 ioSurfaceLayer->setIOSurfaceProperties(1, gfx::Size(10, 10)); | |
| 2872 rootLayer->addChild(ioSurfaceLayer.PassAs<LayerImpl>()); | |
| 2873 | |
| 2874 scoped_ptr<HeadsUpDisplayLayerImpl> hudLayer = HeadsUpDisplayLayerImpl::crea
te(m_hostImpl->activeTree(), layerId++); | |
| 2875 hudLayer->setBounds(gfx::Size(10, 10)); | |
| 2876 hudLayer->setAnchorPoint(gfx::PointF(0, 0)); | |
| 2877 hudLayer->setContentBounds(gfx::Size(10, 10)); | |
| 2878 hudLayer->setDrawsContent(true); | |
| 2879 rootLayer->addChild(hudLayer.PassAs<LayerImpl>()); | |
| 2880 | |
| 2881 scoped_ptr<FakeScrollbarLayerImpl> scrollbarLayer(FakeScrollbarLayerImpl::cr
eate(m_hostImpl->activeTree(), layerId++)); | |
| 2882 scrollbarLayer->setBounds(gfx::Size(10, 10)); | |
| 2883 scrollbarLayer->setContentBounds(gfx::Size(10, 10)); | |
| 2884 scrollbarLayer->setDrawsContent(true); | |
| 2885 scrollbarLayer->createResources(m_hostImpl->resourceProvider()); | |
| 2886 rootLayer->addChild(scrollbarLayer.PassAs<LayerImpl>()); | |
| 2887 | |
| 2888 scoped_ptr<DelegatedRendererLayerImpl> delegatedRendererLayer(DelegatedRende
rerLayerImpl::create(m_hostImpl->activeTree(), layerId++)); | |
| 2889 delegatedRendererLayer->setBounds(gfx::Size(10, 10)); | |
| 2890 delegatedRendererLayer->setContentBounds(gfx::Size(10, 10)); | |
| 2891 delegatedRendererLayer->setDrawsContent(true); | |
| 2892 ScopedPtrVector<RenderPass> passList; | |
| 2893 passList.append(createRenderPassWithResource(m_hostImpl->resourceProvider())
); | |
| 2894 delegatedRendererLayer->setRenderPasses(passList); | |
| 2895 EXPECT_TRUE(passList.isEmpty()); | |
| 2896 rootLayer->addChild(delegatedRendererLayer.PassAs<LayerImpl>()); | |
| 2897 | |
| 2898 // Use a context that supports IOSurfaces | |
| 2899 m_hostImpl->initializeRenderer(FakeOutputSurface::Create3d(scoped_ptr<WebKit
::WebGraphicsContext3D>(new FakeWebGraphicsContext3DWithIOSurface)).PassAs<Outpu
tSurface>()); | |
| 2900 | |
| 2901 FakeVideoFrame hwVideoFrame( | |
| 2902 VideoFrame::WrapNativeTexture( | |
| 2903 m_hostImpl->resourceProvider()->graphicsContext3D()->createTexture()
, | |
| 2904 GL_TEXTURE_2D, | |
| 2905 gfx::Size(4, 4), gfx::Rect(0, 0, 4, 4), gfx::Size(4, 4), base::TimeD
elta(), | |
| 2906 VideoFrame::ReadPixelsCB(), base::Closure())); | |
| 2907 hwProvider.setFrame(&hwVideoFrame); | |
| 2908 | |
| 2909 FakeVideoFrame videoFrameScaled( | |
| 2910 VideoFrame::WrapNativeTexture( | |
| 2911 m_hostImpl->resourceProvider()->graphicsContext3D()->createTexture()
, | |
| 2912 GL_TEXTURE_2D, | |
| 2913 gfx::Size(4, 4), gfx::Rect(0, 0, 3, 2), gfx::Size(4, 4), base::TimeD
elta(), | |
| 2914 VideoFrame::ReadPixelsCB(), base::Closure())); | |
| 2915 providerScaled.setFrame(&videoFrameScaled); | |
| 2916 | |
| 2917 m_hostImpl->setRootLayer(rootLayer.Pass()); | |
| 2918 | |
| 2919 LayerTreeHostImpl::FrameData frame; | |
| 2920 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | |
| 2921 m_hostImpl->drawLayers(frame); | |
| 2922 m_hostImpl->didDrawAllLayers(frame); | |
| 2923 m_hostImpl->swapBuffers(); | |
| 2924 | |
| 2925 unsigned numResources = m_hostImpl->resourceProvider()->numResources(); | |
| 2926 | |
| 2927 // Lose the WebKit::WebGraphicsContext3D, replacing it with a StrictWebGraph
icsContext3DWithIOSurface, | |
| 2928 // that will warn if any resource from the previous context gets used. | |
| 2929 m_hostImpl->initializeRenderer(FakeOutputSurface::Create3d(scoped_ptr<WebKit
::WebGraphicsContext3D>(new StrictWebGraphicsContext3DWithIOSurface)).PassAs<Out
putSurface>()); | |
| 2930 | |
| 2931 // Create dummy resources so that looking up an old resource will get an | |
| 2932 // invalid texture id mapping. | |
| 2933 for (unsigned i = 0; i < numResources; ++i) | |
| 2934 m_hostImpl->resourceProvider()->createResourceFromExternalTexture(Strict
WebGraphicsContext3D::kExternalTextureId); | |
| 2935 | |
| 2936 // The WebKit::WebVideoFrameProvider is expected to recreate its textures af
ter a | |
| 2937 // lost output surface (or not serve a frame). | |
| 2938 hwProvider.setFrame(0); | |
| 2939 providerScaled.setFrame(0); | |
| 2940 | |
| 2941 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | |
| 2942 m_hostImpl->drawLayers(frame); | |
| 2943 m_hostImpl->didDrawAllLayers(frame); | |
| 2944 m_hostImpl->swapBuffers(); | |
| 2945 | |
| 2946 FakeVideoFrame hwVideoFrame2( | |
| 2947 VideoFrame::WrapNativeTexture( | |
| 2948 m_hostImpl->resourceProvider()->graphicsContext3D()->createTexture()
, | |
| 2949 GL_TEXTURE_2D, | |
| 2950 gfx::Size(4, 4), gfx::Rect(0, 0, 4, 4), gfx::Size(4, 4), base::TimeD
elta(), | |
| 2951 VideoFrame::ReadPixelsCB(), base::Closure())); | |
| 2952 hwProvider.setFrame(&hwVideoFrame2); | |
| 2953 | |
| 2954 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | |
| 2955 m_hostImpl->drawLayers(frame); | |
| 2956 m_hostImpl->didDrawAllLayers(frame); | |
| 2957 m_hostImpl->swapBuffers(); | |
| 2958 } | |
| 2959 | |
| 2960 // Fake WebKit::WebGraphicsContext3D that tracks the number of textures in use. | 2454 // Fake WebKit::WebGraphicsContext3D that tracks the number of textures in use. |
| 2961 class TrackingWebGraphicsContext3D : public FakeWebGraphicsContext3D { | 2455 class TrackingWebGraphicsContext3D : public FakeWebGraphicsContext3D { |
| 2962 public: | 2456 public: |
| 2963 TrackingWebGraphicsContext3D() | 2457 TrackingWebGraphicsContext3D() |
| 2964 : FakeWebGraphicsContext3D() | 2458 : FakeWebGraphicsContext3D() |
| 2965 , m_numTextures(0) | 2459 , m_numTextures(0) |
| 2966 { } | 2460 { } |
| 2967 | 2461 |
| 2968 virtual WebKit::WebGLId createTexture() OVERRIDE | 2462 virtual WebKit::WebGLId createTexture() OVERRIDE |
| 2969 { | 2463 { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2991 return WebKit::WebString(); | 2485 return WebKit::WebString(); |
| 2992 } | 2486 } |
| 2993 | 2487 |
| 2994 unsigned numTextures() const { return m_numTextures; } | 2488 unsigned numTextures() const { return m_numTextures; } |
| 2995 | 2489 |
| 2996 private: | 2490 private: |
| 2997 base::hash_map<WebKit::WebGLId, bool> m_textures; | 2491 base::hash_map<WebKit::WebGLId, bool> m_textures; |
| 2998 unsigned m_numTextures; | 2492 unsigned m_numTextures; |
| 2999 }; | 2493 }; |
| 3000 | 2494 |
| 2495 static unsigned createResourceId(ResourceProvider* resourceProvider) |
| 2496 { |
| 2497 return resourceProvider->createResource( |
| 2498 gfx::Size(20, 12), |
| 2499 resourceProvider->bestTextureFormat(), |
| 2500 ResourceProvider::TextureUsageAny); |
| 2501 } |
| 2502 |
| 2503 static unsigned createTextureId(ResourceProvider* resourceProvider) |
| 2504 { |
| 2505 return ResourceProvider::ScopedReadLockGL( |
| 2506 resourceProvider, createResourceId(resourceProvider)).textureId(); |
| 2507 } |
| 2508 |
| 3001 TEST_P(LayerTreeHostImplTest, layersFreeTextures) | 2509 TEST_P(LayerTreeHostImplTest, layersFreeTextures) |
| 3002 { | 2510 { |
| 2511 scoped_ptr<FakeWebGraphicsContext3D> context = |
| 2512 FakeWebGraphicsContext3D::Create(); |
| 2513 FakeWebGraphicsContext3D* context3d = context.get(); |
| 2514 scoped_ptr<OutputSurface> outputSurface = FakeOutputSurface::Create3d( |
| 2515 context.PassAs<WebKit::WebGraphicsContext3D>()).PassAs<OutputSurface>(); |
| 2516 m_hostImpl->initializeRenderer(outputSurface.Pass()); |
| 2517 |
| 3003 scoped_ptr<LayerImpl> rootLayer(LayerImpl::create(m_hostImpl->activeTree(),
1)); | 2518 scoped_ptr<LayerImpl> rootLayer(LayerImpl::create(m_hostImpl->activeTree(),
1)); |
| 3004 rootLayer->setBounds(gfx::Size(10, 10)); | 2519 rootLayer->setBounds(gfx::Size(10, 10)); |
| 3005 rootLayer->setAnchorPoint(gfx::PointF(0, 0)); | 2520 rootLayer->setAnchorPoint(gfx::PointF(0, 0)); |
| 3006 | 2521 |
| 3007 scoped_ptr<TiledLayerImpl> tileLayer = TiledLayerImpl::create(m_hostImpl->ac
tiveTree(), 2); | 2522 FakeVideoFrame softwareFrame(media::VideoFrame::CreateColorFrame( |
| 3008 tileLayer->setBounds(gfx::Size(10, 10)); | 2523 gfx::Size(4, 4), 0x80, 0x80, 0x80, base::TimeDelta())); |
| 3009 tileLayer->setAnchorPoint(gfx::PointF(0, 0)); | |
| 3010 tileLayer->setContentBounds(gfx::Size(10, 10)); | |
| 3011 tileLayer->setDrawsContent(true); | |
| 3012 tileLayer->setSkipsDraw(false); | |
| 3013 scoped_ptr<LayerTilingData> tilingData(LayerTilingData::create(gfx::Size(10,
10), LayerTilingData::NoBorderTexels)); | |
| 3014 tilingData->setBounds(gfx::Size(10, 10)); | |
| 3015 tileLayer->setTilingData(*tilingData); | |
| 3016 tileLayer->pushTileProperties(0, 0, 1, gfx::Rect(0, 0, 10, 10), false); | |
| 3017 rootLayer->addChild(tileLayer.PassAs<LayerImpl>()); | |
| 3018 | |
| 3019 scoped_ptr<TextureLayerImpl> textureLayer = TextureLayerImpl::create(m_hostI
mpl->activeTree(), 3); | |
| 3020 textureLayer->setBounds(gfx::Size(10, 10)); | |
| 3021 textureLayer->setAnchorPoint(gfx::PointF(0, 0)); | |
| 3022 textureLayer->setContentBounds(gfx::Size(10, 10)); | |
| 3023 textureLayer->setDrawsContent(true); | |
| 3024 textureLayer->setTextureId(1); | |
| 3025 rootLayer->addChild(textureLayer.PassAs<LayerImpl>()); | |
| 3026 | |
| 3027 VideoLayerImpl::FrameUnwrapper unwrapper = | 2524 VideoLayerImpl::FrameUnwrapper unwrapper = |
| 3028 base::Bind(FakeVideoFrame::toVideoFrame); | 2525 base::Bind(FakeVideoFrame::ToVideoFrame); |
| 3029 FakeVideoFrameProvider provider; | 2526 FakeVideoFrameProvider provider; |
| 2527 provider.set_frame(&softwareFrame); |
| 3030 scoped_ptr<VideoLayerImpl> videoLayer = VideoLayerImpl::create(m_hostImpl->a
ctiveTree(), 4, &provider, unwrapper); | 2528 scoped_ptr<VideoLayerImpl> videoLayer = VideoLayerImpl::create(m_hostImpl->a
ctiveTree(), 4, &provider, unwrapper); |
| 3031 videoLayer->setBounds(gfx::Size(10, 10)); | 2529 videoLayer->setBounds(gfx::Size(10, 10)); |
| 3032 videoLayer->setAnchorPoint(gfx::PointF(0, 0)); | 2530 videoLayer->setAnchorPoint(gfx::PointF(0, 0)); |
| 3033 videoLayer->setContentBounds(gfx::Size(10, 10)); | 2531 videoLayer->setContentBounds(gfx::Size(10, 10)); |
| 3034 videoLayer->setDrawsContent(true); | 2532 videoLayer->setDrawsContent(true); |
| 3035 rootLayer->addChild(videoLayer.PassAs<LayerImpl>()); | 2533 rootLayer->addChild(videoLayer.PassAs<LayerImpl>()); |
| 3036 | 2534 |
| 3037 scoped_ptr<IOSurfaceLayerImpl> ioSurfaceLayer = IOSurfaceLayerImpl::create(m
_hostImpl->activeTree(), 5); | 2535 scoped_ptr<IOSurfaceLayerImpl> ioSurfaceLayer = IOSurfaceLayerImpl::create(m
_hostImpl->activeTree(), 5); |
| 3038 ioSurfaceLayer->setBounds(gfx::Size(10, 10)); | 2536 ioSurfaceLayer->setBounds(gfx::Size(10, 10)); |
| 3039 ioSurfaceLayer->setAnchorPoint(gfx::PointF(0, 0)); | 2537 ioSurfaceLayer->setAnchorPoint(gfx::PointF(0, 0)); |
| 3040 ioSurfaceLayer->setContentBounds(gfx::Size(10, 10)); | 2538 ioSurfaceLayer->setContentBounds(gfx::Size(10, 10)); |
| 3041 ioSurfaceLayer->setDrawsContent(true); | 2539 ioSurfaceLayer->setDrawsContent(true); |
| 3042 ioSurfaceLayer->setIOSurfaceProperties(1, gfx::Size(10, 10)); | 2540 ioSurfaceLayer->setIOSurfaceProperties(1, gfx::Size(10, 10)); |
| 3043 rootLayer->addChild(ioSurfaceLayer.PassAs<LayerImpl>()); | 2541 rootLayer->addChild(ioSurfaceLayer.PassAs<LayerImpl>()); |
| 3044 | 2542 |
| 3045 // Lose the WebGraphicsContext3D, replacing it with a TrackingWebGraphicsCon
text3D (which the LayerTreeHostImpl takes ownership of). | 2543 m_hostImpl->setRootLayer(rootLayer.Pass()); |
| 3046 scoped_ptr<OutputSurface> outputSurface(FakeOutputSurface::Create3d(scoped_p
tr<WebKit::WebGraphicsContext3D>(new TrackingWebGraphicsContext3D))); | |
| 3047 TrackingWebGraphicsContext3D* trackingWebGraphicsContext3D = static_cast<Tra
ckingWebGraphicsContext3D*>(outputSurface->Context3D()); | |
| 3048 m_hostImpl->initializeRenderer(outputSurface.Pass()); | |
| 3049 | 2544 |
| 3050 m_hostImpl->setRootLayer(rootLayer.Pass()); | 2545 EXPECT_EQ(0u, context3d->NumTextures()); |
| 3051 | 2546 |
| 3052 LayerTreeHostImpl::FrameData frame; | 2547 LayerTreeHostImpl::FrameData frame; |
| 3053 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 2548 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
| 3054 m_hostImpl->drawLayers(frame); | 2549 m_hostImpl->drawLayers(frame); |
| 3055 m_hostImpl->didDrawAllLayers(frame); | 2550 m_hostImpl->didDrawAllLayers(frame); |
| 3056 m_hostImpl->swapBuffers(); | 2551 m_hostImpl->swapBuffers(); |
| 3057 | 2552 |
| 3058 EXPECT_GT(trackingWebGraphicsContext3D->numTextures(), 0u); | 2553 EXPECT_GT(context3d->NumTextures(), 0u); |
| 3059 | 2554 |
| 3060 // Kill the layer tree. | 2555 // Kill the layer tree. |
| 3061 m_hostImpl->setRootLayer(LayerImpl::create(m_hostImpl->activeTree(), 100)); | 2556 m_hostImpl->setRootLayer(LayerImpl::create(m_hostImpl->activeTree(), 100)); |
| 3062 // There should be no textures left in use after. | 2557 // There should be no textures left in use after. |
| 3063 EXPECT_EQ(0u, trackingWebGraphicsContext3D->numTextures()); | 2558 EXPECT_EQ(0u, context3d->NumTextures()); |
| 3064 } | 2559 } |
| 3065 | 2560 |
| 3066 class MockDrawQuadsToFillScreenContext : public FakeWebGraphicsContext3D { | 2561 class MockDrawQuadsToFillScreenContext : public FakeWebGraphicsContext3D { |
| 3067 public: | 2562 public: |
| 3068 MOCK_METHOD1(useProgram, void(WebKit::WebGLId program)); | 2563 MOCK_METHOD1(useProgram, void(WebKit::WebGLId program)); |
| 3069 MOCK_METHOD4(drawElements, void(WebKit::WGC3Denum mode, WebKit::WGC3Dsizei c
ount, WebKit::WGC3Denum type, WebKit::WGC3Dintptr offset)); | 2564 MOCK_METHOD4(drawElements, void(WebKit::WGC3Denum mode, WebKit::WGC3Dsizei c
ount, WebKit::WGC3Denum type, WebKit::WGC3Dintptr offset)); |
| 3070 }; | 2565 }; |
| 3071 | 2566 |
| 3072 TEST_P(LayerTreeHostImplTest, hasTransparentBackground) | 2567 TEST_P(LayerTreeHostImplTest, hasTransparentBackground) |
| 3073 { | 2568 { |
| (...skipping 1771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4845 gfx::Rect noDamage = gfx::Rect(m_hostImpl->deviceViewportSize()); | 4340 gfx::Rect noDamage = gfx::Rect(m_hostImpl->deviceViewportSize()); |
| 4846 drawFrameAndTestDamage(noDamage); | 4341 drawFrameAndTestDamage(noDamage); |
| 4847 } | 4342 } |
| 4848 | 4343 |
| 4849 INSTANTIATE_TEST_CASE_P(LayerTreeHostImplTests, | 4344 INSTANTIATE_TEST_CASE_P(LayerTreeHostImplTests, |
| 4850 LayerTreeHostImplTest, | 4345 LayerTreeHostImplTest, |
| 4851 ::testing::Values(false, true)); | 4346 ::testing::Values(false, true)); |
| 4852 | 4347 |
| 4853 } // namespace | 4348 } // namespace |
| 4854 } // namespace cc | 4349 } // namespace cc |
| OLD | NEW |