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

Side by Side Diff: gm/shaderbounds.cpp

Issue 1790353002: Revert of more shader-->sp conversions (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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
8 #include "gm.h" 7 #include "gm.h"
9 #include "SkGradientShader.h" 8 #include "SkGradientShader.h"
10 9
11 namespace skiagm { 10 namespace skiagm {
12 11
13 static sk_sp<SkShader> MakeLinear(SkScalar width, SkScalar height, bool alternat e, 12 static SkShader* MakeLinear(SkScalar width, SkScalar height, bool alternate,
14 const SkMatrix& localMatrix) { 13 const SkMatrix& localMatrix) {
15 SkPoint pts[2] = { {0, 0}, {width, height}}; 14 SkPoint pts[2] = { {0, 0}, {width, height}};
16 SkColor colors[2] = {SK_ColorRED, SK_ColorGREEN}; 15 SkColor colors[2] = {SK_ColorRED, SK_ColorGREEN};
17 if (alternate) { 16 if (alternate) {
18 pts[1].fY = 0; 17 pts[1].fY = 0;
19 colors[0] = SK_ColorBLUE; 18 colors[0] = SK_ColorBLUE;
20 colors[1] = SK_ColorYELLOW; 19 colors[1] = SK_ColorYELLOW;
21 } 20 }
22 return SkGradientShader::MakeLinear(pts, colors, nullptr, 2, SkShader::kClam p_TileMode, 21 return SkGradientShader::CreateLinear(pts, colors, nullptr, 2,
23 0, &localMatrix); 22 SkShader::kClamp_TileMode, 0, &localMatr ix);
24 } 23 }
25 24
26 /////////////////////////////////////////////////////////////////////////////// 25 ///////////////////////////////////////////////////////////////////////////////
27 26
28 class ShaderBoundsGM : public GM { 27 class ShaderBoundsGM : public GM {
29 public: 28 public:
30 typedef sk_sp<SkShader> (*ShaderGenFunc)(SkScalar width, SkScalar height, 29 typedef SkShader* (*ShaderGenFunc)(SkScalar width, SkScalar height,
31 bool alternate, const SkMatrix& loc alMatrix); 30 bool alternate, const SkMatrix& localMatr ix);
32 ShaderBoundsGM(ShaderGenFunc maker, const SkString& name) 31 ShaderBoundsGM(ShaderGenFunc maker, const SkString& name)
33 : fShaderMaker(maker), 32 : fShaderMaker(maker),
34 fName(name) { 33 fName(name) {
35 } 34 }
36 35
37 protected: 36 protected:
38 37
39 SkString onShortName() override { 38 SkString onShortName() override {
40 return fName; 39 return fName;
41 } 40 }
(...skipping 14 matching lines...) Expand all
56 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(320), 55 canvas->clipRect(SkRect::MakeWH(SkIntToScalar(320),
57 SkIntToScalar(240))); 56 SkIntToScalar(240)));
58 57
59 SkMatrix canvasScale; 58 SkMatrix canvasScale;
60 SkScalar scale = 0.7f; 59 SkScalar scale = 0.7f;
61 canvasScale.setScale(scale, scale); 60 canvasScale.setScale(scale, scale);
62 canvas->concat(canvasScale); 61 canvas->concat(canvasScale);
63 62
64 // Background shader. 63 // Background shader.
65 SkPaint paint; 64 SkPaint paint;
66 paint.setShader(MakeShader(559, 387, false)); 65 paint.setShader(MakeShader(559, 387, false))->unref();
67 SkRect r = SkRect::MakeXYWH(SkIntToScalar(-12), SkIntToScalar(-41), 66 SkRect r = SkRect::MakeXYWH(SkIntToScalar(-12), SkIntToScalar(-41),
68 SkIntToScalar(571), SkIntToScalar(428)); 67 SkIntToScalar(571), SkIntToScalar(428));
69 canvas->drawRect(r, paint); 68 canvas->drawRect(r, paint);
70 69
71 // Constrained shader. 70 // Constrained shader.
72 paint.setShader(MakeShader(101, 151, true)); 71 paint.setShader(MakeShader(101, 151, true))->unref();
73 r = SkRect::MakeXYWH(SkIntToScalar(43), SkIntToScalar(71), 72 r = SkRect::MakeXYWH(SkIntToScalar(43), SkIntToScalar(71),
74 SkIntToScalar(101), SkIntToScalar(151)); 73 SkIntToScalar(101), SkIntToScalar(151));
75 canvas->clipRect(r); 74 canvas->clipRect(r);
76 canvas->drawRect(r, paint); 75 canvas->drawRect(r, paint);
77 } 76 }
78 77
79 sk_sp<SkShader> MakeShader(int width, int height, bool background) { 78 SkShader* MakeShader(int width, int height, bool background) {
80 SkScalar scale = 0.5f; 79 SkScalar scale = 0.5f;
81 if (background) { 80 if (background) {
82 scale = 0.6f; 81 scale = 0.6f;
83 } 82 }
84 SkScalar shaderWidth = width / scale; 83 SkScalar shaderWidth = width / scale;
85 SkScalar shaderHeight = height / scale; 84 SkScalar shaderHeight = height / scale;
86 SkMatrix shaderScale = SkMatrix::MakeScale(scale); 85 SkMatrix shaderScale = SkMatrix::MakeScale(scale);
87 return fShaderMaker(shaderWidth, shaderHeight, background, shaderScale); 86 SkShader* shader = fShaderMaker(shaderWidth, shaderHeight, background, s haderScale);
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 sk_sp<SkShader> MakeShader(bool background); 96 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