| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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); |
| 55 stroke.setStrokeWidth(3); | 55 stroke.setStrokeWidth(3); |
| 56 | 56 |
| 57 SkPictureRecorder recorder; | 57 SkPictureRecorder recorder; |
| 58 SkRTreeFactory bbhFactory; |
| 58 | 59 |
| 59 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth), | 60 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth), |
| 60 SkIntToScalar(kPicHeight)); | 61 SkIntToScalar(kPicHeight), |
| 62 &bbhFactory, |
| 63 SkPictureRecorder::kComputeSaveLa
yerInfo_RecordFlag); |
| 61 | 64 |
| 62 SkScalar xPos, yPos = 0; | 65 SkScalar xPos, yPos = 0; |
| 63 | 66 |
| 64 for (int y = 0; y < kNumHexY; ++y) { | 67 for (int y = 0; y < kNumHexY; ++y) { |
| 65 xPos = 0; | 68 xPos = 0; |
| 66 | 69 |
| 67 for (int x = 0; x < kNumHexX; ++x) { | 70 for (int x = 0; x < kNumHexX; ++x) { |
| 68 canvas->saveLayer(NULL, NULL); | 71 canvas->saveLayer(NULL, NULL); |
| 69 canvas->translate(xPos, yPos + ((x % 2) ? kRoot3Over2 * kHexSide : 0
)); | 72 canvas->translate(xPos, yPos + ((x % 2) ? kRoot3Over2 * kHexSide : 0
)); |
| 70 canvas->drawPath(hex, fill); | 73 canvas->drawPath(hex, fill); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 95 | 98 |
| 96 SkPaint greyFill; | 99 SkPaint greyFill; |
| 97 greyFill.setStyle(SkPaint::kFill_Style); | 100 greyFill.setStyle(SkPaint::kFill_Style); |
| 98 greyFill.setColor(SK_ColorLTGRAY); | 101 greyFill.setColor(SK_ColorLTGRAY); |
| 99 | 102 |
| 100 SkPaint stroke; | 103 SkPaint stroke; |
| 101 stroke.setStyle(SkPaint::kStroke_Style); | 104 stroke.setStyle(SkPaint::kStroke_Style); |
| 102 stroke.setStrokeWidth(3); | 105 stroke.setStrokeWidth(3); |
| 103 | 106 |
| 104 SkPictureRecorder recorder; | 107 SkPictureRecorder recorder; |
| 108 SkRTreeFactory bbhFactory; |
| 105 | 109 |
| 106 static const SkScalar kBig = 10000.0f; | 110 static const SkScalar kBig = 10000.0f; |
| 107 SkCanvas* canvas = recorder.beginRecording(kBig, kBig); | 111 SkCanvas* canvas = recorder.beginRecording(kBig, kBig, &bbhFactory, |
| 112 SkPictureRecorder::kComputeSaveLa
yerInfo_RecordFlag); |
| 108 | 113 |
| 109 canvas->saveLayer(NULL, NULL); | 114 canvas->saveLayer(NULL, NULL); |
| 110 | 115 |
| 111 SkScalar xPos = 0.0f, yPos = 0.0f; | 116 SkScalar xPos = 0.0f, yPos = 0.0f; |
| 112 | 117 |
| 113 for (int y = 0; yPos < kBig; ++y) { | 118 for (int y = 0; yPos < kBig; ++y) { |
| 114 xPos = 0; | 119 xPos = 0; |
| 115 | 120 |
| 116 for (int x = 0; xPos < kBig; ++x) { | 121 for (int x = 0; xPos < kBig; ++x) { |
| 117 canvas->save(); | 122 canvas->save(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 154 |
| 150 SkPaint fill; | 155 SkPaint fill; |
| 151 fill.setStyle(SkPaint::kFill_Style); | 156 fill.setStyle(SkPaint::kFill_Style); |
| 152 fill.setColor(SK_ColorLTGRAY);; | 157 fill.setColor(SK_ColorLTGRAY);; |
| 153 | 158 |
| 154 SkPaint stroke; | 159 SkPaint stroke; |
| 155 stroke.setStyle(SkPaint::kStroke_Style); | 160 stroke.setStyle(SkPaint::kStroke_Style); |
| 156 stroke.setStrokeWidth(3); | 161 stroke.setStrokeWidth(3); |
| 157 | 162 |
| 158 SkPictureRecorder recorder; | 163 SkPictureRecorder recorder; |
| 164 SkRTreeFactory bbhFactory; |
| 159 | 165 |
| 160 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth), | 166 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth), |
| 161 SkIntToScalar(kPicHeight)); | 167 SkIntToScalar(kPicHeight), |
| 168 &bbhFactory, |
| 169 SkPictureRecorder::kComputeSaveLa
yerInfo_RecordFlag); |
| 162 SkRect r = tri.getBounds(); | 170 SkRect r = tri.getBounds(); |
| 163 r.outset(2.0f, 2.0f); // outset for stroke | 171 r.outset(2.0f, 2.0f); // outset for stroke |
| 164 canvas->clipRect(r); | 172 canvas->clipRect(r); |
| 165 // The saveLayer/restore block is to exercise layer hoisting | 173 // The saveLayer/restore block is to exercise layer hoisting |
| 166 canvas->saveLayer(NULL, NULL); | 174 canvas->saveLayer(NULL, NULL); |
| 167 canvas->drawPath(tri, fill); | 175 canvas->drawPath(tri, fill); |
| 168 canvas->drawPath(tri, stroke); | 176 canvas->drawPath(tri, stroke); |
| 169 canvas->restore(); | 177 canvas->restore(); |
| 170 | 178 |
| 171 return recorder.endRecording(); | 179 return recorder.endRecording(); |
| 172 } | 180 } |
| 173 | 181 |
| 174 static const SkPicture* make_sub_picture(const SkPicture* tri) { | 182 static const SkPicture* make_sub_picture(const SkPicture* tri) { |
| 175 SkPictureRecorder recorder; | 183 SkPictureRecorder recorder; |
| 184 SkRTreeFactory bbhFactory; |
| 176 | 185 |
| 177 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth), | 186 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth), |
| 178 SkIntToScalar(kPicHeight)); | 187 SkIntToScalar(kPicHeight), |
| 188 &bbhFactory, |
| 189 SkPictureRecorder::kComputeSaveLa
yerInfo_RecordFlag); |
| 179 | 190 |
| 180 canvas->scale(1.0f/2.0f, 1.0f/2.0f); | 191 canvas->scale(1.0f/2.0f, 1.0f/2.0f); |
| 181 | 192 |
| 182 canvas->save(); | 193 canvas->save(); |
| 183 canvas->translate(SkScalarHalf(kTriSide), 0); | 194 canvas->translate(SkScalarHalf(kTriSide), 0); |
| 184 canvas->drawPicture(tri); | 195 canvas->drawPicture(tri); |
| 185 canvas->restore(); | 196 canvas->restore(); |
| 186 | 197 |
| 187 canvas->save(); | 198 canvas->save(); |
| 188 canvas->translate(SkIntToScalar(kTriSide), 1.5f * kTriSide / kRoot3); | 199 canvas->translate(SkIntToScalar(kTriSide), 1.5f * kTriSide / kRoot3); |
| 189 canvas->drawPicture(tri); | 200 canvas->drawPicture(tri); |
| 190 canvas->restore(); | 201 canvas->restore(); |
| 191 | 202 |
| 192 canvas->save(); | 203 canvas->save(); |
| 193 canvas->translate(0, 1.5f * kTriSide / kRoot3); | 204 canvas->translate(0, 1.5f * kTriSide / kRoot3); |
| 194 canvas->drawPicture(tri); | 205 canvas->drawPicture(tri); |
| 195 canvas->restore(); | 206 canvas->restore(); |
| 196 | 207 |
| 197 return recorder.endRecording(); | 208 return recorder.endRecording(); |
| 198 } | 209 } |
| 199 | 210 |
| 200 // 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 |
| 201 // 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, |
| 202 // 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 |
| 203 // copies of it. | 214 // copies of it. |
| 204 static const SkPicture* make_sierpinski_picture() { | 215 static const SkPicture* make_sierpinski_picture() { |
| 205 SkAutoTUnref<const SkPicture> pic(make_tri_picture()); | 216 SkAutoTUnref<const SkPicture> pic(make_tri_picture()); |
| 206 | 217 |
| 207 SkPictureRecorder recorder; | 218 SkPictureRecorder recorder; |
| 219 SkRTreeFactory bbhFactory; |
| 208 | 220 |
| 209 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth), | 221 SkCanvas* canvas = recorder.beginRecording(SkIntToScalar(kPicWidth), |
| 210 SkIntToScalar(kPicHeight)); | 222 SkIntToScalar(kPicHeight), |
| 223 &bbhFactory, |
| 224 SkPictureRecorder::kComputeSaveLa
yerInfo_RecordFlag); |
| 211 | 225 |
| 212 static const int kNumLevels = 4; | 226 static const int kNumLevels = 4; |
| 213 for (int i = 0; i < kNumLevels; ++i) { | 227 for (int i = 0; i < kNumLevels; ++i) { |
| 214 canvas->save(); | 228 canvas->save(); |
| 215 canvas->translate(kPicWidth/2 - (i+1) * (kTriSide/2.0f), 0.0f); | 229 canvas->translate(kPicWidth/2 - (i+1) * (kTriSide/2.0f), 0.0f); |
| 216 for (int j = 0; j < i+1; ++j) { | 230 for (int j = 0; j < i+1; ++j) { |
| 217 canvas->drawPicture(pic); | 231 canvas->drawPicture(pic); |
| 218 canvas->translate(SkIntToScalar(kTriSide), 0); | 232 canvas->translate(SkIntToScalar(kTriSide), 0); |
| 219 } | 233 } |
| 220 canvas->restore(); | 234 canvas->restore(); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 big_layer, | 350 big_layer, |
| 337 }; | 351 }; |
| 338 | 352 |
| 339 static void create_content(SkMultiPictureDraw* mpd, PFContentMtd pfGen, | 353 static void create_content(SkMultiPictureDraw* mpd, PFContentMtd pfGen, |
| 340 const SkPicture* pictures[kNumPictures], | 354 const SkPicture* pictures[kNumPictures], |
| 341 SkCanvas* dest, const SkMatrix& xform) { | 355 SkCanvas* dest, const SkMatrix& xform) { |
| 342 SkAutoTUnref<SkPicture> composite; | 356 SkAutoTUnref<SkPicture> composite; |
| 343 | 357 |
| 344 { | 358 { |
| 345 SkPictureRecorder recorder; | 359 SkPictureRecorder recorder; |
| 360 SkRTreeFactory bbhFactory; |
| 346 | 361 |
| 347 SkCanvas* pictureCanvas = recorder.beginRecording(SkIntToScalar(kPicWidt
h), | 362 SkCanvas* pictureCanvas = recorder.beginRecording(SkIntToScalar(kPicWidt
h), |
| 348 SkIntToScalar(kPicHeig
ht)); | 363 SkIntToScalar(kPicHeig
ht), |
| 364 &bbhFactory, |
| 365 SkPictureRecorder::kCo
mputeSaveLayerInfo_RecordFlag); |
| 349 | 366 |
| 350 (*pfGen)(pictureCanvas, pictures); | 367 (*pfGen)(pictureCanvas, pictures); |
| 351 | 368 |
| 352 composite.reset(recorder.endRecording()); | 369 composite.reset(recorder.endRecording()); |
| 353 } | 370 } |
| 354 | 371 |
| 355 mpd->add(dest, composite, &xform); | 372 mpd->add(dest, composite, &xform); |
| 356 } | 373 } |
| 357 | 374 |
| 358 typedef void(*PFLayoutMtd)(SkCanvas* finalCanvas, SkMultiPictureDraw* mpd, | 375 typedef void(*PFLayoutMtd)(SkCanvas* finalCanvas, SkMultiPictureDraw* mpd, |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 MultiPictureDraw::kTiled_Layout)
);) | 563 MultiPictureDraw::kTiled_Layout)
);) |
| 547 DEF_GM(return SkNEW_ARGS(MultiPictureDraw, (MultiPictureDraw::kPathClipMulti
_Content, | 564 DEF_GM(return SkNEW_ARGS(MultiPictureDraw, (MultiPictureDraw::kPathClipMulti
_Content, |
| 548 MultiPictureDraw::kTiled_Layout)
);) | 565 MultiPictureDraw::kTiled_Layout)
);) |
| 549 DEF_GM(return SkNEW_ARGS(MultiPictureDraw, (MultiPictureDraw::kInvPathClipMu
lti_Content, | 566 DEF_GM(return SkNEW_ARGS(MultiPictureDraw, (MultiPictureDraw::kInvPathClipMu
lti_Content, |
| 550 MultiPictureDraw::kTiled_Layout)
);) | 567 MultiPictureDraw::kTiled_Layout)
);) |
| 551 DEF_GM(return SkNEW_ARGS(MultiPictureDraw, (MultiPictureDraw::kSierpinski_Co
ntent, | 568 DEF_GM(return SkNEW_ARGS(MultiPictureDraw, (MultiPictureDraw::kSierpinski_Co
ntent, |
| 552 MultiPictureDraw::kTiled_Layout)
);) | 569 MultiPictureDraw::kTiled_Layout)
);) |
| 553 DEF_GM(return SkNEW_ARGS(MultiPictureDraw, (MultiPictureDraw::kBigLayer_Cont
ent, | 570 DEF_GM(return SkNEW_ARGS(MultiPictureDraw, (MultiPictureDraw::kBigLayer_Cont
ent, |
| 554 MultiPictureDraw::kTiled_Layout)
);) | 571 MultiPictureDraw::kTiled_Layout)
);) |
| 555 } | 572 } |
| OLD | NEW |