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

Side by Side Diff: cc/playback/raster_source_unittest.cc

Issue 1837263005: cc: Rename DisplayListRasterSource to just RasterSource. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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/playback/raster_source.cc ('k') | cc/quads/draw_quad_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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "cc/playback/display_list_raster_source.h" 8 #include "cc/playback/raster_source.h"
9 #include "cc/test/fake_display_list_recording_source.h" 9 #include "cc/test/fake_display_list_recording_source.h"
10 #include "cc/test/skia_common.h" 10 #include "cc/test/skia_common.h"
11 #include "skia/ext/refptr.h" 11 #include "skia/ext/refptr.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/skia/include/core/SkPixelRef.h" 13 #include "third_party/skia/include/core/SkPixelRef.h"
14 #include "third_party/skia/include/core/SkShader.h" 14 #include "third_party/skia/include/core/SkShader.h"
15 #include "ui/gfx/geometry/rect.h" 15 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/geometry/size_conversions.h" 16 #include "ui/gfx/geometry/size_conversions.h"
17 17
18 namespace cc { 18 namespace cc {
19 namespace { 19 namespace {
20 20
21 TEST(DisplayListRasterSourceTest, AnalyzeIsSolidUnscaled) { 21 TEST(RasterSourceTest, AnalyzeIsSolidUnscaled) {
22 gfx::Size layer_bounds(400, 400); 22 gfx::Size layer_bounds(400, 400);
23 23
24 scoped_ptr<FakeDisplayListRecordingSource> recording_source = 24 scoped_ptr<FakeDisplayListRecordingSource> recording_source =
25 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); 25 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds);
26 26
27 SkPaint solid_paint; 27 SkPaint solid_paint;
28 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); 28 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34);
29 solid_paint.setColor(solid_color); 29 solid_paint.setColor(solid_color);
30 30
31 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); 31 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67);
32 SkColor color = SK_ColorTRANSPARENT; 32 SkColor color = SK_ColorTRANSPARENT;
33 SkPaint non_solid_paint; 33 SkPaint non_solid_paint;
34 bool is_solid_color = false; 34 bool is_solid_color = false;
35 non_solid_paint.setColor(non_solid_color); 35 non_solid_paint.setColor(non_solid_color);
36 36
37 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), 37 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds),
38 solid_paint); 38 solid_paint);
39 recording_source->Rerecord(); 39 recording_source->Rerecord();
40 40
41 scoped_refptr<DisplayListRasterSource> raster = 41 scoped_refptr<RasterSource> raster =
42 DisplayListRasterSource::CreateFromDisplayListRecordingSource( 42 RasterSource::CreateFromDisplayListRecordingSource(recording_source.get(),
43 recording_source.get(), false); 43 false);
44 44
45 // Ensure everything is solid. 45 // Ensure everything is solid.
46 for (int y = 0; y <= 300; y += 100) { 46 for (int y = 0; y <= 300; y += 100) {
47 for (int x = 0; x <= 300; x += 100) { 47 for (int x = 0; x <= 300; x += 100) {
48 gfx::Rect rect(x, y, 100, 100); 48 gfx::Rect rect(x, y, 100, 100);
49 is_solid_color = raster->PerformSolidColorAnalysis(rect, 1.0, &color); 49 is_solid_color = raster->PerformSolidColorAnalysis(rect, 1.0, &color);
50 EXPECT_TRUE(is_solid_color) << rect.ToString(); 50 EXPECT_TRUE(is_solid_color) << rect.ToString();
51 EXPECT_EQ(solid_color, color) << rect.ToString(); 51 EXPECT_EQ(solid_color, color) << rect.ToString();
52 } 52 }
53 } 53 }
54 54
55 // Add one non-solid pixel and recreate the raster source. 55 // Add one non-solid pixel and recreate the raster source.
56 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), 56 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1),
57 non_solid_paint); 57 non_solid_paint);
58 recording_source->Rerecord(); 58 recording_source->Rerecord();
59 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( 59 raster = RasterSource::CreateFromDisplayListRecordingSource(
60 recording_source.get(), false); 60 recording_source.get(), false);
61 61
62 color = SK_ColorTRANSPARENT; 62 color = SK_ColorTRANSPARENT;
63 is_solid_color = 63 is_solid_color =
64 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 100, 100), 1.0, &color); 64 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 100, 100), 1.0, &color);
65 EXPECT_FALSE(is_solid_color); 65 EXPECT_FALSE(is_solid_color);
66 66
67 color = SK_ColorTRANSPARENT; 67 color = SK_ColorTRANSPARENT;
68 is_solid_color = raster->PerformSolidColorAnalysis( 68 is_solid_color = raster->PerformSolidColorAnalysis(
69 gfx::Rect(100, 0, 100, 100), 1.0, &color); 69 gfx::Rect(100, 0, 100, 100), 1.0, &color);
(...skipping 13 matching lines...) Expand all
83 EXPECT_TRUE(is_solid_color); 83 EXPECT_TRUE(is_solid_color);
84 EXPECT_EQ(solid_color, color); 84 EXPECT_EQ(solid_color, color);
85 85
86 color = SK_ColorTRANSPARENT; 86 color = SK_ColorTRANSPARENT;
87 is_solid_color = raster->PerformSolidColorAnalysis( 87 is_solid_color = raster->PerformSolidColorAnalysis(
88 gfx::Rect(350, 350, 100, 100), 1.0, &color); 88 gfx::Rect(350, 350, 100, 100), 1.0, &color);
89 EXPECT_TRUE(is_solid_color); 89 EXPECT_TRUE(is_solid_color);
90 EXPECT_EQ(solid_color, color); 90 EXPECT_EQ(solid_color, color);
91 } 91 }
92 92
93 TEST(DisplayListRasterSourceTest, AnalyzeIsSolidScaled) { 93 TEST(RasterSourceTest, AnalyzeIsSolidScaled) {
94 gfx::Size layer_bounds(400, 400); 94 gfx::Size layer_bounds(400, 400);
95 95
96 scoped_ptr<FakeDisplayListRecordingSource> recording_source = 96 scoped_ptr<FakeDisplayListRecordingSource> recording_source =
97 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); 97 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds);
98 98
99 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); 99 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34);
100 SkColor color = SK_ColorTRANSPARENT; 100 SkColor color = SK_ColorTRANSPARENT;
101 SkPaint solid_paint; 101 SkPaint solid_paint;
102 bool is_solid_color = false; 102 bool is_solid_color = false;
103 solid_paint.setColor(solid_color); 103 solid_paint.setColor(solid_color);
104 104
105 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); 105 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67);
106 SkPaint non_solid_paint; 106 SkPaint non_solid_paint;
107 non_solid_paint.setColor(non_solid_color); 107 non_solid_paint.setColor(non_solid_color);
108 108
109 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), 109 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400),
110 solid_paint); 110 solid_paint);
111 recording_source->Rerecord(); 111 recording_source->Rerecord();
112 112
113 scoped_refptr<DisplayListRasterSource> raster = 113 scoped_refptr<RasterSource> raster =
114 DisplayListRasterSource::CreateFromDisplayListRecordingSource( 114 RasterSource::CreateFromDisplayListRecordingSource(recording_source.get(),
115 recording_source.get(), false); 115 false);
116 116
117 // Ensure everything is solid. 117 // Ensure everything is solid.
118 for (int y = 0; y <= 30; y += 10) { 118 for (int y = 0; y <= 30; y += 10) {
119 for (int x = 0; x <= 30; x += 10) { 119 for (int x = 0; x <= 30; x += 10) {
120 gfx::Rect rect(x, y, 10, 10); 120 gfx::Rect rect(x, y, 10, 10);
121 is_solid_color = raster->PerformSolidColorAnalysis(rect, 0.1f, &color); 121 is_solid_color = raster->PerformSolidColorAnalysis(rect, 0.1f, &color);
122 EXPECT_TRUE(is_solid_color) << rect.ToString(); 122 EXPECT_TRUE(is_solid_color) << rect.ToString();
123 EXPECT_EQ(color, solid_color) << rect.ToString(); 123 EXPECT_EQ(color, solid_color) << rect.ToString();
124 } 124 }
125 } 125 }
126 126
127 // Add one non-solid pixel and recreate the raster source. 127 // Add one non-solid pixel and recreate the raster source.
128 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), 128 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1),
129 non_solid_paint); 129 non_solid_paint);
130 recording_source->Rerecord(); 130 recording_source->Rerecord();
131 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( 131 raster = RasterSource::CreateFromDisplayListRecordingSource(
132 recording_source.get(), false); 132 recording_source.get(), false);
133 133
134 color = SK_ColorTRANSPARENT; 134 color = SK_ColorTRANSPARENT;
135 is_solid_color = 135 is_solid_color =
136 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 10, 10), 0.1f, &color); 136 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 10, 10), 0.1f, &color);
137 EXPECT_FALSE(is_solid_color); 137 EXPECT_FALSE(is_solid_color);
138 138
139 color = SK_ColorTRANSPARENT; 139 color = SK_ColorTRANSPARENT;
140 is_solid_color = 140 is_solid_color =
141 raster->PerformSolidColorAnalysis(gfx::Rect(10, 0, 10, 10), 0.1f, &color); 141 raster->PerformSolidColorAnalysis(gfx::Rect(10, 0, 10, 10), 0.1f, &color);
(...skipping 13 matching lines...) Expand all
155 EXPECT_TRUE(is_solid_color); 155 EXPECT_TRUE(is_solid_color);
156 EXPECT_EQ(color, solid_color); 156 EXPECT_EQ(color, solid_color);
157 157
158 color = SK_ColorTRANSPARENT; 158 color = SK_ColorTRANSPARENT;
159 is_solid_color = raster->PerformSolidColorAnalysis(gfx::Rect(35, 35, 10, 10), 159 is_solid_color = raster->PerformSolidColorAnalysis(gfx::Rect(35, 35, 10, 10),
160 0.1f, &color); 160 0.1f, &color);
161 EXPECT_TRUE(is_solid_color); 161 EXPECT_TRUE(is_solid_color);
162 EXPECT_EQ(color, solid_color); 162 EXPECT_EQ(color, solid_color);
163 } 163 }
164 164
165 TEST(DisplayListRasterSourceTest, AnalyzeIsSolidEmpty) { 165 TEST(RasterSourceTest, AnalyzeIsSolidEmpty) {
166 gfx::Size layer_bounds(400, 400); 166 gfx::Size layer_bounds(400, 400);
167 167
168 scoped_ptr<FakeDisplayListRecordingSource> recording_source = 168 scoped_ptr<FakeDisplayListRecordingSource> recording_source =
169 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); 169 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds);
170 recording_source->Rerecord(); 170 recording_source->Rerecord();
171 171
172 scoped_refptr<DisplayListRasterSource> raster = 172 scoped_refptr<RasterSource> raster =
173 DisplayListRasterSource::CreateFromDisplayListRecordingSource( 173 RasterSource::CreateFromDisplayListRecordingSource(recording_source.get(),
174 recording_source.get(), false); 174 false);
175 175
176 SkColor color = SK_ColorTRANSPARENT; 176 SkColor color = SK_ColorTRANSPARENT;
177 bool is_solid_color = 177 bool is_solid_color =
178 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 400, 400), 1.f, &color); 178 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 400, 400), 1.f, &color);
179 179
180 EXPECT_TRUE(is_solid_color); 180 EXPECT_TRUE(is_solid_color);
181 EXPECT_EQ(color, SkColorSetARGB(0, 0, 0, 0)); 181 EXPECT_EQ(color, SkColorSetARGB(0, 0, 0, 0));
182 } 182 }
183 183
184 TEST(DisplayListRasterSourceTest, PixelRefIteratorDiscardableRefsOneTile) { 184 TEST(RasterSourceTest, PixelRefIteratorDiscardableRefsOneTile) {
185 gfx::Size layer_bounds(512, 512); 185 gfx::Size layer_bounds(512, 512);
186 186
187 scoped_ptr<FakeDisplayListRecordingSource> recording_source = 187 scoped_ptr<FakeDisplayListRecordingSource> recording_source =
188 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); 188 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds);
189 189
190 skia::RefPtr<SkImage> discardable_image[2][2]; 190 skia::RefPtr<SkImage> discardable_image[2][2];
191 discardable_image[0][0] = CreateDiscardableImage(gfx::Size(32, 32)); 191 discardable_image[0][0] = CreateDiscardableImage(gfx::Size(32, 32));
192 discardable_image[0][1] = CreateDiscardableImage(gfx::Size(32, 32)); 192 discardable_image[0][1] = CreateDiscardableImage(gfx::Size(32, 32));
193 discardable_image[1][1] = CreateDiscardableImage(gfx::Size(32, 32)); 193 discardable_image[1][1] = CreateDiscardableImage(gfx::Size(32, 32));
194 194
195 // Discardable pixel refs are found in the following cells: 195 // Discardable pixel refs are found in the following cells:
196 // |---|---| 196 // |---|---|
197 // | x | x | 197 // | x | x |
198 // |---|---| 198 // |---|---|
199 // | | x | 199 // | | x |
200 // |---|---| 200 // |---|---|
201 recording_source->add_draw_image(discardable_image[0][0].get(), 201 recording_source->add_draw_image(discardable_image[0][0].get(),
202 gfx::Point(0, 0)); 202 gfx::Point(0, 0));
203 recording_source->add_draw_image(discardable_image[0][1].get(), 203 recording_source->add_draw_image(discardable_image[0][1].get(),
204 gfx::Point(260, 0)); 204 gfx::Point(260, 0));
205 recording_source->add_draw_image(discardable_image[1][1].get(), 205 recording_source->add_draw_image(discardable_image[1][1].get(),
206 gfx::Point(260, 260)); 206 gfx::Point(260, 260));
207 recording_source->SetGenerateDiscardableImagesMetadata(true); 207 recording_source->SetGenerateDiscardableImagesMetadata(true);
208 recording_source->Rerecord(); 208 recording_source->Rerecord();
209 209
210 scoped_refptr<DisplayListRasterSource> raster = 210 scoped_refptr<RasterSource> raster =
211 DisplayListRasterSource::CreateFromDisplayListRecordingSource( 211 RasterSource::CreateFromDisplayListRecordingSource(recording_source.get(),
212 recording_source.get(), false); 212 false);
213 213
214 // Tile sized iterators. These should find only one pixel ref. 214 // Tile sized iterators. These should find only one pixel ref.
215 { 215 {
216 std::vector<DrawImage> images; 216 std::vector<DrawImage> images;
217 raster->GetDiscardableImagesInRect(gfx::Rect(0, 0, 256, 256), 1.f, &images); 217 raster->GetDiscardableImagesInRect(gfx::Rect(0, 0, 256, 256), 1.f, &images);
218 EXPECT_EQ(1u, images.size()); 218 EXPECT_EQ(1u, images.size());
219 EXPECT_EQ(discardable_image[0][0].get(), images[0].image()); 219 EXPECT_EQ(discardable_image[0][0].get(), images[0].image());
220 } 220 }
221 // Shifted tile sized iterators. These should find only one pixel ref. 221 // Shifted tile sized iterators. These should find only one pixel ref.
222 { 222 {
(...skipping 14 matching lines...) Expand all
237 { 237 {
238 std::vector<DrawImage> images; 238 std::vector<DrawImage> images;
239 raster->GetDiscardableImagesInRect(gfx::Rect(0, 0, 512, 512), 1.f, &images); 239 raster->GetDiscardableImagesInRect(gfx::Rect(0, 0, 512, 512), 1.f, &images);
240 EXPECT_EQ(3u, images.size()); 240 EXPECT_EQ(3u, images.size());
241 EXPECT_EQ(discardable_image[0][0].get(), images[0].image()); 241 EXPECT_EQ(discardable_image[0][0].get(), images[0].image());
242 EXPECT_EQ(discardable_image[0][1].get(), images[1].image()); 242 EXPECT_EQ(discardable_image[0][1].get(), images[1].image());
243 EXPECT_EQ(discardable_image[1][1].get(), images[2].image()); 243 EXPECT_EQ(discardable_image[1][1].get(), images[2].image());
244 } 244 }
245 } 245 }
246 246
247 TEST(DisplayListRasterSourceTest, RasterFullContents) { 247 TEST(RasterSourceTest, RasterFullContents) {
248 gfx::Size layer_bounds(3, 5); 248 gfx::Size layer_bounds(3, 5);
249 float contents_scale = 1.5f; 249 float contents_scale = 1.5f;
250 float raster_divisions = 2.f; 250 float raster_divisions = 2.f;
251 251
252 scoped_ptr<FakeDisplayListRecordingSource> recording_source = 252 scoped_ptr<FakeDisplayListRecordingSource> recording_source =
253 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); 253 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds);
254 recording_source->SetBackgroundColor(SK_ColorBLACK); 254 recording_source->SetBackgroundColor(SK_ColorBLACK);
255 recording_source->SetClearCanvasWithDebugColor(false); 255 recording_source->SetClearCanvasWithDebugColor(false);
256 256
257 // Because the caller sets content opaque, it also promises that it 257 // Because the caller sets content opaque, it also promises that it
258 // has at least filled in layer_bounds opaquely. 258 // has at least filled in layer_bounds opaquely.
259 SkPaint white_paint; 259 SkPaint white_paint;
260 white_paint.setColor(SK_ColorWHITE); 260 white_paint.setColor(SK_ColorWHITE);
261 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), 261 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds),
262 white_paint); 262 white_paint);
263 recording_source->Rerecord(); 263 recording_source->Rerecord();
264 264
265 scoped_refptr<DisplayListRasterSource> raster = 265 scoped_refptr<RasterSource> raster =
266 DisplayListRasterSource::CreateFromDisplayListRecordingSource( 266 RasterSource::CreateFromDisplayListRecordingSource(recording_source.get(),
267 recording_source.get(), false); 267 false);
268 268
269 gfx::Size content_bounds( 269 gfx::Size content_bounds(
270 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); 270 gfx::ScaleToCeiledSize(layer_bounds, contents_scale));
271 271
272 // Simulate drawing into different tiles at different offsets. 272 // Simulate drawing into different tiles at different offsets.
273 int step_x = std::ceil(content_bounds.width() / raster_divisions); 273 int step_x = std::ceil(content_bounds.width() / raster_divisions);
274 int step_y = std::ceil(content_bounds.height() / raster_divisions); 274 int step_y = std::ceil(content_bounds.height() / raster_divisions);
275 for (int offset_x = 0; offset_x < content_bounds.width(); 275 for (int offset_x = 0; offset_x < content_bounds.width();
276 offset_x += step_x) { 276 offset_x += step_x) {
277 for (int offset_y = 0; offset_y < content_bounds.height(); 277 for (int offset_y = 0; offset_y < content_bounds.height();
(...skipping 27 matching lines...) Expand all
305 } 305 }
306 306
307 // If the canvas doesn't extend past the edge of the content, 307 // If the canvas doesn't extend past the edge of the content,
308 // it should be entirely white. Otherwise, the edge of the content 308 // it should be entirely white. Otherwise, the edge of the content
309 // will be non-white. 309 // will be non-white.
310 EXPECT_EQ(all_white, gfx::Rect(content_bounds).Contains(canvas_rect)); 310 EXPECT_EQ(all_white, gfx::Rect(content_bounds).Contains(canvas_rect));
311 } 311 }
312 } 312 }
313 } 313 }
314 314
315 TEST(DisplayListRasterSourceTest, RasterPartialContents) { 315 TEST(RasterSourceTest, RasterPartialContents) {
316 gfx::Size layer_bounds(3, 5); 316 gfx::Size layer_bounds(3, 5);
317 float contents_scale = 1.5f; 317 float contents_scale = 1.5f;
318 318
319 scoped_ptr<FakeDisplayListRecordingSource> recording_source = 319 scoped_ptr<FakeDisplayListRecordingSource> recording_source =
320 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); 320 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds);
321 recording_source->SetBackgroundColor(SK_ColorGREEN); 321 recording_source->SetBackgroundColor(SK_ColorGREEN);
322 recording_source->SetClearCanvasWithDebugColor(false); 322 recording_source->SetClearCanvasWithDebugColor(false);
323 323
324 // First record everything as white. 324 // First record everything as white.
325 SkPaint white_paint; 325 SkPaint white_paint;
326 white_paint.setColor(SK_ColorWHITE); 326 white_paint.setColor(SK_ColorWHITE);
327 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), 327 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds),
328 white_paint); 328 white_paint);
329 recording_source->Rerecord(); 329 recording_source->Rerecord();
330 330
331 scoped_refptr<DisplayListRasterSource> raster = 331 scoped_refptr<RasterSource> raster =
332 DisplayListRasterSource::CreateFromDisplayListRecordingSource( 332 RasterSource::CreateFromDisplayListRecordingSource(recording_source.get(),
333 recording_source.get(), false); 333 false);
334 334
335 gfx::Size content_bounds( 335 gfx::Size content_bounds(
336 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); 336 gfx::ScaleToCeiledSize(layer_bounds, contents_scale));
337 337
338 SkBitmap bitmap; 338 SkBitmap bitmap;
339 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); 339 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height());
340 SkCanvas canvas(bitmap); 340 SkCanvas canvas(bitmap);
341 canvas.clear(SK_ColorTRANSPARENT); 341 canvas.clear(SK_ColorTRANSPARENT);
342 342
343 // Playback the full rect which should make everything white. 343 // Playback the full rect which should make everything white.
(...skipping 17 matching lines...) Expand all
361 } 361 }
362 } 362 }
363 363
364 // Re-record everything as black. 364 // Re-record everything as black.
365 SkPaint black_paint; 365 SkPaint black_paint;
366 black_paint.setColor(SK_ColorBLACK); 366 black_paint.setColor(SK_ColorBLACK);
367 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), 367 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds),
368 black_paint); 368 black_paint);
369 recording_source->Rerecord(); 369 recording_source->Rerecord();
370 370
371 // Make a new DisplayListRasterSource from the new recording. 371 // Make a new RasterSource from the new recording.
372 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( 372 raster = RasterSource::CreateFromDisplayListRecordingSource(
373 recording_source.get(), false); 373 recording_source.get(), false);
374 374
375 // We're going to playback from "everything is black" into a smaller area, 375 // We're going to playback from "everything is black" into a smaller area,
376 // that touches the edge pixels of the recording. 376 // that touches the edge pixels of the recording.
377 playback_rect.Inset(1, 2, 0, 1); 377 playback_rect.Inset(1, 2, 0, 1);
378 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, 378 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect,
379 contents_scale, include_images); 379 contents_scale, include_images);
380 380
381 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); 381 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels());
382 int num_black = 0; 382 int num_black = 0;
(...skipping 15 matching lines...) Expand all
398 EXPECT_EQ(255u, SkColorGetG(pixels[i + j * bitmap.width()])); 398 EXPECT_EQ(255u, SkColorGetG(pixels[i + j * bitmap.width()]));
399 EXPECT_EQ(255u, SkColorGetB(pixels[i + j * bitmap.width()])); 399 EXPECT_EQ(255u, SkColorGetB(pixels[i + j * bitmap.width()]));
400 ++num_white; 400 ++num_white;
401 } 401 }
402 } 402 }
403 } 403 }
404 EXPECT_GT(num_black, 0); 404 EXPECT_GT(num_black, 0);
405 EXPECT_GT(num_white, 0); 405 EXPECT_GT(num_white, 0);
406 } 406 }
407 407
408 TEST(DisplayListRasterSourceTest, RasterPartialClear) { 408 TEST(RasterSourceTest, RasterPartialClear) {
409 gfx::Size layer_bounds(3, 5); 409 gfx::Size layer_bounds(3, 5);
410 gfx::Size partial_bounds(2, 4); 410 gfx::Size partial_bounds(2, 4);
411 float contents_scale = 1.5f; 411 float contents_scale = 1.5f;
412 412
413 scoped_ptr<FakeDisplayListRecordingSource> recording_source = 413 scoped_ptr<FakeDisplayListRecordingSource> recording_source =
414 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); 414 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds);
415 recording_source->SetBackgroundColor(SK_ColorGREEN); 415 recording_source->SetBackgroundColor(SK_ColorGREEN);
416 recording_source->SetRequiresClear(true); 416 recording_source->SetRequiresClear(true);
417 recording_source->SetClearCanvasWithDebugColor(false); 417 recording_source->SetClearCanvasWithDebugColor(false);
418 418
419 // First record everything as white. 419 // First record everything as white.
420 const unsigned alpha_dark = 10u; 420 const unsigned alpha_dark = 10u;
421 SkPaint white_paint; 421 SkPaint white_paint;
422 white_paint.setColor(SK_ColorWHITE); 422 white_paint.setColor(SK_ColorWHITE);
423 white_paint.setAlpha(alpha_dark); 423 white_paint.setAlpha(alpha_dark);
424 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), 424 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds),
425 white_paint); 425 white_paint);
426 recording_source->Rerecord(); 426 recording_source->Rerecord();
427 427
428 scoped_refptr<DisplayListRasterSource> raster = 428 scoped_refptr<RasterSource> raster =
429 DisplayListRasterSource::CreateFromDisplayListRecordingSource( 429 RasterSource::CreateFromDisplayListRecordingSource(recording_source.get(),
430 recording_source.get(), false); 430 false);
431 431
432 gfx::Size content_bounds( 432 gfx::Size content_bounds(
433 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); 433 gfx::ScaleToCeiledSize(layer_bounds, contents_scale));
434 434
435 SkBitmap bitmap; 435 SkBitmap bitmap;
436 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); 436 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height());
437 SkCanvas canvas(bitmap); 437 SkCanvas canvas(bitmap);
438 canvas.clear(SK_ColorTRANSPARENT); 438 canvas.clear(SK_ColorTRANSPARENT);
439 439
440 // Playback the full rect which should make everything light gray (alpha=10). 440 // Playback the full rect which should make everything light gray (alpha=10).
(...skipping 23 matching lines...) Expand all
464 recording_source_light->SetRequiresClear(true); 464 recording_source_light->SetRequiresClear(true);
465 recording_source_light->SetClearCanvasWithDebugColor(false); 465 recording_source_light->SetClearCanvasWithDebugColor(false);
466 466
467 // Record everything as a slightly lighter white. 467 // Record everything as a slightly lighter white.
468 const unsigned alpha_light = 18u; 468 const unsigned alpha_light = 18u;
469 white_paint.setAlpha(alpha_light); 469 white_paint.setAlpha(alpha_light);
470 recording_source_light->add_draw_rect_with_paint(gfx::Rect(layer_bounds), 470 recording_source_light->add_draw_rect_with_paint(gfx::Rect(layer_bounds),
471 white_paint); 471 white_paint);
472 recording_source_light->Rerecord(); 472 recording_source_light->Rerecord();
473 473
474 // Make a new DisplayListRasterSource from the new recording. 474 // Make a new RasterSource from the new recording.
475 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( 475 raster = RasterSource::CreateFromDisplayListRecordingSource(
476 recording_source_light.get(), false); 476 recording_source_light.get(), false);
477 477
478 // We're going to playback from alpha(18) white rectangle into a smaller area 478 // We're going to playback from alpha(18) white rectangle into a smaller area
479 // of the recording resulting in a smaller lighter white rectangle over a 479 // of the recording resulting in a smaller lighter white rectangle over a
480 // darker white background rectangle. 480 // darker white background rectangle.
481 playback_rect = 481 playback_rect =
482 gfx::Rect(gfx::ScaleToCeiledSize(partial_bounds, contents_scale)); 482 gfx::Rect(gfx::ScaleToCeiledSize(partial_bounds, contents_scale));
483 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, 483 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect,
484 contents_scale, include_images); 484 contents_scale, include_images);
485 485
486 // Test that the whole playback_rect was cleared and repainted with new alpha. 486 // Test that the whole playback_rect was cleared and repainted with new alpha.
487 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); 487 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels());
488 for (int i = 0; i < playback_rect.width(); ++i) { 488 for (int i = 0; i < playback_rect.width(); ++i) {
489 for (int j = 0; j < playback_rect.height(); ++j) { 489 for (int j = 0; j < playback_rect.height(); ++j) {
490 SCOPED_TRACE(j); 490 SCOPED_TRACE(j);
491 SCOPED_TRACE(i); 491 SCOPED_TRACE(i);
492 EXPECT_EQ(alpha_light, SkColorGetA(pixels[i + j * bitmap.width()])); 492 EXPECT_EQ(alpha_light, SkColorGetA(pixels[i + j * bitmap.width()]));
493 EXPECT_EQ(alpha_light, SkColorGetR(pixels[i + j * bitmap.width()])); 493 EXPECT_EQ(alpha_light, SkColorGetR(pixels[i + j * bitmap.width()]));
494 EXPECT_EQ(alpha_light, SkColorGetG(pixels[i + j * bitmap.width()])); 494 EXPECT_EQ(alpha_light, SkColorGetG(pixels[i + j * bitmap.width()]));
495 EXPECT_EQ(alpha_light, SkColorGetB(pixels[i + j * bitmap.width()])); 495 EXPECT_EQ(alpha_light, SkColorGetB(pixels[i + j * bitmap.width()]));
496 } 496 }
497 } 497 }
498 } 498 }
499 499
500 TEST(DisplayListRasterSourceTest, RasterContentsTransparent) { 500 TEST(RasterSourceTest, RasterContentsTransparent) {
501 gfx::Size layer_bounds(5, 3); 501 gfx::Size layer_bounds(5, 3);
502 float contents_scale = 0.5f; 502 float contents_scale = 0.5f;
503 503
504 scoped_ptr<FakeDisplayListRecordingSource> recording_source = 504 scoped_ptr<FakeDisplayListRecordingSource> recording_source =
505 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); 505 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds);
506 recording_source->SetBackgroundColor(SK_ColorTRANSPARENT); 506 recording_source->SetBackgroundColor(SK_ColorTRANSPARENT);
507 recording_source->SetRequiresClear(true); 507 recording_source->SetRequiresClear(true);
508 recording_source->SetClearCanvasWithDebugColor(false); 508 recording_source->SetClearCanvasWithDebugColor(false);
509 recording_source->Rerecord(); 509 recording_source->Rerecord();
510 510
511 scoped_refptr<DisplayListRasterSource> raster = 511 scoped_refptr<RasterSource> raster =
512 DisplayListRasterSource::CreateFromDisplayListRecordingSource( 512 RasterSource::CreateFromDisplayListRecordingSource(recording_source.get(),
513 recording_source.get(), false); 513 false);
514 gfx::Size content_bounds( 514 gfx::Size content_bounds(
515 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); 515 gfx::ScaleToCeiledSize(layer_bounds, contents_scale));
516 516
517 gfx::Rect canvas_rect(content_bounds); 517 gfx::Rect canvas_rect(content_bounds);
518 canvas_rect.Inset(0, 0, -1, -1); 518 canvas_rect.Inset(0, 0, -1, -1);
519 519
520 SkBitmap bitmap; 520 SkBitmap bitmap;
521 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); 521 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height());
522 SkCanvas canvas(bitmap); 522 SkCanvas canvas(bitmap);
523 523
524 const bool include_images = true; 524 const bool include_images = true;
525 raster->PlaybackToCanvas(&canvas, canvas_rect, canvas_rect, contents_scale, 525 raster->PlaybackToCanvas(&canvas, canvas_rect, canvas_rect, contents_scale,
526 include_images); 526 include_images);
527 527
528 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); 528 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels());
529 int num_pixels = bitmap.width() * bitmap.height(); 529 int num_pixels = bitmap.width() * bitmap.height();
530 for (int i = 0; i < num_pixels; ++i) { 530 for (int i = 0; i < num_pixels; ++i) {
531 EXPECT_EQ(SkColorGetA(pixels[i]), 0u); 531 EXPECT_EQ(SkColorGetA(pixels[i]), 0u);
532 } 532 }
533 } 533 }
534 534
535 TEST(DisplayListRasterSourceTest, 535 TEST(RasterSourceTest, GetPictureMemoryUsageIncludesClientReportedMemory) {
536 GetPictureMemoryUsageIncludesClientReportedMemory) {
537 const size_t kReportedMemoryUsageInBytes = 100 * 1024 * 1024; 536 const size_t kReportedMemoryUsageInBytes = 100 * 1024 * 1024;
538 gfx::Size layer_bounds(5, 3); 537 gfx::Size layer_bounds(5, 3);
539 scoped_ptr<FakeDisplayListRecordingSource> recording_source = 538 scoped_ptr<FakeDisplayListRecordingSource> recording_source =
540 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); 539 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds);
541 recording_source->set_reported_memory_usage(kReportedMemoryUsageInBytes); 540 recording_source->set_reported_memory_usage(kReportedMemoryUsageInBytes);
542 recording_source->Rerecord(); 541 recording_source->Rerecord();
543 542
544 scoped_refptr<DisplayListRasterSource> raster = 543 scoped_refptr<RasterSource> raster =
545 DisplayListRasterSource::CreateFromDisplayListRecordingSource( 544 RasterSource::CreateFromDisplayListRecordingSource(recording_source.get(),
546 recording_source.get(), false); 545 false);
547 size_t total_memory_usage = raster->GetPictureMemoryUsage(); 546 size_t total_memory_usage = raster->GetPictureMemoryUsage();
548 EXPECT_GE(total_memory_usage, kReportedMemoryUsageInBytes); 547 EXPECT_GE(total_memory_usage, kReportedMemoryUsageInBytes);
549 EXPECT_LT(total_memory_usage, 2 * kReportedMemoryUsageInBytes); 548 EXPECT_LT(total_memory_usage, 2 * kReportedMemoryUsageInBytes);
550 } 549 }
551 550
552 } // namespace 551 } // namespace
553 } // namespace cc 552 } // namespace cc
OLDNEW
« no previous file with comments | « cc/playback/raster_source.cc ('k') | cc/quads/draw_quad_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698