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

Side by Side Diff: gm/gradientDirtyLaundry.cpp

Issue 1793303002: Reland of "more shader-->sp conversions (patchset #5 id:80001 of https://codereview.chromium… (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: make pictureRef a value, so its clearer what's going on 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 | « no previous file | gm/gradient_matrix.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 /* 2 /*
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 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 "gm.h" 8 #include "gm.h"
9 #include "SkGradientShader.h" 9 #include "SkGradientShader.h"
10 10
(...skipping 17 matching lines...) Expand all
28 }; 28 };
29 29
30 //static const SkScalar gPos[] = { SK_Scalar1*999/2000, SK_Scalar1*1001/2000 }; 30 //static const SkScalar gPos[] = { SK_Scalar1*999/2000, SK_Scalar1*1001/2000 };
31 31
32 static const GradData gGradData[] = { 32 static const GradData gGradData[] = {
33 { 40, gColors, nullptr }, 33 { 40, gColors, nullptr },
34 // { 2, gColors, gPos }, 34 // { 2, gColors, gPos },
35 // { 2, gCol2, nullptr }, 35 // { 2, gCol2, nullptr },
36 }; 36 };
37 37
38 static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, SkShader ::TileMode tm) { 38 static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data, Sk Shader::TileMode tm) {
39 return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCo unt, tm); 39 return SkGradientShader::MakeLinear(pts, data.fColors, data.fPos, data.fCoun t, tm);
40 } 40 }
41 41
42 static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, SkShader ::TileMode tm) { 42 static sk_sp<SkShader> MakeRadial(const SkPoint pts[2], const GradData& data, Sk Shader::TileMode tm) {
43 SkPoint center; 43 const SkPoint pt{ SkScalarAve(pts[0].fX, pts[1].fX), SkScalarAve(pts[0].fY, pts[1].fY) };
44 center.set(SkScalarAve(pts[0].fX, pts[1].fX), 44 return SkGradientShader::MakeRadial(pt, pt.fX, data.fColors, data.fPos, data .fCount, tm);
45 SkScalarAve(pts[0].fY, pts[1].fY));
46 return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
47 data.fPos, data.fCount, tm);
48 } 45 }
49 46
50 static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader: :TileMode) { 47 static sk_sp<SkShader> MakeSweep(const SkPoint pts[2], const GradData& data, SkS hader::TileMode) {
51 SkPoint center; 48 const SkPoint pt{ SkScalarAve(pts[0].fX, pts[1].fX), SkScalarAve(pts[0].fY, pts[1].fY) };
52 center.set(SkScalarAve(pts[0].fX, pts[1].fX), 49 return SkGradientShader::MakeSweep(pt.fX, pt.fY, data.fColors, data.fPos, da ta.fCount);
53 SkScalarAve(pts[0].fY, pts[1].fY));
54 return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, dat a.fPos, data.fCount);
55 } 50 }
56 51
57 52
58 typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkSha der::TileMode tm); 53 typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData&, SkSh ader::TileMode);
59 54
60 static const GradMaker gGradMakers[] = { 55 static const GradMaker gGradMakers[] = {
61 MakeLinear, MakeRadial, MakeSweep, 56 MakeLinear, MakeRadial, MakeSweep,
62 }; 57 };
63 58
64 /////////////////////////////////////////////////////////////////////////////// 59 ///////////////////////////////////////////////////////////////////////////////
65 60
66 class GradientsGM : public GM { 61 class GradientsGM : public GM {
67 public: 62 public:
68 GradientsGM() { 63 GradientsGM() {
(...skipping 10 matching lines...) Expand all
79 }; 74 };
80 SkShader::TileMode tm = SkShader::kClamp_TileMode; 75 SkShader::TileMode tm = SkShader::kClamp_TileMode;
81 SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) }; 76 SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) };
82 SkPaint paint; 77 SkPaint paint;
83 paint.setAntiAlias(true); 78 paint.setAntiAlias(true);
84 79
85 canvas->translate(SkIntToScalar(20), SkIntToScalar(20)); 80 canvas->translate(SkIntToScalar(20), SkIntToScalar(20));
86 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) { 81 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
87 canvas->save(); 82 canvas->save();
88 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) { 83 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) {
89 SkShader* shader = gGradMakers[j](pts, gGradData[i], tm); 84 paint.setShader(gGradMakers[j](pts, gGradData[i], tm));
90 paint.setShader(shader)->unref();
91 canvas->drawRect(r, paint); 85 canvas->drawRect(r, paint);
92 canvas->translate(0, SkIntToScalar(120)); 86 canvas->translate(0, SkIntToScalar(120));
93 } 87 }
94 canvas->restore(); 88 canvas->restore();
95 canvas->translate(SkIntToScalar(120), 0); 89 canvas->translate(SkIntToScalar(120), 0);
96 } 90 }
97 } 91 }
98 92
99 private: 93 private:
100 typedef GM INHERITED; 94 typedef GM INHERITED;
101 }; 95 };
102 96
103 /////////////////////////////////////////////////////////////////////////////// 97 ///////////////////////////////////////////////////////////////////////////////
104 98
105 static GM* MyFactory(void*) { return new GradientsGM; } 99 static GM* MyFactory(void*) { return new GradientsGM; }
106 static GMRegistry reg(MyFactory); 100 static GMRegistry reg(MyFactory);
OLDNEW
« no previous file with comments | « no previous file | gm/gradient_matrix.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698