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

Side by Side Diff: samplecode/SampleArc.cpp

Issue 750723002: add endRecordingAsDrawable experiment (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: seems to work, TODO around immediate mode drawing 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 unified diff | Download patch
« no previous file with comments | « include/core/SkPictureRecorder.h ('k') | src/core/SkCanvasDrawable.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2011 Google Inc. 3 * Copyright 2011 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 #include "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkView.h" 9 #include "SkView.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
11 #include "SkGradientShader.h" 11 #include "SkGradientShader.h"
12 #include "SkPath.h" 12 #include "SkPath.h"
13 #include "SkRegion.h" 13 #include "SkRegion.h"
14 #include "SkShader.h" 14 #include "SkShader.h"
15 #include "SkUtils.h" 15 #include "SkUtils.h"
16 #include "SkComposeShader.h" 16 #include "SkComposeShader.h"
17 #include "Sk1DPathEffect.h" 17 #include "Sk1DPathEffect.h"
18 #include "SkCornerPathEffect.h" 18 #include "SkCornerPathEffect.h"
19 #include "SkPathMeasure.h" 19 #include "SkPathMeasure.h"
20 #include "SkPictureRecorder.h"
20 #include "SkRandom.h" 21 #include "SkRandom.h"
21 #include "SkColorPriv.h" 22 #include "SkColorPriv.h"
22 #include "SkColorFilter.h" 23 #include "SkColorFilter.h"
23 #include "SkLayerRasterizer.h" 24 #include "SkLayerRasterizer.h"
24 25
25 #include "SkCanvasDrawable.h" 26 #include "SkCanvasDrawable.h"
26 27
27 #include "SkParsePath.h" 28 #include "SkParsePath.h"
28 static void testparse() { 29 static void testparse() {
29 SkRect r; 30 SkRect r;
30 r.set(0, 0, 10, 10.5f); 31 r.set(0, 0, 10, 10.5f);
31 SkPath p, p2; 32 SkPath p, p2;
32 SkString str, str2; 33 SkString str, str2;
33 34
34 p.addRect(r); 35 p.addRect(r);
35 SkParsePath::ToSVGString(p, &str); 36 SkParsePath::ToSVGString(p, &str);
36 SkParsePath::FromSVGString(str.c_str(), &p2); 37 SkParsePath::FromSVGString(str.c_str(), &p2);
37 SkParsePath::ToSVGString(p2, &str2); 38 SkParsePath::ToSVGString(p2, &str2);
38 } 39 }
39 40
40 class ArcsView : public SampleView { 41 class ArcsView : public SampleView {
41 class MyDrawable : public SkCanvasDrawable { 42 class MyDrawable : public SkCanvasDrawable {
42 SkRect fR; 43 SkRect fR;
43 SkScalar fSweep; 44 SkScalar fSweep;
44 public: 45 public:
45 MyDrawable(const SkRect& r) : fR(r), fSweep(0) { 46 MyDrawable(const SkRect& r) : fR(r), fSweep(0) {}
46 }
47 47
48 void setSweep(SkScalar sweep) { 48 void setSweep(SkScalar sweep) {
49 if (fSweep != sweep) { 49 if (fSweep != sweep) {
50 fSweep = sweep; 50 fSweep = sweep;
51 this->notifyDrawingChanged(); 51 this->notifyDrawingChanged();
52 } 52 }
53 } 53 }
54 54
55 void onDraw(SkCanvas* canvas) SK_OVERRIDE { 55 void onDraw(SkCanvas* canvas) SK_OVERRIDE {
56 SkPaint paint; 56 SkPaint paint;
(...skipping 19 matching lines...) Expand all
76 SkRect onGetBounds() SK_OVERRIDE { 76 SkRect onGetBounds() SK_OVERRIDE {
77 SkRect r(fR); 77 SkRect r(fR);
78 r.outset(2, 2); 78 r.outset(2, 2);
79 return r; 79 return r;
80 } 80 }
81 }; 81 };
82 82
83 public: 83 public:
84 SkRect fRect; 84 SkRect fRect;
85 MyDrawable* fDrawable; 85 MyDrawable* fDrawable;
86 SkCanvasDrawable* fRootDrawable;
86 87
87 ArcsView() { 88 ArcsView() {
88 testparse(); 89 testparse();
89 fSweep = SkIntToScalar(100); 90 fSweep = SkIntToScalar(100);
90 this->setBGColor(0xFFDDDDDD); 91 this->setBGColor(0xFFDDDDDD);
91 92
92 fRect.set(0, 0, SkIntToScalar(200), SkIntToScalar(200)); 93 fRect.set(0, 0, SkIntToScalar(200), SkIntToScalar(200));
93 fRect.offset(SkIntToScalar(20), SkIntToScalar(20)); 94 fRect.offset(SkIntToScalar(20), SkIntToScalar(20));
94 fDrawable = SkNEW_ARGS(MyDrawable, (fRect)); 95 fDrawable = SkNEW_ARGS(MyDrawable, (fRect));
96
97 SkPictureRecorder recorder;
98 draw_root(recorder.beginRecording(SkRect::MakeWH(800, 500)));
99 fRootDrawable = recorder.EXPERIMENTAL_endRecordingAsDrawable();
95 } 100 }
96 101
97 virtual ~ArcsView() SK_OVERRIDE { 102 virtual ~ArcsView() SK_OVERRIDE {
98 fDrawable->unref(); 103 fDrawable->unref();
104 fRootDrawable->unref();
99 } 105 }
100 106
101 protected: 107 protected:
102 // overrides from SkEventSink 108 // overrides from SkEventSink
103 virtual bool onQuery(SkEvent* evt) { 109 virtual bool onQuery(SkEvent* evt) {
104 if (SampleCode::TitleQ(*evt)) { 110 if (SampleCode::TitleQ(*evt)) {
105 SampleCode::TitleR(evt, "Arcs"); 111 SampleCode::TitleR(evt, "Arcs");
106 return true; 112 return true;
107 } 113 }
108 return this->INHERITED::onQuery(evt); 114 return this->INHERITED::onQuery(evt);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 SkIntToScalar(gAngles[i+1]), false, paint); 174 SkIntToScalar(gAngles[i+1]), false, paint);
169 175
170 draw_label(canvas, r, gAngles[i], gAngles[i+1]); 176 draw_label(canvas, r, gAngles[i], gAngles[i+1]);
171 177
172 canvas->translate(w * 8 / 7, 0); 178 canvas->translate(w * 8 / 7, 0);
173 } 179 }
174 180
175 canvas->restore(); 181 canvas->restore();
176 } 182 }
177 183
178 virtual void onDrawContent(SkCanvas* canvas) { 184 void draw_root(SkCanvas* canvas) {
179 fDrawable->setSweep(SampleCode::GetAnimScalar(SkIntToScalar(360)/24,
180 SkIntToScalar(360)));
181
182 SkPaint paint; 185 SkPaint paint;
183 paint.setAntiAlias(true); 186 paint.setAntiAlias(true);
184 paint.setStrokeWidth(SkIntToScalar(2)); 187 paint.setStrokeWidth(SkIntToScalar(2));
185 paint.setStyle(SkPaint::kStroke_Style); 188 paint.setStyle(SkPaint::kStroke_Style);
186 189
187 drawRectWithLines(canvas, fRect, paint); 190 drawRectWithLines(canvas, fRect, paint);
188 191
189 canvas->EXPERIMENTAL_drawDrawable(fDrawable); 192 canvas->EXPERIMENTAL_drawDrawable(fDrawable);
190 193
191 drawArcs(canvas); 194 drawArcs(canvas);
195 }
196
197 virtual void onDrawContent(SkCanvas* canvas) {
198 fDrawable->setSweep(SampleCode::GetAnimScalar(SkIntToScalar(360)/24,
199 SkIntToScalar(360)));
200 canvas->EXPERIMENTAL_drawDrawable(fRootDrawable);
192 this->inval(NULL); 201 this->inval(NULL);
193 } 202 }
194 203
195 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, 204 virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y,
196 unsigned modi) { 205 unsigned modi) {
197 // fSweep += SK_Scalar1; 206 // fSweep += SK_Scalar1;
198 this->inval(NULL); 207 this->inval(NULL);
199 return this->INHERITED::onFindClickHandler(x, y, modi); 208 return this->INHERITED::onFindClickHandler(x, y, modi);
200 } 209 }
201 210
202 virtual bool onClick(Click* click) { 211 virtual bool onClick(Click* click) {
203 return this->INHERITED::onClick(click); 212 return this->INHERITED::onClick(click);
204 } 213 }
205 214
206 private: 215 private:
207 SkScalar fSweep; 216 SkScalar fSweep;
208 217
209 typedef SampleView INHERITED; 218 typedef SampleView INHERITED;
210 }; 219 };
211 220
212 ////////////////////////////////////////////////////////////////////////////// 221 //////////////////////////////////////////////////////////////////////////////
213 222
214 static SkView* MyFactory() { return new ArcsView; } 223 static SkView* MyFactory() { return new ArcsView; }
215 static SkViewRegister reg(MyFactory); 224 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « include/core/SkPictureRecorder.h ('k') | src/core/SkCanvasDrawable.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698