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

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

Issue 1531013004: cc: Do solid color analysis before scheduling tiles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: use non-solid color for ActivateAndDrawWhenOOM test. Created 4 years, 11 months 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "cc/playback/display_list_raster_source.h" 8 #include "cc/playback/display_list_raster_source.h"
9 #include "cc/test/fake_display_list_recording_source.h" 9 #include "cc/test/fake_display_list_recording_source.h"
10 #include "cc/test/skia_common.h" 10 #include "cc/test/skia_common.h"
(...skipping 11 matching lines...) Expand all
22 gfx::Size layer_bounds(400, 400); 22 gfx::Size layer_bounds(400, 400);
23 23
24 scoped_ptr<FakeDisplayListRecordingSource> recording_source = 24 scoped_ptr<FakeDisplayListRecordingSource> recording_source =
25 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); 25 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds);
26 26
27 SkPaint solid_paint; 27 SkPaint solid_paint;
28 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); 28 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34);
29 solid_paint.setColor(solid_color); 29 solid_paint.setColor(solid_color);
30 30
31 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); 31 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67);
32 SkColor color = SK_ColorTRANSPARENT;
32 SkPaint non_solid_paint; 33 SkPaint non_solid_paint;
34 bool is_solid_color = false;
33 non_solid_paint.setColor(non_solid_color); 35 non_solid_paint.setColor(non_solid_color);
34 36
35 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds), 37 recording_source->add_draw_rect_with_paint(gfx::Rect(layer_bounds),
36 solid_paint); 38 solid_paint);
37 recording_source->Rerecord(); 39 recording_source->Rerecord();
38 40
39 scoped_refptr<DisplayListRasterSource> raster = 41 scoped_refptr<DisplayListRasterSource> raster =
40 DisplayListRasterSource::CreateFromDisplayListRecordingSource( 42 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
41 recording_source.get(), false); 43 recording_source.get(), false);
42 44
43 // Ensure everything is solid. 45 // Ensure everything is solid.
44 for (int y = 0; y <= 300; y += 100) { 46 for (int y = 0; y <= 300; y += 100) {
45 for (int x = 0; x <= 300; x += 100) { 47 for (int x = 0; x <= 300; x += 100) {
46 DisplayListRasterSource::SolidColorAnalysis analysis;
47 gfx::Rect rect(x, y, 100, 100); 48 gfx::Rect rect(x, y, 100, 100);
48 raster->PerformSolidColorAnalysis(rect, 1.0, &analysis); 49 is_solid_color = raster->PerformSolidColorAnalysis(rect, 1.0, &color);
49 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); 50 EXPECT_TRUE(is_solid_color) << rect.ToString();
50 EXPECT_EQ(solid_color, analysis.solid_color) << rect.ToString(); 51 EXPECT_EQ(solid_color, color) << rect.ToString();
51 } 52 }
52 } 53 }
53 54
54 // Add one non-solid pixel and recreate the raster source. 55 // Add one non-solid pixel and recreate the raster source.
55 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), 56 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1),
56 non_solid_paint); 57 non_solid_paint);
57 recording_source->Rerecord(); 58 recording_source->Rerecord();
58 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( 59 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource(
59 recording_source.get(), false); 60 recording_source.get(), false);
60 61
61 DisplayListRasterSource::SolidColorAnalysis analysis; 62 color = SK_ColorTRANSPARENT;
62 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 100, 100), 1.0, &analysis); 63 is_solid_color =
63 EXPECT_FALSE(analysis.is_solid_color); 64 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 100, 100), 1.0, &color);
65 EXPECT_FALSE(is_solid_color);
64 66
65 raster->PerformSolidColorAnalysis(gfx::Rect(100, 0, 100, 100), 1.0, 67 is_solid_color = false;
vmpstr 2016/01/07 22:36:02 nit: you don't need to reset this to false, since
sohanjg 2016/01/08 11:47:56 Done.
66 &analysis); 68 color = SK_ColorTRANSPARENT;
67 EXPECT_TRUE(analysis.is_solid_color); 69 is_solid_color = raster->PerformSolidColorAnalysis(
68 EXPECT_EQ(solid_color, analysis.solid_color); 70 gfx::Rect(100, 0, 100, 100), 1.0, &color);
71 EXPECT_TRUE(is_solid_color);
72 EXPECT_EQ(solid_color, color);
69 73
70 // Boundaries should be clipped. 74 // Boundaries should be clipped.
71 analysis.is_solid_color = false; 75 is_solid_color = false;
72 raster->PerformSolidColorAnalysis(gfx::Rect(350, 0, 100, 100), 1.0, 76 color = SK_ColorTRANSPARENT;
73 &analysis); 77 is_solid_color = raster->PerformSolidColorAnalysis(
74 EXPECT_TRUE(analysis.is_solid_color); 78 gfx::Rect(350, 0, 100, 100), 1.0, &color);
75 EXPECT_EQ(solid_color, analysis.solid_color); 79 EXPECT_TRUE(is_solid_color);
80 EXPECT_EQ(solid_color, color);
76 81
77 analysis.is_solid_color = false; 82 is_solid_color = false;
78 raster->PerformSolidColorAnalysis(gfx::Rect(0, 350, 100, 100), 1.0, 83 color = SK_ColorTRANSPARENT;
79 &analysis); 84 is_solid_color = raster->PerformSolidColorAnalysis(
80 EXPECT_TRUE(analysis.is_solid_color); 85 gfx::Rect(0, 350, 100, 100), 1.0, &color);
81 EXPECT_EQ(solid_color, analysis.solid_color); 86 EXPECT_TRUE(is_solid_color);
87 EXPECT_EQ(solid_color, color);
82 88
83 analysis.is_solid_color = false; 89 is_solid_color = false;
84 raster->PerformSolidColorAnalysis(gfx::Rect(350, 350, 100, 100), 1.0, 90 color = SK_ColorTRANSPARENT;
85 &analysis); 91 is_solid_color = raster->PerformSolidColorAnalysis(
86 EXPECT_TRUE(analysis.is_solid_color); 92 gfx::Rect(350, 350, 100, 100), 1.0, &color);
87 EXPECT_EQ(solid_color, analysis.solid_color); 93 EXPECT_TRUE(is_solid_color);
94 EXPECT_EQ(solid_color, color);
88 } 95 }
89 96
90 TEST(DisplayListRasterSourceTest, AnalyzeIsSolidScaled) { 97 TEST(DisplayListRasterSourceTest, AnalyzeIsSolidScaled) {
91 gfx::Size layer_bounds(400, 400); 98 gfx::Size layer_bounds(400, 400);
92 99
93 scoped_ptr<FakeDisplayListRecordingSource> recording_source = 100 scoped_ptr<FakeDisplayListRecordingSource> recording_source =
94 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); 101 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds);
95 102
96 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34); 103 SkColor solid_color = SkColorSetARGB(255, 12, 23, 34);
104 SkColor color = SK_ColorTRANSPARENT;
97 SkPaint solid_paint; 105 SkPaint solid_paint;
106 bool is_solid_color = false;
98 solid_paint.setColor(solid_color); 107 solid_paint.setColor(solid_color);
99 108
100 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67); 109 SkColor non_solid_color = SkColorSetARGB(128, 45, 56, 67);
101 SkPaint non_solid_paint; 110 SkPaint non_solid_paint;
102 non_solid_paint.setColor(non_solid_color); 111 non_solid_paint.setColor(non_solid_color);
103 112
104 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),
105 solid_paint); 114 solid_paint);
106 recording_source->Rerecord(); 115 recording_source->Rerecord();
107 116
108 scoped_refptr<DisplayListRasterSource> raster = 117 scoped_refptr<DisplayListRasterSource> raster =
109 DisplayListRasterSource::CreateFromDisplayListRecordingSource( 118 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
110 recording_source.get(), false); 119 recording_source.get(), false);
111 120
112 // Ensure everything is solid. 121 // Ensure everything is solid.
113 for (int y = 0; y <= 30; y += 10) { 122 for (int y = 0; y <= 30; y += 10) {
114 for (int x = 0; x <= 30; x += 10) { 123 for (int x = 0; x <= 30; x += 10) {
115 DisplayListRasterSource::SolidColorAnalysis analysis;
116 gfx::Rect rect(x, y, 10, 10); 124 gfx::Rect rect(x, y, 10, 10);
117 raster->PerformSolidColorAnalysis(rect, 0.1f, &analysis); 125 is_solid_color = raster->PerformSolidColorAnalysis(rect, 0.1f, &color);
118 EXPECT_TRUE(analysis.is_solid_color) << rect.ToString(); 126 EXPECT_TRUE(is_solid_color) << rect.ToString();
119 EXPECT_EQ(analysis.solid_color, solid_color) << rect.ToString(); 127 EXPECT_EQ(color, solid_color) << rect.ToString();
120 } 128 }
121 } 129 }
122 130
123 // Add one non-solid pixel and recreate the raster source. 131 // Add one non-solid pixel and recreate the raster source.
124 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1), 132 recording_source->add_draw_rect_with_paint(gfx::Rect(50, 50, 1, 1),
125 non_solid_paint); 133 non_solid_paint);
126 recording_source->Rerecord(); 134 recording_source->Rerecord();
127 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource( 135 raster = DisplayListRasterSource::CreateFromDisplayListRecordingSource(
128 recording_source.get(), false); 136 recording_source.get(), false);
129 137
130 DisplayListRasterSource::SolidColorAnalysis analysis; 138 is_solid_color = false;
131 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 10, 10), 0.1f, &analysis); 139 color = SK_ColorTRANSPARENT;
132 EXPECT_FALSE(analysis.is_solid_color); 140 is_solid_color =
141 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 10, 10), 0.1f, &color);
142 EXPECT_FALSE(is_solid_color);
133 143
134 raster->PerformSolidColorAnalysis(gfx::Rect(10, 0, 10, 10), 0.1f, &analysis); 144 is_solid_color = false;
135 EXPECT_TRUE(analysis.is_solid_color); 145 color = SK_ColorTRANSPARENT;
136 EXPECT_EQ(analysis.solid_color, solid_color); 146 is_solid_color =
147 raster->PerformSolidColorAnalysis(gfx::Rect(10, 0, 10, 10), 0.1f, &color);
148 EXPECT_TRUE(is_solid_color);
149 EXPECT_EQ(color, solid_color);
137 150
138 // Boundaries should be clipped. 151 // Boundaries should be clipped.
139 analysis.is_solid_color = false; 152 is_solid_color = false;
140 raster->PerformSolidColorAnalysis(gfx::Rect(35, 0, 10, 10), 0.1f, &analysis); 153 color = SK_ColorTRANSPARENT;
141 EXPECT_TRUE(analysis.is_solid_color); 154 is_solid_color =
142 EXPECT_EQ(analysis.solid_color, solid_color); 155 raster->PerformSolidColorAnalysis(gfx::Rect(35, 0, 10, 10), 0.1f, &color);
156 EXPECT_TRUE(is_solid_color);
157 EXPECT_EQ(color, solid_color);
143 158
144 analysis.is_solid_color = false; 159 is_solid_color = false;
145 raster->PerformSolidColorAnalysis(gfx::Rect(0, 35, 10, 10), 0.1f, &analysis); 160 color = SK_ColorTRANSPARENT;
146 EXPECT_TRUE(analysis.is_solid_color); 161 is_solid_color =
147 EXPECT_EQ(analysis.solid_color, solid_color); 162 raster->PerformSolidColorAnalysis(gfx::Rect(0, 35, 10, 10), 0.1f, &color);
163 EXPECT_TRUE(is_solid_color);
164 EXPECT_EQ(color, solid_color);
148 165
149 analysis.is_solid_color = false; 166 is_solid_color = false;
150 raster->PerformSolidColorAnalysis(gfx::Rect(35, 35, 10, 10), 0.1f, &analysis); 167 color = SK_ColorTRANSPARENT;
151 EXPECT_TRUE(analysis.is_solid_color); 168 is_solid_color = raster->PerformSolidColorAnalysis(gfx::Rect(35, 35, 10, 10),
152 EXPECT_EQ(analysis.solid_color, solid_color); 169 0.1f, &color);
170 EXPECT_TRUE(is_solid_color);
171 EXPECT_EQ(color, solid_color);
153 } 172 }
154 173
155 TEST(DisplayListRasterSourceTest, AnalyzeIsSolidEmpty) { 174 TEST(DisplayListRasterSourceTest, AnalyzeIsSolidEmpty) {
156 gfx::Size layer_bounds(400, 400); 175 gfx::Size layer_bounds(400, 400);
157 176
158 scoped_ptr<FakeDisplayListRecordingSource> recording_source = 177 scoped_ptr<FakeDisplayListRecordingSource> recording_source =
159 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); 178 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds);
160 recording_source->Rerecord(); 179 recording_source->Rerecord();
161 180
162 scoped_refptr<DisplayListRasterSource> raster = 181 scoped_refptr<DisplayListRasterSource> raster =
163 DisplayListRasterSource::CreateFromDisplayListRecordingSource( 182 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
164 recording_source.get(), false); 183 recording_source.get(), false);
165 DisplayListRasterSource::SolidColorAnalysis analysis;
166 EXPECT_FALSE(analysis.is_solid_color);
167 184
168 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 400, 400), 1.f, &analysis); 185 SkColor color = SK_ColorTRANSPARENT;
186 bool is_solid_color =
187 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 400, 400), 1.f, &color);
169 188
170 EXPECT_TRUE(analysis.is_solid_color); 189 EXPECT_TRUE(is_solid_color);
171 EXPECT_EQ(analysis.solid_color, SkColorSetARGB(0, 0, 0, 0)); 190 EXPECT_EQ(color, SkColorSetARGB(0, 0, 0, 0));
172 } 191 }
173 192
174 TEST(DisplayListRasterSourceTest, PixelRefIteratorDiscardableRefsOneTile) { 193 TEST(DisplayListRasterSourceTest, PixelRefIteratorDiscardableRefsOneTile) {
175 gfx::Size layer_bounds(512, 512); 194 gfx::Size layer_bounds(512, 512);
176 195
177 scoped_ptr<FakeDisplayListRecordingSource> recording_source = 196 scoped_ptr<FakeDisplayListRecordingSource> recording_source =
178 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds); 197 FakeDisplayListRecordingSource::CreateFilledRecordingSource(layer_bounds);
179 198
180 skia::RefPtr<SkImage> discardable_image[2][2]; 199 skia::RefPtr<SkImage> discardable_image[2][2];
181 discardable_image[0][0] = CreateDiscardableImage(gfx::Size(32, 32)); 200 discardable_image[0][0] = CreateDiscardableImage(gfx::Size(32, 32));
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 scoped_refptr<DisplayListRasterSource> raster = 548 scoped_refptr<DisplayListRasterSource> raster =
530 DisplayListRasterSource::CreateFromDisplayListRecordingSource( 549 DisplayListRasterSource::CreateFromDisplayListRecordingSource(
531 recording_source.get(), false); 550 recording_source.get(), false);
532 size_t total_memory_usage = raster->GetPictureMemoryUsage(); 551 size_t total_memory_usage = raster->GetPictureMemoryUsage();
533 EXPECT_GE(total_memory_usage, kReportedMemoryUsageInBytes); 552 EXPECT_GE(total_memory_usage, kReportedMemoryUsageInBytes);
534 EXPECT_LT(total_memory_usage, 2 * kReportedMemoryUsageInBytes); 553 EXPECT_LT(total_memory_usage, 2 * kReportedMemoryUsageInBytes);
535 } 554 }
536 555
537 } // namespace 556 } // namespace
538 } // namespace cc 557 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698