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

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

Issue 2523673004: [NOT FOR COMMIT] Fully replace SkCanvas uses.
Patch Set: Support Android build. Created 4 years 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/playback/recording_source.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 "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
11 #include "cc/test/fake_recording_source.h" 11 #include "cc/test/fake_recording_source.h"
12 #include "cc/test/skia_common.h" 12 #include "cc/test/skia_common.h"
13 #include "cc/tiles/software_image_decode_cache.h" 13 #include "cc/tiles/software_image_decode_cache.h"
14 #include "skia/ext/cdl_paint.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/skia/include/core/SkPixelRef.h" 16 #include "third_party/skia/include/core/SkPixelRef.h"
16 #include "third_party/skia/include/core/SkRefCnt.h" 17 #include "third_party/skia/include/core/SkRefCnt.h"
17 #include "third_party/skia/include/core/SkShader.h" 18 #include "third_party/skia/include/core/SkShader.h"
18 #include "ui/gfx/geometry/rect.h" 19 #include "ui/gfx/geometry/rect.h"
19 #include "ui/gfx/geometry/size_conversions.h" 20 #include "ui/gfx/geometry/size_conversions.h"
20 21
21 namespace cc { 22 namespace cc {
22 namespace { 23 namespace {
23 24
24 TEST(RasterSourceTest, AnalyzeIsSolidUnscaled) { 25 TEST(RasterSourceTest, AnalyzeIsSolidUnscaled) {
25 gfx::Size layer_bounds(400, 400); 26 gfx::Size layer_bounds(400, 400);
26 27
27 std::unique_ptr<FakeRecordingSource> recording_source = 28 std::unique_ptr<FakeRecordingSource> recording_source =
28 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); 29 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds);
29 30
30 SkPaint solid_paint; 31 CdlPaint solid_paint;
31 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); 32 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34);
32 solid_paint.setColor(solid_color); 33 solid_paint.setColor(solid_color);
33 34
34 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); 35 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67);
35 SkColor color = SK_ColorTRANSPARENT; 36 SkColor color = SK_ColorTRANSPARENT;
36 SkPaint non_solid_paint; 37 CdlPaint non_solid_paint;
37 bool is_solid_color = false; 38 bool is_solid_color = false;
38 non_solid_paint.setColor(non_solid_color); 39 non_solid_paint.setColor(non_solid_color);
39 40
40 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), 41 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds),
41 solid_paint); 42 solid_paint);
42 recording_source->Rerecord(); 43 recording_source->Rerecord();
43 44
44 scoped_refptr<RasterSource> raster = 45 scoped_refptr<RasterSource> raster =
45 RasterSource::CreateFromRecordingSource(recording_source.get(), false); 46 RasterSource::CreateFromRecordingSource(recording_source.get(), false);
46 47
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 } 95 }
95 96
96 TEST(RasterSourceTest, AnalyzeIsSolidScaled) { 97 TEST(RasterSourceTest, AnalyzeIsSolidScaled) {
97 gfx::Size layer_bounds(400, 400); 98 gfx::Size layer_bounds(400, 400);
98 99
99 std::unique_ptr<FakeRecordingSource> recording_source = 100 std::unique_ptr<FakeRecordingSource> recording_source =
100 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); 101 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds);
101 102
102 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); 103 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34);
103 SkColor color = SK_ColorTRANSPARENT; 104 SkColor color = SK_ColorTRANSPARENT;
104 SkPaint solid_paint; 105 CdlPaint solid_paint;
105 bool is_solid_color = false; 106 bool is_solid_color = false;
106 solid_paint.setColor(solid_color); 107 solid_paint.setColor(solid_color);
107 108
108 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); 109 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67);
109 SkPaint non_solid_paint; 110 CdlPaint non_solid_paint;
110 non_solid_paint.setColor(non_solid_color); 111 non_solid_paint.setColor(non_solid_color);
111 112
112 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400), 113 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 400, 400),
113 solid_paint); 114 solid_paint);
114 recording_source->Rerecord(); 115 recording_source->Rerecord();
115 116
116 scoped_refptr<RasterSource> raster = 117 scoped_refptr<RasterSource> raster =
117 RasterSource::CreateFromRecordingSource(recording_source.get(), false); 118 RasterSource::CreateFromRecordingSource(recording_source.get(), false);
118 119
119 // Ensure everything is solid. 120 // Ensure everything is solid.
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 float contents_scale = 1.5f; 251 float contents_scale = 1.5f;
251 float raster_divisions = 2.f; 252 float raster_divisions = 2.f;
252 253
253 std::unique_ptr<FakeRecordingSource> recording_source = 254 std::unique_ptr<FakeRecordingSource> recording_source =
254 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); 255 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds);
255 recording_source->SetBackgroundColor(SK_ColorBLACK); 256 recording_source->SetBackgroundColor(SK_ColorBLACK);
256 recording_source->SetClearCanvasWithDebugColor(false); 257 recording_source->SetClearCanvasWithDebugColor(false);
257 258
258 // Because the caller sets content opaque, it also promises that it 259 // Because the caller sets content opaque, it also promises that it
259 // has at least filled in layer_bounds opaquely. 260 // has at least filled in layer_bounds opaquely.
260 SkPaint white_paint; 261 CdlPaint white_paint;
261 white_paint.setColor(SK_ColorWHITE); 262 white_paint.setColor(SK_ColorWHITE);
262 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), 263 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds),
263 white_paint); 264 white_paint);
264 recording_source->Rerecord(); 265 recording_source->Rerecord();
265 266
266 scoped_refptr<RasterSource> raster = 267 scoped_refptr<RasterSource> raster =
267 RasterSource::CreateFromRecordingSource(recording_source.get(), false); 268 RasterSource::CreateFromRecordingSource(recording_source.get(), false);
268 269
269 gfx::Size content_bounds( 270 gfx::Size content_bounds(
270 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); 271 gfx::ScaleToCeiledSize(layer_bounds, contents_scale));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 TEST(RasterSourceTest, RasterPartialContents) { 316 TEST(RasterSourceTest, RasterPartialContents) {
316 gfx::Size layer_bounds(3, 5); 317 gfx::Size layer_bounds(3, 5);
317 float contents_scale = 1.5f; 318 float contents_scale = 1.5f;
318 319
319 std::unique_ptr<FakeRecordingSource> recording_source = 320 std::unique_ptr<FakeRecordingSource> recording_source =
320 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); 321 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds);
321 recording_source->SetBackgroundColor(SK_ColorGREEN); 322 recording_source->SetBackgroundColor(SK_ColorGREEN);
322 recording_source->SetClearCanvasWithDebugColor(false); 323 recording_source->SetClearCanvasWithDebugColor(false);
323 324
324 // First record everything as white. 325 // First record everything as white.
325 SkPaint white_paint; 326 CdlPaint white_paint;
326 white_paint.setColor(SK_ColorWHITE); 327 white_paint.setColor(SK_ColorWHITE);
327 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), 328 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds),
328 white_paint); 329 white_paint);
329 recording_source->Rerecord(); 330 recording_source->Rerecord();
330 331
331 scoped_refptr<RasterSource> raster = 332 scoped_refptr<RasterSource> raster =
332 RasterSource::CreateFromRecordingSource(recording_source.get(), false); 333 RasterSource::CreateFromRecordingSource(recording_source.get(), false);
333 334
334 gfx::Size content_bounds( 335 gfx::Size content_bounds(
335 gfx::ScaleToCeiledSize(layer_bounds, contents_scale)); 336 gfx::ScaleToCeiledSize(layer_bounds, contents_scale));
(...skipping 18 matching lines...) Expand all
354 SCOPED_TRACE(j); 355 SCOPED_TRACE(j);
355 EXPECT_EQ(255u, SkColorGetA(pixels[i + j * bitmap.width()])); 356 EXPECT_EQ(255u, SkColorGetA(pixels[i + j * bitmap.width()]));
356 EXPECT_EQ(255u, SkColorGetR(pixels[i + j * bitmap.width()])); 357 EXPECT_EQ(255u, SkColorGetR(pixels[i + j * bitmap.width()]));
357 EXPECT_EQ(255u, SkColorGetG(pixels[i + j * bitmap.width()])); 358 EXPECT_EQ(255u, SkColorGetG(pixels[i + j * bitmap.width()]));
358 EXPECT_EQ(255u, SkColorGetB(pixels[i + j * bitmap.width()])); 359 EXPECT_EQ(255u, SkColorGetB(pixels[i + j * bitmap.width()]));
359 } 360 }
360 } 361 }
361 } 362 }
362 363
363 // Re-record everything as black. 364 // Re-record everything as black.
364 SkPaint black_paint; 365 CdlPaint black_paint;
365 black_paint.setColor(SK_ColorBLACK); 366 black_paint.setColor(SK_ColorBLACK);
366 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), 367 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds),
367 black_paint); 368 black_paint);
368 recording_source->Rerecord(); 369 recording_source->Rerecord();
369 370
370 // Make a new RasterSource from the new recording. 371 // Make a new RasterSource from the new recording.
371 raster = 372 raster =
372 RasterSource::CreateFromRecordingSource(recording_source.get(), false); 373 RasterSource::CreateFromRecordingSource(recording_source.get(), false);
373 374
374 // 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,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 float contents_scale = 1.5f; 412 float contents_scale = 1.5f;
412 413
413 std::unique_ptr<FakeRecordingSource> recording_source = 414 std::unique_ptr<FakeRecordingSource> recording_source =
414 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); 415 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds);
415 recording_source->SetBackgroundColor(SK_ColorGREEN); 416 recording_source->SetBackgroundColor(SK_ColorGREEN);
416 recording_source->SetRequiresClear(true); 417 recording_source->SetRequiresClear(true);
417 recording_source->SetClearCanvasWithDebugColor(false); 418 recording_source->SetClearCanvasWithDebugColor(false);
418 419
419 // First record everything as white. 420 // First record everything as white.
420 const unsigned alpha_dark = 10u; 421 const unsigned alpha_dark = 10u;
421 SkPaint white_paint; 422 CdlPaint white_paint;
422 white_paint.setColor(SK_ColorWHITE); 423 white_paint.setColor(SK_ColorWHITE);
423 white_paint.setAlpha(alpha_dark); 424 white_paint.setAlpha(alpha_dark);
424 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), 425 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds),
425 white_paint); 426 white_paint);
426 recording_source->Rerecord(); 427 recording_source->Rerecord();
427 428
428 scoped_refptr<RasterSource> raster = 429 scoped_refptr<RasterSource> raster =
429 RasterSource::CreateFromRecordingSource(recording_source.get(), false); 430 RasterSource::CreateFromRecordingSource(recording_source.get(), false);
430 431
431 gfx::Size content_bounds( 432 gfx::Size content_bounds(
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 // scaling). Note that we paint an image first, so that we can force image 555 // scaling). Note that we paint an image first, so that we can force image
555 // hijack canvas to be used. 556 // hijack canvas to be used.
556 std::unique_ptr<FakeRecordingSource> recording_source = 557 std::unique_ptr<FakeRecordingSource> recording_source =
557 FakeRecordingSource::CreateFilledRecordingSource(size); 558 FakeRecordingSource::CreateFilledRecordingSource(size);
558 559
559 // 1. Paint the image. 560 // 1. Paint the image.
560 recording_source->add_draw_image(CreateDiscardableImage(gfx::Size(5, 5)), 561 recording_source->add_draw_image(CreateDiscardableImage(gfx::Size(5, 5)),
561 gfx::Point(0, 0)); 562 gfx::Point(0, 0));
562 563
563 // 2. Cover everything in red. 564 // 2. Cover everything in red.
564 SkPaint paint; 565 CdlPaint paint;
565 paint.setColor(SK_ColorRED); 566 paint.setColor(SK_ColorRED);
566 recording_source->add_draw_rect_with_paint(gfx::Rect(size), paint); 567 recording_source->add_draw_rect_with_paint(gfx::Rect(size), paint);
567 568
568 // 3. Draw 4x4 green rects into every corner. 569 // 3. Draw 4x4 green rects into every corner.
569 paint.setColor(SK_ColorGREEN); 570 paint.setColor(SK_ColorGREEN);
570 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 4, 4), paint); 571 recording_source->add_draw_rect_with_paint(gfx::Rect(0, 0, 4, 4), paint);
571 recording_source->add_draw_rect_with_paint( 572 recording_source->add_draw_rect_with_paint(
572 gfx::Rect(size.width() - 4, 0, 4, 4), paint); 573 gfx::Rect(size.width() - 4, 0, 4, 4), paint);
573 recording_source->add_draw_rect_with_paint( 574 recording_source->add_draw_rect_with_paint(
574 gfx::Rect(0, size.height() - 4, 4, 4), paint); 575 gfx::Rect(0, size.height() - 4, 4, 4), paint);
(...skipping 27 matching lines...) Expand all
602 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(0, 24)); 603 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(0, 24));
603 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(49, 24)); 604 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(49, 24));
604 for (int x = 0; x < 49; ++x) 605 for (int x = 0; x < 49; ++x)
605 EXPECT_EQ(SK_ColorRED, bitmap.getColor(x, 12)); 606 EXPECT_EQ(SK_ColorRED, bitmap.getColor(x, 12));
606 for (int y = 0; y < 24; ++y) 607 for (int y = 0; y < 24; ++y)
607 EXPECT_EQ(SK_ColorRED, bitmap.getColor(24, y)); 608 EXPECT_EQ(SK_ColorRED, bitmap.getColor(24, y));
608 } 609 }
609 610
610 } // namespace 611 } // namespace
611 } // namespace cc 612 } // namespace cc
OLDNEW
« no previous file with comments | « cc/playback/raster_source.cc ('k') | cc/playback/recording_source.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698