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

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

Issue 2877483003: Implements core logic for Pixel Canvas (Closed)
Patch Set: nits Created 3 years, 6 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 "cc/raster/raster_source.h" 5 #include "cc/raster/raster_source.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 solid_flags); 46 solid_flags);
47 recording_source->Rerecord(); 47 recording_source->Rerecord();
48 48
49 scoped_refptr<RasterSource> raster = 49 scoped_refptr<RasterSource> raster =
50 RasterSource::CreateFromRecordingSource(recording_source.get(), false); 50 RasterSource::CreateFromRecordingSource(recording_source.get(), false);
51 51
52 // Ensure everything is solid. 52 // Ensure everything is solid.
53 for (int y = 0; y <= 300; y += 100) { 53 for (int y = 0; y <= 300; y += 100) {
54 for (int x = 0; x <= 300; x += 100) { 54 for (int x = 0; x <= 300; x += 100) {
55 gfx::Rect rect(x, y, 100, 100); 55 gfx::Rect rect(x, y, 100, 100);
56 is_solid_color = raster->PerformSolidColorAnalysis(rect, 1.f, &color); 56 is_solid_color = raster->PerformSolidColorAnalysis(
57 rect, gfx::AxisTransform2d(1.f, gfx::Vector2dF()), &color);
57 EXPECT_TRUE(is_solid_color) << rect.ToString(); 58 EXPECT_TRUE(is_solid_color) << rect.ToString();
58 EXPECT_EQ(solid_color, color) << rect.ToString(); 59 EXPECT_EQ(solid_color, color) << rect.ToString();
59 } 60 }
60 } 61 }
61 62
62 // Add one non-solid pixel and recreate the raster source. 63 // Add one non-solid pixel and recreate the raster source.
63 recording_source->add_draw_rect_with_flags(gfx::Rect(50, 50, 1, 1), 64 recording_source->add_draw_rect_with_flags(gfx::Rect(50, 50, 1, 1),
64 non_solid_flags); 65 non_solid_flags);
65 recording_source->Rerecord(); 66 recording_source->Rerecord();
66 raster = 67 raster =
67 RasterSource::CreateFromRecordingSource(recording_source.get(), false); 68 RasterSource::CreateFromRecordingSource(recording_source.get(), false);
68 69
69 color = SK_ColorTRANSPARENT; 70 color = SK_ColorTRANSPARENT;
70 is_solid_color = 71 is_solid_color = raster->PerformSolidColorAnalysis(
71 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 100, 100), 1.f, &color); 72 gfx::Rect(0, 0, 100, 100), gfx::AxisTransform2d(1.f, gfx::Vector2dF()),
73 &color);
72 EXPECT_FALSE(is_solid_color); 74 EXPECT_FALSE(is_solid_color);
73 75
74 color = SK_ColorTRANSPARENT; 76 color = SK_ColorTRANSPARENT;
75 is_solid_color = raster->PerformSolidColorAnalysis( 77 is_solid_color = raster->PerformSolidColorAnalysis(
76 gfx::Rect(100, 0, 100, 100), 1.f, &color); 78 gfx::Rect(100, 0, 100, 100), gfx::AxisTransform2d(1.f, gfx::Vector2dF()),
79 &color);
77 EXPECT_TRUE(is_solid_color); 80 EXPECT_TRUE(is_solid_color);
78 EXPECT_EQ(solid_color, color); 81 EXPECT_EQ(solid_color, color);
79 82
80 // Boundaries should be clipped. 83 // Boundaries should be clipped.
81 color = SK_ColorTRANSPARENT; 84 color = SK_ColorTRANSPARENT;
82 is_solid_color = raster->PerformSolidColorAnalysis( 85 is_solid_color = raster->PerformSolidColorAnalysis(
83 gfx::Rect(350, 0, 100, 100), 1.f, &color); 86 gfx::Rect(350, 0, 100, 100), gfx::AxisTransform2d(1.f, gfx::Vector2dF()),
87 &color);
84 EXPECT_TRUE(is_solid_color); 88 EXPECT_TRUE(is_solid_color);
85 EXPECT_EQ(solid_color, color); 89 EXPECT_EQ(solid_color, color);
86 90
87 color = SK_ColorTRANSPARENT; 91 color = SK_ColorTRANSPARENT;
88 is_solid_color = raster->PerformSolidColorAnalysis( 92 is_solid_color = raster->PerformSolidColorAnalysis(
89 gfx::Rect(0, 350, 100, 100), 1.f, &color); 93 gfx::Rect(0, 350, 100, 100), gfx::AxisTransform2d(1.f, gfx::Vector2dF()),
94 &color);
90 EXPECT_TRUE(is_solid_color); 95 EXPECT_TRUE(is_solid_color);
91 EXPECT_EQ(solid_color, color); 96 EXPECT_EQ(solid_color, color);
92 97
93 color = SK_ColorTRANSPARENT; 98 color = SK_ColorTRANSPARENT;
94 is_solid_color = raster->PerformSolidColorAnalysis( 99 is_solid_color = raster->PerformSolidColorAnalysis(
95 gfx::Rect(350, 350, 100, 100), 1.f, &color); 100 gfx::Rect(350, 350, 100, 100),
101 gfx::AxisTransform2d(1.f, gfx::Vector2dF()), &color);
96 EXPECT_TRUE(is_solid_color); 102 EXPECT_TRUE(is_solid_color);
97 EXPECT_EQ(solid_color, color); 103 EXPECT_EQ(solid_color, color);
98 } 104 }
99 105
100 TEST(RasterSourceTest, AnalyzeIsSolidScaled) { 106 TEST(RasterSourceTest, AnalyzeIsSolidScaled) {
101 gfx::Size layer_bounds(400, 400); 107 gfx::Size layer_bounds(400, 400);
102 108
103 std::unique_ptr<FakeRecordingSource> recording_source = 109 std::unique_ptr<FakeRecordingSource> recording_source =
104 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); 110 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds);
105 111
(...skipping 11 matching lines...) Expand all
117 solid_flags); 123 solid_flags);
118 recording_source->Rerecord(); 124 recording_source->Rerecord();
119 125
120 scoped_refptr<RasterSource> raster = 126 scoped_refptr<RasterSource> raster =
121 RasterSource::CreateFromRecordingSource(recording_source.get(), false); 127 RasterSource::CreateFromRecordingSource(recording_source.get(), false);
122 128
123 // Ensure everything is solid. 129 // Ensure everything is solid.
124 for (int y = 0; y <= 30; y += 10) { 130 for (int y = 0; y <= 30; y += 10) {
125 for (int x = 0; x <= 30; x += 10) { 131 for (int x = 0; x <= 30; x += 10) {
126 gfx::Rect rect(x, y, 10, 10); 132 gfx::Rect rect(x, y, 10, 10);
127 is_solid_color = raster->PerformSolidColorAnalysis(rect, 0.1f, &color); 133 is_solid_color = raster->PerformSolidColorAnalysis(
134 rect, gfx::AxisTransform2d(0.1f, gfx::Vector2dF()), &color);
128 EXPECT_TRUE(is_solid_color) << rect.ToString(); 135 EXPECT_TRUE(is_solid_color) << rect.ToString();
129 EXPECT_EQ(color, solid_color) << rect.ToString(); 136 EXPECT_EQ(color, solid_color) << rect.ToString();
130 } 137 }
131 } 138 }
132 139
133 // Add one non-solid pixel and recreate the raster source. 140 // Add one non-solid pixel and recreate the raster source.
134 recording_source->add_draw_rect_with_flags(gfx::Rect(50, 50, 1, 1), 141 recording_source->add_draw_rect_with_flags(gfx::Rect(50, 50, 1, 1),
135 non_solid_flags); 142 non_solid_flags);
136 recording_source->Rerecord(); 143 recording_source->Rerecord();
137 raster = 144 raster =
138 RasterSource::CreateFromRecordingSource(recording_source.get(), false); 145 RasterSource::CreateFromRecordingSource(recording_source.get(), false);
139 146
140 color = SK_ColorTRANSPARENT; 147 color = SK_ColorTRANSPARENT;
141 is_solid_color = 148 is_solid_color = raster->PerformSolidColorAnalysis(
142 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 10, 10), 0.1f, &color); 149 gfx::Rect(0, 0, 10, 10), gfx::AxisTransform2d(0.1f, gfx::Vector2dF()),
150 &color);
143 EXPECT_FALSE(is_solid_color); 151 EXPECT_FALSE(is_solid_color);
144 152
145 color = SK_ColorTRANSPARENT; 153 color = SK_ColorTRANSPARENT;
146 is_solid_color = 154 is_solid_color = raster->PerformSolidColorAnalysis(
147 raster->PerformSolidColorAnalysis(gfx::Rect(10, 0, 10, 10), 0.1f, &color); 155 gfx::Rect(10, 0, 10, 10), gfx::AxisTransform2d(0.1f, gfx::Vector2dF()),
156 &color);
148 EXPECT_TRUE(is_solid_color); 157 EXPECT_TRUE(is_solid_color);
149 EXPECT_EQ(color, solid_color); 158 EXPECT_EQ(color, solid_color);
150 159
151 // Boundaries should be clipped. 160 // Boundaries should be clipped.
152 color = SK_ColorTRANSPARENT; 161 color = SK_ColorTRANSPARENT;
153 is_solid_color = 162 is_solid_color = raster->PerformSolidColorAnalysis(
154 raster->PerformSolidColorAnalysis(gfx::Rect(35, 0, 10, 10), 0.1f, &color); 163 gfx::Rect(35, 0, 10, 10), gfx::AxisTransform2d(0.1f, gfx::Vector2dF()),
164 &color);
155 EXPECT_TRUE(is_solid_color); 165 EXPECT_TRUE(is_solid_color);
156 EXPECT_EQ(color, solid_color); 166 EXPECT_EQ(color, solid_color);
157 167
158 color = SK_ColorTRANSPARENT; 168 color = SK_ColorTRANSPARENT;
159 is_solid_color = 169 is_solid_color = raster->PerformSolidColorAnalysis(
160 raster->PerformSolidColorAnalysis(gfx::Rect(0, 35, 10, 10), 0.1f, &color); 170 gfx::Rect(0, 35, 10, 10), gfx::AxisTransform2d(0.1f, gfx::Vector2dF()),
171 &color);
161 EXPECT_TRUE(is_solid_color); 172 EXPECT_TRUE(is_solid_color);
162 EXPECT_EQ(color, solid_color); 173 EXPECT_EQ(color, solid_color);
163 174
164 color = SK_ColorTRANSPARENT; 175 color = SK_ColorTRANSPARENT;
165 is_solid_color = raster->PerformSolidColorAnalysis(gfx::Rect(35, 35, 10, 10), 176 is_solid_color = raster->PerformSolidColorAnalysis(
166 0.1f, &color); 177 gfx::Rect(35, 35, 10, 10), gfx::AxisTransform2d(0.1f, gfx::Vector2dF()),
178 &color);
167 EXPECT_TRUE(is_solid_color); 179 EXPECT_TRUE(is_solid_color);
168 EXPECT_EQ(color, solid_color); 180 EXPECT_EQ(color, solid_color);
169 } 181 }
170 182
171 TEST(RasterSourceTest, AnalyzeIsSolidEmpty) { 183 TEST(RasterSourceTest, AnalyzeIsSolidEmpty) {
172 gfx::Size layer_bounds(400, 400); 184 gfx::Size layer_bounds(400, 400);
173 185
174 std::unique_ptr<FakeRecordingSource> recording_source = 186 std::unique_ptr<FakeRecordingSource> recording_source =
175 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); 187 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds);
176 recording_source->Rerecord(); 188 recording_source->Rerecord();
177 189
178 scoped_refptr<RasterSource> raster = 190 scoped_refptr<RasterSource> raster =
179 RasterSource::CreateFromRecordingSource(recording_source.get(), false); 191 RasterSource::CreateFromRecordingSource(recording_source.get(), false);
180 192
181 SkColor color = SK_ColorTRANSPARENT; 193 SkColor color = SK_ColorTRANSPARENT;
182 bool is_solid_color = 194 bool is_solid_color = raster->PerformSolidColorAnalysis(
183 raster->PerformSolidColorAnalysis(gfx::Rect(0, 0, 400, 400), 1.f, &color); 195 gfx::Rect(0, 0, 400, 400), gfx::AxisTransform2d(0.1f, gfx::Vector2dF()),
196 &color);
184 197
185 EXPECT_TRUE(is_solid_color); 198 EXPECT_TRUE(is_solid_color);
186 EXPECT_EQ(color, SkColorSetARGB(0, 0, 0, 0)); 199 EXPECT_EQ(color, SkColorSetARGB(0, 0, 0, 0));
187 } 200 }
188 201
189 TEST(RasterSourceTest, PixelRefIteratorDiscardableRefsOneTile) { 202 TEST(RasterSourceTest, PixelRefIteratorDiscardableRefsOneTile) {
190 gfx::Size layer_bounds(512, 512); 203 gfx::Size layer_bounds(512, 512);
191 204
192 std::unique_ptr<FakeRecordingSource> recording_source = 205 std::unique_ptr<FakeRecordingSource> recording_source =
193 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds); 206 FakeRecordingSource::CreateFilledRecordingSource(layer_bounds);
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(0, 24)); 632 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(0, 24));
620 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(49, 24)); 633 EXPECT_EQ(SK_ColorGREEN, bitmap.getColor(49, 24));
621 for (int x = 0; x < 49; ++x) 634 for (int x = 0; x < 49; ++x)
622 EXPECT_EQ(SK_ColorRED, bitmap.getColor(x, 12)); 635 EXPECT_EQ(SK_ColorRED, bitmap.getColor(x, 12));
623 for (int y = 0; y < 24; ++y) 636 for (int y = 0; y < 24; ++y)
624 EXPECT_EQ(SK_ColorRED, bitmap.getColor(24, y)); 637 EXPECT_EQ(SK_ColorRED, bitmap.getColor(24, y));
625 } 638 }
626 639
627 } // namespace 640 } // namespace
628 } // namespace cc 641 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698