| 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 } | 355 } |
| 356 } | 356 } |
| 357 | 357 |
| 358 // Re-record everything as black. | 358 // Re-record everything as black. |
| 359 SkPaint black_paint; | 359 SkPaint black_paint; |
| 360 black_paint.setColor(SK_ColorBLACK); | 360 black_paint.setColor(SK_ColorBLACK); |
| 361 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), | 361 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), |
| 362 black_paint); | 362 black_paint); |
| 363 recording_source->Rerecord(); | 363 recording_source->Rerecord(); |
| 364 | 364 |
| 365 // Make a new RasterSource from the new recording. | 365 // Make a new DisplayListRasterSource from the new recording. |
| 366 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( | 366 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
| 367 recording_source.get(), false); | 367 recording_source.get(), false); |
| 368 | 368 |
| 369 // 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, |
| 370 // that touches the edge pixels of the recording. | 370 // that touches the edge pixels of the recording. |
| 371 playback_rect.Inset(1, 2, 0, 1); | 371 playback_rect.Inset(1, 2, 0, 1); |
| 372 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, | 372 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, |
| 373 contents_scale); | 373 contents_scale); |
| 374 | 374 |
| 375 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); | 375 SkColor* pixels = reinterpret_cast<SkColor*>(bitmap.getPixels()); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 recording_source_light->SetRequiresClear(true); | 457 recording_source_light->SetRequiresClear(true); |
| 458 recording_source_light->SetClearCanvasWithDebugColor(false); | 458 recording_source_light->SetClearCanvasWithDebugColor(false); |
| 459 | 459 |
| 460 // Record everything as a slightly lighter white. | 460 // Record everything as a slightly lighter white. |
| 461 const unsigned alpha_light = 18u; | 461 const unsigned alpha_light = 18u; |
| 462 white_paint.setAlpha(alpha_light); | 462 white_paint.setAlpha(alpha_light); |
| 463 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), |
| 464 white_paint); | 464 white_paint); |
| 465 recording_source_light->Rerecord(); | 465 recording_source_light->Rerecord(); |
| 466 | 466 |
| 467 // Make a new RasterSource from the new recording. | 467 // Make a new DisplayListRasterSource from the new recording. |
| 468 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( | 468 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
| 469 recording_source_light.get(), false); | 469 recording_source_light.get(), false); |
| 470 | 470 |
| 471 // We're going to playback from alpha(18) white rectangle into a smaller area | 471 // We're going to playback from alpha(18) white rectangle into a smaller area |
| 472 // of the recording resulting in a smaller lighter white rectangle over a | 472 // of the recording resulting in a smaller lighter white rectangle over a |
| 473 // darker white background rectangle. | 473 // darker white background rectangle. |
| 474 playback_rect = | 474 playback_rect = |
| 475 gfx::Rect(gfx::ScaleToCeiledSize(partial_bounds, contents_scale)); | 475 gfx::Rect(gfx::ScaleToCeiledSize(partial_bounds, contents_scale)); |
| 476 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, | 476 raster->PlaybackToCanvas(&canvas, raster_full_rect, playback_rect, |
| 477 contents_scale); | 477 contents_scale); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 scoped_refptr<DisplayListRasterSource> raster = | 535 scoped_refptr<DisplayListRasterSource> raster = |
| 536 DisplayListRasterSource::CreateFromDisplayListRecordingSource( | 536 DisplayListRasterSource::CreateFromDisplayListRecordingSource( |
| 537 recording_source.get(), false); | 537 recording_source.get(), false); |
| 538 size_t total_memory_usage = raster->GetPictureMemoryUsage(); | 538 size_t total_memory_usage = raster->GetPictureMemoryUsage(); |
| 539 EXPECT_GE(total_memory_usage, kReportedMemoryUsageInBytes); | 539 EXPECT_GE(total_memory_usage, kReportedMemoryUsageInBytes); |
| 540 EXPECT_LT(total_memory_usage, 2 * kReportedMemoryUsageInBytes); | 540 EXPECT_LT(total_memory_usage, 2 * kReportedMemoryUsageInBytes); |
| 541 } | 541 } |
| 542 | 542 |
| 543 } // namespace | 543 } // namespace |
| 544 } // namespace cc | 544 } // namespace cc |
| OLD | NEW |