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

Side by Side Diff: samplecode/SampleArc.cpp

Issue 1811703002: return pictures as sk_sp (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rely on RVO in picturerecorder Created 4 years, 9 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 unified diff | Download patch
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | samplecode/SampleFilterFuzz.cpp » ('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 * Copyright 2011 Google Inc. 2 * Copyright 2011 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 "SampleCode.h" 8 #include "SampleCode.h"
9 #include "SkAnimTimer.h" 9 #include "SkAnimTimer.h"
10 #include "SkView.h" 10 #include "SkView.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 74
75 SkRect onGetBounds() override { 75 SkRect onGetBounds() override {
76 SkRect r(fR); 76 SkRect r(fR);
77 r.outset(2, 2); 77 r.outset(2, 2);
78 return r; 78 return r;
79 } 79 }
80 }; 80 };
81 81
82 public: 82 public:
83 SkRect fRect; 83 SkRect fRect;
84 MyDrawable* fAnimatingDrawable; 84 sk_sp<MyDrawable> fAnimatingDrawable;
85 SkDrawable* fRootDrawable; 85 sk_sp<SkDrawable> fRootDrawable;
86 86
87 ArcsView() { 87 ArcsView() {
88 testparse(); 88 testparse();
89 fSweep = SkIntToScalar(100); 89 fSweep = SkIntToScalar(100);
90 this->setBGColor(0xFFDDDDDD); 90 this->setBGColor(0xFFDDDDDD);
91 91
92 fRect.set(0, 0, SkIntToScalar(200), SkIntToScalar(200)); 92 fRect.set(0, 0, SkIntToScalar(200), SkIntToScalar(200));
93 fRect.offset(SkIntToScalar(20), SkIntToScalar(20)); 93 fRect.offset(SkIntToScalar(20), SkIntToScalar(20));
94 fAnimatingDrawable = new MyDrawable(fRect); 94 fAnimatingDrawable = sk_make_sp<MyDrawable>(fRect);
95 95
96 SkPictureRecorder recorder; 96 SkPictureRecorder recorder;
97 this->drawRoot(recorder.beginRecording(SkRect::MakeWH(800, 500))); 97 this->drawRoot(recorder.beginRecording(SkRect::MakeWH(800, 500)));
98 fRootDrawable = recorder.endRecordingAsDrawable(); 98 fRootDrawable = recorder.finishRecordingAsDrawable();
99 }
100
101 ~ArcsView() override {
102 fAnimatingDrawable->unref();
103 fRootDrawable->unref();
104 } 99 }
105 100
106 protected: 101 protected:
107 // overrides from SkEventSink 102 // overrides from SkEventSink
108 bool onQuery(SkEvent* evt) override { 103 bool onQuery(SkEvent* evt) override {
109 if (SampleCode::TitleQ(*evt)) { 104 if (SampleCode::TitleQ(*evt)) {
110 SampleCode::TitleR(evt, "Arcs"); 105 SampleCode::TitleR(evt, "Arcs");
111 return true; 106 return true;
112 } 107 }
113 return this->INHERITED::onQuery(evt); 108 return this->INHERITED::onQuery(evt);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 174 }
180 175
181 void drawRoot(SkCanvas* canvas) { 176 void drawRoot(SkCanvas* canvas) {
182 SkPaint paint; 177 SkPaint paint;
183 paint.setAntiAlias(true); 178 paint.setAntiAlias(true);
184 paint.setStrokeWidth(SkIntToScalar(2)); 179 paint.setStrokeWidth(SkIntToScalar(2));
185 paint.setStyle(SkPaint::kStroke_Style); 180 paint.setStyle(SkPaint::kStroke_Style);
186 181
187 DrawRectWithLines(canvas, fRect, paint); 182 DrawRectWithLines(canvas, fRect, paint);
188 183
189 canvas->drawDrawable(fAnimatingDrawable); 184 canvas->drawDrawable(fAnimatingDrawable.get());
190 185
191 DrawArcs(canvas); 186 DrawArcs(canvas);
192 } 187 }
193 188
194 void onDrawContent(SkCanvas* canvas) override { 189 void onDrawContent(SkCanvas* canvas) override {
195 canvas->drawDrawable(fRootDrawable); 190 canvas->drawDrawable(fRootDrawable.get());
196 } 191 }
197 192
198 bool onAnimate(const SkAnimTimer& timer) override { 193 bool onAnimate(const SkAnimTimer& timer) override {
199 SkScalar angle = SkDoubleToScalar(fmod(timer.secs() * 360 / 24, 360)); 194 SkScalar angle = SkDoubleToScalar(fmod(timer.secs() * 360 / 24, 360));
200 fAnimatingDrawable->setSweep(angle); 195 fAnimatingDrawable->setSweep(angle);
201 return true; 196 return true;
202 } 197 }
203 198
204 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove rride { 199 SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned modi) ove rride {
205 // fSweep += SK_Scalar1; 200 // fSweep += SK_Scalar1;
206 this->inval(nullptr); 201 this->inval(nullptr);
207 return this->INHERITED::onFindClickHandler(x, y, modi); 202 return this->INHERITED::onFindClickHandler(x, y, modi);
208 } 203 }
209 204
210 private: 205 private:
211 SkScalar fSweep; 206 SkScalar fSweep;
212 207
213 typedef SampleView INHERITED; 208 typedef SampleView INHERITED;
214 }; 209 };
215 210
216 ////////////////////////////////////////////////////////////////////////////// 211 //////////////////////////////////////////////////////////////////////////////
217 212
218 static SkView* MyFactory() { return new ArcsView; } 213 static SkView* MyFactory() { return new ArcsView; }
219 static SkViewRegister reg(MyFactory); 214 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « samplecode/SampleApp.cpp ('k') | samplecode/SampleFilterFuzz.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698