Index: samplecode/GMSampleView.cpp |
diff --git a/samplecode/GMSampleView.cpp b/samplecode/GMSampleView.cpp |
index 76d0c59738730dde8f841ce69c8e6b97efd94f27..80a6803148047cc848e37b3009c4bb94b2f02c38 100644 |
--- a/samplecode/GMSampleView.cpp |
+++ b/samplecode/GMSampleView.cpp |
@@ -37,11 +37,39 @@ bool GMSampleView::onEvent(const SkEvent& evt) { |
return this->INHERITED::onEvent(evt); |
} |
+#include "SkPicture.h" |
+#include "SkStream.h" |
+static sk_sp<SkPicture> round_trip_serialize(SkPicture* src) { |
+ SkDynamicMemoryWStream stream; |
+ src->serialize(&stream); |
+ SkAutoTDelete<SkStream> reader(stream.detachAsStream()); |
+ return SkPicture::MakeFromStream(reader); |
+} |
+ |
+#include "SkPictureRecorder.h" |
void GMSampleView::onDrawContent(SkCanvas* canvas) { |
+ SkPictureRecorder recorder; |
+ SkCanvas* origCanvas = canvas; |
+ |
+ if (false) { |
+ SkISize size = fGM->getISize(); |
+ canvas = recorder.beginRecording(SkRect::MakeIWH(size.width(), size.height())); |
+ } |
+ |
{ |
SkAutoCanvasRestore acr(canvas, fShowSize); |
fGM->drawContent(canvas); |
} |
+ |
+ if (origCanvas != canvas) { |
+ sk_sp<SkPicture> pic = recorder.finishRecordingAsPicture(); |
+ if (false) { |
+ pic = round_trip_serialize(pic.get()); |
+ } |
+ origCanvas->drawPicture(pic); |
+ canvas = origCanvas; |
+ } |
+ |
if (fShowSize) { |
SkISize size = fGM->getISize(); |
SkRect r = SkRect::MakeWH(SkIntToScalar(size.width()), |