OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "gm.h" | 8 #include "gm.h" |
9 | 9 |
10 #include "SkColorFilter.h" | 10 #include "SkColorFilter.h" |
(...skipping 23 matching lines...) Expand all Loading... |
34 hex.rLineTo(SkScalarHalf(kHexSide), -kHexSide * kRoot3Over2); | 34 hex.rLineTo(SkScalarHalf(kHexSide), -kHexSide * kRoot3Over2); |
35 hex.rLineTo(-SkScalarHalf(kHexSide), -kHexSide * kRoot3Over2); | 35 hex.rLineTo(-SkScalarHalf(kHexSide), -kHexSide * kRoot3Over2); |
36 hex.rLineTo(-SkIntToScalar(kHexSide), 0); | 36 hex.rLineTo(-SkIntToScalar(kHexSide), 0); |
37 hex.close(); | 37 hex.close(); |
38 return hex; | 38 return hex; |
39 } | 39 } |
40 | 40 |
41 // Make a picture that is a tiling of the plane with stroked hexagons where | 41 // Make a picture that is a tiling of the plane with stroked hexagons where |
42 // each hexagon is in its own layer. The layers are to exercise Ganesh's | 42 // each hexagon is in its own layer. The layers are to exercise Ganesh's |
43 // layer hoisting. | 43 // layer hoisting. |
44 static const SkPicture* make_hex_plane_picture(SkColor fillColor) { | 44 static sk_sp<SkPicture> make_hex_plane_picture(SkColor fillColor) { |
45 | 45 |
46 // Create a hexagon with its center at the origin | 46 // Create a hexagon with its center at the origin |
47 SkPath hex = make_hex_path(0, 0); | 47 SkPath hex = make_hex_path(0, 0); |
48 | 48 |
49 SkPaint fill; | 49 SkPaint fill; |
50 fill.setStyle(SkPaint::kFill_Style); | 50 fill.setStyle(SkPaint::kFill_Style); |
51 fill.setColor(fillColor); | 51 fill.setColor(fillColor); |
52 | 52 |
53 SkPaint stroke; | 53 SkPaint stroke; |
54 stroke.setStyle(SkPaint::kStroke_Style); | 54 stroke.setStyle(SkPaint::kStroke_Style); |
(...skipping 18 matching lines...) Expand all Loading... |
73 canvas->drawPath(hex, fill); | 73 canvas->drawPath(hex, fill); |
74 canvas->drawPath(hex, stroke); | 74 canvas->drawPath(hex, stroke); |
75 canvas->restore(); | 75 canvas->restore(); |
76 | 76 |
77 xPos += 1.5f * kHexSide; | 77 xPos += 1.5f * kHexSide; |
78 } | 78 } |
79 | 79 |
80 yPos += 2 * kHexSide * kRoot3Over2; | 80 yPos += 2 * kHexSide * kRoot3Over2; |
81 } | 81 } |
82 | 82 |
83 return recorder.endRecording(); | 83 return recorder.finishRecordingAsPicture(); |
84 } | 84 } |
85 | 85 |
86 // Create a picture that consists of a single large layer that is tiled | 86 // Create a picture that consists of a single large layer that is tiled |
87 // with hexagons. | 87 // with hexagons. |
88 // This is intended to exercise the layer hoisting code's clip handling (in | 88 // This is intended to exercise the layer hoisting code's clip handling (in |
89 // tile mode). | 89 // tile mode). |
90 static const SkPicture* make_single_layer_hex_plane_picture() { | 90 static sk_sp<SkPicture> make_single_layer_hex_plane_picture() { |
91 | 91 |
92 // Create a hexagon with its center at the origin | 92 // Create a hexagon with its center at the origin |
93 SkPath hex = make_hex_path(0, 0); | 93 SkPath hex = make_hex_path(0, 0); |
94 | 94 |
95 SkPaint whiteFill; | 95 SkPaint whiteFill; |
96 whiteFill.setStyle(SkPaint::kFill_Style); | 96 whiteFill.setStyle(SkPaint::kFill_Style); |
97 whiteFill.setColor(SK_ColorWHITE); | 97 whiteFill.setColor(SK_ColorWHITE); |
98 | 98 |
99 SkPaint greyFill; | 99 SkPaint greyFill; |
100 greyFill.setStyle(SkPaint::kFill_Style); | 100 greyFill.setStyle(SkPaint::kFill_Style); |
(...skipping 28 matching lines...) Expand all Loading... |
129 canvas->restore(); | 129 canvas->restore(); |
130 | 130 |
131 xPos += 1.5f * kHexSide; | 131 xPos += 1.5f * kHexSide; |
132 } | 132 } |
133 | 133 |
134 yPos += 2 * kHexSide * kRoot3Over2; | 134 yPos += 2 * kHexSide * kRoot3Over2; |
135 } | 135 } |
136 | 136 |
137 canvas->restore(); | 137 canvas->restore(); |
138 | 138 |
139 return recorder.endRecording(); | 139 return recorder.finishRecordingAsPicture(); |
140 } | 140 } |
141 | 141 |
142 // Make an equilateral triangle path with its top corner at (originX, originY) | 142 // Make an equilateral triangle path with its top corner at (originX, originY) |
143 static SkPath make_tri_path(SkScalar originX, SkScalar originY) { | 143 static SkPath make_tri_path(SkScalar originX, SkScalar originY) { |
144 SkPath tri; | 144 SkPath tri; |
145 tri.moveTo(originX, originY); | 145 tri.moveTo(originX, originY); |
146 tri.rLineTo(SkScalarHalf(kTriSide), 1.5f * kTriSide / kRoot3); | 146 tri.rLineTo(SkScalarHalf(kTriSide), 1.5f * kTriSide / kRoot3); |
147 tri.rLineTo(-kTriSide, 0); | 147 tri.rLineTo(-kTriSide, 0); |
148 tri.close(); | 148 tri.close(); |
149 return tri; | 149 return tri; |
150 } | 150 } |
151 | 151 |
152 static const SkPicture* make_tri_picture() { | 152 static sk_sp<SkPicture> make_tri_picture() { |
153 SkPath tri = make_tri_path(SkScalarHalf(kTriSide), 0); | 153 SkPath tri = make_tri_path(SkScalarHalf(kTriSide), 0); |
154 | 154 |
155 SkPaint fill; | 155 SkPaint fill; |
156 fill.setStyle(SkPaint::kFill_Style); | 156 fill.setStyle(SkPaint::kFill_Style); |
157 fill.setColor(sk_tool_utils::color_to_565(SK_ColorLTGRAY)); | 157 fill.setColor(sk_tool_utils::color_to_565(SK_ColorLTGRAY)); |
158 | 158 |
159 SkPaint stroke; | 159 SkPaint stroke; |
160 stroke.setStyle(SkPaint::kStroke_Style); | 160 stroke.setStyle(SkPaint::kStroke_Style); |
161 stroke.setStrokeWidth(3); | 161 stroke.setStrokeWidth(3); |
162 | 162 |
163 SkPictureRecorder recorder; | 163 SkPictureRecorder recorder; |
164 SkRTreeFactory bbhFactory; | 164 SkRTreeFactory bbhFactory; |
165 | 165 |
166 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth), | 166 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth), |
167 SkIntToScalar(kPicHeight), | 167 SkIntToScalar(kPicHeight), |
168 &bbhFactory, | 168 &bbhFactory, |
169 SkPictureRecorder::kComputeSaveLa
yerInfo_RecordFlag); | 169 SkPictureRecorder::kComputeSaveLa
yerInfo_RecordFlag); |
170 SkRect r = tri.getBounds(); | 170 SkRect r = tri.getBounds(); |
171 r.outset(2.0f, 2.0f); // outset for stroke | 171 r.outset(2.0f, 2.0f); // outset for stroke |
172 canvas->clipRect(r); | 172 canvas->clipRect(r); |
173 // The saveLayer/restore block is to exercise layer hoisting | 173 // The saveLayer/restore block is to exercise layer hoisting |
174 canvas->saveLayer(nullptr, nullptr); | 174 canvas->saveLayer(nullptr, nullptr); |
175 canvas->drawPath(tri, fill); | 175 canvas->drawPath(tri, fill); |
176 canvas->drawPath(tri, stroke); | 176 canvas->drawPath(tri, stroke); |
177 canvas->restore(); | 177 canvas->restore(); |
178 | 178 |
179 return recorder.endRecording(); | 179 return recorder.finishRecordingAsPicture(); |
180 } | 180 } |
181 | 181 |
182 static const SkPicture* make_sub_picture(const SkPicture* tri) { | 182 static sk_sp<SkPicture> make_sub_picture(const SkPicture* tri) { |
183 SkPictureRecorder recorder; | 183 SkPictureRecorder recorder; |
184 SkRTreeFactory bbhFactory; | 184 SkRTreeFactory bbhFactory; |
185 | 185 |
186 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth), | 186 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth), |
187 SkIntToScalar(kPicHeight), | 187 SkIntToScalar(kPicHeight), |
188 &bbhFactory, | 188 &bbhFactory, |
189 SkPictureRecorder::kComputeSaveLa
yerInfo_RecordFlag); | 189 SkPictureRecorder::kComputeSaveLa
yerInfo_RecordFlag); |
190 | 190 |
191 canvas->scale(1.0f/2.0f, 1.0f/2.0f); | 191 canvas->scale(1.0f/2.0f, 1.0f/2.0f); |
192 | 192 |
193 canvas->save(); | 193 canvas->save(); |
194 canvas->translate(SkScalarHalf(kTriSide), 0); | 194 canvas->translate(SkScalarHalf(kTriSide), 0); |
195 canvas->drawPicture(tri); | 195 canvas->drawPicture(tri); |
196 canvas->restore(); | 196 canvas->restore(); |
197 | 197 |
198 canvas->save(); | 198 canvas->save(); |
199 canvas->translate(SkIntToScalar(kTriSide), 1.5f * kTriSide / kRoot3); | 199 canvas->translate(SkIntToScalar(kTriSide), 1.5f * kTriSide / kRoot3); |
200 canvas->drawPicture(tri); | 200 canvas->drawPicture(tri); |
201 canvas->restore(); | 201 canvas->restore(); |
202 | 202 |
203 canvas->save(); | 203 canvas->save(); |
204 canvas->translate(0, 1.5f * kTriSide / kRoot3); | 204 canvas->translate(0, 1.5f * kTriSide / kRoot3); |
205 canvas->drawPicture(tri); | 205 canvas->drawPicture(tri); |
206 canvas->restore(); | 206 canvas->restore(); |
207 | 207 |
208 return recorder.endRecording(); | 208 return recorder.finishRecordingAsPicture(); |
209 } | 209 } |
210 | 210 |
211 // Create a Sierpinkski-like picture that starts with a top row with a picture | 211 // Create a Sierpinkski-like picture that starts with a top row with a picture |
212 // that just contains a triangle. Subsequent rows take the prior row's picture, | 212 // that just contains a triangle. Subsequent rows take the prior row's picture, |
213 // shrinks it and replicates it 3 times then draws and appropriate number of | 213 // shrinks it and replicates it 3 times then draws and appropriate number of |
214 // copies of it. | 214 // copies of it. |
215 static const SkPicture* make_sierpinski_picture() { | 215 static sk_sp<SkPicture> make_sierpinski_picture() { |
216 SkAutoTUnref<const SkPicture> pic(make_tri_picture()); | 216 sk_sp<SkPicture> pic(make_tri_picture()); |
217 | 217 |
218 SkPictureRecorder recorder; | 218 SkPictureRecorder recorder; |
219 SkRTreeFactory bbhFactory; | 219 SkRTreeFactory bbhFactory; |
220 | 220 |
221 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth), | 221 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth), |
222 SkIntToScalar(kPicHeight), | 222 SkIntToScalar(kPicHeight), |
223 &bbhFactory, | 223 &bbhFactory, |
224 SkPictureRecorder::kComputeSaveLa
yerInfo_RecordFlag); | 224 SkPictureRecorder::kComputeSaveLa
yerInfo_RecordFlag); |
225 | 225 |
226 static const int kNumLevels = 4; | 226 static const int kNumLevels = 4; |
227 for (int i = 0; i < kNumLevels; ++i) { | 227 for (int i = 0; i < kNumLevels; ++i) { |
228 canvas->save(); | 228 canvas->save(); |
229 canvas->translate(kPicWidth/2 - (i+1) * (kTriSide/2.0f), 0.0f); | 229 canvas->translate(kPicWidth/2 - (i+1) * (kTriSide/2.0f), 0.0f); |
230 for (int j = 0; j < i+1; ++j) { | 230 for (int j = 0; j < i+1; ++j) { |
231 canvas->drawPicture(pic); | 231 canvas->drawPicture(pic); |
232 canvas->translate(SkIntToScalar(kTriSide), 0); | 232 canvas->translate(SkIntToScalar(kTriSide), 0); |
233 } | 233 } |
234 canvas->restore(); | 234 canvas->restore(); |
235 | 235 |
236 pic.reset(make_sub_picture(pic)); | 236 pic = make_sub_picture(pic.get()); |
237 | 237 |
238 canvas->translate(0, 1.5f * kTriSide / kRoot3); | 238 canvas->translate(0, 1.5f * kTriSide / kRoot3); |
239 } | 239 } |
240 | 240 |
241 return recorder.endRecording(); | 241 return recorder.finishRecordingAsPicture(); |
242 } | 242 } |
243 | 243 |
244 static SkSurface* create_compat_surface(SkCanvas* canvas, int width, int height)
{ | 244 static SkSurface* create_compat_surface(SkCanvas* canvas, int width, int height)
{ |
245 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 245 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
246 | 246 |
247 SkSurface* surface = canvas->newSurface(info); | 247 SkSurface* surface = canvas->newSurface(info); |
248 if (nullptr == surface) { | 248 if (nullptr == surface) { |
249 // picture canvas returns nullptr so fall back to raster | 249 // picture canvas returns nullptr so fall back to raster |
250 surface = SkSurface::NewRaster(info); | 250 surface = SkSurface::NewRaster(info); |
251 } | 251 } |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 rrect_clip, | 349 rrect_clip, |
350 path_clip, | 350 path_clip, |
351 invpath_clip, | 351 invpath_clip, |
352 sierpinski, | 352 sierpinski, |
353 big_layer, | 353 big_layer, |
354 }; | 354 }; |
355 | 355 |
356 static void create_content(SkMultiPictureDraw* mpd, PFContentMtd pfGen, | 356 static void create_content(SkMultiPictureDraw* mpd, PFContentMtd pfGen, |
357 const SkPicture* pictures[kNumPictures], | 357 const SkPicture* pictures[kNumPictures], |
358 SkCanvas* dest, const SkMatrix& xform) { | 358 SkCanvas* dest, const SkMatrix& xform) { |
359 SkAutoTUnref<SkPicture> composite; | 359 sk_sp<SkPicture> composite; |
360 | 360 |
361 { | 361 { |
362 SkPictureRecorder recorder; | 362 SkPictureRecorder recorder; |
363 SkRTreeFactory bbhFactory; | 363 SkRTreeFactory bbhFactory; |
364 | 364 |
365 SkCanvas* pictureCanvas = recorder.beginRecording(SkIntToScalar(kPicWidt
h), | 365 SkCanvas* pictureCanvas = recorder.beginRecording(SkIntToScalar(kPicWidt
h), |
366 SkIntToScalar(kPicHeig
ht), | 366 SkIntToScalar(kPicHeig
ht), |
367 &bbhFactory, | 367 &bbhFactory, |
368 SkPictureRecorder::kCo
mputeSaveLayerInfo_RecordFlag); | 368 SkPictureRecorder::kCo
mputeSaveLayerInfo_RecordFlag); |
369 | 369 |
370 (*pfGen)(pictureCanvas, pictures); | 370 (*pfGen)(pictureCanvas, pictures); |
371 | 371 |
372 composite.reset(recorder.endRecording()); | 372 composite = recorder.finishRecordingAsPicture(); |
373 } | 373 } |
374 | 374 |
375 mpd->add(dest, composite, &xform); | 375 mpd->add(dest, composite.get(), &xform); |
376 } | 376 } |
377 | 377 |
378 typedef void(*PFLayoutMtd)(SkCanvas* finalCanvas, SkMultiPictureDraw* mpd, | 378 typedef void(*PFLayoutMtd)(SkCanvas* finalCanvas, SkMultiPictureDraw* mpd, |
379 PFContentMtd pfGen, const SkPicture* pictures[kNumPic
tures], | 379 PFContentMtd pfGen, const SkPicture* pictures[kNumPic
tures], |
380 SkTArray<ComposeStep>* composeSteps); | 380 SkTArray<ComposeStep>* composeSteps); |
381 | 381 |
382 // Draw the content into a single canvas | 382 // Draw the content into a single canvas |
383 static void simple(SkCanvas* finalCanvas, SkMultiPictureDraw* mpd, | 383 static void simple(SkCanvas* finalCanvas, SkMultiPictureDraw* mpd, |
384 PFContentMtd pfGen, | 384 PFContentMtd pfGen, |
385 const SkPicture* pictures[kNumPictures], | 385 const SkPicture* pictures[kNumPictures], |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 SkSafeUnref(fPictures[i]); | 483 SkSafeUnref(fPictures[i]); |
484 } | 484 } |
485 } | 485 } |
486 | 486 |
487 protected: | 487 protected: |
488 Content fContent; | 488 Content fContent; |
489 Layout fLayout; | 489 Layout fLayout; |
490 const SkPicture* fPictures[kNumPictures]; | 490 const SkPicture* fPictures[kNumPictures]; |
491 | 491 |
492 void onOnceBeforeDraw() override { | 492 void onOnceBeforeDraw() override { |
493 fPictures[0] = make_hex_plane_picture(SK_ColorWHITE); | 493 fPictures[0] = make_hex_plane_picture(SK_ColorWHITE).release(); |
494 fPictures[1] = make_hex_plane_picture(sk_tool_utils::color_to_565(SK
_ColorGRAY)); | 494 fPictures[1] = make_hex_plane_picture(sk_tool_utils::color_to_565(SK
_ColorGRAY)).release(); |
495 fPictures[2] = make_sierpinski_picture(); | 495 fPictures[2] = make_sierpinski_picture().release(); |
496 fPictures[3] = make_single_layer_hex_plane_picture(); | 496 fPictures[3] = make_single_layer_hex_plane_picture().release(); |
497 } | 497 } |
498 | 498 |
499 void onDraw(SkCanvas* canvas) override { | 499 void onDraw(SkCanvas* canvas) override { |
500 SkMultiPictureDraw mpd; | 500 SkMultiPictureDraw mpd; |
501 SkTArray<ComposeStep> composeSteps; | 501 SkTArray<ComposeStep> composeSteps; |
502 | 502 |
503 // Fill up the MultiPictureDraw | 503 // Fill up the MultiPictureDraw |
504 (*gLayoutMthds[fLayout])(canvas, &mpd, | 504 (*gLayoutMthds[fLayout])(canvas, &mpd, |
505 gContentMthds[fContent], | 505 gContentMthds[fContent], |
506 fPictures, &composeSteps); | 506 fPictures, &composeSteps); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 MultiPictureDraw::kTiled_Layout);) | 565 MultiPictureDraw::kTiled_Layout);) |
566 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kPathClipMulti_Content, | 566 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kPathClipMulti_Content, |
567 MultiPictureDraw::kTiled_Layout);) | 567 MultiPictureDraw::kTiled_Layout);) |
568 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kInvPathClipMulti_Conte
nt, | 568 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kInvPathClipMulti_Conte
nt, |
569 MultiPictureDraw::kTiled_Layout);) | 569 MultiPictureDraw::kTiled_Layout);) |
570 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kSierpinski_Content, | 570 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kSierpinski_Content, |
571 MultiPictureDraw::kTiled_Layout);) | 571 MultiPictureDraw::kTiled_Layout);) |
572 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kBigLayer_Content, | 572 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kBigLayer_Content, |
573 MultiPictureDraw::kTiled_Layout);) | 573 MultiPictureDraw::kTiled_Layout);) |
574 } | 574 } |
OLD | NEW |