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

Side by Side Diff: cc/resources/pixel_ref_map_unittest.cc

Issue 909353002: Move PixelRefMap and its Iterator out from Picture class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address review comments Created 5 years, 10 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
« cc/resources/pixel_ref_map.h ('K') | « cc/resources/pixel_ref_map.cc ('k') | no next file » | 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 2015 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/resources/pixel_ref_map.h"
6
7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/values.h"
10 #include "cc/resources/picture.h"
11 #include "cc/test/fake_content_layer_client.h"
12 #include "cc/test/skia_common.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/skia/include/core/SkGraphics.h"
15 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/skia_util.h"
17
18 namespace cc {
19 namespace {
20
21 TEST(PixelRefMapTest, PixelRefMapIterator) {
22 gfx::Rect layer_rect(2048, 2048);
23
24 gfx::Size tile_grid_size(512, 512);
25
26 FakeContentLayerClient content_layer_client;
27
28 // Discardable pixel refs are found in the following grids:
29 // |---|---|---|---|
30 // | | x | | x |
31 // |---|---|---|---|
32 // | x | | x | |
33 // |---|---|---|---|
34 // | | x | | x |
35 // |---|---|---|---|
36 // | x | | x | |
37 // |---|---|---|---|
38 SkBitmap discardable_bitmap[4][4];
39 for (int y = 0; y < 4; ++y) {
40 for (int x = 0; x < 4; ++x) {
41 if ((x + y) & 1) {
42 CreateBitmap(gfx::Size(500, 500), "discardable",
43 &discardable_bitmap[y][x]);
44 SkPaint paint;
45 content_layer_client.add_draw_bitmap(
46 discardable_bitmap[y][x], gfx::Point(x * 512 + 6, y * 512 + 6),
47 paint);
48 }
49 }
50 }
51
52 scoped_refptr<Picture> picture =
53 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true,
54 RecordingSource::RECORD_NORMALLY);
55
56 // Default iterator does not have any pixel refs.
57 {
58 PixelRefMapIterator iterator;
59 EXPECT_FALSE(iterator);
60 }
61
62 for (int y = 0; y < 4; ++y) {
63 for (int x = 0; x < 4; ++x) {
64 PixelRefMapIterator iterator(gfx::Rect(x * 512, y * 512, 500, 500),
65 picture.get());
66 if ((x + y) & 1) {
67 EXPECT_TRUE(iterator) << x << " " << y;
68 EXPECT_TRUE(*iterator == discardable_bitmap[y][x].pixelRef())
69 << x << " " << y;
70 EXPECT_FALSE(++iterator) << x << " " << y;
71 } else {
72 EXPECT_FALSE(iterator) << x << " " << y;
73 }
74 }
75 }
76 // Capture 4 pixel refs.
77 {
78 PixelRefMapIterator iterator(gfx::Rect(512, 512, 2048, 2048),
79 picture.get());
80 EXPECT_TRUE(iterator);
81 EXPECT_TRUE(*iterator == discardable_bitmap[1][2].pixelRef());
82 EXPECT_TRUE(++iterator);
83 EXPECT_TRUE(*iterator == discardable_bitmap[2][1].pixelRef());
84 EXPECT_TRUE(++iterator);
85 EXPECT_TRUE(*iterator == discardable_bitmap[2][3].pixelRef());
86 EXPECT_TRUE(++iterator);
87 EXPECT_TRUE(*iterator == discardable_bitmap[3][2].pixelRef());
88 EXPECT_FALSE(++iterator);
89 }
90
91 // Copy test.
92 PixelRefMapIterator iterator(gfx::Rect(512, 512, 2048, 2048), picture.get());
93 EXPECT_TRUE(iterator);
94 EXPECT_TRUE(*iterator == discardable_bitmap[1][2].pixelRef());
95 EXPECT_TRUE(++iterator);
96 EXPECT_TRUE(*iterator == discardable_bitmap[2][1].pixelRef());
97
98 // copy now points to the same spot as iterator,
99 // but both can be incremented independently.
100 PixelRefMapIterator copy = iterator;
101 EXPECT_TRUE(++iterator);
102 EXPECT_TRUE(*iterator == discardable_bitmap[2][3].pixelRef());
103 EXPECT_TRUE(++iterator);
104 EXPECT_TRUE(*iterator == discardable_bitmap[3][2].pixelRef());
105 EXPECT_FALSE(++iterator);
106
107 EXPECT_TRUE(copy);
108 EXPECT_TRUE(*copy == discardable_bitmap[2][1].pixelRef());
109 EXPECT_TRUE(++copy);
110 EXPECT_TRUE(*copy == discardable_bitmap[2][3].pixelRef());
111 EXPECT_TRUE(++copy);
112 EXPECT_TRUE(*copy == discardable_bitmap[3][2].pixelRef());
113 EXPECT_FALSE(++copy);
114 }
115
116 TEST(PixelRefMapTest, PixelRefMapIteratorNonZeroLayer) {
117 gfx::Rect layer_rect(1024, 0, 2048, 2048);
118
119 gfx::Size tile_grid_size(512, 512);
120
121 FakeContentLayerClient content_layer_client;
122
123 // Discardable pixel refs are found in the following grids:
124 // |---|---|---|---|
125 // | | x | | x |
126 // |---|---|---|---|
127 // | x | | x | |
128 // |---|---|---|---|
129 // | | x | | x |
130 // |---|---|---|---|
131 // | x | | x | |
132 // |---|---|---|---|
133 SkBitmap discardable_bitmap[4][4];
134 for (int y = 0; y < 4; ++y) {
135 for (int x = 0; x < 4; ++x) {
136 if ((x + y) & 1) {
137 CreateBitmap(gfx::Size(500, 500), "discardable",
138 &discardable_bitmap[y][x]);
139 SkPaint paint;
140 content_layer_client.add_draw_bitmap(
141 discardable_bitmap[y][x],
142 gfx::Point(1024 + x * 512 + 6, y * 512 + 6), paint);
143 }
144 }
145 }
146
147 scoped_refptr<Picture> picture =
148 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true,
149 RecordingSource::RECORD_NORMALLY);
150
151 // Default iterator does not have any pixel refs.
152 {
153 PixelRefMapIterator iterator;
154 EXPECT_FALSE(iterator);
155 }
156
157 for (int y = 0; y < 4; ++y) {
158 for (int x = 0; x < 4; ++x) {
159 PixelRefMapIterator iterator(gfx::Rect(1024 + x * 512, y * 512, 500, 500),
160 picture.get());
161 if ((x + y) & 1) {
162 EXPECT_TRUE(iterator) << x << " " << y;
163 EXPECT_TRUE(*iterator == discardable_bitmap[y][x].pixelRef());
164 EXPECT_FALSE(++iterator) << x << " " << y;
165 } else {
166 EXPECT_FALSE(iterator) << x << " " << y;
167 }
168 }
169 }
170 // Capture 4 pixel refs.
171 {
172 PixelRefMapIterator iterator(gfx::Rect(1024 + 512, 512, 2048, 2048),
173 picture.get());
174 EXPECT_TRUE(iterator);
175 EXPECT_TRUE(*iterator == discardable_bitmap[1][2].pixelRef());
176 EXPECT_TRUE(++iterator);
177 EXPECT_TRUE(*iterator == discardable_bitmap[2][1].pixelRef());
178 EXPECT_TRUE(++iterator);
179 EXPECT_TRUE(*iterator == discardable_bitmap[2][3].pixelRef());
180 EXPECT_TRUE(++iterator);
181 EXPECT_TRUE(*iterator == discardable_bitmap[3][2].pixelRef());
182 EXPECT_FALSE(++iterator);
183 }
184
185 // Copy test.
186 {
187 PixelRefMapIterator iterator(gfx::Rect(1024 + 512, 512, 2048, 2048),
188 picture.get());
189 EXPECT_TRUE(iterator);
190 EXPECT_TRUE(*iterator == discardable_bitmap[1][2].pixelRef());
191 EXPECT_TRUE(++iterator);
192 EXPECT_TRUE(*iterator == discardable_bitmap[2][1].pixelRef());
193
194 // copy now points to the same spot as iterator,
195 // but both can be incremented independently.
196 PixelRefMapIterator copy = iterator;
197 EXPECT_TRUE(++iterator);
198 EXPECT_TRUE(*iterator == discardable_bitmap[2][3].pixelRef());
199 EXPECT_TRUE(++iterator);
200 EXPECT_TRUE(*iterator == discardable_bitmap[3][2].pixelRef());
201 EXPECT_FALSE(++iterator);
202
203 EXPECT_TRUE(copy);
204 EXPECT_TRUE(*copy == discardable_bitmap[2][1].pixelRef());
205 EXPECT_TRUE(++copy);
206 EXPECT_TRUE(*copy == discardable_bitmap[2][3].pixelRef());
207 EXPECT_TRUE(++copy);
208 EXPECT_TRUE(*copy == discardable_bitmap[3][2].pixelRef());
209 EXPECT_FALSE(++copy);
210 }
211
212 // Non intersecting rects
213 {
214 PixelRefMapIterator iterator(gfx::Rect(0, 0, 1000, 1000), picture.get());
215 EXPECT_FALSE(iterator);
216 }
217 {
218 PixelRefMapIterator iterator(gfx::Rect(3500, 0, 1000, 1000), picture.get());
219 EXPECT_FALSE(iterator);
220 }
221 {
222 PixelRefMapIterator iterator(gfx::Rect(0, 1100, 1000, 1000), picture.get());
223 EXPECT_FALSE(iterator);
224 }
225 {
226 PixelRefMapIterator iterator(gfx::Rect(3500, 1100, 1000, 1000),
227 picture.get());
228 EXPECT_FALSE(iterator);
229 }
230 }
231
232 TEST(PixelRefMapTest, PixelRefMapIteratorOnePixelQuery) {
233 gfx::Rect layer_rect(2048, 2048);
234
235 gfx::Size tile_grid_size(512, 512);
236
237 FakeContentLayerClient content_layer_client;
238
239 // Discardable pixel refs are found in the following grids:
240 // |---|---|---|---|
241 // | | x | | x |
242 // |---|---|---|---|
243 // | x | | x | |
244 // |---|---|---|---|
245 // | | x | | x |
246 // |---|---|---|---|
247 // | x | | x | |
248 // |---|---|---|---|
249 SkBitmap discardable_bitmap[4][4];
250 for (int y = 0; y < 4; ++y) {
251 for (int x = 0; x < 4; ++x) {
252 if ((x + y) & 1) {
253 CreateBitmap(gfx::Size(500, 500), "discardable",
254 &discardable_bitmap[y][x]);
255 SkPaint paint;
256 content_layer_client.add_draw_bitmap(
257 discardable_bitmap[y][x], gfx::Point(x * 512 + 6, y * 512 + 6),
258 paint);
259 }
260 }
261 }
262
263 scoped_refptr<Picture> picture =
264 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true,
265 RecordingSource::RECORD_NORMALLY);
266
267 // Default iterator does not have any pixel refs.
268 {
269 PixelRefMapIterator iterator;
270 EXPECT_FALSE(iterator);
271 }
272
273 for (int y = 0; y < 4; ++y) {
274 for (int x = 0; x < 4; ++x) {
275 PixelRefMapIterator iterator(gfx::Rect(x * 512, y * 512 + 256, 1, 1),
276 picture.get());
277 if ((x + y) & 1) {
278 EXPECT_TRUE(iterator) << x << " " << y;
279 EXPECT_TRUE(*iterator == discardable_bitmap[y][x].pixelRef());
280 EXPECT_FALSE(++iterator) << x << " " << y;
281 } else {
282 EXPECT_FALSE(iterator) << x << " " << y;
283 }
284 }
285 }
286 }
287
288 } // namespace
289 } // namespace cc
OLDNEW
« cc/resources/pixel_ref_map.h ('K') | « cc/resources/pixel_ref_map.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698