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

Side by Side Diff: gm/shaderbounds.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 | « gm/samplerstress.cpp ('k') | gm/shadertext.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 2012 Google Inc. 2 * Copyright 2012 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 #include "gm.h" 8 #include "gm.h"
8 #include "SkGradientShader.h" 9 #include "SkGradientShader.h"
9 10
10 namespace skiagm { 11 namespace skiagm {
11 12
12 static SkShader* MakeLinear(SkScalar width, SkScalar height, bool alternate, 13 static sk_sp<SkShader> MakeLinear(SkScalar width, SkScalar height, bool alternat e,
13 const SkMatrix& localMatrix) { 14 const SkMatrix& localMatrix) {
14 SkPoint pts[2] = { {0, 0}, {width, height}}; 15 SkPoint pts[2] = { {0, 0}, {width, height}};
15 SkColor colors[2] = {SK_ColorRED, SK_ColorGREEN}; 16 SkColor colors[2] = {SK_ColorRED, SK_ColorGREEN};
16 if (alternate) { 17 if (alternate) {
17 pts[1].fY = 0; 18 pts[1].fY = 0;
18 colors[0] = SK_ColorBLUE; 19 colors[0] = SK_ColorBLUE;
19 colors[1] = SK_ColorYELLOW; 20 colors[1] = SK_ColorYELLOW;
20 } 21 }
21 return SkGradientShader::CreateLinear(pts, colors, nullptr, 2, 22 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClam p_TileMode,
22 SkShader::kClamp_TileMode, 0, &localMatr ix); 23 0, &localMatrix);
23 } 24 }
24 25
25 /////////////////////////////////////////////////////////////////////////////// 26 ///////////////////////////////////////////////////////////////////////////////
26 27
27 class ShaderBoundsGM : public GM { 28 class ShaderBoundsGM : public GM {
28 public: 29 public:
29 typedef SkShader* (*ShaderGenFunc)(SkScalar width, SkScalar height, 30 typedef sk_sp<SkShader> (*ShaderGenFunc)(SkScalar width, SkScalar height,
30 bool alternate, const SkMatrix& localMatr ix); 31 bool alternate, const SkMatrix& loc alMatrix);
31 ShaderBoundsGM(ShaderGenFunc maker, const SkString& name) 32 ShaderBoundsGM(ShaderGenFunc maker, const SkString& name)
32 : fShaderMaker(maker), 33 : fShaderMaker(maker),
33 fName(name) { 34 fName(name) {
34 } 35 }
35 36
36 protected: 37 protected:
37 38
38 SkString onShortName() override { 39 SkString onShortName() override {
39 return fName; 40 return fName;
40 } 41 }
(...skipping 14 matching lines...) Expand all
55 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(320), 56 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(320),
56 SkIntToScalar(240))); 57 SkIntToScalar(240)));
57 58
58 SkMatrix canvasScale; 59 SkMatrix canvasScale;
59 SkScalar scale = 0.7f; 60 SkScalar scale = 0.7f;
60 canvasScale.setScale(scale, scale); 61 canvasScale.setScale(scale, scale);
61 canvas->concat(canvasScale); 62 canvas->concat(canvasScale);
62 63
63 // Background shader. 64 // Background shader.
64 SkPaint paint; 65 SkPaint paint;
65 paint.setShader(MakeShader(559, 387, false))->unref(); 66 paint.setShader(MakeShader(559, 387, false));
66 SkRect r = SkRect::MakeXYWH(SkIntToScalar(-12), SkIntToScalar(-41), 67 SkRect r = SkRect::MakeXYWH(SkIntToScalar(-12), SkIntToScalar(-41),
67 SkIntToScalar(571), SkIntToScalar(428)); 68 SkIntToScalar(571), SkIntToScalar(428));
68 canvas->drawRect(r, paint); 69 canvas->drawRect(r, paint);
69 70
70 // Constrained shader. 71 // Constrained shader.
71 paint.setShader(MakeShader(101, 151, true))->unref(); 72 paint.setShader(MakeShader(101, 151, true));
72 r = SkRect::MakeXYWH(SkIntToScalar(43), SkIntToScalar(71), 73 r = SkRect::MakeXYWH(SkIntToScalar(43), SkIntToScalar(71),
73 SkIntToScalar(101), SkIntToScalar(151)); 74 SkIntToScalar(101), SkIntToScalar(151));
74 canvas->clipRect(r); 75 canvas->clipRect(r);
75 canvas->drawRect(r, paint); 76 canvas->drawRect(r, paint);
76 } 77 }
77 78
78 SkShader* MakeShader(int width, int height, bool background) { 79 sk_sp<SkShader> MakeShader(int width, int height, bool background) {
79 SkScalar scale = 0.5f; 80 SkScalar scale = 0.5f;
80 if (background) { 81 if (background) {
81 scale = 0.6f; 82 scale = 0.6f;
82 } 83 }
83 SkScalar shaderWidth = width / scale; 84 SkScalar shaderWidth = width / scale;
84 SkScalar shaderHeight = height / scale; 85 SkScalar shaderHeight = height / scale;
85 SkMatrix shaderScale = SkMatrix::MakeScale(scale); 86 SkMatrix shaderScale = SkMatrix::MakeScale(scale);
86 SkShader* shader = fShaderMaker(shaderWidth, shaderHeight, background, s haderScale); 87 return fShaderMaker(shaderWidth, shaderHeight, background, shaderScale);
87 return shader;
88 } 88 }
89 89
90 private: 90 private:
91 typedef GM INHERITED; 91 typedef GM INHERITED;
92 92
93 ShaderGenFunc fShaderMaker; 93 ShaderGenFunc fShaderMaker;
94 SkString fName; 94 SkString fName;
95 95
96 SkShader* MakeShader(bool background); 96 sk_sp<SkShader> MakeShader(bool background);
97 }; 97 };
98 98
99 /////////////////////////////////////////////////////////////////////////////// 99 ///////////////////////////////////////////////////////////////////////////////
100 100
101 static GM* MyFactory(void*) { 101 static GM* MyFactory(void*) {
102 return new ShaderBoundsGM(MakeLinear, SkString("shaderbounds_linear")); 102 return new ShaderBoundsGM(MakeLinear, SkString("shaderbounds_linear"));
103 } 103 }
104 static GMRegistry reg(MyFactory); 104 static GMRegistry reg(MyFactory);
105 105
106 } 106 }
OLDNEW
« no previous file with comments | « gm/samplerstress.cpp ('k') | gm/shadertext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698