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/solid_color_layer_impl.h" | 5 #include "cc/solid_color_layer_impl.h" |
6 | 6 |
7 #include "cc/append_quads_data.h" | 7 #include "cc/append_quads_data.h" |
8 #include "cc/single_thread_proxy.h" | 8 #include "cc/single_thread_proxy.h" |
9 #include "cc/solid_color_draw_quad.h" | 9 #include "cc/solid_color_draw_quad.h" |
10 #include "cc/solid_color_layer.h" | 10 #include "cc/solid_color_layer.h" |
11 #include "cc/test/layer_test_common.h" | 11 #include "cc/test/layer_test_common.h" |
12 #include "cc/test/mock_quad_culler.h" | 12 #include "cc/test/mock_quad_culler.h" |
13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
15 | 15 |
16 using namespace LayerTestCommon; | 16 using namespace LayerTestCommon; |
17 | 17 |
18 namespace cc { | 18 namespace cc { |
19 namespace { | 19 namespace { |
20 | 20 |
21 TEST(SolidColorLayerImplTest, verifyTilingCompleteAndNoOverlap) | 21 TEST(SolidColorLayerImplTest, verifyTilingCompleteAndNoOverlap) |
22 { | 22 { |
23 MockQuadCuller quadCuller; | 23 MockQuadCuller quadCuller; |
24 gfx::Size layerSize = gfx::Size(800, 600); | 24 gfx::Size layerSize = gfx::Size(800, 600); |
25 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); | 25 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); |
26 | 26 |
27 scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::create(1); | 27 scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::create(1); |
28 layer->setVisibleContentRect(visibleContentRect); | 28 layer->drawProperties().visible_content_rect = visibleContentRect; |
29 layer->setBounds(layerSize); | 29 layer->setBounds(layerSize); |
30 layer->setContentBounds(layerSize); | 30 layer->setContentBounds(layerSize); |
31 layer->createRenderSurface(); | 31 layer->createRenderSurface(); |
32 layer->setRenderTarget(layer.get()); | 32 layer->drawProperties().render_target = layer.get(); |
33 | 33 |
34 AppendQuadsData data; | 34 AppendQuadsData data; |
35 layer->appendQuads(quadCuller, data); | 35 layer->appendQuads(quadCuller, data); |
36 | 36 |
37 verifyQuadsExactlyCoverRect(quadCuller.quadList(), visibleContentRect); | 37 verifyQuadsExactlyCoverRect(quadCuller.quadList(), visibleContentRect); |
38 } | 38 } |
39 | 39 |
40 TEST(SolidColorLayerImplTest, verifyCorrectBackgroundColorInQuad) | 40 TEST(SolidColorLayerImplTest, verifyCorrectBackgroundColorInQuad) |
41 { | 41 { |
42 SkColor testColor = 0xFFA55AFF; | 42 SkColor testColor = 0xFFA55AFF; |
43 | 43 |
44 MockQuadCuller quadCuller; | 44 MockQuadCuller quadCuller; |
45 gfx::Size layerSize = gfx::Size(100, 100); | 45 gfx::Size layerSize = gfx::Size(100, 100); |
46 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); | 46 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); |
47 | 47 |
48 scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::create(1); | 48 scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::create(1); |
49 layer->setVisibleContentRect(visibleContentRect); | 49 layer->drawProperties().visible_content_rect = visibleContentRect; |
50 layer->setBounds(layerSize); | 50 layer->setBounds(layerSize); |
51 layer->setContentBounds(layerSize); | 51 layer->setContentBounds(layerSize); |
52 layer->setBackgroundColor(testColor); | 52 layer->setBackgroundColor(testColor); |
53 layer->createRenderSurface(); | 53 layer->createRenderSurface(); |
54 layer->setRenderTarget(layer.get()); | 54 layer->drawProperties().render_target = layer.get(); |
55 | 55 |
56 AppendQuadsData data; | 56 AppendQuadsData data; |
57 layer->appendQuads(quadCuller, data); | 57 layer->appendQuads(quadCuller, data); |
58 | 58 |
59 ASSERT_EQ(quadCuller.quadList().size(), 1U); | 59 ASSERT_EQ(quadCuller.quadList().size(), 1U); |
60 EXPECT_EQ(SolidColorDrawQuad::MaterialCast(quadCuller.quadList()[0])->color,
testColor); | 60 EXPECT_EQ(SolidColorDrawQuad::MaterialCast(quadCuller.quadList()[0])->color,
testColor); |
61 } | 61 } |
62 | 62 |
63 TEST(SolidColorLayerImplTest, verifyCorrectOpacityInQuad) | 63 TEST(SolidColorLayerImplTest, verifyCorrectOpacityInQuad) |
64 { | 64 { |
65 const float opacity = 0.5f; | 65 const float opacity = 0.5f; |
66 | 66 |
67 MockQuadCuller quadCuller; | 67 MockQuadCuller quadCuller; |
68 gfx::Size layerSize = gfx::Size(100, 100); | 68 gfx::Size layerSize = gfx::Size(100, 100); |
69 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); | 69 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); |
70 | 70 |
71 scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::create(1); | 71 scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::create(1); |
72 layer->setVisibleContentRect(visibleContentRect); | 72 layer->drawProperties().visible_content_rect = visibleContentRect; |
73 layer->setBounds(layerSize); | 73 layer->setBounds(layerSize); |
74 layer->setContentBounds(layerSize); | 74 layer->setContentBounds(layerSize); |
75 layer->setDrawOpacity(opacity); | 75 layer->drawProperties().opacity = opacity; |
76 layer->createRenderSurface(); | 76 layer->createRenderSurface(); |
77 layer->setRenderTarget(layer.get()); | 77 layer->drawProperties().render_target = layer.get(); |
78 | 78 |
79 AppendQuadsData data; | 79 AppendQuadsData data; |
80 layer->appendQuads(quadCuller, data); | 80 layer->appendQuads(quadCuller, data); |
81 | 81 |
82 ASSERT_EQ(quadCuller.quadList().size(), 1U); | 82 ASSERT_EQ(quadCuller.quadList().size(), 1U); |
83 EXPECT_EQ(opacity, SolidColorDrawQuad::MaterialCast(quadCuller.quadList()[0]
)->opacity()); | 83 EXPECT_EQ(opacity, SolidColorDrawQuad::MaterialCast(quadCuller.quadList()[0]
)->opacity()); |
84 } | 84 } |
85 | 85 |
86 TEST(SolidColorLayerImplTest, verifyOpaqueRect) | 86 TEST(SolidColorLayerImplTest, verifyOpaqueRect) |
87 { | 87 { |
88 scoped_refptr<SolidColorLayer> layer = SolidColorLayer::create(); | 88 scoped_refptr<SolidColorLayer> layer = SolidColorLayer::create(); |
89 gfx::Size layerSize = gfx::Size(100, 100); | 89 gfx::Size layerSize = gfx::Size(100, 100); |
90 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); | 90 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); |
91 | 91 |
92 layer->setVisibleContentRect(visibleContentRect); | 92 layer->drawProperties().visible_content_rect = visibleContentRect; |
93 layer->setBounds(layerSize); | 93 layer->setBounds(layerSize); |
94 layer->createRenderSurface(); | 94 layer->createRenderSurface(); |
95 layer->setRenderTarget(layer.get()); | 95 layer->drawProperties().render_target = layer.get(); |
96 | 96 |
97 EXPECT_FALSE(layer->contentsOpaque()); | 97 EXPECT_FALSE(layer->contentsOpaque()); |
98 layer->setBackgroundColor(SkColorSetARGBInline(255, 10, 20, 30)); | 98 layer->setBackgroundColor(SkColorSetARGBInline(255, 10, 20, 30)); |
99 EXPECT_TRUE(layer->contentsOpaque()); | 99 EXPECT_TRUE(layer->contentsOpaque()); |
100 | 100 |
101 { | 101 { |
102 scoped_ptr<SolidColorLayerImpl> layerImpl = SolidColorLayerImpl::create(
layer->id()); | 102 scoped_ptr<SolidColorLayerImpl> layerImpl = SolidColorLayerImpl::create(
layer->id()); |
103 layer->pushPropertiesTo(layerImpl.get()); | 103 layer->pushPropertiesTo(layerImpl.get()); |
104 | 104 |
105 // The impl layer should call itself opaque as well. | 105 // The impl layer should call itself opaque as well. |
106 EXPECT_TRUE(layerImpl->contentsOpaque()); | 106 EXPECT_TRUE(layerImpl->contentsOpaque()); |
107 | 107 |
108 // Impl layer has 1 opacity, and the color is opaque, so the opaqueRect
should be the full tile. | 108 // Impl layer has 1 opacity, and the color is opaque, so the opaqueRect
should be the full tile. |
109 layerImpl->setDrawOpacity(1); | 109 layerImpl->drawProperties().opacity = 1; |
110 | 110 |
111 MockQuadCuller quadCuller; | 111 MockQuadCuller quadCuller; |
112 AppendQuadsData data; | 112 AppendQuadsData data; |
113 layerImpl->appendQuads(quadCuller, data); | 113 layerImpl->appendQuads(quadCuller, data); |
114 | 114 |
115 ASSERT_EQ(quadCuller.quadList().size(), 1U); | 115 ASSERT_EQ(quadCuller.quadList().size(), 1U); |
116 EXPECT_EQ(visibleContentRect.ToString(), quadCuller.quadList()[0]->opaqu
e_rect.ToString()); | 116 EXPECT_EQ(visibleContentRect.ToString(), quadCuller.quadList()[0]->opaqu
e_rect.ToString()); |
117 } | 117 } |
118 | 118 |
119 EXPECT_TRUE(layer->contentsOpaque()); | 119 EXPECT_TRUE(layer->contentsOpaque()); |
120 layer->setBackgroundColor(SkColorSetARGBInline(254, 10, 20, 30)); | 120 layer->setBackgroundColor(SkColorSetARGBInline(254, 10, 20, 30)); |
121 EXPECT_FALSE(layer->contentsOpaque()); | 121 EXPECT_FALSE(layer->contentsOpaque()); |
122 | 122 |
123 { | 123 { |
124 scoped_ptr<SolidColorLayerImpl> layerImpl = SolidColorLayerImpl::create(
layer->id()); | 124 scoped_ptr<SolidColorLayerImpl> layerImpl = SolidColorLayerImpl::create(
layer->id()); |
125 layer->pushPropertiesTo(layerImpl.get()); | 125 layer->pushPropertiesTo(layerImpl.get()); |
126 | 126 |
127 // The impl layer should callnot itself opaque anymore. | 127 // The impl layer should callnot itself opaque anymore. |
128 EXPECT_FALSE(layerImpl->contentsOpaque()); | 128 EXPECT_FALSE(layerImpl->contentsOpaque()); |
129 | 129 |
130 // Impl layer has 1 opacity, but the color is not opaque, so the opaque_
rect should be empty. | 130 // Impl layer has 1 opacity, but the color is not opaque, so the opaque_
rect should be empty. |
131 layerImpl->setDrawOpacity(1); | 131 layerImpl->drawProperties().opacity = 1; |
132 | 132 |
133 MockQuadCuller quadCuller; | 133 MockQuadCuller quadCuller; |
134 AppendQuadsData data; | 134 AppendQuadsData data; |
135 layerImpl->appendQuads(quadCuller, data); | 135 layerImpl->appendQuads(quadCuller, data); |
136 | 136 |
137 ASSERT_EQ(quadCuller.quadList().size(), 1U); | 137 ASSERT_EQ(quadCuller.quadList().size(), 1U); |
138 EXPECT_EQ(gfx::Rect().ToString(), quadCuller.quadList()[0]->opaque_rect.
ToString()); | 138 EXPECT_EQ(gfx::Rect().ToString(), quadCuller.quadList()[0]->opaque_rect.
ToString()); |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
142 } // namespace | 142 } // namespace |
143 } // namespace cc | 143 } // namespace cc |
OLD | NEW |