OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "cc/solid_color_layer_impl.h" | |
6 | |
7 #include "cc/append_quads_data.h" | |
8 #include "cc/quads/solid_color_draw_quad.h" | |
9 #include "cc/solid_color_layer.h" | |
10 #include "cc/test/fake_impl_proxy.h" | |
11 #include "cc/test/fake_layer_tree_host_impl.h" | |
12 #include "cc/test/layer_test_common.h" | |
13 #include "cc/test/mock_quad_culler.h" | |
14 #include "cc/trees/single_thread_proxy.h" | |
15 #include "testing/gmock/include/gmock/gmock.h" | |
16 #include "testing/gtest/include/gtest/gtest.h" | |
17 | |
18 namespace cc { | |
19 namespace { | |
20 | |
21 TEST(SolidColorLayerImplTest, verifyTilingCompleteAndNoOverlap) | |
22 { | |
23 MockQuadCuller quadCuller; | |
24 gfx::Size layerSize = gfx::Size(800, 600); | |
25 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); | |
26 | |
27 FakeImplProxy proxy; | |
28 FakeLayerTreeHostImpl hostImpl(&proxy); | |
29 scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::Create(hostImpl
.active_tree(), 1); | |
30 layer->draw_properties().visible_content_rect = visibleContentRect; | |
31 layer->SetBounds(layerSize); | |
32 layer->SetContentBounds(layerSize); | |
33 layer->CreateRenderSurface(); | |
34 layer->draw_properties().render_target = layer.get(); | |
35 | |
36 AppendQuadsData data; | |
37 layer->AppendQuads(&quadCuller, &data); | |
38 | |
39 LayerTestCommon::verifyQuadsExactlyCoverRect(quadCuller.quadList(), visibleC
ontentRect); | |
40 } | |
41 | |
42 TEST(SolidColorLayerImplTest, verifyCorrectBackgroundColorInQuad) | |
43 { | |
44 SkColor testColor = 0xFFA55AFF; | |
45 | |
46 MockQuadCuller quadCuller; | |
47 gfx::Size layerSize = gfx::Size(100, 100); | |
48 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); | |
49 | |
50 FakeImplProxy proxy; | |
51 FakeLayerTreeHostImpl hostImpl(&proxy); | |
52 scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::Create(hostImpl
.active_tree(), 1); | |
53 layer->draw_properties().visible_content_rect = visibleContentRect; | |
54 layer->SetBounds(layerSize); | |
55 layer->SetContentBounds(layerSize); | |
56 layer->SetBackgroundColor(testColor); | |
57 layer->CreateRenderSurface(); | |
58 layer->draw_properties().render_target = layer.get(); | |
59 | |
60 AppendQuadsData data; | |
61 layer->AppendQuads(&quadCuller, &data); | |
62 | |
63 ASSERT_EQ(quadCuller.quadList().size(), 1U); | |
64 EXPECT_EQ(SolidColorDrawQuad::MaterialCast(quadCuller.quadList()[0])->color,
testColor); | |
65 } | |
66 | |
67 TEST(SolidColorLayerImplTest, verifyCorrectOpacityInQuad) | |
68 { | |
69 const float opacity = 0.5f; | |
70 | |
71 MockQuadCuller quadCuller; | |
72 gfx::Size layerSize = gfx::Size(100, 100); | |
73 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); | |
74 | |
75 FakeImplProxy proxy; | |
76 FakeLayerTreeHostImpl hostImpl(&proxy); | |
77 scoped_ptr<SolidColorLayerImpl> layer = SolidColorLayerImpl::Create(hostImpl
.active_tree(), 1); | |
78 layer->draw_properties().visible_content_rect = visibleContentRect; | |
79 layer->SetBounds(layerSize); | |
80 layer->SetContentBounds(layerSize); | |
81 layer->draw_properties().opacity = opacity; | |
82 layer->CreateRenderSurface(); | |
83 layer->draw_properties().render_target = layer.get(); | |
84 | |
85 AppendQuadsData data; | |
86 layer->AppendQuads(&quadCuller, &data); | |
87 | |
88 ASSERT_EQ(quadCuller.quadList().size(), 1U); | |
89 EXPECT_EQ(opacity, SolidColorDrawQuad::MaterialCast(quadCuller.quadList()[0]
)->opacity()); | |
90 } | |
91 | |
92 TEST(SolidColorLayerImplTest, verifyOpaqueRect) | |
93 { | |
94 FakeImplProxy proxy; | |
95 FakeLayerTreeHostImpl hostImpl(&proxy); | |
96 | |
97 gfx::Size layerSize = gfx::Size(100, 100); | |
98 gfx::Rect visibleContentRect = gfx::Rect(gfx::Point(), layerSize); | |
99 | |
100 scoped_refptr<SolidColorLayer> layer = SolidColorLayer::Create(); | |
101 layer->SetBounds(layerSize); | |
102 layer->SetForceRenderSurface(true); | |
103 | |
104 scoped_refptr<Layer> root = Layer::Create(); | |
105 root->AddChild(layer); | |
106 | |
107 std::vector<scoped_refptr<Layer> > renderSurfaceLayerList; | |
108 LayerTreeHostCommon::calculateDrawProperties( | |
109 root, | |
110 gfx::Size(500, 500), | |
111 1, | |
112 1, | |
113 1024, | |
114 false, | |
115 renderSurfaceLayerList); | |
116 | |
117 EXPECT_FALSE(layer->contents_opaque()); | |
118 layer->SetBackgroundColor(SkColorSetARGBInline(255, 10, 20, 30)); | |
119 EXPECT_TRUE(layer->contents_opaque()); | |
120 | |
121 { | |
122 scoped_ptr<SolidColorLayerImpl> layerImpl = SolidColorLayerImpl::Create(
hostImpl.active_tree(), layer->id()); | |
123 layer->PushPropertiesTo(layerImpl.get()); | |
124 | |
125 // The impl layer should call itself opaque as well. | |
126 EXPECT_TRUE(layerImpl->contents_opaque()); | |
127 | |
128 // Impl layer has 1 opacity, and the color is opaque, so the opaqueRect
should be the full tile. | |
129 layerImpl->draw_properties().opacity = 1; | |
130 | |
131 MockQuadCuller quadCuller; | |
132 AppendQuadsData data; | |
133 layerImpl->AppendQuads(&quadCuller, &data); | |
134 | |
135 ASSERT_EQ(quadCuller.quadList().size(), 1U); | |
136 EXPECT_EQ(visibleContentRect.ToString(), quadCuller.quadList()[0]->opaqu
e_rect.ToString()); | |
137 } | |
138 | |
139 EXPECT_TRUE(layer->contents_opaque()); | |
140 layer->SetBackgroundColor(SkColorSetARGBInline(254, 10, 20, 30)); | |
141 EXPECT_FALSE(layer->contents_opaque()); | |
142 | |
143 { | |
144 scoped_ptr<SolidColorLayerImpl> layerImpl = SolidColorLayerImpl::Create(
hostImpl.active_tree(), layer->id()); | |
145 layer->PushPropertiesTo(layerImpl.get()); | |
146 | |
147 // The impl layer should callnot itself opaque anymore. | |
148 EXPECT_FALSE(layerImpl->contents_opaque()); | |
149 | |
150 // Impl layer has 1 opacity, but the color is not opaque, so the opaque_
rect should be empty. | |
151 layerImpl->draw_properties().opacity = 1; | |
152 | |
153 MockQuadCuller quadCuller; | |
154 AppendQuadsData data; | |
155 layerImpl->AppendQuads(&quadCuller, &data); | |
156 | |
157 ASSERT_EQ(quadCuller.quadList().size(), 1U); | |
158 EXPECT_EQ(gfx::Rect().ToString(), quadCuller.quadList()[0]->opaque_rect.
ToString()); | |
159 } | |
160 } | |
161 | |
162 } // namespace | |
163 } // namespace cc | |
OLD | NEW |