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

Side by Side Diff: samplecode/SampleBigGradient.cpp

Issue 1772463002: use Make instead of Create to return a shared shader (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: partial update of skia call-sites 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
OLDNEW
1
2 /* 1 /*
3 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
4 * 3 *
5 * 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
6 * found in the LICENSE file. 5 * found in the LICENSE file.
7 */ 6 */
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 12
13 static SkShader* make_grad(SkScalar w, SkScalar h) { 13 static sk_sp<SkShader> make_grad(SkScalar w, SkScalar h) {
14 SkColor colors[] = { 0xFF000000, 0xFF333333 }; 14 SkColor colors[] = { 0xFF000000, 0xFF333333 };
15 SkPoint pts[] = { { 0, 0 }, { w, h } }; 15 SkPoint pts[] = { { 0, 0 }, { w, h } };
16 return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, 16 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClam p_TileMode);
17 SkShader::kClamp_TileMode);
18 } 17 }
19 18
20 class BigGradientView : public SampleView { 19 class BigGradientView : public SampleView {
21 public: 20 public:
22 BigGradientView() {} 21 BigGradientView() {}
23 22
24 protected: 23 protected:
25 // overrides from SkEventSink 24 bool onQuery(SkEvent* evt) override {
26 virtual bool onQuery(SkEvent* evt) {
27 if (SampleCode::TitleQ(*evt)) { 25 if (SampleCode::TitleQ(*evt)) {
28 SampleCode::TitleR(evt, "BigGradient"); 26 SampleCode::TitleR(evt, "BigGradient");
29 return true; 27 return true;
30 } 28 }
31 return this->INHERITED::onQuery(evt); 29 return this->INHERITED::onQuery(evt);
32 } 30 }
33 31
34 virtual void onDrawContent(SkCanvas* canvas) { 32 void onDrawContent(SkCanvas* canvas) override {
35 SkRect r; 33 SkRect r;
36 r.set(0, 0, this->width(), this->height()); 34 r.set(0, 0, this->width(), this->height());
37 SkPaint p; 35 SkPaint p;
38 p.setShader(make_grad(this->width(), this->height()))->unref(); 36 p.setShader(make_grad(this->width(), this->height()));
39 canvas->drawRect(r, p); 37 canvas->drawRect(r, p);
40 } 38 }
41 39
42 private: 40 private:
43 typedef SampleView INHERITED; 41 typedef SampleView INHERITED;
44 }; 42 };
45 43
46 /////////////////////////////////////////////////////////////////////////////// 44 ///////////////////////////////////////////////////////////////////////////////
47 45
48 static SkView* MyFactory() { return new BigGradientView; } 46 static SkView* MyFactory() { return new BigGradientView; }
49 static SkViewRegister reg(MyFactory); 47 static SkViewRegister reg(MyFactory);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698