| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/quads/render_pass.h" | 5 #include "cc/quads/render_pass.h" |
| 6 | 6 |
| 7 #include "cc/base/math_util.h" | 7 #include "cc/base/math_util.h" |
| 8 #include "cc/base/scoped_ptr_vector.h" | 8 #include "cc/base/scoped_ptr_vector.h" |
| 9 #include "cc/output/copy_output_request.h" | 9 #include "cc/output/copy_output_request.h" |
| 10 #include "cc/quads/checkerboard_draw_quad.h" | 10 #include "cc/quads/checkerboard_draw_quad.h" |
| 11 #include "cc/quads/render_pass_draw_quad.h" | 11 #include "cc/quads/render_pass_draw_quad.h" |
| 12 #include "cc/test/geometry_test_utils.h" | 12 #include "cc/test/geometry_test_utils.h" |
| 13 #include "cc/test/render_pass_test_common.h" | 13 #include "cc/test/render_pass_test_common.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "third_party/skia/include/effects/SkBlurImageFilter.h" | 15 #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
| 16 #include "ui/gfx/transform.h" | 16 #include "ui/gfx/transform.h" |
| 17 | 17 |
| 18 using cc::TestRenderPass; | 18 using cc::TestRenderPass; |
| 19 | 19 |
| 20 namespace cc { | 20 namespace cc { |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 struct RenderPassSize { | 23 struct RenderPassSize { |
| 24 // If you add a new field to this class, make sure to add it to the | 24 // If you add a new field to this class, make sure to add it to the |
| 25 // Copy() tests. | 25 // Copy() tests. |
| 26 RenderPass::Id id; | 26 RenderPassId id; |
| 27 QuadList quad_list; | 27 QuadList quad_list; |
| 28 SharedQuadStateList shared_quad_state_list; | 28 SharedQuadStateList shared_quad_state_list; |
| 29 gfx::Transform transform_to_root_target; | 29 gfx::Transform transform_to_root_target; |
| 30 gfx::Rect output_rect; | 30 gfx::Rect output_rect; |
| 31 gfx::Rect damage_rect; | 31 gfx::Rect damage_rect; |
| 32 bool has_transparent_background; | 32 bool has_transparent_background; |
| 33 ScopedPtrVector<CopyOutputRequest> copy_callbacks; | 33 ScopedPtrVector<CopyOutputRequest> copy_callbacks; |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 static void CompareRenderPassLists(const RenderPassList& expected_list, | 36 static void CompareRenderPassLists(const RenderPassList& expected_list, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 56 EXPECT_EQ(expected->quad_list[i]->rect.ToString(), | 56 EXPECT_EQ(expected->quad_list[i]->rect.ToString(), |
| 57 actual->quad_list[i]->rect.ToString()); | 57 actual->quad_list[i]->rect.ToString()); |
| 58 EXPECT_EQ( | 58 EXPECT_EQ( |
| 59 expected->quad_list[i]->shared_quad_state->content_bounds.ToString(), | 59 expected->quad_list[i]->shared_quad_state->content_bounds.ToString(), |
| 60 actual->quad_list[i]->shared_quad_state->content_bounds.ToString()); | 60 actual->quad_list[i]->shared_quad_state->content_bounds.ToString()); |
| 61 } | 61 } |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 | 64 |
| 65 TEST(RenderPassTest, CopyShouldBeIdenticalExceptIdAndQuads) { | 65 TEST(RenderPassTest, CopyShouldBeIdenticalExceptIdAndQuads) { |
| 66 RenderPass::Id id(3, 2); | 66 RenderPassId id(3, 2); |
| 67 gfx::Rect output_rect(45, 22, 120, 13); | 67 gfx::Rect output_rect(45, 22, 120, 13); |
| 68 gfx::Transform transform_to_root = | 68 gfx::Transform transform_to_root = |
| 69 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); | 69 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); |
| 70 gfx::Rect damage_rect(56, 123, 19, 43); | 70 gfx::Rect damage_rect(56, 123, 19, 43); |
| 71 bool has_transparent_background = true; | 71 bool has_transparent_background = true; |
| 72 | 72 |
| 73 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); | 73 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); |
| 74 pass->SetAll(id, | 74 pass->SetAll(id, |
| 75 output_rect, | 75 output_rect, |
| 76 damage_rect, | 76 damage_rect, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 87 false, | 87 false, |
| 88 1, | 88 1, |
| 89 SkXfermode::kSrcOver_Mode, | 89 SkXfermode::kSrcOver_Mode, |
| 90 0); | 90 0); |
| 91 | 91 |
| 92 CheckerboardDrawQuad* checkerboard_quad = | 92 CheckerboardDrawQuad* checkerboard_quad = |
| 93 pass->CreateAndAppendDrawQuad<CheckerboardDrawQuad>(); | 93 pass->CreateAndAppendDrawQuad<CheckerboardDrawQuad>(); |
| 94 checkerboard_quad->SetNew( | 94 checkerboard_quad->SetNew( |
| 95 pass->shared_quad_state_list.back(), gfx::Rect(), gfx::Rect(), SkColor()); | 95 pass->shared_quad_state_list.back(), gfx::Rect(), gfx::Rect(), SkColor()); |
| 96 | 96 |
| 97 RenderPass::Id new_id(63, 4); | 97 RenderPassId new_id(63, 4); |
| 98 | 98 |
| 99 scoped_ptr<RenderPass> copy = pass->Copy(new_id); | 99 scoped_ptr<RenderPass> copy = pass->Copy(new_id); |
| 100 EXPECT_EQ(new_id, copy->id); | 100 EXPECT_EQ(new_id, copy->id); |
| 101 EXPECT_RECT_EQ(pass->output_rect, copy->output_rect); | 101 EXPECT_RECT_EQ(pass->output_rect, copy->output_rect); |
| 102 EXPECT_EQ(pass->transform_to_root_target, copy->transform_to_root_target); | 102 EXPECT_EQ(pass->transform_to_root_target, copy->transform_to_root_target); |
| 103 EXPECT_RECT_EQ(pass->damage_rect, copy->damage_rect); | 103 EXPECT_RECT_EQ(pass->damage_rect, copy->damage_rect); |
| 104 EXPECT_EQ(pass->has_transparent_background, copy->has_transparent_background); | 104 EXPECT_EQ(pass->has_transparent_background, copy->has_transparent_background); |
| 105 EXPECT_EQ(0u, copy->quad_list.size()); | 105 EXPECT_EQ(0u, copy->quad_list.size()); |
| 106 | 106 |
| 107 // The copy request should not be copied/duplicated. | 107 // The copy request should not be copied/duplicated. |
| 108 EXPECT_EQ(1u, pass->copy_requests.size()); | 108 EXPECT_EQ(1u, pass->copy_requests.size()); |
| 109 EXPECT_EQ(0u, copy->copy_requests.size()); | 109 EXPECT_EQ(0u, copy->copy_requests.size()); |
| 110 | 110 |
| 111 EXPECT_EQ(sizeof(RenderPassSize), sizeof(RenderPass)); | 111 EXPECT_EQ(sizeof(RenderPassSize), sizeof(RenderPass)); |
| 112 } | 112 } |
| 113 | 113 |
| 114 TEST(RenderPassTest, CopyAllShouldBeIdentical) { | 114 TEST(RenderPassTest, CopyAllShouldBeIdentical) { |
| 115 RenderPassList pass_list; | 115 RenderPassList pass_list; |
| 116 | 116 |
| 117 RenderPass::Id id(3, 2); | 117 RenderPassId id(3, 2); |
| 118 gfx::Rect output_rect(45, 22, 120, 13); | 118 gfx::Rect output_rect(45, 22, 120, 13); |
| 119 gfx::Transform transform_to_root = | 119 gfx::Transform transform_to_root = |
| 120 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); | 120 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); |
| 121 gfx::Rect damage_rect(56, 123, 19, 43); | 121 gfx::Rect damage_rect(56, 123, 19, 43); |
| 122 bool has_transparent_background = true; | 122 bool has_transparent_background = true; |
| 123 | 123 |
| 124 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); | 124 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); |
| 125 pass->SetAll(id, | 125 pass->SetAll(id, |
| 126 output_rect, | 126 output_rect, |
| 127 damage_rect, | 127 damage_rect, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 SkColor()); | 172 SkColor()); |
| 173 | 173 |
| 174 CheckerboardDrawQuad* checkerboard_quad4 = | 174 CheckerboardDrawQuad* checkerboard_quad4 = |
| 175 pass->CreateAndAppendDrawQuad<CheckerboardDrawQuad>(); | 175 pass->CreateAndAppendDrawQuad<CheckerboardDrawQuad>(); |
| 176 checkerboard_quad4->SetNew(pass->shared_quad_state_list.back(), | 176 checkerboard_quad4->SetNew(pass->shared_quad_state_list.back(), |
| 177 gfx::Rect(4, 4, 4, 4), | 177 gfx::Rect(4, 4, 4, 4), |
| 178 gfx::Rect(4, 4, 4, 4), | 178 gfx::Rect(4, 4, 4, 4), |
| 179 SkColor()); | 179 SkColor()); |
| 180 | 180 |
| 181 // A second render pass with a quad. | 181 // A second render pass with a quad. |
| 182 RenderPass::Id contrib_id(4, 1); | 182 RenderPassId contrib_id(4, 1); |
| 183 gfx::Rect contrib_output_rect(10, 15, 12, 17); | 183 gfx::Rect contrib_output_rect(10, 15, 12, 17); |
| 184 gfx::Transform contrib_transform_to_root = | 184 gfx::Transform contrib_transform_to_root = |
| 185 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); | 185 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); |
| 186 gfx::Rect contrib_damage_rect(11, 16, 10, 15); | 186 gfx::Rect contrib_damage_rect(11, 16, 10, 15); |
| 187 bool contrib_has_transparent_background = true; | 187 bool contrib_has_transparent_background = true; |
| 188 | 188 |
| 189 scoped_ptr<TestRenderPass> contrib = TestRenderPass::Create(); | 189 scoped_ptr<TestRenderPass> contrib = TestRenderPass::Create(); |
| 190 contrib->SetAll(contrib_id, | 190 contrib->SetAll(contrib_id, |
| 191 contrib_output_rect, | 191 contrib_output_rect, |
| 192 contrib_damage_rect, | 192 contrib_damage_rect, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 // Make a copy with CopyAll(). | 230 // Make a copy with CopyAll(). |
| 231 RenderPassList copy_list; | 231 RenderPassList copy_list; |
| 232 RenderPass::CopyAll(pass_list, ©_list); | 232 RenderPass::CopyAll(pass_list, ©_list); |
| 233 | 233 |
| 234 CompareRenderPassLists(pass_list, copy_list); | 234 CompareRenderPassLists(pass_list, copy_list); |
| 235 } | 235 } |
| 236 | 236 |
| 237 TEST(RenderPassTest, CopyAllWithCulledQuads) { | 237 TEST(RenderPassTest, CopyAllWithCulledQuads) { |
| 238 RenderPassList pass_list; | 238 RenderPassList pass_list; |
| 239 | 239 |
| 240 RenderPass::Id id(3, 2); | 240 RenderPassId id(3, 2); |
| 241 gfx::Rect output_rect(45, 22, 120, 13); | 241 gfx::Rect output_rect(45, 22, 120, 13); |
| 242 gfx::Transform transform_to_root = | 242 gfx::Transform transform_to_root = |
| 243 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); | 243 gfx::Transform(1.0, 0.5, 0.5, -0.5, -1.0, 0.0); |
| 244 gfx::Rect damage_rect(56, 123, 19, 43); | 244 gfx::Rect damage_rect(56, 123, 19, 43); |
| 245 bool has_transparent_background = true; | 245 bool has_transparent_background = true; |
| 246 | 246 |
| 247 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); | 247 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); |
| 248 pass->SetAll(id, | 248 pass->SetAll(id, |
| 249 output_rect, | 249 output_rect, |
| 250 damage_rect, | 250 damage_rect, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 | 313 |
| 314 // Make a copy with CopyAll(). | 314 // Make a copy with CopyAll(). |
| 315 RenderPassList copy_list; | 315 RenderPassList copy_list; |
| 316 RenderPass::CopyAll(pass_list, ©_list); | 316 RenderPass::CopyAll(pass_list, ©_list); |
| 317 | 317 |
| 318 CompareRenderPassLists(pass_list, copy_list); | 318 CompareRenderPassLists(pass_list, copy_list); |
| 319 } | 319 } |
| 320 | 320 |
| 321 } // namespace | 321 } // namespace |
| 322 } // namespace cc | 322 } // namespace cc |
| OLD | NEW |