Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(868)

Unified Diff: samplecode/GMSampleView.cpp

Issue 1934313002: move colorshader into its own .cpp, add color4f variant (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: register for serialization, amend GM view for future picture expansion Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/core/SkShader.h ('k') | src/core/SkColorShader.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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()),
« no previous file with comments | « include/core/SkShader.h ('k') | src/core/SkColorShader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698