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/render_pass.h" | 5 #include "cc/render_pass.h" |
6 | 6 |
7 #include "cc/checkerboard_draw_quad.h" | 7 #include "cc/checkerboard_draw_quad.h" |
8 #include "cc/math_util.h" | 8 #include "cc/math_util.h" |
9 #include "cc/test/geometry_test_utils.h" | 9 #include "cc/test/geometry_test_utils.h" |
10 #include "cc/test/render_pass_test_common.h" | 10 #include "cc/test/render_pass_test_common.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations
.h" | 12 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations
.h" |
13 #include "third_party/skia/include/effects/SkBlurImageFilter.h" | 13 #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
14 #include "ui/gfx/transform.h" | 14 #include "ui/gfx/transform.h" |
15 | 15 |
16 using WebKit::WebFilterOperation; | |
17 using WebKit::WebFilterOperations; | |
18 using cc::TestRenderPass; | 16 using cc::TestRenderPass; |
19 | 17 |
20 namespace cc { | 18 namespace cc { |
21 namespace { | 19 namespace { |
22 | 20 |
23 struct RenderPassSize { | 21 struct RenderPassSize { |
24 // If you add a new field to this class, make sure to add it to the copy() t
ests. | 22 // If you add a new field to this class, make sure to add it to the copy() t
ests. |
25 RenderPass::Id m_id; | 23 RenderPass::Id m_id; |
26 QuadList m_quadList; | 24 QuadList m_quadList; |
27 SharedQuadStateList m_sharedQuadStateList; | 25 SharedQuadStateList m_sharedQuadStateList; |
28 gfx::Transform m_transformToRootTarget; | 26 gfx::Transform m_transformToRootTarget; |
29 gfx::Rect m_outputRect; | 27 gfx::Rect m_outputRect; |
30 gfx::RectF m_damageRect; | 28 gfx::RectF m_damageRect; |
31 bool m_hasTransparentBackground; | 29 bool m_hasTransparentBackground; |
32 bool m_hasOcclusionFromOutsideTargetSurface; | 30 bool m_hasOcclusionFromOutsideTargetSurface; |
33 WebKit::WebFilterOperations m_filters; | |
34 WebKit::WebFilterOperations m_backgroundFilters; | |
35 SkImageFilter* m_filter; | |
36 }; | 31 }; |
37 | 32 |
38 TEST(RenderPassTest, copyShouldBeIdenticalExceptIdAndQuads) | 33 TEST(RenderPassTest, copyShouldBeIdenticalExceptIdAndQuads) |
39 { | 34 { |
40 RenderPass::Id id(3, 2); | 35 RenderPass::Id id(3, 2); |
41 gfx::Rect outputRect(45, 22, 120, 13); | 36 gfx::Rect outputRect(45, 22, 120, 13); |
42 gfx::Transform transformToRoot = MathUtil::createGfxTransform(1, 0.5, 0.5, -
0.5, -1, 0); | 37 gfx::Transform transformToRoot = MathUtil::createGfxTransform(1, 0.5, 0.5, -
0.5, -1, 0); |
43 gfx::Rect damageRect(56, 123, 19, 43); | 38 gfx::Rect damageRect(56, 123, 19, 43); |
44 bool hasTransparentBackground = true; | 39 bool hasTransparentBackground = true; |
45 bool hasOcclusionFromOutsideTargetSurface = true; | 40 bool hasOcclusionFromOutsideTargetSurface = true; |
46 WebFilterOperations filters; | |
47 WebFilterOperations backgroundFilters; | |
48 | |
49 filters.append(WebFilterOperation::createGrayscaleFilter(0.2f)); | |
50 backgroundFilters.append(WebFilterOperation::createInvertFilter(0.2f)); | |
51 skia::RefPtr<SkImageFilter> filter = skia::AdoptRef(new SkBlurImageFilter(SK
_Scalar1, SK_Scalar1)); | |
52 | 41 |
53 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); | 42 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); |
54 pass->SetAll(id, | 43 pass->SetAll(id, |
55 outputRect, | 44 outputRect, |
56 damageRect, | 45 damageRect, |
57 transformToRoot, | 46 transformToRoot, |
58 hasTransparentBackground, | 47 hasTransparentBackground, |
59 hasOcclusionFromOutsideTargetSurface, | 48 hasOcclusionFromOutsideTargetSurface); |
60 filters, | |
61 filter, | |
62 backgroundFilters); | |
63 | 49 |
64 // Stick a quad in the pass, this should not get copied. | 50 // Stick a quad in the pass, this should not get copied. |
65 scoped_ptr<SharedQuadState> sharedState = SharedQuadState::Create(); | 51 scoped_ptr<SharedQuadState> sharedState = SharedQuadState::Create(); |
66 sharedState->SetAll(gfx::Transform(), gfx::Rect(), gfx::Rect(), gfx::Rect(),
false, 1); | 52 sharedState->SetAll(gfx::Transform(), gfx::Rect(), gfx::Rect(), gfx::Rect(),
false, 1); |
67 pass->AppendSharedQuadState(sharedState.Pass()); | 53 pass->AppendSharedQuadState(sharedState.Pass()); |
68 | 54 |
69 scoped_ptr<CheckerboardDrawQuad> checkerboardQuad = CheckerboardDrawQuad::Cr
eate(); | 55 scoped_ptr<CheckerboardDrawQuad> checkerboardQuad = CheckerboardDrawQuad::Cr
eate(); |
70 checkerboardQuad->SetNew(pass->shared_quad_state_list.last(), gfx::Rect(), S
kColor()); | 56 checkerboardQuad->SetNew(pass->shared_quad_state_list.last(), gfx::Rect(), S
kColor()); |
71 pass->quad_list.append(checkerboardQuad.PassAs<DrawQuad>()); | 57 pass->quad_list.append(checkerboardQuad.PassAs<DrawQuad>()); |
72 | 58 |
73 RenderPass::Id newId(63, 4); | 59 RenderPass::Id newId(63, 4); |
74 | 60 |
75 scoped_ptr<RenderPass> copy = pass->Copy(newId); | 61 scoped_ptr<RenderPass> copy = pass->Copy(newId); |
76 EXPECT_EQ(newId, copy->id); | 62 EXPECT_EQ(newId, copy->id); |
77 EXPECT_RECT_EQ(pass->output_rect, copy->output_rect); | 63 EXPECT_RECT_EQ(pass->output_rect, copy->output_rect); |
78 EXPECT_EQ(pass->transform_to_root_target, copy->transform_to_root_target); | 64 EXPECT_EQ(pass->transform_to_root_target, copy->transform_to_root_target); |
79 EXPECT_RECT_EQ(pass->damage_rect, copy->damage_rect); | 65 EXPECT_RECT_EQ(pass->damage_rect, copy->damage_rect); |
80 EXPECT_EQ(pass->has_transparent_background, copy->has_transparent_background
); | 66 EXPECT_EQ(pass->has_transparent_background, copy->has_transparent_background
); |
81 EXPECT_EQ(pass->has_occlusion_from_outside_target_surface, copy->has_occlusi
on_from_outside_target_surface); | 67 EXPECT_EQ(pass->has_occlusion_from_outside_target_surface, copy->has_occlusi
on_from_outside_target_surface); |
82 EXPECT_EQ(pass->filters, copy->filters); | |
83 EXPECT_EQ(pass->filter, copy->filter); | |
84 EXPECT_EQ(pass->background_filters, copy->background_filters); | |
85 EXPECT_EQ(0u, copy->quad_list.size()); | 68 EXPECT_EQ(0u, copy->quad_list.size()); |
86 | 69 |
87 EXPECT_EQ(sizeof(RenderPassSize), sizeof(RenderPass)); | 70 EXPECT_EQ(sizeof(RenderPassSize), sizeof(RenderPass)); |
88 } | 71 } |
89 | 72 |
90 } // namespace | 73 } // namespace |
91 } // namespace cc | 74 } // namespace cc |
OLD | NEW |