OLD | NEW |
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 "cc/playback/raster_source.h" | 5 #include "cc/playback/raster_source.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 solid_paint); | 41 solid_paint); |
42 recording_source->Rerecord(); | 42 recording_source->Rerecord(); |
43 | 43 |
44 scoped_refptr<RasterSource> raster = | 44 scoped_refptr<RasterSource> raster = |
45 RasterSource::CreateFromRecordingSource(recording_source.get(), false); | 45 RasterSource::CreateFromRecordingSource(recording_source.get(), false); |
46 | 46 |
47 // Ensure everything is solid. | 47 // Ensure everything is solid. |
48 for (int y = 0; y <= 300; y += 100) { | 48 for (int y = 0; y <= 300; y += 100) { |
49 for (int x = 0; x <= 300; x += 100) { | 49 for (int x = 0; x <= 300; x += 100) { |
50 gfx::Rect rect(x, y, 100, 100); | 50 gfx::Rect rect(x, y, 100, 100); |
51 is_solid_color = | 51 is_solid_color = raster->PerformSolidColorAnalysis(rect, 1.f, &color); |
52 raster->PerformSolidColorAnalysis(rect, gfx::SizeF(1.f, 1.f), &color); | |
53 EXPECT_TRUE(is_solid_color) << rect.ToString(); | 52 EXPECT_TRUE(is_solid_color) << rect.ToString(); |
54 EXPECT_EQ(solid_color, color) << rect.ToString(); | 53 EXPECT_EQ(solid_color, color) << rect.ToString(); |
55 } | 54 } |
56 } | 55 } |
57 | 56 |
58 // Add one non-solid pixel and recreate the raster source. | 57 // Add one non-solid pixel and recreate the raster source. |
59 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), | 58 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), |
60 non_solid_paint); | 59 non_solid_paint); |
61 recording_source->Rerecord(); | 60 recording_source->Rerecord(); |
62 raster = | 61 raster = |
63 RasterSource::CreateFromRecordingSource(recording_source.get(), false); | 62 RasterSource::CreateFromRecordingSource(recording_source.get(), false); |
64 | 63 |
65 color = SK_ColorTRANSPARENT; | 64 color = SK_ColorTRANSPARENT; |
66 is_solid_color = raster->PerformSolidColorAnalysis( | 65 is_solid_color = |
67 gfx::Rect(0, 0, 100, 100), gfx::SizeF(1.f, 1.f), &color); | 66 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 100, 100), 1.f, &color); |
68 EXPECT_FALSE(is_solid_color); | 67 EXPECT_FALSE(is_solid_color); |
69 | 68 |
70 color = SK_ColorTRANSPARENT; | 69 color = SK_ColorTRANSPARENT; |
71 is_solid_color = raster->PerformSolidColorAnalysis( | 70 is_solid_color = raster->PerformSolidColorAnalysis( |
72 gfx::Rect(100, 0, 100, 100), gfx::SizeF(1.f, 1.f), &color); | 71 gfx::Rect(100, 0, 100, 100), 1.f, &color); |
73 EXPECT_TRUE(is_solid_color); | 72 EXPECT_TRUE(is_solid_color); |
74 EXPECT_EQ(solid_color, color); | 73 EXPECT_EQ(solid_color, color); |
75 | 74 |
76 // Boundaries should be clipped. | 75 // Boundaries should be clipped. |
77 color = SK_ColorTRANSPARENT; | 76 color = SK_ColorTRANSPARENT; |
78 is_solid_color = raster->PerformSolidColorAnalysis( | 77 is_solid_color = raster->PerformSolidColorAnalysis( |
79 gfx::Rect(350, 0, 100, 100), gfx::SizeF(1.f, 1.f), &color); | 78 gfx::Rect(350, 0, 100, 100), 1.f, &color); |
80 EXPECT_TRUE(is_solid_color); | 79 EXPECT_TRUE(is_solid_color); |
81 EXPECT_EQ(solid_color, color); | 80 EXPECT_EQ(solid_color, color); |
82 | 81 |
83 color = SK_ColorTRANSPARENT; | 82 color = SK_ColorTRANSPARENT; |
84 is_solid_color = raster->PerformSolidColorAnalysis( | 83 is_solid_color = raster->PerformSolidColorAnalysis( |
85 gfx::Rect(0, 350, 100, 100), gfx::SizeF(1.f, 1.f), &color); | 84 gfx::Rect(0, 350, 100, 100), 1.f, &color); |
86 EXPECT_TRUE(is_solid_color); | 85 EXPECT_TRUE(is_solid_color); |
87 EXPECT_EQ(solid_color, color); | 86 EXPECT_EQ(solid_color, color); |
88 | 87 |
89 color = SK_ColorTRANSPARENT; | 88 color = SK_ColorTRANSPARENT; |
90 is_solid_color = raster->PerformSolidColorAnalysis( | 89 is_solid_color = raster->PerformSolidColorAnalysis( |
91 gfx::Rect(350, 350, 100, 100), gfx::SizeF(1.f, 1.f), &color); | 90 gfx::Rect(350, 350, 100, 100), 1.f, &color); |
92 EXPECT_TRUE(is_solid_color); | 91 EXPECT_TRUE(is_solid_color); |
93 EXPECT_EQ(solid_color, color); | 92 EXPECT_EQ(solid_color, color); |
94 } | 93 } |
95 | 94 |
96 TEST(RasterSourceTest, AnalyzeIsSolidScaled) { | 95 TEST(RasterSourceTest, AnalyzeIsSolidScaled) { |
97 gfx::Size layer_bounds(400, 400); | 96 gfx::Size layer_bounds(400, 400); |
98 | 97 |
99 std::unique_ptr<FakeRecordingSource> recording_source = | 98 std::unique_ptr<FakeRecordingSource> recording_source = |
100 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); | 99 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); |
101 | 100 |
(...skipping 11 matching lines...) Expand all Loading... |
113 solid_paint); | 112 solid_paint); |
114 recording_source->Rerecord(); | 113 recording_source->Rerecord(); |
115 | 114 |
116 scoped_refptr<RasterSource> raster = | 115 scoped_refptr<RasterSource> raster = |
117 RasterSource::CreateFromRecordingSource(recording_source.get(), false); | 116 RasterSource::CreateFromRecordingSource(recording_source.get(), false); |
118 | 117 |
119 // Ensure everything is solid. | 118 // Ensure everything is solid. |
120 for (int y = 0; y <= 30; y += 10) { | 119 for (int y = 0; y <= 30; y += 10) { |
121 for (int x = 0; x <= 30; x += 10) { | 120 for (int x = 0; x <= 30; x += 10) { |
122 gfx::Rect rect(x, y, 10, 10); | 121 gfx::Rect rect(x, y, 10, 10); |
123 is_solid_color = raster->PerformSolidColorAnalysis( | 122 is_solid_color = raster->PerformSolidColorAnalysis(rect, 0.1f, &color); |
124 rect, gfx::SizeF(0.1f, 0.1f), &color); | |
125 EXPECT_TRUE(is_solid_color) << rect.ToString(); | 123 EXPECT_TRUE(is_solid_color) << rect.ToString(); |
126 EXPECT_EQ(color, solid_color) << rect.ToString(); | 124 EXPECT_EQ(color, solid_color) << rect.ToString(); |
127 } | 125 } |
128 } | 126 } |
129 | 127 |
130 // Add one non-solid pixel and recreate the raster source. | 128 // Add one non-solid pixel and recreate the raster source. |
131 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), | 129 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), |
132 non_solid_paint); | 130 non_solid_paint); |
133 recording_source->Rerecord(); | 131 recording_source->Rerecord(); |
134 raster = | 132 raster = |
135 RasterSource::CreateFromRecordingSource(recording_source.get(), false); | 133 RasterSource::CreateFromRecordingSource(recording_source.get(), false); |
136 | 134 |
137 color = SK_ColorTRANSPARENT; | 135 color = SK_ColorTRANSPARENT; |
138 is_solid_color = raster->PerformSolidColorAnalysis( | 136 is_solid_color = |
139 gfx::Rect(0, 0, 10, 10), gfx::SizeF(0.1f, 0.1f), &color); | 137 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 10, 10), 0.1f, &color); |
140 EXPECT_FALSE(is_solid_color); | 138 EXPECT_FALSE(is_solid_color); |
141 | 139 |
142 color = SK_ColorTRANSPARENT; | 140 color = SK_ColorTRANSPARENT; |
143 is_solid_color = raster->PerformSolidColorAnalysis( | 141 is_solid_color = |
144 gfx::Rect(10, 0, 10, 10), gfx::SizeF(0.1f, 0.1f), &color); | 142 raster->PerformSolidColorAnalysis(gfx::Rect(10, 0, 10, 10), 0.1f, &color); |
145 EXPECT_TRUE(is_solid_color); | 143 EXPECT_TRUE(is_solid_color); |
146 EXPECT_EQ(color, solid_color); | 144 EXPECT_EQ(color, solid_color); |
147 | 145 |
148 // Boundaries should be clipped. | 146 // Boundaries should be clipped. |
149 color = SK_ColorTRANSPARENT; | 147 color = SK_ColorTRANSPARENT; |
150 is_solid_color = raster->PerformSolidColorAnalysis( | 148 is_solid_color = |
151 gfx::Rect(35, 0, 10, 10), gfx::SizeF(0.1f, 0.1f), &color); | 149 raster->PerformSolidColorAnalysis(gfx::Rect(35, 0, 10, 10), 0.1f, &color); |
152 EXPECT_TRUE(is_solid_color); | 150 EXPECT_TRUE(is_solid_color); |
153 EXPECT_EQ(color, solid_color); | 151 EXPECT_EQ(color, solid_color); |
154 | 152 |
155 color = SK_ColorTRANSPARENT; | 153 color = SK_ColorTRANSPARENT; |
156 is_solid_color = raster->PerformSolidColorAnalysis( | 154 is_solid_color = |
157 gfx::Rect(0, 35, 10, 10), gfx::SizeF(0.1f, 0.1f), &color); | 155 raster->PerformSolidColorAnalysis(gfx::Rect(0, 35, 10, 10), 0.1f, &color); |
158 EXPECT_TRUE(is_solid_color); | 156 EXPECT_TRUE(is_solid_color); |
159 EXPECT_EQ(color, solid_color); | 157 EXPECT_EQ(color, solid_color); |
160 | 158 |
161 color = SK_ColorTRANSPARENT; | 159 color = SK_ColorTRANSPARENT; |
162 is_solid_color = raster->PerformSolidColorAnalysis( | 160 is_solid_color = raster->PerformSolidColorAnalysis(gfx::Rect(35, 35, 10, 10), |
163 gfx::Rect(35, 35, 10, 10), gfx::SizeF(0.1f, 0.1f), &color); | 161 0.1f, &color); |
164 EXPECT_TRUE(is_solid_color); | 162 EXPECT_TRUE(is_solid_color); |
165 EXPECT_EQ(color, solid_color); | 163 EXPECT_EQ(color, solid_color); |
166 } | 164 } |
167 | 165 |
168 TEST(RasterSourceTest, AnalyzeIsSolidEmpty) { | 166 TEST(RasterSourceTest, AnalyzeIsSolidEmpty) { |
169 gfx::Size layer_bounds(400, 400); | 167 gfx::Size layer_bounds(400, 400); |
170 | 168 |
171 std::unique_ptr<FakeRecordingSource> recording_source = | 169 std::unique_ptr<FakeRecordingSource> recording_source = |
172 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); | 170 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); |
173 recording_source->Rerecord(); | 171 recording_source->Rerecord(); |
174 | 172 |
175 scoped_refptr<RasterSource> raster = | 173 scoped_refptr<RasterSource> raster = |
176 RasterSource::CreateFromRecordingSource(recording_source.get(), false); | 174 RasterSource::CreateFromRecordingSource(recording_source.get(), false); |
177 | 175 |
178 SkColor color = SK_ColorTRANSPARENT; | 176 SkColor color = SK_ColorTRANSPARENT; |
179 bool is_solid_color = raster->PerformSolidColorAnalysis( | 177 bool is_solid_color = |
180 gfx::Rect(0, 0, 400, 400), gfx::SizeF(1.f, 1.f), &color); | 178 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 400, 400), 1.f, &color); |
181 | 179 |
182 EXPECT_TRUE(is_solid_color); | 180 EXPECT_TRUE(is_solid_color); |
183 EXPECT_EQ(color, SkColorSetARGB(0, 0, 0, 0)); | 181 EXPECT_EQ(color, SkColorSetARGB(0, 0, 0, 0)); |
184 } | 182 } |
185 | 183 |
186 TEST(RasterSourceTest, PixelRefIteratorDiscardableRefsOneTile) { | 184 TEST(RasterSourceTest, PixelRefIteratorDiscardableRefsOneTile) { |
187 gfx::Size layer_bounds(512, 512); | 185 gfx::Size layer_bounds(512, 512); |
188 | 186 |
189 std::unique_ptr<FakeRecordingSource> recording_source = | 187 std::unique_ptr<FakeRecordingSource> recording_source = |
190 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); | 188 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); |
(...skipping 15 matching lines...) Expand all Loading... |
206 gfx::Point(260, 260)); | 204 gfx::Point(260, 260)); |
207 recording_source->SetGenerateDiscardableImagesMetadata(true); | 205 recording_source->SetGenerateDiscardableImagesMetadata(true); |
208 recording_source->Rerecord(); | 206 recording_source->Rerecord(); |
209 | 207 |
210 scoped_refptr<RasterSource> raster = | 208 scoped_refptr<RasterSource> raster = |
211 RasterSource::CreateFromRecordingSource(recording_source.get(), false); | 209 RasterSource::CreateFromRecordingSource(recording_source.get(), false); |
212 | 210 |
213 // Tile sized iterators. These should find only one pixel ref. | 211 // Tile sized iterators. These should find only one pixel ref. |
214 { | 212 { |
215 std::vector<DrawImage> images; | 213 std::vector<DrawImage> images; |
216 raster->GetDiscardableImagesInRect(gfx::Rect(0, 0, 256, 256), | 214 raster->GetDiscardableImagesInRect(gfx::Rect(0, 0, 256, 256), 1.f, &images); |
217 gfx::SizeF(1.f, 1.f), &images); | |
218 EXPECT_EQ(1u, images.size()); | 215 EXPECT_EQ(1u, images.size()); |
219 EXPECT_EQ(discardable_image[0][0], images[0].image()); | 216 EXPECT_EQ(discardable_image[0][0], images[0].image()); |
220 } | 217 } |
221 // Shifted tile sized iterators. These should find only one pixel ref. | 218 // Shifted tile sized iterators. These should find only one pixel ref. |
222 { | 219 { |
223 std::vector<DrawImage> images; | 220 std::vector<DrawImage> images; |
224 raster->GetDiscardableImagesInRect(gfx::Rect(260, 260, 256, 256), | 221 raster->GetDiscardableImagesInRect(gfx::Rect(260, 260, 256, 256), 1.f, |
225 gfx::SizeF(1.f, 1.f), &images); | 222 &images); |
226 EXPECT_EQ(1u, images.size()); | 223 EXPECT_EQ(1u, images.size()); |
227 EXPECT_EQ(discardable_image[1][1], images[0].image()); | 224 EXPECT_EQ(discardable_image[1][1], images[0].image()); |
228 } | 225 } |
229 // Ensure there's no discardable pixel refs in the empty cell | 226 // Ensure there's no discardable pixel refs in the empty cell |
230 { | 227 { |
231 std::vector<DrawImage> images; | 228 std::vector<DrawImage> images; |
232 raster->GetDiscardableImagesInRect(gfx::Rect(0, 256, 256, 256), | 229 raster->GetDiscardableImagesInRect(gfx::Rect(0, 256, 256, 256), 1.f, |
233 gfx::SizeF(1.f, 1.f), &images); | 230 &images); |
234 EXPECT_EQ(0u, images.size()); | 231 EXPECT_EQ(0u, images.size()); |
235 } | 232 } |
236 // Layer sized iterators. These should find three pixel ref. | 233 // Layer sized iterators. These should find three pixel ref. |
237 { | 234 { |
238 std::vector<DrawImage> images; | 235 std::vector<DrawImage> images; |
239 raster->GetDiscardableImagesInRect(gfx::Rect(0, 0, 512, 512), | 236 raster->GetDiscardableImagesInRect(gfx::Rect(0, 0, 512, 512), 1.f, &images); |
240 gfx::SizeF(1.f, 1.f), &images); | |
241 EXPECT_EQ(3u, images.size()); | 237 EXPECT_EQ(3u, images.size()); |
242 EXPECT_EQ(discardable_image[0][0], images[0].image()); | 238 EXPECT_EQ(discardable_image[0][0], images[0].image()); |
243 EXPECT_EQ(discardable_image[0][1], images[1].image()); | 239 EXPECT_EQ(discardable_image[0][1], images[1].image()); |
244 EXPECT_EQ(discardable_image[1][1], images[2].image()); | 240 EXPECT_EQ(discardable_image[1][1], images[2].image()); |
245 } | 241 } |
246 } | 242 } |
247 | 243 |
248 TEST(RasterSourceTest, RasterFullContents) { | 244 TEST(RasterSourceTest, RasterFullContents) { |
249 gfx::Size layer_bounds(3, 5); | 245 gfx::Size layer_bounds(3, 5); |
250 float contents_scale = 1.5f; | 246 float contents_scale = 1.5f; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 // Outside of that is undefined. | 280 // Outside of that is undefined. |
285 gfx::Rect canvas_rect(content_rect); | 281 gfx::Rect canvas_rect(content_rect); |
286 canvas_rect.Inset(0, 0, -1, -1); | 282 canvas_rect.Inset(0, 0, -1, -1); |
287 | 283 |
288 SkBitmap bitmap; | 284 SkBitmap bitmap; |
289 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); | 285 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); |
290 SkCanvas canvas(bitmap); | 286 SkCanvas canvas(bitmap); |
291 canvas.clear(SK_ColorTRANSPARENT); | 287 canvas.clear(SK_ColorTRANSPARENT); |
292 | 288 |
293 raster->PlaybackToCanvas(&canvas, canvas_rect, canvas_rect, | 289 raster->PlaybackToCanvas(&canvas, canvas_rect, canvas_rect, |
294 gfx::SizeF(contents_scale, contents_scale), | 290 contents_scale, |
295 RasterSource::PlaybackSettings()); | 291 RasterSource::PlaybackSettings()); |
296 | 292 |
297 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | 293 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); |
298 int num_pixels = bitmap.width() * bitmap.height(); | 294 int num_pixels = bitmap.width() * bitmap.height(); |
299 bool all_white = true; | 295 bool all_white = true; |
300 for (int i = 0; i < num_pixels; ++i) { | 296 for (int i = 0; i < num_pixels; ++i) { |
301 EXPECT_EQ(SkColorGetA(pixels[i]), 255u); | 297 EXPECT_EQ(SkColorGetA(pixels[i]), 255u); |
302 all_white &= (SkColorGetR(pixels[i]) == 255); | 298 all_white &= (SkColorGetR(pixels[i]) == 255); |
303 all_white &= (SkColorGetG(pixels[i]) == 255); | 299 all_white &= (SkColorGetG(pixels[i]) == 255); |
304 all_white &= (SkColorGetB(pixels[i]) == 255); | 300 all_white &= (SkColorGetB(pixels[i]) == 255); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 | 332 |
337 SkBitmap bitmap; | 333 SkBitmap bitmap; |
338 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); | 334 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); |
339 SkCanvas canvas(bitmap); | 335 SkCanvas canvas(bitmap); |
340 canvas.clear(SK_ColorTRANSPARENT); | 336 canvas.clear(SK_ColorTRANSPARENT); |
341 | 337 |
342 // Playback the full rect which should make everything white. | 338 // Playback the full rect which should make everything white. |
343 gfx::Rect raster_full_rect(content_bounds); | 339 gfx::Rect raster_full_rect(content_bounds); |
344 gfx::Rect playback_rect(content_bounds); | 340 gfx::Rect playback_rect(content_bounds); |
345 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, | 341 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, |
346 gfx::SizeF(contents_scale, contents_scale), | 342 contents_scale, RasterSource::PlaybackSettings()); |
347 RasterSource::PlaybackSettings()); | |
348 | 343 |
349 { | 344 { |
350 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | 345 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); |
351 for (int i = 0; i < bitmap.width(); ++i) { | 346 for (int i = 0; i < bitmap.width(); ++i) { |
352 for (int j = 0; j < bitmap.height(); ++j) { | 347 for (int j = 0; j < bitmap.height(); ++j) { |
353 SCOPED_TRACE(i); | 348 SCOPED_TRACE(i); |
354 SCOPED_TRACE(j); | 349 SCOPED_TRACE(j); |
355 EXPECT_EQ(255u, SkColorGetA(pixels[i + j * bitmap.width()])); | 350 EXPECT_EQ(255u, SkColorGetA(pixels[i + j * bitmap.width()])); |
356 EXPECT_EQ(255u, SkColorGetR(pixels[i + j * bitmap.width()])); | 351 EXPECT_EQ(255u, SkColorGetR(pixels[i + j * bitmap.width()])); |
357 EXPECT_EQ(255u, SkColorGetG(pixels[i + j * bitmap.width()])); | 352 EXPECT_EQ(255u, SkColorGetG(pixels[i + j * bitmap.width()])); |
(...skipping 10 matching lines...) Expand all Loading... |
368 recording_source->Rerecord(); | 363 recording_source->Rerecord(); |
369 | 364 |
370 // Make a new RasterSource from the new recording. | 365 // Make a new RasterSource from the new recording. |
371 raster = | 366 raster = |
372 RasterSource::CreateFromRecordingSource(recording_source.get(), false); | 367 RasterSource::CreateFromRecordingSource(recording_source.get(), false); |
373 | 368 |
374 // We're going to playback from "everything is black" into a smaller area, | 369 // We're going to playback from "everything is black" into a smaller area, |
375 // that touches the edge pixels of the recording. | 370 // that touches the edge pixels of the recording. |
376 playback_rect.Inset(1, 2, 0, 1); | 371 playback_rect.Inset(1, 2, 0, 1); |
377 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, | 372 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, |
378 gfx::SizeF(contents_scale, contents_scale), | 373 contents_scale, RasterSource::PlaybackSettings()); |
379 RasterSource::PlaybackSettings()); | |
380 | 374 |
381 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | 375 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); |
382 int num_black = 0; | 376 int num_black = 0; |
383 int num_white = 0; | 377 int num_white = 0; |
384 for (int i = 0; i < bitmap.width(); ++i) { | 378 for (int i = 0; i < bitmap.width(); ++i) { |
385 for (int j = 0; j < bitmap.height(); ++j) { | 379 for (int j = 0; j < bitmap.height(); ++j) { |
386 SCOPED_TRACE(j); | 380 SCOPED_TRACE(j); |
387 SCOPED_TRACE(i); | 381 SCOPED_TRACE(i); |
388 bool expect_black = playback_rect.Contains(i, j); | 382 bool expect_black = playback_rect.Contains(i, j); |
389 if (expect_black) { | 383 if (expect_black) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 | 427 |
434 SkBitmap bitmap; | 428 SkBitmap bitmap; |
435 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); | 429 bitmap.allocN32Pixels(content_bounds.width(), content_bounds.height()); |
436 SkCanvas canvas(bitmap); | 430 SkCanvas canvas(bitmap); |
437 canvas.clear(SK_ColorTRANSPARENT); | 431 canvas.clear(SK_ColorTRANSPARENT); |
438 | 432 |
439 // Playback the full rect which should make everything light gray (alpha=10). | 433 // Playback the full rect which should make everything light gray (alpha=10). |
440 gfx::Rect raster_full_rect(content_bounds); | 434 gfx::Rect raster_full_rect(content_bounds); |
441 gfx::Rect playback_rect(content_bounds); | 435 gfx::Rect playback_rect(content_bounds); |
442 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, | 436 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, |
443 gfx::SizeF(contents_scale, contents_scale), | 437 contents_scale, RasterSource::PlaybackSettings()); |
444 RasterSource::PlaybackSettings()); | |
445 | 438 |
446 { | 439 { |
447 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | 440 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); |
448 for (int i = 0; i < bitmap.width(); ++i) { | 441 for (int i = 0; i < bitmap.width(); ++i) { |
449 for (int j = 0; j < bitmap.height(); ++j) { | 442 for (int j = 0; j < bitmap.height(); ++j) { |
450 SCOPED_TRACE(i); | 443 SCOPED_TRACE(i); |
451 SCOPED_TRACE(j); | 444 SCOPED_TRACE(j); |
452 EXPECT_EQ(alpha_dark, SkColorGetA(pixels[i + j * bitmap.width()])); | 445 EXPECT_EQ(alpha_dark, SkColorGetA(pixels[i + j * bitmap.width()])); |
453 EXPECT_EQ(alpha_dark, SkColorGetR(pixels[i + j * bitmap.width()])); | 446 EXPECT_EQ(alpha_dark, SkColorGetR(pixels[i + j * bitmap.width()])); |
454 EXPECT_EQ(alpha_dark, SkColorGetG(pixels[i + j * bitmap.width()])); | 447 EXPECT_EQ(alpha_dark, SkColorGetG(pixels[i + j * bitmap.width()])); |
(...skipping 18 matching lines...) Expand all Loading... |
473 // Make a new RasterSource from the new recording. | 466 // Make a new RasterSource from the new recording. |
474 raster = RasterSource::CreateFromRecordingSource(recording_source_light.get(), | 467 raster = RasterSource::CreateFromRecordingSource(recording_source_light.get(), |
475 false); | 468 false); |
476 | 469 |
477 // We're going to playback from alpha(18) white rectangle into a smaller area | 470 // We're going to playback from alpha(18) white rectangle into a smaller area |
478 // of the recording resulting in a smaller lighter white rectangle over a | 471 // of the recording resulting in a smaller lighter white rectangle over a |
479 // darker white background rectangle. | 472 // darker white background rectangle. |
480 playback_rect = | 473 playback_rect = |
481 gfx::Rect(gfx::ScaleToCeiledSize(partial_bounds, contents_scale)); | 474 gfx::Rect(gfx::ScaleToCeiledSize(partial_bounds, contents_scale)); |
482 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, | 475 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, |
483 gfx::SizeF(contents_scale, contents_scale), | 476 contents_scale, RasterSource::PlaybackSettings()); |
484 RasterSource::PlaybackSettings()); | |
485 | 477 |
486 // Test that the whole playback_rect was cleared and repainted with new alpha. | 478 // Test that the whole playback_rect was cleared and repainted with new alpha. |
487 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | 479 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); |
488 for (int i = 0; i < playback_rect.width(); ++i) { | 480 for (int i = 0; i < playback_rect.width(); ++i) { |
489 for (int j = 0; j < playback_rect.height(); ++j) { | 481 for (int j = 0; j < playback_rect.height(); ++j) { |
490 SCOPED_TRACE(j); | 482 SCOPED_TRACE(j); |
491 SCOPED_TRACE(i); | 483 SCOPED_TRACE(i); |
492 EXPECT_EQ(alpha_light, SkColorGetA(pixels[i + j * bitmap.width()])); | 484 EXPECT_EQ(alpha_light, SkColorGetA(pixels[i + j * bitmap.width()])); |
493 EXPECT_EQ(alpha_light, SkColorGetR(pixels[i + j * bitmap.width()])); | 485 EXPECT_EQ(alpha_light, SkColorGetR(pixels[i + j * bitmap.width()])); |
494 EXPECT_EQ(alpha_light, SkColorGetG(pixels[i + j * bitmap.width()])); | 486 EXPECT_EQ(alpha_light, SkColorGetG(pixels[i + j * bitmap.width()])); |
(...skipping 18 matching lines...) Expand all Loading... |
513 gfx::Size content_bounds( | 505 gfx::Size content_bounds( |
514 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); | 506 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); |
515 | 507 |
516 gfx::Rect canvas_rect(content_bounds); | 508 gfx::Rect canvas_rect(content_bounds); |
517 canvas_rect.Inset(0, 0, -1, -1); | 509 canvas_rect.Inset(0, 0, -1, -1); |
518 | 510 |
519 SkBitmap bitmap; | 511 SkBitmap bitmap; |
520 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); | 512 bitmap.allocN32Pixels(canvas_rect.width(), canvas_rect.height()); |
521 SkCanvas canvas(bitmap); | 513 SkCanvas canvas(bitmap); |
522 | 514 |
523 raster->PlaybackToCanvas(&canvas, canvas_rect, canvas_rect, | 515 raster->PlaybackToCanvas(&canvas, canvas_rect, canvas_rect, contents_scale, |
524 gfx::SizeF(contents_scale, contents_scale), | |
525 RasterSource::PlaybackSettings()); | 516 RasterSource::PlaybackSettings()); |
526 | 517 |
527 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | 518 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); |
528 int num_pixels = bitmap.width() * bitmap.height(); | 519 int num_pixels = bitmap.width() * bitmap.height(); |
529 for (int i = 0; i < num_pixels; ++i) { | 520 for (int i = 0; i < num_pixels; ++i) { |
530 EXPECT_EQ(SkColorGetA(pixels[i]), 0u); | 521 EXPECT_EQ(SkColorGetA(pixels[i]), 0u); |
531 } | 522 } |
532 } | 523 } |
533 | 524 |
534 TEST(RasterSourceTest, GetPictureMemoryUsageIncludesClientReportedMemory) { | 525 TEST(RasterSourceTest, GetPictureMemoryUsageIncludesClientReportedMemory) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
588 | 579 |
589 SkBitmap bitmap; | 580 SkBitmap bitmap; |
590 bitmap.allocN32Pixels(size.width() * 0.5f, size.height() * 0.25f); | 581 bitmap.allocN32Pixels(size.width() * 0.5f, size.height() * 0.25f); |
591 SkCanvas canvas(bitmap); | 582 SkCanvas canvas(bitmap); |
592 canvas.scale(0.5f, 0.25f); | 583 canvas.scale(0.5f, 0.25f); |
593 | 584 |
594 RasterSource::PlaybackSettings settings; | 585 RasterSource::PlaybackSettings settings; |
595 settings.playback_to_shared_canvas = true; | 586 settings.playback_to_shared_canvas = true; |
596 settings.use_image_hijack_canvas = true; | 587 settings.use_image_hijack_canvas = true; |
597 raster_source->PlaybackToCanvas(&canvas, gfx::Rect(size), gfx::Rect(size), | 588 raster_source->PlaybackToCanvas(&canvas, gfx::Rect(size), gfx::Rect(size), |
598 gfx::SizeF(1.f, 1.f), settings); | 589 1.f, settings); |
599 | 590 |
600 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(0, 0)); | 591 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(0, 0)); |
601 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(49, 0)); | 592 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(49, 0)); |
602 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(0, 24)); | 593 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(0, 24)); |
603 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(49, 24)); | 594 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(49, 24)); |
604 for (int x = 0; x < 49; ++x) | 595 for (int x = 0; x < 49; ++x) |
605 EXPECT_EQ(SK_ColorRED, bitmap.getColor(x, 12)); | 596 EXPECT_EQ(SK_ColorRED, bitmap.getColor(x, 12)); |
606 for (int y = 0; y < 24; ++y) | 597 for (int y = 0; y < 24; ++y) |
607 EXPECT_EQ(SK_ColorRED, bitmap.getColor(24, y)); | 598 EXPECT_EQ(SK_ColorRED, bitmap.getColor(24, y)); |
608 } | 599 } |
609 | 600 |
610 } // namespace | 601 } // namespace |
611 } // namespace cc | 602 } // namespace cc |
OLD | NEW |