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" |
| 6 |
5 #include <stddef.h> | 7 #include <stddef.h> |
6 | 8 |
7 #include "base/memory/scoped_ptr.h" | 9 #include <memory> |
8 #include "cc/playback/raster_source.h" | 10 |
9 #include "cc/test/fake_recording_source.h" | 11 #include "cc/test/fake_recording_source.h" |
10 #include "cc/test/skia_common.h" | 12 #include "cc/test/skia_common.h" |
11 #include "skia/ext/refptr.h" | 13 #include "skia/ext/refptr.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "third_party/skia/include/core/SkPixelRef.h" | 15 #include "third_party/skia/include/core/SkPixelRef.h" |
14 #include "third_party/skia/include/core/SkShader.h" | 16 #include "third_party/skia/include/core/SkShader.h" |
15 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
16 #include "ui/gfx/geometry/size_conversions.h" | 18 #include "ui/gfx/geometry/size_conversions.h" |
17 | 19 |
18 namespace cc { | 20 namespace cc { |
19 namespace { | 21 namespace { |
20 | 22 |
21 TEST(RasterSourceTest, AnalyzeIsSolidUnscaled) { | 23 TEST(RasterSourceTest, AnalyzeIsSolidUnscaled) { |
22 gfx::Size layer_bounds(400, 400); | 24 gfx::Size layer_bounds(400, 400); |
23 | 25 |
24 scoped_ptr<FakeRecordingSource> recording_source = | 26 std::unique_ptr<FakeRecordingSource> recording_source = |
25 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); | 27 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); |
26 | 28 |
27 SkPaint solid_paint; | 29 SkPaint solid_paint; |
28 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); | 30 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); |
29 solid_paint.setColor(solid_color); | 31 solid_paint.setColor(solid_color); |
30 | 32 |
31 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); | 33 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); |
32 SkColor color = SK_ColorTRANSPARENT; | 34 SkColor color = SK_ColorTRANSPARENT; |
33 SkPaint non_solid_paint; | 35 SkPaint non_solid_paint; |
34 bool is_solid_color = false; | 36 bool is_solid_color = false; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 color = SK_ColorTRANSPARENT; | 87 color = SK_ColorTRANSPARENT; |
86 is_solid_color = raster->PerformSolidColorAnalysis( | 88 is_solid_color = raster->PerformSolidColorAnalysis( |
87 gfx::Rect(350, 350, 100, 100), 1.0, &color); | 89 gfx::Rect(350, 350, 100, 100), 1.0, &color); |
88 EXPECT_TRUE(is_solid_color); | 90 EXPECT_TRUE(is_solid_color); |
89 EXPECT_EQ(solid_color, color); | 91 EXPECT_EQ(solid_color, color); |
90 } | 92 } |
91 | 93 |
92 TEST(RasterSourceTest, AnalyzeIsSolidScaled) { | 94 TEST(RasterSourceTest, AnalyzeIsSolidScaled) { |
93 gfx::Size layer_bounds(400, 400); | 95 gfx::Size layer_bounds(400, 400); |
94 | 96 |
95 scoped_ptr<FakeRecordingSource> recording_source = | 97 std::unique_ptr<FakeRecordingSource> recording_source = |
96 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); | 98 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); |
97 | 99 |
98 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); | 100 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); |
99 SkColor color = SK_ColorTRANSPARENT; | 101 SkColor color = SK_ColorTRANSPARENT; |
100 SkPaint solid_paint; | 102 SkPaint solid_paint; |
101 bool is_solid_color = false; | 103 bool is_solid_color = false; |
102 solid_paint.setColor(solid_color); | 104 solid_paint.setColor(solid_color); |
103 | 105 |
104 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); | 106 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); |
105 SkPaint non_solid_paint; | 107 SkPaint non_solid_paint; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 color = SK_ColorTRANSPARENT; | 158 color = SK_ColorTRANSPARENT; |
157 is_solid_color = raster->PerformSolidColorAnalysis(gfx::Rect(35, 35, 10, 10), | 159 is_solid_color = raster->PerformSolidColorAnalysis(gfx::Rect(35, 35, 10, 10), |
158 0.1f, &color); | 160 0.1f, &color); |
159 EXPECT_TRUE(is_solid_color); | 161 EXPECT_TRUE(is_solid_color); |
160 EXPECT_EQ(color, solid_color); | 162 EXPECT_EQ(color, solid_color); |
161 } | 163 } |
162 | 164 |
163 TEST(RasterSourceTest, AnalyzeIsSolidEmpty) { | 165 TEST(RasterSourceTest, AnalyzeIsSolidEmpty) { |
164 gfx::Size layer_bounds(400, 400); | 166 gfx::Size layer_bounds(400, 400); |
165 | 167 |
166 scoped_ptr<FakeRecordingSource> recording_source = | 168 std::unique_ptr<FakeRecordingSource> recording_source = |
167 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); | 169 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); |
168 recording_source->Rerecord(); | 170 recording_source->Rerecord(); |
169 | 171 |
170 scoped_refptr<RasterSource> raster = | 172 scoped_refptr<RasterSource> raster = |
171 RasterSource::CreateFromRecordingSource(recording_source.get(), false); | 173 RasterSource::CreateFromRecordingSource(recording_source.get(), false); |
172 | 174 |
173 SkColor color = SK_ColorTRANSPARENT; | 175 SkColor color = SK_ColorTRANSPARENT; |
174 bool is_solid_color = | 176 bool is_solid_color = |
175 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 400, 400), 1.f, &color); | 177 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 400, 400), 1.f, &color); |
176 | 178 |
177 EXPECT_TRUE(is_solid_color); | 179 EXPECT_TRUE(is_solid_color); |
178 EXPECT_EQ(color, SkColorSetARGB(0, 0, 0, 0)); | 180 EXPECT_EQ(color, SkColorSetARGB(0, 0, 0, 0)); |
179 } | 181 } |
180 | 182 |
181 TEST(RasterSourceTest, PixelRefIteratorDiscardableRefsOneTile) { | 183 TEST(RasterSourceTest, PixelRefIteratorDiscardableRefsOneTile) { |
182 gfx::Size layer_bounds(512, 512); | 184 gfx::Size layer_bounds(512, 512); |
183 | 185 |
184 scoped_ptr<FakeRecordingSource> recording_source = | 186 std::unique_ptr<FakeRecordingSource> recording_source = |
185 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); | 187 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); |
186 | 188 |
187 skia::RefPtr<SkImage> discardable_image[2][2]; | 189 skia::RefPtr<SkImage> discardable_image[2][2]; |
188 discardable_image[0][0] = CreateDiscardableImage(gfx::Size(32, 32)); | 190 discardable_image[0][0] = CreateDiscardableImage(gfx::Size(32, 32)); |
189 discardable_image[0][1] = CreateDiscardableImage(gfx::Size(32, 32)); | 191 discardable_image[0][1] = CreateDiscardableImage(gfx::Size(32, 32)); |
190 discardable_image[1][1] = CreateDiscardableImage(gfx::Size(32, 32)); | 192 discardable_image[1][1] = CreateDiscardableImage(gfx::Size(32, 32)); |
191 | 193 |
192 // Discardable pixel refs are found in the following cells: | 194 // Discardable pixel refs are found in the following cells: |
193 // |---|---| | 195 // |---|---| |
194 // | x | x | | 196 // | x | x | |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 EXPECT_EQ(discardable_image[0][1].get(), images[1].image()); | 240 EXPECT_EQ(discardable_image[0][1].get(), images[1].image()); |
239 EXPECT_EQ(discardable_image[1][1].get(), images[2].image()); | 241 EXPECT_EQ(discardable_image[1][1].get(), images[2].image()); |
240 } | 242 } |
241 } | 243 } |
242 | 244 |
243 TEST(RasterSourceTest, RasterFullContents) { | 245 TEST(RasterSourceTest, RasterFullContents) { |
244 gfx::Size layer_bounds(3, 5); | 246 gfx::Size layer_bounds(3, 5); |
245 float contents_scale = 1.5f; | 247 float contents_scale = 1.5f; |
246 float raster_divisions = 2.f; | 248 float raster_divisions = 2.f; |
247 | 249 |
248 scoped_ptr<FakeRecordingSource> recording_source = | 250 std::unique_ptr<FakeRecordingSource> recording_source = |
249 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); | 251 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); |
250 recording_source->SetBackgroundColor(SK_ColorBLACK); | 252 recording_source->SetBackgroundColor(SK_ColorBLACK); |
251 recording_source->SetClearCanvasWithDebugColor(false); | 253 recording_source->SetClearCanvasWithDebugColor(false); |
252 | 254 |
253 // Because the caller sets content opaque, it also promises that it | 255 // Because the caller sets content opaque, it also promises that it |
254 // has at least filled in layer_bounds opaquely. | 256 // has at least filled in layer_bounds opaquely. |
255 SkPaint white_paint; | 257 SkPaint white_paint; |
256 white_paint.setColor(SK_ColorWHITE); | 258 white_paint.setColor(SK_ColorWHITE); |
257 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), | 259 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), |
258 white_paint); | 260 white_paint); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 // will be non-white. | 306 // will be non-white. |
305 EXPECT_EQ(all_white, gfx::Rect(content_bounds).Contains(canvas_rect)); | 307 EXPECT_EQ(all_white, gfx::Rect(content_bounds).Contains(canvas_rect)); |
306 } | 308 } |
307 } | 309 } |
308 } | 310 } |
309 | 311 |
310 TEST(RasterSourceTest, RasterPartialContents) { | 312 TEST(RasterSourceTest, RasterPartialContents) { |
311 gfx::Size layer_bounds(3, 5); | 313 gfx::Size layer_bounds(3, 5); |
312 float contents_scale = 1.5f; | 314 float contents_scale = 1.5f; |
313 | 315 |
314 scoped_ptr<FakeRecordingSource> recording_source = | 316 std::unique_ptr<FakeRecordingSource> recording_source = |
315 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); | 317 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); |
316 recording_source->SetBackgroundColor(SK_ColorGREEN); | 318 recording_source->SetBackgroundColor(SK_ColorGREEN); |
317 recording_source->SetClearCanvasWithDebugColor(false); | 319 recording_source->SetClearCanvasWithDebugColor(false); |
318 | 320 |
319 // First record everything as white. | 321 // First record everything as white. |
320 SkPaint white_paint; | 322 SkPaint white_paint; |
321 white_paint.setColor(SK_ColorWHITE); | 323 white_paint.setColor(SK_ColorWHITE); |
322 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), | 324 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), |
323 white_paint); | 325 white_paint); |
324 recording_source->Rerecord(); | 326 recording_source->Rerecord(); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 } | 398 } |
397 EXPECT_GT(num_black, 0); | 399 EXPECT_GT(num_black, 0); |
398 EXPECT_GT(num_white, 0); | 400 EXPECT_GT(num_white, 0); |
399 } | 401 } |
400 | 402 |
401 TEST(RasterSourceTest, RasterPartialClear) { | 403 TEST(RasterSourceTest, RasterPartialClear) { |
402 gfx::Size layer_bounds(3, 5); | 404 gfx::Size layer_bounds(3, 5); |
403 gfx::Size partial_bounds(2, 4); | 405 gfx::Size partial_bounds(2, 4); |
404 float contents_scale = 1.5f; | 406 float contents_scale = 1.5f; |
405 | 407 |
406 scoped_ptr<FakeRecordingSource> recording_source = | 408 std::unique_ptr<FakeRecordingSource> recording_source = |
407 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); | 409 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); |
408 recording_source->SetBackgroundColor(SK_ColorGREEN); | 410 recording_source->SetBackgroundColor(SK_ColorGREEN); |
409 recording_source->SetRequiresClear(true); | 411 recording_source->SetRequiresClear(true); |
410 recording_source->SetClearCanvasWithDebugColor(false); | 412 recording_source->SetClearCanvasWithDebugColor(false); |
411 | 413 |
412 // First record everything as white. | 414 // First record everything as white. |
413 const unsigned alpha_dark = 10u; | 415 const unsigned alpha_dark = 10u; |
414 SkPaint white_paint; | 416 SkPaint white_paint; |
415 white_paint.setColor(SK_ColorWHITE); | 417 white_paint.setColor(SK_ColorWHITE); |
416 white_paint.setAlpha(alpha_dark); | 418 white_paint.setAlpha(alpha_dark); |
(...skipping 25 matching lines...) Expand all Loading... |
442 SCOPED_TRACE(i); | 444 SCOPED_TRACE(i); |
443 SCOPED_TRACE(j); | 445 SCOPED_TRACE(j); |
444 EXPECT_EQ(alpha_dark, SkColorGetA(pixels[i + j * bitmap.width()])); | 446 EXPECT_EQ(alpha_dark, SkColorGetA(pixels[i + j * bitmap.width()])); |
445 EXPECT_EQ(alpha_dark, SkColorGetR(pixels[i + j * bitmap.width()])); | 447 EXPECT_EQ(alpha_dark, SkColorGetR(pixels[i + j * bitmap.width()])); |
446 EXPECT_EQ(alpha_dark, SkColorGetG(pixels[i + j * bitmap.width()])); | 448 EXPECT_EQ(alpha_dark, SkColorGetG(pixels[i + j * bitmap.width()])); |
447 EXPECT_EQ(alpha_dark, SkColorGetB(pixels[i + j * bitmap.width()])); | 449 EXPECT_EQ(alpha_dark, SkColorGetB(pixels[i + j * bitmap.width()])); |
448 } | 450 } |
449 } | 451 } |
450 } | 452 } |
451 | 453 |
452 scoped_ptr<FakeRecordingSource> recording_source_light = | 454 std::unique_ptr<FakeRecordingSource> recording_source_light = |
453 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); | 455 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); |
454 recording_source_light->SetBackgroundColor(SK_ColorGREEN); | 456 recording_source_light->SetBackgroundColor(SK_ColorGREEN); |
455 recording_source_light->SetRequiresClear(true); | 457 recording_source_light->SetRequiresClear(true); |
456 recording_source_light->SetClearCanvasWithDebugColor(false); | 458 recording_source_light->SetClearCanvasWithDebugColor(false); |
457 | 459 |
458 // Record everything as a slightly lighter white. | 460 // Record everything as a slightly lighter white. |
459 const unsigned alpha_light = 18u; | 461 const unsigned alpha_light = 18u; |
460 white_paint.setAlpha(alpha_light); | 462 white_paint.setAlpha(alpha_light); |
461 recording_source_light->add_draw_rect_with_paint(gfx::Rect(layer_bounds), | 463 recording_source_light->add_draw_rect_with_paint(gfx::Rect(layer_bounds), |
462 white_paint); | 464 white_paint); |
(...skipping 22 matching lines...) Expand all Loading... |
485 EXPECT_EQ(alpha_light, SkColorGetG(pixels[i + j * bitmap.width()])); | 487 EXPECT_EQ(alpha_light, SkColorGetG(pixels[i + j * bitmap.width()])); |
486 EXPECT_EQ(alpha_light, SkColorGetB(pixels[i + j * bitmap.width()])); | 488 EXPECT_EQ(alpha_light, SkColorGetB(pixels[i + j * bitmap.width()])); |
487 } | 489 } |
488 } | 490 } |
489 } | 491 } |
490 | 492 |
491 TEST(RasterSourceTest, RasterContentsTransparent) { | 493 TEST(RasterSourceTest, RasterContentsTransparent) { |
492 gfx::Size layer_bounds(5, 3); | 494 gfx::Size layer_bounds(5, 3); |
493 float contents_scale = 0.5f; | 495 float contents_scale = 0.5f; |
494 | 496 |
495 scoped_ptr<FakeRecordingSource> recording_source = | 497 std::unique_ptr<FakeRecordingSource> recording_source = |
496 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); | 498 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); |
497 recording_source->SetBackgroundColor(SK_ColorTRANSPARENT); | 499 recording_source->SetBackgroundColor(SK_ColorTRANSPARENT); |
498 recording_source->SetRequiresClear(true); | 500 recording_source->SetRequiresClear(true); |
499 recording_source->SetClearCanvasWithDebugColor(false); | 501 recording_source->SetClearCanvasWithDebugColor(false); |
500 recording_source->Rerecord(); | 502 recording_source->Rerecord(); |
501 | 503 |
502 scoped_refptr<RasterSource> raster = | 504 scoped_refptr<RasterSource> raster = |
503 RasterSource::CreateFromRecordingSource(recording_source.get(), false); | 505 RasterSource::CreateFromRecordingSource(recording_source.get(), false); |
504 gfx::Size content_bounds( | 506 gfx::Size content_bounds( |
505 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); | 507 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); |
(...skipping 11 matching lines...) Expand all Loading... |
517 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | 519 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); |
518 int num_pixels = bitmap.width() * bitmap.height(); | 520 int num_pixels = bitmap.width() * bitmap.height(); |
519 for (int i = 0; i < num_pixels; ++i) { | 521 for (int i = 0; i < num_pixels; ++i) { |
520 EXPECT_EQ(SkColorGetA(pixels[i]), 0u); | 522 EXPECT_EQ(SkColorGetA(pixels[i]), 0u); |
521 } | 523 } |
522 } | 524 } |
523 | 525 |
524 TEST(RasterSourceTest, GetPictureMemoryUsageIncludesClientReportedMemory) { | 526 TEST(RasterSourceTest, GetPictureMemoryUsageIncludesClientReportedMemory) { |
525 const size_t kReportedMemoryUsageInBytes = 100 * 1024 * 1024; | 527 const size_t kReportedMemoryUsageInBytes = 100 * 1024 * 1024; |
526 gfx::Size layer_bounds(5, 3); | 528 gfx::Size layer_bounds(5, 3); |
527 scoped_ptr<FakeRecordingSource> recording_source = | 529 std::unique_ptr<FakeRecordingSource> recording_source = |
528 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); | 530 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); |
529 recording_source->set_reported_memory_usage(kReportedMemoryUsageInBytes); | 531 recording_source->set_reported_memory_usage(kReportedMemoryUsageInBytes); |
530 recording_source->Rerecord(); | 532 recording_source->Rerecord(); |
531 | 533 |
532 scoped_refptr<RasterSource> raster = | 534 scoped_refptr<RasterSource> raster = |
533 RasterSource::CreateFromRecordingSource(recording_source.get(), false); | 535 RasterSource::CreateFromRecordingSource(recording_source.get(), false); |
534 size_t total_memory_usage = raster->GetPictureMemoryUsage(); | 536 size_t total_memory_usage = raster->GetPictureMemoryUsage(); |
535 EXPECT_GE(total_memory_usage, kReportedMemoryUsageInBytes); | 537 EXPECT_GE(total_memory_usage, kReportedMemoryUsageInBytes); |
536 EXPECT_LT(total_memory_usage, 2 * kReportedMemoryUsageInBytes); | 538 EXPECT_LT(total_memory_usage, 2 * kReportedMemoryUsageInBytes); |
537 } | 539 } |
538 | 540 |
539 } // namespace | 541 } // namespace |
540 } // namespace cc | 542 } // namespace cc |
OLD | NEW |