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

Side by Side Diff: cc/resources/picture_unittest.cc

Issue 684653004: Plumb can_use_lcd_text, contents_opaque directly to ContentLayerClient. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
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/resources/picture.h" 5 #include "cc/resources/picture.h"
6 6
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "cc/test/fake_content_layer_client.h" 10 #include "cc/test/fake_content_layer_client.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 scoped_refptr<Picture> invalid_picture = 42 scoped_refptr<Picture> invalid_picture =
43 Picture::CreateFromValue(tmp.get()); 43 Picture::CreateFromValue(tmp.get());
44 EXPECT_FALSE(invalid_picture.get()); 44 EXPECT_FALSE(invalid_picture.get());
45 45
46 // Single full-size rect picture. 46 // Single full-size rect picture.
47 content_layer_client.add_draw_rect(layer_rect, red_paint); 47 content_layer_client.add_draw_rect(layer_rect, red_paint);
48 48
49 scoped_refptr<Picture> one_rect_picture = 49 scoped_refptr<Picture> one_rect_picture =
50 Picture::Create(layer_rect, 50 Picture::Create(layer_rect,
51 &content_layer_client, 51 &content_layer_client,
52 false,
53 false,
52 tile_grid_info, 54 tile_grid_info,
53 false, 55 false,
54 Picture::RECORD_NORMALLY); 56 Picture::RECORD_NORMALLY);
55 scoped_ptr<base::Value> serialized_one_rect(one_rect_picture->AsValue()); 57 scoped_ptr<base::Value> serialized_one_rect(one_rect_picture->AsValue());
56 58
57 // Reconstruct the picture. 59 // Reconstruct the picture.
58 scoped_refptr<Picture> one_rect_picture_check = 60 scoped_refptr<Picture> one_rect_picture_check =
59 Picture::CreateFromValue(serialized_one_rect.get()); 61 Picture::CreateFromValue(serialized_one_rect.get());
60 EXPECT_TRUE(!!one_rect_picture_check.get()); 62 EXPECT_TRUE(!!one_rect_picture_check.get());
61 63
62 // Check for equivalence. 64 // Check for equivalence.
63 unsigned char one_rect_buffer[4 * 100 * 100] = {0}; 65 unsigned char one_rect_buffer[4 * 100 * 100] = {0};
64 DrawPicture(one_rect_buffer, layer_rect, one_rect_picture); 66 DrawPicture(one_rect_buffer, layer_rect, one_rect_picture);
65 unsigned char one_rect_buffer_check[4 * 100 * 100] = {0}; 67 unsigned char one_rect_buffer_check[4 * 100 * 100] = {0};
66 DrawPicture(one_rect_buffer_check, layer_rect, one_rect_picture_check); 68 DrawPicture(one_rect_buffer_check, layer_rect, one_rect_picture_check);
67 69
68 EXPECT_EQ(one_rect_picture->LayerRect(), one_rect_picture_check->LayerRect()); 70 EXPECT_EQ(one_rect_picture->LayerRect(), one_rect_picture_check->LayerRect());
69 EXPECT_EQ(0, memcmp(one_rect_buffer, one_rect_buffer_check, 4 * 100 * 100)); 71 EXPECT_EQ(0, memcmp(one_rect_buffer, one_rect_buffer_check, 4 * 100 * 100));
70 72
71 // Two rect picture. 73 // Two rect picture.
72 content_layer_client.add_draw_rect(gfx::Rect(25, 25, 50, 50), green_paint); 74 content_layer_client.add_draw_rect(gfx::Rect(25, 25, 50, 50), green_paint);
73 75
74 scoped_refptr<Picture> two_rect_picture = 76 scoped_refptr<Picture> two_rect_picture =
75 Picture::Create(layer_rect, 77 Picture::Create(layer_rect,
76 &content_layer_client, 78 &content_layer_client,
79 false,
80 false,
77 tile_grid_info, 81 tile_grid_info,
78 false, 82 false,
79 Picture::RECORD_NORMALLY); 83 Picture::RECORD_NORMALLY);
80 84
81 scoped_ptr<base::Value> serialized_two_rect(two_rect_picture->AsValue()); 85 scoped_ptr<base::Value> serialized_two_rect(two_rect_picture->AsValue());
82 86
83 // Reconstruct the picture. 87 // Reconstruct the picture.
84 scoped_refptr<Picture> two_rect_picture_check = 88 scoped_refptr<Picture> two_rect_picture_check =
85 Picture::CreateFromValue(serialized_two_rect.get()); 89 Picture::CreateFromValue(serialized_two_rect.get());
86 EXPECT_TRUE(!!two_rect_picture_check.get()); 90 EXPECT_TRUE(!!two_rect_picture_check.get());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 SkPaint paint; 128 SkPaint paint;
125 content_layer_client.add_draw_bitmap( 129 content_layer_client.add_draw_bitmap(
126 discardable_bitmap[y][x], 130 discardable_bitmap[y][x],
127 gfx::Point(x * 512 + 6, y * 512 + 6), paint); 131 gfx::Point(x * 512 + 6, y * 512 + 6), paint);
128 } 132 }
129 } 133 }
130 } 134 }
131 135
132 scoped_refptr<Picture> picture = Picture::Create(layer_rect, 136 scoped_refptr<Picture> picture = Picture::Create(layer_rect,
133 &content_layer_client, 137 &content_layer_client,
138 false,
139 false,
134 tile_grid_info, 140 tile_grid_info,
135 true, 141 true,
136 Picture::RECORD_NORMALLY); 142 Picture::RECORD_NORMALLY);
137 143
138 // Default iterator does not have any pixel refs 144 // Default iterator does not have any pixel refs
139 { 145 {
140 Picture::PixelRefIterator iterator; 146 Picture::PixelRefIterator iterator;
141 EXPECT_FALSE(iterator); 147 EXPECT_FALSE(iterator);
142 } 148 }
143 for (int y = 0; y < 4; ++y) { 149 for (int y = 0; y < 4; ++y) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 SkPaint paint; 230 SkPaint paint;
225 content_layer_client.add_draw_bitmap( 231 content_layer_client.add_draw_bitmap(
226 discardable_bitmap[y][x], 232 discardable_bitmap[y][x],
227 gfx::Point(1024 + x * 512 + 6, y * 512 + 6), paint); 233 gfx::Point(1024 + x * 512 + 6, y * 512 + 6), paint);
228 } 234 }
229 } 235 }
230 } 236 }
231 237
232 scoped_refptr<Picture> picture = Picture::Create(layer_rect, 238 scoped_refptr<Picture> picture = Picture::Create(layer_rect,
233 &content_layer_client, 239 &content_layer_client,
240 false,
241 false,
234 tile_grid_info, 242 tile_grid_info,
235 true, 243 true,
236 Picture::RECORD_NORMALLY); 244 Picture::RECORD_NORMALLY);
237 245
238 // Default iterator does not have any pixel refs 246 // Default iterator does not have any pixel refs
239 { 247 {
240 Picture::PixelRefIterator iterator; 248 Picture::PixelRefIterator iterator;
241 EXPECT_FALSE(iterator); 249 EXPECT_FALSE(iterator);
242 } 250 }
243 for (int y = 0; y < 4; ++y) { 251 for (int y = 0; y < 4; ++y) {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 SkPaint paint; 355 SkPaint paint;
348 content_layer_client.add_draw_bitmap( 356 content_layer_client.add_draw_bitmap(
349 discardable_bitmap[y][x], 357 discardable_bitmap[y][x],
350 gfx::Point(x * 512 + 6, y * 512 + 6), paint); 358 gfx::Point(x * 512 + 6, y * 512 + 6), paint);
351 } 359 }
352 } 360 }
353 } 361 }
354 362
355 scoped_refptr<Picture> picture = Picture::Create(layer_rect, 363 scoped_refptr<Picture> picture = Picture::Create(layer_rect,
356 &content_layer_client, 364 &content_layer_client,
365 false,
366 false,
357 tile_grid_info, 367 tile_grid_info,
358 true, 368 true,
359 Picture::RECORD_NORMALLY); 369 Picture::RECORD_NORMALLY);
360 370
361 for (int y = 0; y < 4; ++y) { 371 for (int y = 0; y < 4; ++y) {
362 for (int x = 0; x < 4; ++x) { 372 for (int x = 0; x < 4; ++x) {
363 Picture::PixelRefIterator iterator( 373 Picture::PixelRefIterator iterator(
364 gfx::Rect(x * 512, y * 512 + 256, 1, 1), picture.get()); 374 gfx::Rect(x * 512, y * 512 + 256, 1, 1), picture.get());
365 if ((x + y) & 1) { 375 if ((x + y) & 1) {
366 EXPECT_TRUE(iterator) << x << " " << y; 376 EXPECT_TRUE(iterator) << x << " " << y;
(...skipping 29 matching lines...) Expand all
396 tmp.reset(new base::StringValue("abc!@#$%")); 406 tmp.reset(new base::StringValue("abc!@#$%"));
397 scoped_refptr<Picture> invalid_picture = 407 scoped_refptr<Picture> invalid_picture =
398 Picture::CreateFromSkpValue(tmp.get()); 408 Picture::CreateFromSkpValue(tmp.get());
399 EXPECT_TRUE(!invalid_picture.get()); 409 EXPECT_TRUE(!invalid_picture.get());
400 410
401 // Single full-size rect picture. 411 // Single full-size rect picture.
402 content_layer_client.add_draw_rect(layer_rect, red_paint); 412 content_layer_client.add_draw_rect(layer_rect, red_paint);
403 scoped_refptr<Picture> one_rect_picture = 413 scoped_refptr<Picture> one_rect_picture =
404 Picture::Create(layer_rect, 414 Picture::Create(layer_rect,
405 &content_layer_client, 415 &content_layer_client,
416 false,
417 false,
406 tile_grid_info, 418 tile_grid_info,
407 false, 419 false,
408 Picture::RECORD_NORMALLY); 420 Picture::RECORD_NORMALLY);
409 scoped_ptr<base::Value> serialized_one_rect( 421 scoped_ptr<base::Value> serialized_one_rect(
410 one_rect_picture->AsValue()); 422 one_rect_picture->AsValue());
411 423
412 const base::DictionaryValue* value = NULL; 424 const base::DictionaryValue* value = NULL;
413 EXPECT_TRUE(serialized_one_rect->GetAsDictionary(&value)); 425 EXPECT_TRUE(serialized_one_rect->GetAsDictionary(&value));
414 426
415 // Decode the picture from base64. 427 // Decode the picture from base64.
(...skipping 17 matching lines...) Expand all
433 SkTileGridFactory::TileGridInfo tile_grid_info; 445 SkTileGridFactory::TileGridInfo tile_grid_info;
434 tile_grid_info.fTileInterval = SkISize::Make(100, 200); 446 tile_grid_info.fTileInterval = SkISize::Make(100, 200);
435 tile_grid_info.fMargin.setEmpty(); 447 tile_grid_info.fMargin.setEmpty();
436 tile_grid_info.fOffset.setZero(); 448 tile_grid_info.fOffset.setZero();
437 449
438 FakeContentLayerClient content_layer_client; 450 FakeContentLayerClient content_layer_client;
439 EXPECT_EQ(NULL, content_layer_client.last_canvas()); 451 EXPECT_EQ(NULL, content_layer_client.last_canvas());
440 452
441 scoped_refptr<Picture> picture = Picture::Create(layer_rect, 453 scoped_refptr<Picture> picture = Picture::Create(layer_rect,
442 &content_layer_client, 454 &content_layer_client,
455 false,
456 false,
443 tile_grid_info, 457 tile_grid_info,
444 false, 458 false,
445 Picture::RECORD_NORMALLY); 459 Picture::RECORD_NORMALLY);
446 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); 460 EXPECT_TRUE(content_layer_client.last_canvas() != NULL);
447 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_ENABLED, 461 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_ENABLED,
448 content_layer_client.last_context_status()); 462 content_layer_client.last_context_status());
449 EXPECT_TRUE(picture.get()); 463 EXPECT_TRUE(picture.get());
450 464
451 picture = Picture::Create(layer_rect, 465 picture = Picture::Create(layer_rect,
452 &content_layer_client, 466 &content_layer_client,
467 false,
468 false,
453 tile_grid_info, 469 tile_grid_info,
454 false, 470 false,
455 Picture::RECORD_WITH_SK_NULL_CANVAS); 471 Picture::RECORD_WITH_SK_NULL_CANVAS);
456 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); 472 EXPECT_TRUE(content_layer_client.last_canvas() != NULL);
457 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_ENABLED, 473 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_ENABLED,
458 content_layer_client.last_context_status()); 474 content_layer_client.last_context_status());
459 EXPECT_TRUE(picture.get()); 475 EXPECT_TRUE(picture.get());
460 476
461 picture = Picture::Create(layer_rect, 477 picture = Picture::Create(layer_rect,
462 &content_layer_client, 478 &content_layer_client,
479 false,
480 false,
463 tile_grid_info, 481 tile_grid_info,
464 false, 482 false,
465 Picture::RECORD_WITH_PAINTING_DISABLED); 483 Picture::RECORD_WITH_PAINTING_DISABLED);
466 EXPECT_TRUE(content_layer_client.last_canvas() != NULL); 484 EXPECT_TRUE(content_layer_client.last_canvas() != NULL);
467 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_DISABLED, 485 EXPECT_EQ(ContentLayerClient::GRAPHICS_CONTEXT_DISABLED,
468 content_layer_client.last_context_status()); 486 content_layer_client.last_context_status());
469 EXPECT_TRUE(picture.get()); 487 EXPECT_TRUE(picture.get());
470 488
471 EXPECT_EQ(3, Picture::RECORDING_MODE_COUNT); 489 EXPECT_EQ(3, Picture::RECORDING_MODE_COUNT);
472 } 490 }
473 491
474 } // namespace 492 } // namespace
475 } // namespace cc 493 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698