OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "GMSampleView.h" | 8 #include "GMSampleView.h" |
9 | 9 |
10 GMSampleView::GMSampleView(GM* gm) : fShowSize(false), fGM(gm) {} | 10 GMSampleView::GMSampleView(GM* gm) : fShowSize(false), fGM(gm) {} |
(...skipping 19 matching lines...) Expand all Loading... |
30 } | 30 } |
31 | 31 |
32 bool GMSampleView::onEvent(const SkEvent& evt) { | 32 bool GMSampleView::onEvent(const SkEvent& evt) { |
33 if (evt.isType("GMSampleView::showSize")) { | 33 if (evt.isType("GMSampleView::showSize")) { |
34 fShowSize = SkToBool(evt.getFast32()); | 34 fShowSize = SkToBool(evt.getFast32()); |
35 return true; | 35 return true; |
36 } | 36 } |
37 return this->INHERITED::onEvent(evt); | 37 return this->INHERITED::onEvent(evt); |
38 } | 38 } |
39 | 39 |
| 40 #include "SkPicture.h" |
| 41 #include "SkStream.h" |
| 42 static sk_sp<SkPicture> round_trip_serialize(SkPicture* src) { |
| 43 SkDynamicMemoryWStream stream; |
| 44 src->serialize(&stream); |
| 45 SkAutoTDelete<SkStream> reader(stream.detachAsStream()); |
| 46 return SkPicture::MakeFromStream(reader); |
| 47 } |
| 48 |
| 49 #include "SkPictureRecorder.h" |
40 void GMSampleView::onDrawContent(SkCanvas* canvas) { | 50 void GMSampleView::onDrawContent(SkCanvas* canvas) { |
| 51 SkPictureRecorder recorder; |
| 52 SkCanvas* origCanvas = canvas; |
| 53 |
| 54 if (false) { |
| 55 SkISize size = fGM->getISize(); |
| 56 canvas = recorder.beginRecording(SkRect::MakeIWH(size.width(), size.heig
ht())); |
| 57 } |
| 58 |
41 { | 59 { |
42 SkAutoCanvasRestore acr(canvas, fShowSize); | 60 SkAutoCanvasRestore acr(canvas, fShowSize); |
43 fGM->drawContent(canvas); | 61 fGM->drawContent(canvas); |
44 } | 62 } |
| 63 |
| 64 if (origCanvas != canvas) { |
| 65 sk_sp<SkPicture> pic = recorder.finishRecordingAsPicture(); |
| 66 if (false) { |
| 67 pic = round_trip_serialize(pic.get()); |
| 68 } |
| 69 origCanvas->drawPicture(pic); |
| 70 canvas = origCanvas; |
| 71 } |
| 72 |
45 if (fShowSize) { | 73 if (fShowSize) { |
46 SkISize size = fGM->getISize(); | 74 SkISize size = fGM->getISize(); |
47 SkRect r = SkRect::MakeWH(SkIntToScalar(size.width()), | 75 SkRect r = SkRect::MakeWH(SkIntToScalar(size.width()), |
48 SkIntToScalar(size.height())); | 76 SkIntToScalar(size.height())); |
49 SkPaint paint; | 77 SkPaint paint; |
50 paint.setColor(0x40FF8833); | 78 paint.setColor(0x40FF8833); |
51 canvas->drawRect(r, paint); | 79 canvas->drawRect(r, paint); |
52 } | 80 } |
53 } | 81 } |
54 | 82 |
55 void GMSampleView::onDrawBackground(SkCanvas* canvas) { | 83 void GMSampleView::onDrawBackground(SkCanvas* canvas) { |
56 fGM->drawBackground(canvas); | 84 fGM->drawBackground(canvas); |
57 } | 85 } |
58 | 86 |
59 bool GMSampleView::onAnimate(const SkAnimTimer& timer) { | 87 bool GMSampleView::onAnimate(const SkAnimTimer& timer) { |
60 return fGM->animate(timer); | 88 return fGM->animate(timer); |
61 } | 89 } |
OLD | NEW |