Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: cc/layers/ui_resource_layer_impl_unittest.cc

Issue 1057283003: Remove parts of //cc we aren't using (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layers/ui_resource_layer_impl.cc ('k') | cc/layers/ui_resource_layer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2013 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/layers/append_quads_data.h"
6 #include "cc/layers/ui_resource_layer_impl.h"
7 #include "cc/quads/draw_quad.h"
8 #include "cc/resources/ui_resource_bitmap.h"
9 #include "cc/resources/ui_resource_client.h"
10 #include "cc/test/fake_impl_proxy.h"
11 #include "cc/test/fake_layer_tree_host_impl.h"
12 #include "cc/test/fake_ui_resource_layer_tree_host_impl.h"
13 #include "cc/test/layer_test_common.h"
14 #include "cc/test/test_shared_bitmap_manager.h"
15 #include "cc/trees/single_thread_proxy.h"
16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "ui/gfx/transform.h"
19
20 namespace cc {
21 namespace {
22
23 scoped_ptr<UIResourceLayerImpl> GenerateUIResourceLayer(
24 FakeUIResourceLayerTreeHostImpl* host_impl,
25 const gfx::Size& bitmap_size,
26 const gfx::Size& layer_size,
27 bool opaque,
28 UIResourceId uid) {
29 gfx::Rect visible_content_rect(layer_size);
30 scoped_ptr<UIResourceLayerImpl> layer =
31 UIResourceLayerImpl::Create(host_impl->active_tree(), 1);
32 layer->draw_properties().visible_content_rect = visible_content_rect;
33 layer->SetBounds(layer_size);
34 layer->SetContentBounds(layer_size);
35 layer->SetHasRenderSurface(true);
36 layer->draw_properties().render_target = layer.get();
37
38 UIResourceBitmap bitmap(bitmap_size, opaque);
39
40 host_impl->CreateUIResource(uid, bitmap);
41 layer->SetUIResourceId(uid);
42
43 return layer.Pass();
44 }
45
46 void QuadSizeTest(scoped_ptr<UIResourceLayerImpl> layer,
47 size_t expected_quad_size) {
48 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
49
50 AppendQuadsData data;
51 layer->AppendQuads(render_pass.get(), &data);
52
53 // Verify quad rects
54 const QuadList& quads = render_pass->quad_list;
55 EXPECT_EQ(expected_quad_size, quads.size());
56 }
57
58 TEST(UIResourceLayerImplTest, VerifyDrawQuads) {
59 FakeImplProxy proxy;
60 TestSharedBitmapManager shared_bitmap_manager;
61 FakeUIResourceLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
62 // Make sure we're appending quads when there are valid values.
63 gfx::Size bitmap_size(100, 100);
64 gfx::Size layer_size(100, 100);;
65 size_t expected_quad_size = 1;
66 bool opaque = true;
67 UIResourceId uid = 1;
68 scoped_ptr<UIResourceLayerImpl> layer = GenerateUIResourceLayer(&host_impl,
69 bitmap_size,
70 layer_size,
71 opaque,
72 uid);
73 QuadSizeTest(layer.Pass(), expected_quad_size);
74
75 // Make sure we're not appending quads when there are invalid values.
76 expected_quad_size = 0;
77 uid = 0;
78 layer = GenerateUIResourceLayer(&host_impl,
79 bitmap_size,
80 layer_size,
81 opaque,
82 uid);
83 QuadSizeTest(layer.Pass(), expected_quad_size);
84 }
85
86 void OpaqueBoundsTest(scoped_ptr<UIResourceLayerImpl> layer,
87 const gfx::Rect& expected_opaque_bounds) {
88 scoped_ptr<RenderPass> render_pass = RenderPass::Create();
89
90 AppendQuadsData data;
91 layer->AppendQuads(render_pass.get(), &data);
92
93 // Verify quad rects
94 const QuadList& quads = render_pass->quad_list;
95 EXPECT_GE(quads.size(), (size_t)0);
96 gfx::Rect opaque_rect = quads.front()->opaque_rect;
97 EXPECT_EQ(expected_opaque_bounds, opaque_rect);
98 }
99
100 TEST(UIResourceLayerImplTest, VerifySetOpaqueOnSkBitmap) {
101 FakeImplProxy proxy;
102 TestSharedBitmapManager shared_bitmap_manager;
103 FakeUIResourceLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
104
105 gfx::Size bitmap_size(100, 100);
106 gfx::Size layer_size(100, 100);;
107 bool opaque = false;
108 UIResourceId uid = 1;
109 scoped_ptr<UIResourceLayerImpl> layer = GenerateUIResourceLayer(&host_impl,
110 bitmap_size,
111 layer_size,
112 opaque,
113 uid);
114 gfx::Rect expected_opaque_bounds;
115 OpaqueBoundsTest(layer.Pass(), expected_opaque_bounds);
116
117 opaque = true;
118 layer = GenerateUIResourceLayer(&host_impl,
119 bitmap_size,
120 layer_size,
121 opaque,
122 uid);
123 expected_opaque_bounds = gfx::Rect(layer->bounds());
124 OpaqueBoundsTest(layer.Pass(), expected_opaque_bounds);
125 }
126
127 TEST(UIResourceLayerImplTest, VerifySetOpaqueOnLayer) {
128 FakeImplProxy proxy;
129 TestSharedBitmapManager shared_bitmap_manager;
130 FakeUIResourceLayerTreeHostImpl host_impl(&proxy, &shared_bitmap_manager);
131
132 gfx::Size bitmap_size(100, 100);
133 gfx::Size layer_size(100, 100);
134 bool skbitmap_opaque = false;
135 UIResourceId uid = 1;
136 scoped_ptr<UIResourceLayerImpl> layer = GenerateUIResourceLayer(
137 &host_impl, bitmap_size, layer_size, skbitmap_opaque, uid);
138 layer->SetContentsOpaque(false);
139 gfx::Rect expected_opaque_bounds;
140 OpaqueBoundsTest(layer.Pass(), expected_opaque_bounds);
141
142 layer = GenerateUIResourceLayer(
143 &host_impl, bitmap_size, layer_size, skbitmap_opaque, uid);
144 layer->SetContentsOpaque(true);
145 expected_opaque_bounds = gfx::Rect(layer->bounds());
146 OpaqueBoundsTest(layer.Pass(), expected_opaque_bounds);
147 }
148
149 TEST(UIResourceLayerImplTest, Occlusion) {
150 gfx::Size layer_size(1000, 1000);
151 gfx::Size viewport_size(1000, 1000);
152
153 LayerTestCommon::LayerImplTest impl;
154
155 SkBitmap sk_bitmap;
156 sk_bitmap.allocN32Pixels(10, 10);
157 sk_bitmap.setImmutable();
158 UIResourceId uid = 5;
159 UIResourceBitmap bitmap(sk_bitmap);
160 impl.host_impl()->CreateUIResource(uid, bitmap);
161
162 UIResourceLayerImpl* ui_resource_layer_impl =
163 impl.AddChildToRoot<UIResourceLayerImpl>();
164 ui_resource_layer_impl->SetBounds(layer_size);
165 ui_resource_layer_impl->SetContentBounds(layer_size);
166 ui_resource_layer_impl->SetDrawsContent(true);
167 ui_resource_layer_impl->SetUIResourceId(uid);
168
169 impl.CalcDrawProps(viewport_size);
170
171 {
172 SCOPED_TRACE("No occlusion");
173 gfx::Rect occluded;
174 impl.AppendQuadsWithOcclusion(ui_resource_layer_impl, occluded);
175
176 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
177 gfx::Rect(layer_size));
178 EXPECT_EQ(1u, impl.quad_list().size());
179 }
180
181 {
182 SCOPED_TRACE("Full occlusion");
183 gfx::Rect occluded(ui_resource_layer_impl->visible_content_rect());
184 impl.AppendQuadsWithOcclusion(ui_resource_layer_impl, occluded);
185
186 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
187 EXPECT_EQ(impl.quad_list().size(), 0u);
188 }
189
190 {
191 SCOPED_TRACE("Partial occlusion");
192 gfx::Rect occluded(200, 0, 800, 1000);
193 impl.AppendQuadsWithOcclusion(ui_resource_layer_impl, occluded);
194
195 size_t partially_occluded_count = 0;
196 LayerTestCommon::VerifyQuadsAreOccluded(
197 impl.quad_list(), occluded, &partially_occluded_count);
198 // The layer outputs one quad, which is partially occluded.
199 EXPECT_EQ(1u, impl.quad_list().size());
200 EXPECT_EQ(1u, partially_occluded_count);
201 }
202 }
203
204 } // namespace
205 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/ui_resource_layer_impl.cc ('k') | cc/layers/ui_resource_layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698