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

Unified Diff: samplecode/SampleArc.cpp

Issue 732653004: option to return drawable from recording (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: plumb pictlist down to layer hoister Created 6 years, 1 month 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
Index: samplecode/SampleArc.cpp
diff --git a/samplecode/SampleArc.cpp b/samplecode/SampleArc.cpp
index a44eeb59ba1545cd30d5a2183355c48e71166e98..a87f9c905cc7d8501983442b43bb2768bca3b0ec 100644
--- a/samplecode/SampleArc.cpp
+++ b/samplecode/SampleArc.cpp
@@ -17,6 +17,7 @@
#include "Sk1DPathEffect.h"
#include "SkCornerPathEffect.h"
#include "SkPathMeasure.h"
+#include "SkPictureRecorder.h"
#include "SkRandom.h"
#include "SkColorPriv.h"
#include "SkColorFilter.h"
@@ -42,8 +43,7 @@ class ArcsView : public SampleView {
SkRect fR;
SkScalar fSweep;
public:
- MyDrawable(const SkRect& r) : fR(r), fSweep(0) {
- }
+ MyDrawable(const SkRect& r) : fR(r), fSweep(0) {}
void setSweep(SkScalar sweep) {
if (fSweep != sweep) {
@@ -82,7 +82,8 @@ class ArcsView : public SampleView {
public:
SkRect fRect;
- MyDrawable* fDrawable;
+ MyDrawable* fAnimatingDrawable;
+ SkCanvasDrawable* fRootDrawable;
ArcsView() {
testparse();
@@ -91,11 +92,16 @@ public:
fRect.set(0, 0, SkIntToScalar(200), SkIntToScalar(200));
fRect.offset(SkIntToScalar(20), SkIntToScalar(20));
- fDrawable = SkNEW_ARGS(MyDrawable, (fRect));
+ fAnimatingDrawable = SkNEW_ARGS(MyDrawable, (fRect));
+
+ SkPictureRecorder recorder;
+ draw_root(recorder.beginRecording(SkRect::MakeWH(800, 500)));
+ fRootDrawable = recorder.EXPERIMENTAL_endRecordingAsDrawable();
}
virtual ~ArcsView() SK_OVERRIDE {
- fDrawable->unref();
+ fAnimatingDrawable->unref();
+ fRootDrawable->unref();
}
protected:
@@ -175,10 +181,7 @@ protected:
canvas->restore();
}
robertphillips 2014/11/24 15:42:02 drawRoot due to fRect usage ?
reed1 2014/11/24 17:10:48 Done.
- virtual void onDrawContent(SkCanvas* canvas) {
- fDrawable->setSweep(SampleCode::GetAnimScalar(SkIntToScalar(360)/24,
- SkIntToScalar(360)));
-
+ void draw_root(SkCanvas* canvas) {
SkPaint paint;
paint.setAntiAlias(true);
paint.setStrokeWidth(SkIntToScalar(2));
@@ -186,9 +189,14 @@ protected:
drawRectWithLines(canvas, fRect, paint);
- canvas->EXPERIMENTAL_drawDrawable(fDrawable);
+ canvas->EXPERIMENTAL_drawDrawable(fAnimatingDrawable);
drawArcs(canvas);
+ }
+
robertphillips 2014/11/24 15:42:02 SK_OVERRIDE ?
reed1 2014/11/24 17:10:48 Done.
+ virtual void onDrawContent(SkCanvas* canvas) {
+ fAnimatingDrawable->setSweep(SampleCode::GetAnimScalar(360/24, 360));
+ canvas->EXPERIMENTAL_drawDrawable(fRootDrawable);
this->inval(NULL);
}

Powered by Google App Engine
This is Rietveld 408576698