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

Side by Side Diff: skia/ext/pixel_ref_utils_unittest.cc

Issue 246393005: Switching unit tests to use new Skia SkPictureRecorder API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/compiler_specific.h" 5 #include "base/compiler_specific.h"
6 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
7 #include "cc/test/geometry_test_utils.h" 7 #include "cc/test/geometry_test_utils.h"
8 #include "skia/ext/pixel_ref_utils.h" 8 #include "skia/ext/pixel_ref_utils.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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 const SkImageInfo info = { 62 const SkImageInfo info = {
63 size.width(), size.height(), kPMColor_SkColorType, kPremul_SkAlphaType 63 size.width(), size.height(), kPMColor_SkColorType, kPremul_SkAlphaType
64 }; 64 };
65 65
66 bitmap->setConfig(info); 66 bitmap->setConfig(info);
67 bitmap->allocPixels(); 67 bitmap->allocPixels();
68 bitmap->pixelRef()->setImmutable(); 68 bitmap->pixelRef()->setImmutable();
69 bitmap->pixelRef()->setURI(uri); 69 bitmap->pixelRef()->setURI(uri);
70 } 70 }
71 71
72 SkCanvas* StartRecording(SkPicture* picture, gfx::Rect layer_rect) { 72 SkCanvas* StartRecording(SkPictureRecorder* recorder, gfx::Rect layer_rect) {
73 SkCanvas* canvas = picture->beginRecording( 73 SkCanvas* canvas = recorder->beginRecording(
74 layer_rect.width(), 74 layer_rect.width(),
75 layer_rect.height(), 75 layer_rect.height(),
76 SkPicture::kUsePathBoundsForClip_RecordingFlag); 76 SkPicture::kUsePathBoundsForClip_RecordingFlag);
77 77
78 canvas->save(); 78 canvas->save();
79 canvas->translate(-layer_rect.x(), -layer_rect.y()); 79 canvas->translate(-layer_rect.x(), -layer_rect.y());
80 canvas->clipRect(SkRect::MakeXYWH( 80 canvas->clipRect(SkRect::MakeXYWH(
81 layer_rect.x(), layer_rect.y(), layer_rect.width(), layer_rect.height())); 81 layer_rect.x(), layer_rect.y(), layer_rect.width(), layer_rect.height()));
82 82
83 return canvas; 83 return canvas;
84 } 84 }
85 85
86 void StopRecording(SkPicture* picture, SkCanvas* canvas) { 86 SkPicture* StopRecording(SkPictureRecorder* recorder, SkCanvas* canvas) {
87 canvas->restore(); 87 canvas->restore();
88 picture->endRecording(); 88 return recorder->endRecording();
89 } 89 }
90 90
91 } // namespace 91 } // namespace
92 92
93 TEST(PixelRefUtilsTest, DrawPaint) { 93 TEST(PixelRefUtilsTest, DrawPaint) {
94 gfx::Rect layer_rect(0, 0, 256, 256); 94 gfx::Rect layer_rect(0, 0, 256, 256);
95 95
96 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture); 96 SkPictureRecorder recorder;
97 SkCanvas* canvas = StartRecording(picture.get(), layer_rect); 97 SkCanvas* canvas = StartRecording(&recorder, layer_rect);
98 98
99 TestDiscardableShader first_shader; 99 TestDiscardableShader first_shader;
100 SkPaint first_paint; 100 SkPaint first_paint;
101 first_paint.setShader(&first_shader); 101 first_paint.setShader(&first_shader);
102 102
103 TestDiscardableShader second_shader; 103 TestDiscardableShader second_shader;
104 SkPaint second_paint; 104 SkPaint second_paint;
105 second_paint.setShader(&second_shader); 105 second_paint.setShader(&second_shader);
106 106
107 TestDiscardableShader third_shader; 107 TestDiscardableShader third_shader;
108 SkPaint third_paint; 108 SkPaint third_paint;
109 third_paint.setShader(&third_shader); 109 third_paint.setShader(&third_shader);
110 110
111 canvas->drawPaint(first_paint); 111 canvas->drawPaint(first_paint);
112 canvas->clipRect(SkRect::MakeXYWH(34, 45, 56, 67)); 112 canvas->clipRect(SkRect::MakeXYWH(34, 45, 56, 67));
113 canvas->drawPaint(second_paint); 113 canvas->drawPaint(second_paint);
114 // Total clip is now (34, 45, 56, 55) 114 // Total clip is now (34, 45, 56, 55)
115 canvas->clipRect(SkRect::MakeWH(100, 100)); 115 canvas->clipRect(SkRect::MakeWH(100, 100));
116 canvas->drawPaint(third_paint); 116 canvas->drawPaint(third_paint);
117 117
118 StopRecording(picture.get(), canvas); 118 skia::RefPtr<SkPicture> picture = skia::AdoptRef(StopRecording(&recorder, canv as));
119 119
120 std::vector<skia::PixelRefUtils::PositionPixelRef> pixel_refs; 120 std::vector<skia::PixelRefUtils::PositionPixelRef> pixel_refs;
121 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture.get(), &pixel_refs); 121 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture.get(), &pixel_refs);
122 122
123 EXPECT_EQ(3u, pixel_refs.size()); 123 EXPECT_EQ(3u, pixel_refs.size());
124 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 256, 256), 124 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 256, 256),
125 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect)); 125 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect));
126 EXPECT_FLOAT_RECT_EQ(gfx::RectF(34, 45, 56, 67), 126 EXPECT_FLOAT_RECT_EQ(gfx::RectF(34, 45, 56, 67),
127 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect)); 127 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect));
128 EXPECT_FLOAT_RECT_EQ(gfx::RectF(34, 45, 56, 55), 128 EXPECT_FLOAT_RECT_EQ(gfx::RectF(34, 45, 56, 55),
129 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect)); 129 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect));
130 } 130 }
131 131
132 TEST(PixelRefUtilsTest, DrawPoints) { 132 TEST(PixelRefUtilsTest, DrawPoints) {
133 gfx::Rect layer_rect(0, 0, 256, 256); 133 gfx::Rect layer_rect(0, 0, 256, 256);
134 134
135 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture); 135 SkPictureRecorder recorder;
136 SkCanvas* canvas = StartRecording(picture.get(), layer_rect); 136 SkCanvas* canvas = StartRecording(&recorder, layer_rect);
137 137
138 TestDiscardableShader first_shader; 138 TestDiscardableShader first_shader;
139 SkPaint first_paint; 139 SkPaint first_paint;
140 first_paint.setShader(&first_shader); 140 first_paint.setShader(&first_shader);
141 141
142 TestDiscardableShader second_shader; 142 TestDiscardableShader second_shader;
143 SkPaint second_paint; 143 SkPaint second_paint;
144 second_paint.setShader(&second_shader); 144 second_paint.setShader(&second_shader);
145 145
146 TestDiscardableShader third_shader; 146 TestDiscardableShader third_shader;
(...skipping 14 matching lines...) Expand all
161 canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, points, second_paint); 161 canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, points, second_paint);
162 162
163 canvas->restore(); 163 canvas->restore();
164 164
165 points[0].set(50, 55); 165 points[0].set(50, 55);
166 points[1].set(50, 55); 166 points[1].set(50, 55);
167 points[2].set(200, 200); 167 points[2].set(200, 200);
168 // (50, 55, 150, 145). 168 // (50, 55, 150, 145).
169 canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, points, third_paint); 169 canvas->drawPoints(SkCanvas::kPolygon_PointMode, 3, points, third_paint);
170 170
171 StopRecording(picture.get(), canvas); 171 skia::RefPtr<SkPicture> picture = skia::AdoptRef(StopRecording(&recorder, canv as));
172 172
173 std::vector<skia::PixelRefUtils::PositionPixelRef> pixel_refs; 173 std::vector<skia::PixelRefUtils::PositionPixelRef> pixel_refs;
174 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture.get(), &pixel_refs); 174 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture.get(), &pixel_refs);
175 175
176 EXPECT_EQ(3u, pixel_refs.size()); 176 EXPECT_EQ(3u, pixel_refs.size());
177 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 90, 90), 177 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 90, 90),
178 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect)); 178 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect));
179 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 40, 40), 179 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 40, 40),
180 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect)); 180 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect));
181 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 55, 150, 145), 181 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 55, 150, 145),
182 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect)); 182 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect));
183 } 183 }
184 184
185 TEST(PixelRefUtilsTest, DrawRect) { 185 TEST(PixelRefUtilsTest, DrawRect) {
186 gfx::Rect layer_rect(0, 0, 256, 256); 186 gfx::Rect layer_rect(0, 0, 256, 256);
187 187
188 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture); 188 SkPictureRecorder recorder;
189 SkCanvas* canvas = StartRecording(picture.get(), layer_rect); 189 SkCanvas* canvas = StartRecording(&recorder, layer_rect);
190 190
191 TestDiscardableShader first_shader; 191 TestDiscardableShader first_shader;
192 SkPaint first_paint; 192 SkPaint first_paint;
193 first_paint.setShader(&first_shader); 193 first_paint.setShader(&first_shader);
194 194
195 TestDiscardableShader second_shader; 195 TestDiscardableShader second_shader;
196 SkPaint second_paint; 196 SkPaint second_paint;
197 second_paint.setShader(&second_shader); 197 second_paint.setShader(&second_shader);
198 198
199 TestDiscardableShader third_shader; 199 TestDiscardableShader third_shader;
200 SkPaint third_paint; 200 SkPaint third_paint;
201 third_paint.setShader(&third_shader); 201 third_paint.setShader(&third_shader);
202 202
203 // (10, 20, 30, 40). 203 // (10, 20, 30, 40).
204 canvas->drawRect(SkRect::MakeXYWH(10, 20, 30, 40), first_paint); 204 canvas->drawRect(SkRect::MakeXYWH(10, 20, 30, 40), first_paint);
205 205
206 canvas->save(); 206 canvas->save();
207 207
208 canvas->translate(5, 17); 208 canvas->translate(5, 17);
209 // (5, 50, 25, 35) 209 // (5, 50, 25, 35)
210 canvas->drawRect(SkRect::MakeXYWH(0, 33, 25, 35), second_paint); 210 canvas->drawRect(SkRect::MakeXYWH(0, 33, 25, 35), second_paint);
211 211
212 canvas->restore(); 212 canvas->restore();
213 213
214 canvas->clipRect(SkRect::MakeXYWH(50, 50, 50, 50)); 214 canvas->clipRect(SkRect::MakeXYWH(50, 50, 50, 50));
215 canvas->translate(20, 20); 215 canvas->translate(20, 20);
216 // (50, 50, 50, 50) 216 // (50, 50, 50, 50)
217 canvas->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), third_paint); 217 canvas->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), third_paint);
218 218
219 skia::RefPtr<SkPicture> picture = skia::AdoptRef(StopRecording(&recorder, canv as));
220
219 std::vector<skia::PixelRefUtils::PositionPixelRef> pixel_refs; 221 std::vector<skia::PixelRefUtils::PositionPixelRef> pixel_refs;
220 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture.get(), &pixel_refs); 222 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture.get(), &pixel_refs);
221 223
222 EXPECT_EQ(3u, pixel_refs.size()); 224 EXPECT_EQ(3u, pixel_refs.size());
223 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 20, 30, 40), 225 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 20, 30, 40),
224 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect)); 226 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect));
225 EXPECT_FLOAT_RECT_EQ(gfx::RectF(5, 50, 25, 35), 227 EXPECT_FLOAT_RECT_EQ(gfx::RectF(5, 50, 25, 35),
226 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect)); 228 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect));
227 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50), 229 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50),
228 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect)); 230 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect));
229 } 231 }
230 232
231 TEST(PixelRefUtilsTest, DrawRRect) { 233 TEST(PixelRefUtilsTest, DrawRRect) {
232 gfx::Rect layer_rect(0, 0, 256, 256); 234 gfx::Rect layer_rect(0, 0, 256, 256);
233 235
234 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture); 236 SkPictureRecorder recorder;
235 SkCanvas* canvas = StartRecording(picture.get(), layer_rect); 237 SkCanvas* canvas = StartRecording(&recorder, layer_rect);
236 238
237 TestDiscardableShader first_shader; 239 TestDiscardableShader first_shader;
238 SkPaint first_paint; 240 SkPaint first_paint;
239 first_paint.setShader(&first_shader); 241 first_paint.setShader(&first_shader);
240 242
241 TestDiscardableShader second_shader; 243 TestDiscardableShader second_shader;
242 SkPaint second_paint; 244 SkPaint second_paint;
243 second_paint.setShader(&second_shader); 245 second_paint.setShader(&second_shader);
244 246
245 TestDiscardableShader third_shader; 247 TestDiscardableShader third_shader;
(...skipping 14 matching lines...) Expand all
260 canvas->drawRRect(rrect, second_paint); 262 canvas->drawRRect(rrect, second_paint);
261 263
262 canvas->restore(); 264 canvas->restore();
263 265
264 canvas->clipRect(SkRect::MakeXYWH(50, 50, 50, 50)); 266 canvas->clipRect(SkRect::MakeXYWH(50, 50, 50, 50));
265 canvas->translate(20, 20); 267 canvas->translate(20, 20);
266 rrect.setRect(SkRect::MakeXYWH(0, 0, 100, 100)); 268 rrect.setRect(SkRect::MakeXYWH(0, 0, 100, 100));
267 // (50, 50, 50, 50) 269 // (50, 50, 50, 50)
268 canvas->drawRRect(rrect, third_paint); 270 canvas->drawRRect(rrect, third_paint);
269 271
272 skia::RefPtr<SkPicture> picture = skia::AdoptRef(StopRecording(&recorder, canv as));
273
270 std::vector<skia::PixelRefUtils::PositionPixelRef> pixel_refs; 274 std::vector<skia::PixelRefUtils::PositionPixelRef> pixel_refs;
271 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture.get(), &pixel_refs); 275 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture.get(), &pixel_refs);
272 276
273 EXPECT_EQ(3u, pixel_refs.size()); 277 EXPECT_EQ(3u, pixel_refs.size());
274 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 20, 30, 40), 278 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 20, 30, 40),
275 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect)); 279 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect));
276 EXPECT_FLOAT_RECT_EQ(gfx::RectF(5, 50, 25, 35), 280 EXPECT_FLOAT_RECT_EQ(gfx::RectF(5, 50, 25, 35),
277 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect)); 281 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect));
278 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50), 282 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50),
279 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect)); 283 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect));
280 } 284 }
281 285
282 TEST(PixelRefUtilsTest, DrawOval) { 286 TEST(PixelRefUtilsTest, DrawOval) {
283 gfx::Rect layer_rect(0, 0, 256, 256); 287 gfx::Rect layer_rect(0, 0, 256, 256);
284 288
285 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture); 289 SkPictureRecorder recorder;
286 SkCanvas* canvas = StartRecording(picture.get(), layer_rect); 290 SkCanvas* canvas = StartRecording(&recorder, layer_rect);
287 291
288 TestDiscardableShader first_shader; 292 TestDiscardableShader first_shader;
289 SkPaint first_paint; 293 SkPaint first_paint;
290 first_paint.setShader(&first_shader); 294 first_paint.setShader(&first_shader);
291 295
292 TestDiscardableShader second_shader; 296 TestDiscardableShader second_shader;
293 SkPaint second_paint; 297 SkPaint second_paint;
294 second_paint.setShader(&second_shader); 298 second_paint.setShader(&second_shader);
295 299
296 TestDiscardableShader third_shader; 300 TestDiscardableShader third_shader;
(...skipping 13 matching lines...) Expand all
310 // (1, 35, 25, 35) 314 // (1, 35, 25, 35)
311 canvas->drawRect(SkRect::MakeXYWH(0, 33, 25, 35), second_paint); 315 canvas->drawRect(SkRect::MakeXYWH(0, 33, 25, 35), second_paint);
312 316
313 canvas->restore(); 317 canvas->restore();
314 318
315 canvas->clipRect(SkRect::MakeXYWH(50, 50, 50, 50)); 319 canvas->clipRect(SkRect::MakeXYWH(50, 50, 50, 50));
316 canvas->translate(20, 20); 320 canvas->translate(20, 20);
317 // (50, 50, 50, 50) 321 // (50, 50, 50, 50)
318 canvas->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), third_paint); 322 canvas->drawRect(SkRect::MakeXYWH(0, 0, 100, 100), third_paint);
319 323
324 skia::RefPtr<SkPicture> picture = skia::AdoptRef(StopRecording(&recorder, canv as));
325
320 std::vector<skia::PixelRefUtils::PositionPixelRef> pixel_refs; 326 std::vector<skia::PixelRefUtils::PositionPixelRef> pixel_refs;
321 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture.get(), &pixel_refs); 327 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture.get(), &pixel_refs);
322 328
323 EXPECT_EQ(3u, pixel_refs.size()); 329 EXPECT_EQ(3u, pixel_refs.size());
324 EXPECT_FLOAT_RECT_EQ(gfx::RectF(20, 10, 60, 20), 330 EXPECT_FLOAT_RECT_EQ(gfx::RectF(20, 10, 60, 20),
325 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect)); 331 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect));
326 EXPECT_FLOAT_RECT_EQ(gfx::RectF(1, 35, 25, 35), 332 EXPECT_FLOAT_RECT_EQ(gfx::RectF(1, 35, 25, 35),
327 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect)); 333 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect));
328 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50), 334 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50),
329 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect)); 335 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect));
330 } 336 }
331 337
332 TEST(PixelRefUtilsTest, DrawPath) { 338 TEST(PixelRefUtilsTest, DrawPath) {
333 gfx::Rect layer_rect(0, 0, 256, 256); 339 gfx::Rect layer_rect(0, 0, 256, 256);
334 340
335 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture); 341 SkPictureRecorder recorder;
336 SkCanvas* canvas = StartRecording(picture.get(), layer_rect); 342 SkCanvas* canvas = StartRecording(&recorder, layer_rect);
337 343
338 TestDiscardableShader first_shader; 344 TestDiscardableShader first_shader;
339 SkPaint first_paint; 345 SkPaint first_paint;
340 first_paint.setShader(&first_shader); 346 first_paint.setShader(&first_shader);
341 347
342 TestDiscardableShader second_shader; 348 TestDiscardableShader second_shader;
343 SkPaint second_paint; 349 SkPaint second_paint;
344 second_paint.setShader(&second_shader); 350 second_paint.setShader(&second_shader);
345 351
346 SkPath path; 352 SkPath path;
347 path.moveTo(12, 13); 353 path.moveTo(12, 13);
348 path.lineTo(50, 50); 354 path.lineTo(50, 50);
349 path.lineTo(22, 101); 355 path.lineTo(22, 101);
350 356
351 // (12, 13, 38, 88). 357 // (12, 13, 38, 88).
352 canvas->drawPath(path, first_paint); 358 canvas->drawPath(path, first_paint);
353 359
354 canvas->save(); 360 canvas->save();
355 canvas->clipRect(SkRect::MakeWH(50, 50)); 361 canvas->clipRect(SkRect::MakeWH(50, 50));
356 362
357 // (12, 13, 38, 37). 363 // (12, 13, 38, 37).
358 canvas->drawPath(path, second_paint); 364 canvas->drawPath(path, second_paint);
359 365
360 canvas->restore(); 366 canvas->restore();
361 367
362 StopRecording(picture.get(), canvas); 368 skia::RefPtr<SkPicture> picture = skia::AdoptRef(StopRecording(&recorder, canv as));
363 369
364 std::vector<skia::PixelRefUtils::PositionPixelRef> pixel_refs; 370 std::vector<skia::PixelRefUtils::PositionPixelRef> pixel_refs;
365 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture.get(), &pixel_refs); 371 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture.get(), &pixel_refs);
366 372
367 EXPECT_EQ(2u, pixel_refs.size()); 373 EXPECT_EQ(2u, pixel_refs.size());
368 EXPECT_FLOAT_RECT_EQ(gfx::RectF(12, 13, 38, 88), 374 EXPECT_FLOAT_RECT_EQ(gfx::RectF(12, 13, 38, 88),
369 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect)); 375 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect));
370 EXPECT_FLOAT_RECT_EQ(gfx::RectF(12, 13, 38, 37), 376 EXPECT_FLOAT_RECT_EQ(gfx::RectF(12, 13, 38, 37),
371 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect)); 377 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect));
372 } 378 }
373 379
374 TEST(PixelRefUtilsTest, DrawBitmap) { 380 TEST(PixelRefUtilsTest, DrawBitmap) {
375 gfx::Rect layer_rect(0, 0, 256, 256); 381 gfx::Rect layer_rect(0, 0, 256, 256);
376 382
377 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture); 383 SkPictureRecorder recorder;
378 SkCanvas* canvas = StartRecording(picture.get(), layer_rect); 384 SkCanvas* canvas = StartRecording(&recorder, layer_rect);
379 385
380 SkBitmap first; 386 SkBitmap first;
381 CreateBitmap(gfx::Size(50, 50), "discardable", &first); 387 CreateBitmap(gfx::Size(50, 50), "discardable", &first);
382 SkBitmap second; 388 SkBitmap second;
383 CreateBitmap(gfx::Size(50, 50), "discardable", &second); 389 CreateBitmap(gfx::Size(50, 50), "discardable", &second);
384 SkBitmap third; 390 SkBitmap third;
385 CreateBitmap(gfx::Size(50, 50), "discardable", &third); 391 CreateBitmap(gfx::Size(50, 50), "discardable", &third);
386 SkBitmap fourth; 392 SkBitmap fourth;
387 CreateBitmap(gfx::Size(50, 1), "discardable", &fourth); 393 CreateBitmap(gfx::Size(50, 1), "discardable", &fourth);
388 SkBitmap fifth; 394 SkBitmap fifth;
(...skipping 17 matching lines...) Expand all
406 canvas->rotate(90); 412 canvas->rotate(90);
407 // At (1, 0), rotated 90 degrees 413 // At (1, 0), rotated 90 degrees
408 canvas->drawBitmap(fourth, 0, 0); 414 canvas->drawBitmap(fourth, 0, 0);
409 415
410 canvas->restore(); 416 canvas->restore();
411 417
412 canvas->scale(5, 6); 418 canvas->scale(5, 6);
413 // At (0, 0), scaled by 5 and 6 419 // At (0, 0), scaled by 5 and 6
414 canvas->drawBitmap(fifth, 0, 0); 420 canvas->drawBitmap(fifth, 0, 0);
415 421
416 StopRecording(picture.get(), canvas); 422 skia::RefPtr<SkPicture> picture = skia::AdoptRef(StopRecording(&recorder, canv as));
417 423
418 std::vector<skia::PixelRefUtils::PositionPixelRef> pixel_refs; 424 std::vector<skia::PixelRefUtils::PositionPixelRef> pixel_refs;
419 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture.get(), &pixel_refs); 425 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture.get(), &pixel_refs);
420 426
421 EXPECT_EQ(5u, pixel_refs.size()); 427 EXPECT_EQ(5u, pixel_refs.size());
422 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 50), 428 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 50),
423 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect)); 429 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect));
424 EXPECT_FLOAT_RECT_EQ(gfx::RectF(25, 0, 50, 50), 430 EXPECT_FLOAT_RECT_EQ(gfx::RectF(25, 0, 50, 50),
425 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect)); 431 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect));
426 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50), 432 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 50, 50, 50),
427 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect)); 433 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect));
428 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 1, 50), 434 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 1, 50),
429 gfx::SkRectToRectF(pixel_refs[3].pixel_ref_rect)); 435 gfx::SkRectToRectF(pixel_refs[3].pixel_ref_rect));
430 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 60), 436 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 60),
431 gfx::SkRectToRectF(pixel_refs[4].pixel_ref_rect)); 437 gfx::SkRectToRectF(pixel_refs[4].pixel_ref_rect));
432 438
433 } 439 }
434 440
435 TEST(PixelRefUtilsTest, DrawBitmapRect) { 441 TEST(PixelRefUtilsTest, DrawBitmapRect) {
436 gfx::Rect layer_rect(0, 0, 256, 256); 442 gfx::Rect layer_rect(0, 0, 256, 256);
437 443
438 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture); 444 SkPictureRecorder recorder;
439 SkCanvas* canvas = StartRecording(picture.get(), layer_rect); 445 SkCanvas* canvas = StartRecording(&recorder, layer_rect);
440 446
441 SkBitmap first; 447 SkBitmap first;
442 CreateBitmap(gfx::Size(50, 50), "discardable", &first); 448 CreateBitmap(gfx::Size(50, 50), "discardable", &first);
443 SkBitmap second; 449 SkBitmap second;
444 CreateBitmap(gfx::Size(50, 50), "discardable", &second); 450 CreateBitmap(gfx::Size(50, 50), "discardable", &second);
445 SkBitmap third; 451 SkBitmap third;
446 CreateBitmap(gfx::Size(50, 50), "discardable", &third); 452 CreateBitmap(gfx::Size(50, 50), "discardable", &third);
447 453
448 TestDiscardableShader first_shader; 454 TestDiscardableShader first_shader;
449 SkPaint first_paint; 455 SkPaint first_paint;
(...skipping 10 matching lines...) Expand all
460 // (75, 50, 10, 10). 466 // (75, 50, 10, 10).
461 canvas->drawBitmapRect( 467 canvas->drawBitmapRect(
462 second, SkRect::MakeXYWH(50, 50, 10, 10), &non_discardable_paint); 468 second, SkRect::MakeXYWH(50, 50, 10, 10), &non_discardable_paint);
463 canvas->translate(5, 50); 469 canvas->translate(5, 50);
464 // (0, 30, 100, 100). One from bitmap, one from paint. 470 // (0, 30, 100, 100). One from bitmap, one from paint.
465 canvas->drawBitmapRect( 471 canvas->drawBitmapRect(
466 third, SkRect::MakeXYWH(-30, -20, 100, 100), &first_paint); 472 third, SkRect::MakeXYWH(-30, -20, 100, 100), &first_paint);
467 473
468 canvas->restore(); 474 canvas->restore();
469 475
470 StopRecording(picture.get(), canvas); 476 skia::RefPtr<SkPicture> picture = skia::AdoptRef(StopRecording(&recorder, canv as));
471 477
472 std::vector<skia::PixelRefUtils::PositionPixelRef> pixel_refs; 478 std::vector<skia::PixelRefUtils::PositionPixelRef> pixel_refs;
473 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture.get(), &pixel_refs); 479 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture.get(), &pixel_refs);
474 480
475 EXPECT_EQ(4u, pixel_refs.size()); 481 EXPECT_EQ(4u, pixel_refs.size());
476 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 100, 100), 482 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 100, 100),
477 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect)); 483 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect));
478 EXPECT_FLOAT_RECT_EQ(gfx::RectF(75, 50, 10, 10), 484 EXPECT_FLOAT_RECT_EQ(gfx::RectF(75, 50, 10, 10),
479 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect)); 485 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect));
480 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 30, 100, 100), 486 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 30, 100, 100),
481 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect)); 487 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect));
482 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 30, 100, 100), 488 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 30, 100, 100),
483 gfx::SkRectToRectF(pixel_refs[3].pixel_ref_rect)); 489 gfx::SkRectToRectF(pixel_refs[3].pixel_ref_rect));
484 } 490 }
485 491
486 TEST(PixelRefUtilsTest, DrawSprite) { 492 TEST(PixelRefUtilsTest, DrawSprite) {
487 gfx::Rect layer_rect(0, 0, 256, 256); 493 gfx::Rect layer_rect(0, 0, 256, 256);
488 494
489 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture); 495 SkPictureRecorder recorder;
490 SkCanvas* canvas = StartRecording(picture.get(), layer_rect); 496 SkCanvas* canvas = StartRecording(&recorder, layer_rect);
491 497
492 SkBitmap first; 498 SkBitmap first;
493 CreateBitmap(gfx::Size(50, 50), "discardable", &first); 499 CreateBitmap(gfx::Size(50, 50), "discardable", &first);
494 SkBitmap second; 500 SkBitmap second;
495 CreateBitmap(gfx::Size(50, 50), "discardable", &second); 501 CreateBitmap(gfx::Size(50, 50), "discardable", &second);
496 SkBitmap third; 502 SkBitmap third;
497 CreateBitmap(gfx::Size(50, 50), "discardable", &third); 503 CreateBitmap(gfx::Size(50, 50), "discardable", &third);
498 SkBitmap fourth; 504 SkBitmap fourth;
499 CreateBitmap(gfx::Size(50, 50), "discardable", &fourth); 505 CreateBitmap(gfx::Size(50, 50), "discardable", &fourth);
500 SkBitmap fifth; 506 SkBitmap fifth;
(...skipping 22 matching lines...) Expand all
523 canvas->restore(); 529 canvas->restore();
524 530
525 TestDiscardableShader first_shader; 531 TestDiscardableShader first_shader;
526 SkPaint first_paint; 532 SkPaint first_paint;
527 first_paint.setShader(&first_shader); 533 first_paint.setShader(&first_shader);
528 534
529 canvas->scale(5, 6); 535 canvas->scale(5, 6);
530 // (100, 100, 50, 50). 536 // (100, 100, 50, 50).
531 canvas->drawSprite(fifth, 100, 100, &first_paint); 537 canvas->drawSprite(fifth, 100, 100, &first_paint);
532 538
533 StopRecording(picture.get(), canvas); 539 skia::RefPtr<SkPicture> picture = skia::AdoptRef(StopRecording(&recorder, canv as));
534 540
535 std::vector<skia::PixelRefUtils::PositionPixelRef> pixel_refs; 541 std::vector<skia::PixelRefUtils::PositionPixelRef> pixel_refs;
536 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture.get(), &pixel_refs); 542 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture.get(), &pixel_refs);
537 543
538 EXPECT_EQ(6u, pixel_refs.size()); 544 EXPECT_EQ(6u, pixel_refs.size());
539 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 50), 545 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 50),
540 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect)); 546 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect));
541 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 0, 50, 50), 547 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 0, 50, 50),
542 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect)); 548 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect));
543 EXPECT_FLOAT_RECT_EQ(gfx::RectF(25, 0, 50, 50), 549 EXPECT_FLOAT_RECT_EQ(gfx::RectF(25, 0, 50, 50),
544 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect)); 550 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect));
545 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 50), 551 EXPECT_FLOAT_RECT_EQ(gfx::RectF(0, 0, 50, 50),
546 gfx::SkRectToRectF(pixel_refs[3].pixel_ref_rect)); 552 gfx::SkRectToRectF(pixel_refs[3].pixel_ref_rect));
547 EXPECT_FLOAT_RECT_EQ(gfx::RectF(100, 100, 50, 50), 553 EXPECT_FLOAT_RECT_EQ(gfx::RectF(100, 100, 50, 50),
548 gfx::SkRectToRectF(pixel_refs[4].pixel_ref_rect)); 554 gfx::SkRectToRectF(pixel_refs[4].pixel_ref_rect));
549 EXPECT_FLOAT_RECT_EQ(gfx::RectF(100, 100, 50, 50), 555 EXPECT_FLOAT_RECT_EQ(gfx::RectF(100, 100, 50, 50),
550 gfx::SkRectToRectF(pixel_refs[5].pixel_ref_rect)); 556 gfx::SkRectToRectF(pixel_refs[5].pixel_ref_rect));
551 } 557 }
552 558
553 TEST(PixelRefUtilsTest, DrawText) { 559 TEST(PixelRefUtilsTest, DrawText) {
554 gfx::Rect layer_rect(0, 0, 256, 256); 560 gfx::Rect layer_rect(0, 0, 256, 256);
555 561
556 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture); 562 SkPictureRecorder recorder;
557 SkCanvas* canvas = StartRecording(picture.get(), layer_rect); 563 SkCanvas* canvas = StartRecording(&recorder, layer_rect);
558 564
559 TestDiscardableShader first_shader; 565 TestDiscardableShader first_shader;
560 SkPaint first_paint; 566 SkPaint first_paint;
561 first_paint.setShader(&first_shader); 567 first_paint.setShader(&first_shader);
562 568
563 SkPoint points[4]; 569 SkPoint points[4];
564 points[0].set(10, 50); 570 points[0].set(10, 50);
565 points[1].set(20, 50); 571 points[1].set(20, 50);
566 points[2].set(30, 50); 572 points[2].set(30, 50);
567 points[3].set(40, 50); 573 points[3].set(40, 50);
568 574
569 SkPath path; 575 SkPath path;
570 path.moveTo(10, 50); 576 path.moveTo(10, 50);
571 path.lineTo(20, 50); 577 path.lineTo(20, 50);
572 path.lineTo(30, 50); 578 path.lineTo(30, 50);
573 path.lineTo(40, 50); 579 path.lineTo(40, 50);
574 path.lineTo(50, 50); 580 path.lineTo(50, 50);
575 581
576 canvas->drawText("text", 4, 50, 50, first_paint); 582 canvas->drawText("text", 4, 50, 50, first_paint);
577 canvas->drawPosText("text", 4, points, first_paint); 583 canvas->drawPosText("text", 4, points, first_paint);
578 canvas->drawTextOnPath("text", 4, path, NULL, first_paint); 584 canvas->drawTextOnPath("text", 4, path, NULL, first_paint);
579 585
586 skia::RefPtr<SkPicture> picture = skia::AdoptRef(StopRecording(&recorder, canv as));
587
580 std::vector<skia::PixelRefUtils::PositionPixelRef> pixel_refs; 588 std::vector<skia::PixelRefUtils::PositionPixelRef> pixel_refs;
581 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture.get(), &pixel_refs); 589 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture.get(), &pixel_refs);
582 590
583 EXPECT_EQ(3u, pixel_refs.size()); 591 EXPECT_EQ(3u, pixel_refs.size());
584 } 592 }
585 593
586 TEST(PixelRefUtilsTest, DrawVertices) { 594 TEST(PixelRefUtilsTest, DrawVertices) {
587 gfx::Rect layer_rect(0, 0, 256, 256); 595 gfx::Rect layer_rect(0, 0, 256, 256);
588 596
589 skia::RefPtr<SkPicture> picture = skia::AdoptRef(new SkPicture); 597 SkPictureRecorder recorder;
590 SkCanvas* canvas = StartRecording(picture.get(), layer_rect); 598 SkCanvas* canvas = StartRecording(&recorder, layer_rect);
591 599
592 TestDiscardableShader first_shader; 600 TestDiscardableShader first_shader;
593 SkPaint first_paint; 601 SkPaint first_paint;
594 first_paint.setShader(&first_shader); 602 first_paint.setShader(&first_shader);
595 603
596 TestDiscardableShader second_shader; 604 TestDiscardableShader second_shader;
597 SkPaint second_paint; 605 SkPaint second_paint;
598 second_paint.setShader(&second_shader); 606 second_paint.setShader(&second_shader);
599 607
600 TestDiscardableShader third_shader; 608 TestDiscardableShader third_shader;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 canvas->drawVertices(SkCanvas::kTriangles_VertexMode, 649 canvas->drawVertices(SkCanvas::kTriangles_VertexMode,
642 3, 650 3,
643 points, 651 points,
644 points, 652 points,
645 colors, 653 colors,
646 NULL, 654 NULL,
647 indecies, 655 indecies,
648 3, 656 3,
649 third_paint); 657 third_paint);
650 658
651 StopRecording(picture.get(), canvas); 659 skia::RefPtr<SkPicture> picture = skia::AdoptRef(StopRecording(&recorder, canv as));
652 660
653 std::vector<skia::PixelRefUtils::PositionPixelRef> pixel_refs; 661 std::vector<skia::PixelRefUtils::PositionPixelRef> pixel_refs;
654 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture.get(), &pixel_refs); 662 skia::PixelRefUtils::GatherDiscardablePixelRefs(picture.get(), &pixel_refs);
655 663
656 EXPECT_EQ(3u, pixel_refs.size()); 664 EXPECT_EQ(3u, pixel_refs.size());
657 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 90, 90), 665 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 90, 90),
658 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect)); 666 gfx::SkRectToRectF(pixel_refs[0].pixel_ref_rect));
659 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 40, 40), 667 EXPECT_FLOAT_RECT_EQ(gfx::RectF(10, 10, 40, 40),
660 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect)); 668 gfx::SkRectToRectF(pixel_refs[1].pixel_ref_rect));
661 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 55, 150, 145), 669 EXPECT_FLOAT_RECT_EQ(gfx::RectF(50, 55, 150, 145),
662 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect)); 670 gfx::SkRectToRectF(pixel_refs[2].pixel_ref_rect));
663 } 671 }
664 672
665 } // namespace skia 673 } // namespace skia
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698