| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 SkIntToScalar(kPicHeight), | 61 SkIntToScalar(kPicHeight), |
| 62 &bbhFactory, | 62 &bbhFactory, |
| 63 SkPictureRecorder::kComputeSaveLa
yerInfo_RecordFlag); | 63 SkPictureRecorder::kComputeSaveLa
yerInfo_RecordFlag); |
| 64 | 64 |
| 65 SkScalar xPos, yPos = 0; | 65 SkScalar xPos, yPos = 0; |
| 66 | 66 |
| 67 for (int y = 0; y < kNumHexY; ++y) { | 67 for (int y = 0; y < kNumHexY; ++y) { |
| 68 xPos = 0; | 68 xPos = 0; |
| 69 | 69 |
| 70 for (int x = 0; x < kNumHexX; ++x) { | 70 for (int x = 0; x < kNumHexX; ++x) { |
| 71 canvas->saveLayer(NULL, NULL); | 71 canvas->saveLayer(nullptr, nullptr); |
| 72 canvas->translate(xPos, yPos + ((x % 2) ? kRoot3Over2 * kHexSide : 0
)); | 72 canvas->translate(xPos, yPos + ((x % 2) ? kRoot3Over2 * kHexSide : 0
)); |
| 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 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 104 stroke.setStyle(SkPaint::kStroke_Style); | 104 stroke.setStyle(SkPaint::kStroke_Style); |
| 105 stroke.setStrokeWidth(3); | 105 stroke.setStrokeWidth(3); |
| 106 | 106 |
| 107 SkPictureRecorder recorder; | 107 SkPictureRecorder recorder; |
| 108 SkRTreeFactory bbhFactory; | 108 SkRTreeFactory bbhFactory; |
| 109 | 109 |
| 110 static const SkScalar kBig = 10000.0f; | 110 static const SkScalar kBig = 10000.0f; |
| 111 SkCanvas* canvas = recorder.beginRecording(kBig, kBig, &bbhFactory, | 111 SkCanvas* canvas = recorder.beginRecording(kBig, kBig, &bbhFactory, |
| 112 SkPictureRecorder::kComputeSaveLa
yerInfo_RecordFlag); | 112 SkPictureRecorder::kComputeSaveLa
yerInfo_RecordFlag); |
| 113 | 113 |
| 114 canvas->saveLayer(NULL, NULL); | 114 canvas->saveLayer(nullptr, nullptr); |
| 115 | 115 |
| 116 SkScalar xPos = 0.0f, yPos = 0.0f; | 116 SkScalar xPos = 0.0f, yPos = 0.0f; |
| 117 | 117 |
| 118 for (int y = 0; yPos < kBig; ++y) { | 118 for (int y = 0; yPos < kBig; ++y) { |
| 119 xPos = 0; | 119 xPos = 0; |
| 120 | 120 |
| 121 for (int x = 0; xPos < kBig; ++x) { | 121 for (int x = 0; xPos < kBig; ++x) { |
| 122 canvas->save(); | 122 canvas->save(); |
| 123 canvas->translate(xPos, yPos + ((x % 2) ? kRoot3Over2 * kHexSide : 0
)); | 123 canvas->translate(xPos, yPos + ((x % 2) ? kRoot3Over2 * kHexSide : 0
)); |
| 124 // The color of the filled hex is swapped to yield a different | 124 // The color of the filled hex is swapped to yield a different |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(NULL, NULL); | 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.endRecording(); |
| 180 } | 180 } |
| 181 | 181 |
| 182 static const SkPicture* make_sub_picture(const SkPicture* tri) { | 182 static const SkPicture* make_sub_picture(const SkPicture* tri) { |
| 183 SkPictureRecorder recorder; | 183 SkPictureRecorder recorder; |
| 184 SkRTreeFactory bbhFactory; | 184 SkRTreeFactory bbhFactory; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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.endRecording(); |
| 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 (NULL == surface) { | 248 if (nullptr == surface) { |
| 249 // picture canvas returns NULL 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 } |
| 252 | 252 |
| 253 return surface; | 253 return surface; |
| 254 } | 254 } |
| 255 | 255 |
| 256 // This class stores the information required to compose all the result | 256 // This class stores the information required to compose all the result |
| 257 // fragments potentially generated by the MultiPictureDraw object | 257 // fragments potentially generated by the MultiPictureDraw object |
| 258 class ComposeStep { | 258 class ComposeStep { |
| 259 public: | 259 public: |
| 260 ComposeStep() : fSurf(NULL), fX(0.0f), fY(0.0f), fPaint(NULL) { } | 260 ComposeStep() : fSurf(nullptr), fX(0.0f), fY(0.0f), fPaint(nullptr) { } |
| 261 ~ComposeStep() { | 261 ~ComposeStep() { |
| 262 SkSafeUnref(fSurf); | 262 SkSafeUnref(fSurf); |
| 263 delete fPaint; | 263 delete fPaint; |
| 264 } | 264 } |
| 265 | 265 |
| 266 SkSurface* fSurf; | 266 SkSurface* fSurf; |
| 267 SkScalar fX; | 267 SkScalar fX; |
| 268 SkScalar fY; | 268 SkScalar fY; |
| 269 SkPaint* fPaint; | 269 SkPaint* fPaint; |
| 270 }; | 270 }; |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 kLast_Layout = kTiled_Layout | 467 kLast_Layout = kTiled_Layout |
| 468 }; | 468 }; |
| 469 | 469 |
| 470 static const int kLayoutCnt = kLast_Layout + 1; | 470 static const int kLayoutCnt = kLast_Layout + 1; |
| 471 | 471 |
| 472 MultiPictureDraw(Content content, Layout layout) : fContent(content), fL
ayout(layout) { | 472 MultiPictureDraw(Content content, Layout layout) : fContent(content), fL
ayout(layout) { |
| 473 SkASSERT(SK_ARRAY_COUNT(gLayoutMthds) == kLayoutCnt); | 473 SkASSERT(SK_ARRAY_COUNT(gLayoutMthds) == kLayoutCnt); |
| 474 SkASSERT(SK_ARRAY_COUNT(gContentMthds) == kContentCnt); | 474 SkASSERT(SK_ARRAY_COUNT(gContentMthds) == kContentCnt); |
| 475 | 475 |
| 476 for (int i = 0; i < kNumPictures; ++i) { | 476 for (int i = 0; i < kNumPictures; ++i) { |
| 477 fPictures[i] = NULL; | 477 fPictures[i] = nullptr; |
| 478 } | 478 } |
| 479 } | 479 } |
| 480 | 480 |
| 481 virtual ~MultiPictureDraw() { | 481 virtual ~MultiPictureDraw() { |
| 482 for (int i = 0; i < kNumPictures; ++i) { | 482 for (int i = 0; i < kNumPictures; ++i) { |
| 483 SkSafeUnref(fPictures[i]); | 483 SkSafeUnref(fPictures[i]); |
| 484 } | 484 } |
| 485 } | 485 } |
| 486 | 486 |
| 487 protected: | 487 protected: |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 MultiPictureDraw::kTiled_Layout);) | 566 MultiPictureDraw::kTiled_Layout);) |
| 567 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kPathClipMulti_Content, | 567 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kPathClipMulti_Content, |
| 568 MultiPictureDraw::kTiled_Layout);) | 568 MultiPictureDraw::kTiled_Layout);) |
| 569 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kInvPathClipMulti_Conte
nt, | 569 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kInvPathClipMulti_Conte
nt, |
| 570 MultiPictureDraw::kTiled_Layout);) | 570 MultiPictureDraw::kTiled_Layout);) |
| 571 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kSierpinski_Content, | 571 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kSierpinski_Content, |
| 572 MultiPictureDraw::kTiled_Layout);) | 572 MultiPictureDraw::kTiled_Layout);) |
| 573 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kBigLayer_Content, | 573 DEF_GM(return new MultiPictureDraw(MultiPictureDraw::kBigLayer_Content, |
| 574 MultiPictureDraw::kTiled_Layout);) | 574 MultiPictureDraw::kTiled_Layout);) |
| 575 } | 575 } |
| OLD | NEW |