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/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/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" |
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 EXPECT_EQ(4.f, metadata.max_page_scale_factor); | 987 EXPECT_EQ(4.f, metadata.max_page_scale_factor); |
988 } | 988 } |
989 } | 989 } |
990 | 990 |
991 class DidDrawCheckLayer : public TiledLayerImpl { | 991 class DidDrawCheckLayer : public TiledLayerImpl { |
992 public: | 992 public: |
993 static scoped_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) { | 993 static scoped_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) { |
994 return scoped_ptr<LayerImpl>(new DidDrawCheckLayer(tree_impl, id)); | 994 return scoped_ptr<LayerImpl>(new DidDrawCheckLayer(tree_impl, id)); |
995 } | 995 } |
996 | 996 |
997 virtual void DidDraw(ResourceProvider*) OVERRIDE { | 997 virtual void DidDraw(ResourceProvider* provider) OVERRIDE { |
998 did_draw_called_ = true; | 998 did_draw_called_ = true; |
999 } | 999 } |
1000 | 1000 |
1001 virtual void WillDraw(ResourceProvider*) OVERRIDE { | 1001 virtual void WillDraw(ResourceProvider* provider) OVERRIDE { |
1002 will_draw_called_ = true; | 1002 will_draw_called_ = true; |
1003 } | 1003 } |
1004 | 1004 |
1005 bool did_draw_called() const { return did_draw_called_; } | 1005 bool did_draw_called() const { return did_draw_called_; } |
1006 bool will_draw_called() const { return will_draw_called_; } | 1006 bool will_draw_called() const { return will_draw_called_; } |
1007 | 1007 |
1008 void ClearDidDrawCheck() { | 1008 void ClearDidDrawCheck() { |
1009 did_draw_called_ = false; | 1009 did_draw_called_ = false; |
1010 will_draw_called_ = false; | 1010 will_draw_called_ = false; |
1011 } | 1011 } |
(...skipping 1299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2311 // without blending. | 2311 // without blending. |
2312 layer1->SetContentsOpaque(false); | 2312 layer1->SetContentsOpaque(false); |
2313 layer1->SetQuadRect(gfx::Rect(5, 5, 5, 5)); | 2313 layer1->SetQuadRect(gfx::Rect(5, 5, 5, 5)); |
2314 layer1->SetQuadVisibleRect(gfx::Rect(5, 5, 2, 5)); | 2314 layer1->SetQuadVisibleRect(gfx::Rect(5, 5, 2, 5)); |
2315 layer1->SetOpaqueContentRect(gfx::Rect(5, 5, 2, 5)); | 2315 layer1->SetOpaqueContentRect(gfx::Rect(5, 5, 2, 5)); |
2316 layer1->SetExpectation(false, false); | 2316 layer1->SetExpectation(false, false); |
2317 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); | 2317 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame)); |
2318 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); | 2318 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); |
2319 EXPECT_TRUE(layer1->quads_appended()); | 2319 EXPECT_TRUE(layer1->quads_appended()); |
2320 host_impl_->DidDrawAllLayers(frame); | 2320 host_impl_->DidDrawAllLayers(frame); |
2321 | |
2322 } | 2321 } |
2323 | 2322 |
2324 TEST_F(LayerTreeHostImplTest, ViewportCovered) { | 2323 TEST_F(LayerTreeHostImplTest, ViewportCovered) { |
2325 host_impl_->InitializeRenderer(CreateOutputSurface()); | 2324 host_impl_->InitializeRenderer(CreateOutputSurface()); |
2326 host_impl_->active_tree()->set_background_color(SK_ColorGRAY); | 2325 host_impl_->active_tree()->set_background_color(SK_ColorGRAY); |
2327 | 2326 |
2328 gfx::Size viewport_size(1000, 1000); | 2327 gfx::Size viewport_size(1000, 1000); |
2329 host_impl_->SetViewportSize(viewport_size, viewport_size); | 2328 host_impl_->SetViewportSize(viewport_size, viewport_size); |
2330 | 2329 |
2331 host_impl_->active_tree()->SetRootLayer( | 2330 host_impl_->active_tree()->SetRootLayer( |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2406 for (size_t i = 0; i < frame.render_passes[0]->quad_list.size(); ++i) | 2405 for (size_t i = 0; i < frame.render_passes[0]->quad_list.size(); ++i) |
2407 num_gutter_quads += (frame.render_passes[0]->quad_list[i]->material == | 2406 num_gutter_quads += (frame.render_passes[0]->quad_list[i]->material == |
2408 DrawQuad::SOLID_COLOR) ? 1 : 0; | 2407 DrawQuad::SOLID_COLOR) ? 1 : 0; |
2409 EXPECT_EQ(4u, num_gutter_quads); | 2408 EXPECT_EQ(4u, num_gutter_quads); |
2410 EXPECT_EQ(5u, frame.render_passes[0]->quad_list.size()); | 2409 EXPECT_EQ(5u, frame.render_passes[0]->quad_list.size()); |
2411 | 2410 |
2412 LayerTestCommon::VerifyQuadsExactlyCoverRect( | 2411 LayerTestCommon::VerifyQuadsExactlyCoverRect( |
2413 frame.render_passes[0]->quad_list, gfx::Rect(viewport_size)); | 2412 frame.render_passes[0]->quad_list, gfx::Rect(viewport_size)); |
2414 host_impl_->DidDrawAllLayers(frame); | 2413 host_impl_->DidDrawAllLayers(frame); |
2415 } | 2414 } |
2416 | |
2417 } | 2415 } |
2418 | 2416 |
2419 | 2417 |
2420 class ReshapeTrackerContext: public TestWebGraphicsContext3D { | 2418 class ReshapeTrackerContext: public TestWebGraphicsContext3D { |
2421 public: | 2419 public: |
2422 ReshapeTrackerContext() : reshape_called_(false) {} | 2420 ReshapeTrackerContext() : reshape_called_(false) {} |
2423 | 2421 |
2424 virtual void reshape(int width, int height) OVERRIDE { | 2422 virtual void reshape(int width, int height) OVERRIDE { |
2425 reshape_called_ = true; | 2423 reshape_called_ = true; |
2426 } | 2424 } |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2647 MOCK_METHOD1(disable, void(WebKit::WGC3Denum cap)); | 2645 MOCK_METHOD1(disable, void(WebKit::WGC3Denum cap)); |
2648 MOCK_METHOD4(scissor, void(WebKit::WGC3Dint x, | 2646 MOCK_METHOD4(scissor, void(WebKit::WGC3Dint x, |
2649 WebKit::WGC3Dint y, | 2647 WebKit::WGC3Dint y, |
2650 WebKit::WGC3Dsizei width, | 2648 WebKit::WGC3Dsizei width, |
2651 WebKit::WGC3Dsizei height)); | 2649 WebKit::WGC3Dsizei height)); |
2652 }; | 2650 }; |
2653 | 2651 |
2654 class MockContextHarness { | 2652 class MockContextHarness { |
2655 private: | 2653 private: |
2656 MockContext* context_; | 2654 MockContext* context_; |
| 2655 |
2657 public: | 2656 public: |
2658 MockContextHarness(MockContext* context) | 2657 explicit MockContextHarness(MockContext* context) |
2659 : context_(context) { | 2658 : context_(context) { |
2660 // Catch "uninteresting" calls | 2659 // Catch "uninteresting" calls |
2661 EXPECT_CALL(*context_, useProgram(_)) | 2660 EXPECT_CALL(*context_, useProgram(_)) |
2662 .Times(0); | 2661 .Times(0); |
2663 | 2662 |
2664 EXPECT_CALL(*context_, drawElements(_, _, _, _)) | 2663 EXPECT_CALL(*context_, drawElements(_, _, _, _)) |
2665 .Times(0); | 2664 .Times(0); |
2666 | 2665 |
2667 // These are not asserted | 2666 // These are not asserted |
2668 EXPECT_CALL(*context_, uniformMatrix4fv(_, _, _, _)) | 2667 EXPECT_CALL(*context_, uniformMatrix4fv(_, _, _, _)) |
(...skipping 25 matching lines...) Expand all Loading... |
2694 } | 2693 } |
2695 | 2694 |
2696 void MustDrawSolidQuad() { | 2695 void MustDrawSolidQuad() { |
2697 EXPECT_CALL(*context_, drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0)) | 2696 EXPECT_CALL(*context_, drawElements(GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, 0)) |
2698 .WillOnce(Return()) | 2697 .WillOnce(Return()) |
2699 .RetiresOnSaturation(); | 2698 .RetiresOnSaturation(); |
2700 | 2699 |
2701 EXPECT_CALL(*context_, useProgram(_)) | 2700 EXPECT_CALL(*context_, useProgram(_)) |
2702 .WillOnce(Return()) | 2701 .WillOnce(Return()) |
2703 .RetiresOnSaturation(); | 2702 .RetiresOnSaturation(); |
2704 | |
2705 } | 2703 } |
2706 | 2704 |
2707 void MustSetScissor(int x, int y, int width, int height) { | 2705 void MustSetScissor(int x, int y, int width, int height) { |
2708 EXPECT_CALL(*context_, enable(GL_SCISSOR_TEST)) | 2706 EXPECT_CALL(*context_, enable(GL_SCISSOR_TEST)) |
2709 .WillRepeatedly(Return()); | 2707 .WillRepeatedly(Return()); |
2710 | 2708 |
2711 EXPECT_CALL(*context_, scissor(x, y, width, height)) | 2709 EXPECT_CALL(*context_, scissor(x, y, width, height)) |
2712 .Times(AtLeast(1)) | 2710 .Times(AtLeast(1)) |
2713 .WillRepeatedly(Return()); | 2711 .WillRepeatedly(Return()); |
2714 } | 2712 } |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3275 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); | 3273 EXPECT_TRUE(my_host_impl->PrepareToDraw(&frame)); |
3276 | 3274 |
3277 // Must receive 1 render pass - for the root. | 3275 // Must receive 1 render pass - for the root. |
3278 ASSERT_EQ(1U, frame.render_passes.size()); | 3276 ASSERT_EQ(1U, frame.render_passes.size()); |
3279 | 3277 |
3280 EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size()); | 3278 EXPECT_EQ(2U, frame.render_passes[0]->quad_list.size()); |
3281 | 3279 |
3282 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); | 3280 my_host_impl->DrawLayers(&frame, base::TimeTicks::Now()); |
3283 my_host_impl->DidDrawAllLayers(frame); | 3281 my_host_impl->DidDrawAllLayers(frame); |
3284 } | 3282 } |
3285 | |
3286 } | 3283 } |
3287 | 3284 |
3288 TEST_F(LayerTreeHostImplTest, TextureCachingWithOcclusionEarlyOut) { | 3285 TEST_F(LayerTreeHostImplTest, TextureCachingWithOcclusionEarlyOut) { |
3289 LayerTreeSettings settings; | 3286 LayerTreeSettings settings; |
3290 settings.minimum_occlusion_tracking_size = gfx::Size(); | 3287 settings.minimum_occlusion_tracking_size = gfx::Size(); |
3291 settings.cache_render_pass_contents = true; | 3288 settings.cache_render_pass_contents = true; |
3292 scoped_ptr<LayerTreeHostImpl> my_host_impl = | 3289 scoped_ptr<LayerTreeHostImpl> my_host_impl = |
3293 LayerTreeHostImpl::Create(settings, | 3290 LayerTreeHostImpl::Create(settings, |
3294 this, | 3291 this, |
3295 &proxy_, | 3292 &proxy_, |
(...skipping 1281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4577 | 4574 |
4578 "R0ssssA0sss\n" | 4575 "R0ssssA0sss\n" |
4579 "A0sssB0C0s\n" | 4576 "A0sssB0C0s\n" |
4580 "B0sssD0ss\n" | 4577 "B0sssD0ss\n" |
4581 "D0sssssss\n" | 4578 "D0sssssss\n" |
4582 }, { | 4579 }, { |
4583 0, 0, 0 | 4580 0, 0, 0 |
4584 } | 4581 } |
4585 }; | 4582 }; |
4586 | 4583 |
4587 static void VerifyRenderPassTestData(TestCase& test_case, | 4584 static void VerifyRenderPassTestData( |
4588 RenderPassRemovalTestData& test_data) { | 4585 const TestCase& test_case, |
| 4586 const RenderPassRemovalTestData& test_data) { |
4589 char actual_result[1024]; | 4587 char actual_result[1024]; |
4590 DumpRenderPassTestData(test_data, actual_result); | 4588 DumpRenderPassTestData(test_data, actual_result); |
4591 EXPECT_STREQ(test_case.expected_result, actual_result) << "In test case: " << | 4589 EXPECT_STREQ(test_case.expected_result, actual_result) << "In test case: " << |
4592 test_case.name; | 4590 test_case.name; |
4593 } | 4591 } |
4594 | 4592 |
4595 TEST_F(LayerTreeHostImplTest, TestRemoveRenderPasses) { | 4593 TEST_F(LayerTreeHostImplTest, TestRemoveRenderPasses) { |
4596 scoped_ptr<OutputSurface> output_surface(CreateOutputSurface()); | 4594 scoped_ptr<OutputSurface> output_surface(CreateOutputSurface()); |
4597 ASSERT_TRUE(output_surface->context3d()); | 4595 ASSERT_TRUE(output_surface->context3d()); |
4598 scoped_ptr<ResourceProvider> resource_provider = | 4596 scoped_ptr<ResourceProvider> resource_provider = |
4599 ResourceProvider::Create(output_surface.get()); | 4597 ResourceProvider::Create(output_surface.get()); |
4600 | 4598 |
4601 scoped_ptr<TestRenderer> renderer = | 4599 scoped_ptr<TestRenderer> renderer = |
4602 TestRenderer::Create(resource_provider.get(), | 4600 TestRenderer::Create(resource_provider.get(), |
4603 output_surface.get(), | 4601 output_surface.get(), |
4604 &proxy_); | 4602 &proxy_); |
4605 | 4603 |
4606 int test_case_index = 0; | 4604 int test_case_index = 0; |
4607 while (remove_render_passes_cases[test_case_index].name) { | 4605 while (remove_render_passes_cases[test_case_index].name) { |
4608 RenderPassRemovalTestData test_data; | 4606 RenderPassRemovalTestData test_data; |
4609 ConfigureRenderPassTestData( | 4607 ConfigureRenderPassTestData( |
4610 remove_render_passes_cases[test_case_index].init_script, | 4608 remove_render_passes_cases[test_case_index].init_script, |
4611 test_data, | 4609 test_data, |
4612 renderer.get()); | 4610 renderer.get()); |
4613 LayerTreeHostImpl::RemoveRenderPasses( | 4611 LayerTreeHostImpl::RemoveRenderPasses( |
4614 LayerTreeHostImpl::CullRenderPassesWithCachedTextures(*renderer), | 4612 LayerTreeHostImpl::CullRenderPassesWithCachedTextures(renderer.get()), |
4615 &test_data); | 4613 &test_data); |
4616 VerifyRenderPassTestData(remove_render_passes_cases[test_case_index], | 4614 VerifyRenderPassTestData(remove_render_passes_cases[test_case_index], |
4617 test_data); | 4615 test_data); |
4618 test_case_index++; | 4616 test_case_index++; |
4619 } | 4617 } |
4620 } | 4618 } |
4621 | 4619 |
4622 class LayerTreeHostImplTestWithDelegatingRenderer | 4620 class LayerTreeHostImplTestWithDelegatingRenderer |
4623 : public LayerTreeHostImplTest { | 4621 : public LayerTreeHostImplTest { |
4624 protected: | 4622 protected: |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4956 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), | 4954 EXPECT_EQ(gfx::RectF(0.f, 0.f, 1.f, 1.f).ToString(), |
4957 render_pass_quad->mask_uv_rect.ToString()); | 4955 render_pass_quad->mask_uv_rect.ToString()); |
4958 | 4956 |
4959 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); | 4957 host_impl_->DrawLayers(&frame, base::TimeTicks::Now()); |
4960 host_impl_->DidDrawAllLayers(frame); | 4958 host_impl_->DidDrawAllLayers(frame); |
4961 } | 4959 } |
4962 } | 4960 } |
4963 | 4961 |
4964 } // namespace | 4962 } // namespace |
4965 } // namespace cc | 4963 } // namespace cc |
OLD | NEW |