| OLD | NEW |
| 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 "gm.h" | 8 #include "gm.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkGradientShader.h" | 10 #include "SkGradientShader.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 } | 30 } |
| 31 | 31 |
| 32 /////////////////////////////////////////////////////////////////////////////// | 32 /////////////////////////////////////////////////////////////////////////////// |
| 33 | 33 |
| 34 struct GradData { | 34 struct GradData { |
| 35 int fCount; | 35 int fCount; |
| 36 const SkColor* fColors; | 36 const SkColor* fColors; |
| 37 const SkScalar* fPos; | 37 const SkScalar* fPos; |
| 38 }; | 38 }; |
| 39 | 39 |
| 40 static const SkColor gColors[] = { | 40 constexpr SkColor gColors[] = { |
| 41 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK | 41 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 static const GradData gGradData[] = { | 44 constexpr GradData gGradData[] = { |
| 45 { 2, gColors, nullptr }, | 45 { 2, gColors, nullptr }, |
| 46 { 5, gColors, nullptr }, | 46 { 5, gColors, nullptr }, |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data, Sk
Shader::TileMode tm) { | 49 static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data, Sk
Shader::TileMode tm) { |
| 50 return SkGradientShader::MakeLinear(pts, data.fColors, data.fPos, data.fCoun
t, tm); | 50 return SkGradientShader::MakeLinear(pts, data.fColors, data.fPos, data.fCoun
t, tm); |
| 51 } | 51 } |
| 52 | 52 |
| 53 static sk_sp<SkShader> MakeRadial(const SkPoint pts[2], const GradData& data, Sk
Shader::TileMode tm) { | 53 static sk_sp<SkShader> MakeRadial(const SkPoint pts[2], const GradData& data, Sk
Shader::TileMode tm) { |
| 54 SkPoint center; | 54 SkPoint center; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 72 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), | 72 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5), |
| 73 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); | 73 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4)); |
| 74 return SkGradientShader::MakeTwoPointConical( | 74 return SkGradientShader::MakeTwoPointConical( |
| 75 center1, (pts[1].fX - pts[0].fX) / 7, | 75 center1, (pts[1].fX - pts[0].fX) / 7, |
| 76 center0, (pts[1].fX - pts[0].fX) / 2, | 76 center0, (pts[1].fX - pts[0].fX) / 2, |
| 77 data.fColors, data.fPos, data.fCount, tm); | 77 data.fColors, data.fPos, data.fCount, tm); |
| 78 } | 78 } |
| 79 | 79 |
| 80 typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data,
SkShader::TileMode tm); | 80 typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData& data,
SkShader::TileMode tm); |
| 81 | 81 |
| 82 static const GradMaker gGradMakers[] = { | 82 constexpr GradMaker gGradMakers[] = { |
| 83 MakeLinear, MakeRadial, MakeSweep, Make2Conical | 83 MakeLinear, MakeRadial, MakeSweep, Make2Conical |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 /////////////////////////////////////////////////////////////////////////////// | 86 /////////////////////////////////////////////////////////////////////////////// |
| 87 | 87 |
| 88 class ShaderTextGM : public GM { | 88 class ShaderTextGM : public GM { |
| 89 public: | 89 public: |
| 90 ShaderTextGM() { | 90 ShaderTextGM() { |
| 91 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); | 91 this->setBGColor(sk_tool_utils::color_to_565(0xFFDDDDDD)); |
| 92 } | 92 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 112 { SkIntToScalar(w), SkIntToScalar(h) } | 112 { SkIntToScalar(w), SkIntToScalar(h) } |
| 113 }; | 113 }; |
| 114 SkScalar textBase = SkIntToScalar(h/2); | 114 SkScalar textBase = SkIntToScalar(h/2); |
| 115 | 115 |
| 116 SkShader::TileMode tileModes[] = { | 116 SkShader::TileMode tileModes[] = { |
| 117 SkShader::kClamp_TileMode, | 117 SkShader::kClamp_TileMode, |
| 118 SkShader::kRepeat_TileMode, | 118 SkShader::kRepeat_TileMode, |
| 119 SkShader::kMirror_TileMode | 119 SkShader::kMirror_TileMode |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 static const int gradCount = SK_ARRAY_COUNT(gGradData) * | 122 constexpr int gradCount = SK_ARRAY_COUNT(gGradData) * |
| 123 SK_ARRAY_COUNT(gGradMakers); | 123 SK_ARRAY_COUNT(gGradMakers); |
| 124 static const int bmpCount = SK_ARRAY_COUNT(tileModes) * | 124 constexpr int bmpCount = SK_ARRAY_COUNT(tileModes) * |
| 125 SK_ARRAY_COUNT(tileModes); | 125 SK_ARRAY_COUNT(tileModes); |
| 126 sk_sp<SkShader> shaders[gradCount + bmpCount]; | 126 sk_sp<SkShader> shaders[gradCount + bmpCount]; |
| 127 | 127 |
| 128 int shdIdx = 0; | 128 int shdIdx = 0; |
| 129 for (size_t d = 0; d < SK_ARRAY_COUNT(gGradData); ++d) { | 129 for (size_t d = 0; d < SK_ARRAY_COUNT(gGradData); ++d) { |
| 130 for (size_t m = 0; m < SK_ARRAY_COUNT(gGradMakers); ++m) { | 130 for (size_t m = 0; m < SK_ARRAY_COUNT(gGradMakers); ++m) { |
| 131 shaders[shdIdx++] = gGradMakers[m](pts, | 131 shaders[shdIdx++] = gGradMakers[m](pts, |
| 132 gGradData[d], | 132 gGradData[d], |
| 133 SkShader::kClamp_TileMode); | 133 SkShader::kClamp_TileMode); |
| 134 } | 134 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 151 canvas->save(); | 151 canvas->save(); |
| 152 canvas->translate(SkIntToScalar(20), SkIntToScalar(10)); | 152 canvas->translate(SkIntToScalar(20), SkIntToScalar(10)); |
| 153 | 153 |
| 154 SkPath path; | 154 SkPath path; |
| 155 path.arcTo(SkRect::MakeXYWH(SkIntToScalar(-40), SkIntToScalar(15), | 155 path.arcTo(SkRect::MakeXYWH(SkIntToScalar(-40), SkIntToScalar(15), |
| 156 SkIntToScalar(300), SkIntToScalar(90)), | 156 SkIntToScalar(300), SkIntToScalar(90)), |
| 157 SkIntToScalar(225), SkIntToScalar(90), | 157 SkIntToScalar(225), SkIntToScalar(90), |
| 158 false); | 158 false); |
| 159 path.close(); | 159 path.close(); |
| 160 | 160 |
| 161 static const int testsPerCol = 8; | 161 constexpr int testsPerCol = 8; |
| 162 static const int rowHeight = 60; | 162 constexpr int rowHeight = 60; |
| 163 static const int colWidth = 300; | 163 constexpr int colWidth = 300; |
| 164 canvas->save(); | 164 canvas->save(); |
| 165 for (int s = 0; s < static_cast<int>(SK_ARRAY_COUNT(shaders)); s++) { | 165 for (int s = 0; s < static_cast<int>(SK_ARRAY_COUNT(shaders)); s++) { |
| 166 canvas->save(); | 166 canvas->save(); |
| 167 int i = 2*s; | 167 int i = 2*s; |
| 168 canvas->translate(SkIntToScalar((i / testsPerCol) * colWidth), | 168 canvas->translate(SkIntToScalar((i / testsPerCol) * colWidth), |
| 169 SkIntToScalar((i % testsPerCol) * rowHeight)); | 169 SkIntToScalar((i % testsPerCol) * rowHeight)); |
| 170 paint.setShader(shaders[s]); | 170 paint.setShader(shaders[s]); |
| 171 canvas->drawText(text, textLen, 0, textBase, paint); | 171 canvas->drawText(text, textLen, 0, textBase, paint); |
| 172 canvas->restore(); | 172 canvas->restore(); |
| 173 canvas->save(); | 173 canvas->save(); |
| 174 ++i; | 174 ++i; |
| 175 canvas->translate(SkIntToScalar((i / testsPerCol) * colWidth), | 175 canvas->translate(SkIntToScalar((i / testsPerCol) * colWidth), |
| 176 SkIntToScalar((i % testsPerCol) * rowHeight)); | 176 SkIntToScalar((i % testsPerCol) * rowHeight)); |
| 177 canvas->drawTextOnPath(text, textLen, path, nullptr, paint); | 177 canvas->drawTextOnPath(text, textLen, path, nullptr, paint); |
| 178 canvas->restore(); | 178 canvas->restore(); |
| 179 } | 179 } |
| 180 canvas->restore(); | 180 canvas->restore(); |
| 181 | 181 |
| 182 } | 182 } |
| 183 | 183 |
| 184 private: | 184 private: |
| 185 typedef GM INHERITED; | 185 typedef GM INHERITED; |
| 186 }; | 186 }; |
| 187 | 187 |
| 188 /////////////////////////////////////////////////////////////////////////////// | 188 /////////////////////////////////////////////////////////////////////////////// |
| 189 | 189 |
| 190 static GM* MyFactory(void*) { return new ShaderTextGM; } | 190 static GM* MyFactory(void*) { return new ShaderTextGM; } |
| 191 static GMRegistry reg(MyFactory); | 191 static GMRegistry reg(MyFactory); |
| 192 } | 192 } |
| OLD | NEW |