Update V8 to version 4.6.62.
[chromium-blink-merge.git] / cc / playback / pixel_ref_map_unittest.cc
blobaf88b44c8731cc4c37005d3345917b752a635d2f
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.
5 #include "cc/playback/pixel_ref_map.h"
7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/values.h"
10 #include "cc/playback/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"
18 namespace cc {
19 namespace {
21 TEST(PixelRefMapTest, PixelRefMapIterator) {
22 gfx::Rect layer_rect(2048, 2048);
24 gfx::Size tile_grid_size(512, 512);
26 FakeContentLayerClient content_layer_client;
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);
52 scoped_refptr<Picture> picture =
53 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true,
54 RecordingSource::RECORD_NORMALLY);
56 // Default iterator does not have any pixel refs.
58 PixelRefMap::Iterator iterator;
59 EXPECT_FALSE(iterator);
62 for (int y = 0; y < 4; ++y) {
63 for (int x = 0; x < 4; ++x) {
64 PixelRefMap::Iterator 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;
76 // Capture 4 pixel refs.
78 PixelRefMap::Iterator 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);
91 // Copy test.
92 PixelRefMap::Iterator iterator(gfx::Rect(512, 512, 2048, 2048),
93 picture.get());
94 EXPECT_TRUE(iterator);
95 EXPECT_TRUE(*iterator == discardable_bitmap[1][2].pixelRef());
96 EXPECT_TRUE(++iterator);
97 EXPECT_TRUE(*iterator == discardable_bitmap[2][1].pixelRef());
99 // copy now points to the same spot as iterator,
100 // but both can be incremented independently.
101 PixelRefMap::Iterator copy = iterator;
102 EXPECT_TRUE(++iterator);
103 EXPECT_TRUE(*iterator == discardable_bitmap[2][3].pixelRef());
104 EXPECT_TRUE(++iterator);
105 EXPECT_TRUE(*iterator == discardable_bitmap[3][2].pixelRef());
106 EXPECT_FALSE(++iterator);
108 EXPECT_TRUE(copy);
109 EXPECT_TRUE(*copy == discardable_bitmap[2][1].pixelRef());
110 EXPECT_TRUE(++copy);
111 EXPECT_TRUE(*copy == discardable_bitmap[2][3].pixelRef());
112 EXPECT_TRUE(++copy);
113 EXPECT_TRUE(*copy == discardable_bitmap[3][2].pixelRef());
114 EXPECT_FALSE(++copy);
117 TEST(PixelRefMapTest, PixelRefMapIteratorNonZeroLayer) {
118 gfx::Rect layer_rect(1024, 0, 2048, 2048);
120 gfx::Size tile_grid_size(512, 512);
122 FakeContentLayerClient content_layer_client;
124 // Discardable pixel refs are found in the following grids:
125 // |---|---|---|---|
126 // | | x | | x |
127 // |---|---|---|---|
128 // | x | | x | |
129 // |---|---|---|---|
130 // | | x | | x |
131 // |---|---|---|---|
132 // | x | | x | |
133 // |---|---|---|---|
134 SkBitmap discardable_bitmap[4][4];
135 for (int y = 0; y < 4; ++y) {
136 for (int x = 0; x < 4; ++x) {
137 if ((x + y) & 1) {
138 CreateBitmap(gfx::Size(500, 500), "discardable",
139 &discardable_bitmap[y][x]);
140 SkPaint paint;
141 content_layer_client.add_draw_bitmap(
142 discardable_bitmap[y][x],
143 gfx::Point(1024 + x * 512 + 6, y * 512 + 6), paint);
148 scoped_refptr<Picture> picture =
149 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true,
150 RecordingSource::RECORD_NORMALLY);
152 // Default iterator does not have any pixel refs.
154 PixelRefMap::Iterator iterator;
155 EXPECT_FALSE(iterator);
158 for (int y = 0; y < 4; ++y) {
159 for (int x = 0; x < 4; ++x) {
160 PixelRefMap::Iterator iterator(
161 gfx::Rect(1024 + x * 512, y * 512, 500, 500), picture.get());
162 if ((x + y) & 1) {
163 EXPECT_TRUE(iterator) << x << " " << y;
164 EXPECT_TRUE(*iterator == discardable_bitmap[y][x].pixelRef());
165 EXPECT_FALSE(++iterator) << x << " " << y;
166 } else {
167 EXPECT_FALSE(iterator) << x << " " << y;
171 // Capture 4 pixel refs.
173 PixelRefMap::Iterator iterator(gfx::Rect(1024 + 512, 512, 2048, 2048),
174 picture.get());
175 EXPECT_TRUE(iterator);
176 EXPECT_TRUE(*iterator == discardable_bitmap[1][2].pixelRef());
177 EXPECT_TRUE(++iterator);
178 EXPECT_TRUE(*iterator == discardable_bitmap[2][1].pixelRef());
179 EXPECT_TRUE(++iterator);
180 EXPECT_TRUE(*iterator == discardable_bitmap[2][3].pixelRef());
181 EXPECT_TRUE(++iterator);
182 EXPECT_TRUE(*iterator == discardable_bitmap[3][2].pixelRef());
183 EXPECT_FALSE(++iterator);
186 // Copy test.
188 PixelRefMap::Iterator iterator(gfx::Rect(1024 + 512, 512, 2048, 2048),
189 picture.get());
190 EXPECT_TRUE(iterator);
191 EXPECT_TRUE(*iterator == discardable_bitmap[1][2].pixelRef());
192 EXPECT_TRUE(++iterator);
193 EXPECT_TRUE(*iterator == discardable_bitmap[2][1].pixelRef());
195 // copy now points to the same spot as iterator,
196 // but both can be incremented independently.
197 PixelRefMap::Iterator copy = iterator;
198 EXPECT_TRUE(++iterator);
199 EXPECT_TRUE(*iterator == discardable_bitmap[2][3].pixelRef());
200 EXPECT_TRUE(++iterator);
201 EXPECT_TRUE(*iterator == discardable_bitmap[3][2].pixelRef());
202 EXPECT_FALSE(++iterator);
204 EXPECT_TRUE(copy);
205 EXPECT_TRUE(*copy == discardable_bitmap[2][1].pixelRef());
206 EXPECT_TRUE(++copy);
207 EXPECT_TRUE(*copy == discardable_bitmap[2][3].pixelRef());
208 EXPECT_TRUE(++copy);
209 EXPECT_TRUE(*copy == discardable_bitmap[3][2].pixelRef());
210 EXPECT_FALSE(++copy);
213 // Non intersecting rects
215 PixelRefMap::Iterator iterator(gfx::Rect(0, 0, 1000, 1000), picture.get());
216 EXPECT_FALSE(iterator);
219 PixelRefMap::Iterator iterator(gfx::Rect(3500, 0, 1000, 1000),
220 picture.get());
221 EXPECT_FALSE(iterator);
224 PixelRefMap::Iterator iterator(gfx::Rect(0, 1100, 1000, 1000),
225 picture.get());
226 EXPECT_FALSE(iterator);
229 PixelRefMap::Iterator iterator(gfx::Rect(3500, 1100, 1000, 1000),
230 picture.get());
231 EXPECT_FALSE(iterator);
235 TEST(PixelRefMapTest, PixelRefMapIteratorOnePixelQuery) {
236 gfx::Rect layer_rect(2048, 2048);
238 gfx::Size tile_grid_size(512, 512);
240 FakeContentLayerClient content_layer_client;
242 // Discardable pixel refs are found in the following grids:
243 // |---|---|---|---|
244 // | | x | | x |
245 // |---|---|---|---|
246 // | x | | x | |
247 // |---|---|---|---|
248 // | | x | | x |
249 // |---|---|---|---|
250 // | x | | x | |
251 // |---|---|---|---|
252 SkBitmap discardable_bitmap[4][4];
253 for (int y = 0; y < 4; ++y) {
254 for (int x = 0; x < 4; ++x) {
255 if ((x + y) & 1) {
256 CreateBitmap(gfx::Size(500, 500), "discardable",
257 &discardable_bitmap[y][x]);
258 SkPaint paint;
259 content_layer_client.add_draw_bitmap(
260 discardable_bitmap[y][x], gfx::Point(x * 512 + 6, y * 512 + 6),
261 paint);
266 scoped_refptr<Picture> picture =
267 Picture::Create(layer_rect, &content_layer_client, tile_grid_size, true,
268 RecordingSource::RECORD_NORMALLY);
270 // Default iterator does not have any pixel refs.
272 PixelRefMap::Iterator iterator;
273 EXPECT_FALSE(iterator);
276 for (int y = 0; y < 4; ++y) {
277 for (int x = 0; x < 4; ++x) {
278 PixelRefMap::Iterator iterator(gfx::Rect(x * 512, y * 512 + 256, 1, 1),
279 picture.get());
280 if ((x + y) & 1) {
281 EXPECT_TRUE(iterator) << x << " " << y;
282 EXPECT_TRUE(*iterator == discardable_bitmap[y][x].pixelRef());
283 EXPECT_FALSE(++iterator) << x << " " << y;
284 } else {
285 EXPECT_FALSE(iterator) << x << " " << y;
291 } // namespace
292 } // namespace cc