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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "cc/playback/display_list_raster_source.h" | 6 #include "cc/playback/display_list_raster_source.h" |
7 #include "cc/test/fake_display_list_recording_source.h" | 7 #include "cc/test/fake_display_list_recording_source.h" |
8 #include "cc/test/skia_common.h" | 8 #include "cc/test/skia_common.h" |
9 #include "skia/ext/refptr.h" | 9 #include "skia/ext/refptr.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 solid_paint); | 34 solid_paint); |
35 recording_source->Rerecord(); | 35 recording_source->Rerecord(); |
36 | 36 |
37 scoped_refptr<DisplayListRasterSource> raster = | 37 scoped_refptr<DisplayListRasterSource> raster = |
38 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | 38 DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
39 recording_source.get(), false); | 39 recording_source.get(), false); |
40 | 40 |
41 // Ensure everything is solid. | 41 // Ensure everything is solid. |
42 for (int y = 0; y <= 300; y += 100) { | 42 for (int y = 0; y <= 300; y += 100) { |
43 for (int x = 0; x <= 300; x += 100) { | 43 for (int x = 0; x <= 300; x += 100) { |
44 RasterSource::SolidColorAnalysis analysis; | 44 DisplayListRasterSource::SolidColorAnalysis analysis; |
45 gfx::Rect rect(x, y, 100, 100); | 45 gfx::Rect rect(x, y, 100, 100); |
46 raster->PerformSolidColorAnalysis(rect, 1.0, &analysis); | 46 raster->PerformSolidColorAnalysis(rect, 1.0, &analysis); |
47 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); | 47 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); |
48 EXPECT_EQ(solid_color, analysis.solid_color) << rect.ToString(); | 48 EXPECT_EQ(solid_color, analysis.solid_color) << rect.ToString(); |
49 } | 49 } |
50 } | 50 } |
51 | 51 |
52 // Add one non-solid pixel and recreate the raster source. | 52 // Add one non-solid pixel and recreate the raster source. |
53 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), | 53 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), |
54 non_solid_paint); | 54 non_solid_paint); |
55 recording_source->Rerecord(); | 55 recording_source->Rerecord(); |
56 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( | 56 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
57 recording_source.get(), false); | 57 recording_source.get(), false); |
58 | 58 |
59 RasterSource::SolidColorAnalysis analysis; | 59 DisplayListRasterSource::SolidColorAnalysis analysis; |
60 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 100, 100), 1.0, &analysis); | 60 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 100, 100), 1.0, &analysis); |
61 EXPECT_FALSE(analysis.is_solid_color); | 61 EXPECT_FALSE(analysis.is_solid_color); |
62 | 62 |
63 raster->PerformSolidColorAnalysis(gfx::Rect(100, 0, 100, 100), 1.0, | 63 raster->PerformSolidColorAnalysis(gfx::Rect(100, 0, 100, 100), 1.0, |
64 &analysis); | 64 &analysis); |
65 EXPECT_TRUE(analysis.is_solid_color); | 65 EXPECT_TRUE(analysis.is_solid_color); |
66 EXPECT_EQ(solid_color, analysis.solid_color); | 66 EXPECT_EQ(solid_color, analysis.solid_color); |
67 | 67 |
68 // Boundaries should be clipped. | 68 // Boundaries should be clipped. |
69 analysis.is_solid_color = false; | 69 analysis.is_solid_color = false; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 solid_paint); | 103 solid_paint); |
104 recording_source->Rerecord(); | 104 recording_source->Rerecord(); |
105 | 105 |
106 scoped_refptr<DisplayListRasterSource> raster = | 106 scoped_refptr<DisplayListRasterSource> raster = |
107 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | 107 DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
108 recording_source.get(), false); | 108 recording_source.get(), false); |
109 | 109 |
110 // Ensure everything is solid. | 110 // Ensure everything is solid. |
111 for (int y = 0; y <= 30; y += 10) { | 111 for (int y = 0; y <= 30; y += 10) { |
112 for (int x = 0; x <= 30; x += 10) { | 112 for (int x = 0; x <= 30; x += 10) { |
113 RasterSource::SolidColorAnalysis analysis; | 113 DisplayListRasterSource::SolidColorAnalysis analysis; |
114 gfx::Rect rect(x, y, 10, 10); | 114 gfx::Rect rect(x, y, 10, 10); |
115 raster->PerformSolidColorAnalysis(rect, 0.1f, &analysis); | 115 raster->PerformSolidColorAnalysis(rect, 0.1f, &analysis); |
116 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); | 116 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); |
117 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString(); | 117 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString(); |
118 } | 118 } |
119 } | 119 } |
120 | 120 |
121 // Add one non-solid pixel and recreate the raster source. | 121 // Add one non-solid pixel and recreate the raster source. |
122 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), | 122 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), |
123 non_solid_paint); | 123 non_solid_paint); |
124 recording_source->Rerecord(); | 124 recording_source->Rerecord(); |
125 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( | 125 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
126 recording_source.get(), false); | 126 recording_source.get(), false); |
127 | 127 |
128 RasterSource::SolidColorAnalysis analysis; | 128 DisplayListRasterSource::SolidColorAnalysis analysis; |
129 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 10, 10), 0.1f, &analysis); | 129 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 10, 10), 0.1f, &analysis); |
130 EXPECT_FALSE(analysis.is_solid_color); | 130 EXPECT_FALSE(analysis.is_solid_color); |
131 | 131 |
132 raster->PerformSolidColorAnalysis(gfx::Rect(10, 0, 10, 10), 0.1f, &analysis); | 132 raster->PerformSolidColorAnalysis(gfx::Rect(10, 0, 10, 10), 0.1f, &analysis); |
133 EXPECT_TRUE(analysis.is_solid_color); | 133 EXPECT_TRUE(analysis.is_solid_color); |
134 EXPECT_EQ(analysis.solid_color, solid_color); | 134 EXPECT_EQ(analysis.solid_color, solid_color); |
135 | 135 |
136 // Boundaries should be clipped. | 136 // Boundaries should be clipped. |
137 analysis.is_solid_color = false; | 137 analysis.is_solid_color = false; |
138 raster->PerformSolidColorAnalysis(gfx::Rect(35, 0, 10, 10), 0.1f, &analysis); | 138 raster->PerformSolidColorAnalysis(gfx::Rect(35, 0, 10, 10), 0.1f, &analysis); |
(...skipping 14 matching lines...) Expand all Loading... |
153 TEST(DisplayListRasterSourceTest, AnalyzeIsSolidEmpty) { | 153 TEST(DisplayListRasterSourceTest, AnalyzeIsSolidEmpty) { |
154 gfx::Size layer_bounds(400, 400); | 154 gfx::Size layer_bounds(400, 400); |
155 | 155 |
156 scoped_ptr<FakeDisplayListRecordingSource> recording_source = | 156 scoped_ptr<FakeDisplayListRecordingSource> recording_source = |
157 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); | 157 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); |
158 recording_source->Rerecord(); | 158 recording_source->Rerecord(); |
159 | 159 |
160 scoped_refptr<DisplayListRasterSource> raster = | 160 scoped_refptr<DisplayListRasterSource> raster = |
161 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | 161 DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
162 recording_source.get(), false); | 162 recording_source.get(), false); |
163 RasterSource::SolidColorAnalysis analysis; | 163 DisplayListRasterSource::SolidColorAnalysis analysis; |
164 EXPECT_FALSE(analysis.is_solid_color); | 164 EXPECT_FALSE(analysis.is_solid_color); |
165 | 165 |
166 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 400, 400), 1.f, &analysis); | 166 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 400, 400), 1.f, &analysis); |
167 | 167 |
168 EXPECT_TRUE(analysis.is_solid_color); | 168 EXPECT_TRUE(analysis.is_solid_color); |
169 EXPECT_EQ(analysis.solid_color, SkColorSetARGB(0, 0, 0, 0)); | 169 EXPECT_EQ(analysis.solid_color, SkColorSetARGB(0, 0, 0, 0)); |
170 } | 170 } |
171 | 171 |
172 TEST(DisplayListRasterSourceTest, PixelRefIteratorDiscardableRefsOneTile) { | 172 TEST(DisplayListRasterSourceTest, PixelRefIteratorDiscardableRefsOneTile) { |
173 gfx::Size layer_bounds(512, 512); | 173 gfx::Size layer_bounds(512, 512); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 } | 345 } |
346 } | 346 } |
347 | 347 |
348 // Re-record everything as black. | 348 // Re-record everything as black. |
349 SkPaint black_paint; | 349 SkPaint black_paint; |
350 black_paint.setColor(SK_ColorBLACK); | 350 black_paint.setColor(SK_ColorBLACK); |
351 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), | 351 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), |
352 black_paint); | 352 black_paint); |
353 recording_source->Rerecord(); | 353 recording_source->Rerecord(); |
354 | 354 |
355 // Make a new RasterSource from the new recording. | 355 // Make a new DisplayListRasterSource from the new recording. |
356 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( | 356 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
357 recording_source.get(), false); | 357 recording_source.get(), false); |
358 | 358 |
359 // We're going to playback from "everything is black" into a smaller area, | 359 // We're going to playback from "everything is black" into a smaller area, |
360 // that touches the edge pixels of the recording. | 360 // that touches the edge pixels of the recording. |
361 playback_rect.Inset(1, 2, 0, 1); | 361 playback_rect.Inset(1, 2, 0, 1); |
362 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, | 362 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, |
363 contents_scale); | 363 contents_scale); |
364 | 364 |
365 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | 365 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 recording_source_light->SetRequiresClear(true); | 447 recording_source_light->SetRequiresClear(true); |
448 recording_source_light->SetClearCanvasWithDebugColor(false); | 448 recording_source_light->SetClearCanvasWithDebugColor(false); |
449 | 449 |
450 // Record everything as a slightly lighter white. | 450 // Record everything as a slightly lighter white. |
451 const unsigned alpha_light = 18u; | 451 const unsigned alpha_light = 18u; |
452 white_paint.setAlpha(alpha_light); | 452 white_paint.setAlpha(alpha_light); |
453 recording_source_light->add_draw_rect_with_paint(gfx::Rect(layer_bounds), | 453 recording_source_light->add_draw_rect_with_paint(gfx::Rect(layer_bounds), |
454 white_paint); | 454 white_paint); |
455 recording_source_light->Rerecord(); | 455 recording_source_light->Rerecord(); |
456 | 456 |
457 // Make a new RasterSource from the new recording. | 457 // Make a new DisplayListRasterSource from the new recording. |
458 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( | 458 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
459 recording_source_light.get(), false); | 459 recording_source_light.get(), false); |
460 | 460 |
461 // We're going to playback from alpha(18) white rectangle into a smaller area | 461 // We're going to playback from alpha(18) white rectangle into a smaller area |
462 // of the recording resulting in a smaller lighter white rectangle over a | 462 // of the recording resulting in a smaller lighter white rectangle over a |
463 // darker white background rectangle. | 463 // darker white background rectangle. |
464 playback_rect = | 464 playback_rect = |
465 gfx::Rect(gfx::ScaleToCeiledSize(partial_bounds, contents_scale)); | 465 gfx::Rect(gfx::ScaleToCeiledSize(partial_bounds, contents_scale)); |
466 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, | 466 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, |
467 contents_scale); | 467 contents_scale); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 scoped_refptr<DisplayListRasterSource> raster = | 525 scoped_refptr<DisplayListRasterSource> raster = |
526 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | 526 DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
527 recording_source.get(), false); | 527 recording_source.get(), false); |
528 size_t total_memory_usage = raster->GetPictureMemoryUsage(); | 528 size_t total_memory_usage = raster->GetPictureMemoryUsage(); |
529 EXPECT_GE(total_memory_usage, kReportedMemoryUsageInBytes); | 529 EXPECT_GE(total_memory_usage, kReportedMemoryUsageInBytes); |
530 EXPECT_LT(total_memory_usage, 2 * kReportedMemoryUsageInBytes); | 530 EXPECT_LT(total_memory_usage, 2 * kReportedMemoryUsageInBytes); |
531 } | 531 } |
532 | 532 |
533 } // namespace | 533 } // namespace |
534 } // namespace cc | 534 } // namespace cc |
OLD | NEW |