| 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 10 matching lines...) Expand all Loading... |
| 21 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; | 21 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE }; |
| 22 SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; | 22 SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; |
| 23 SkPaint paint; | 23 SkPaint paint; |
| 24 | 24 |
| 25 paint.setDither(true); | 25 paint.setDither(true); |
| 26 paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos, | 26 paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos, |
| 27 SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode))->unref(); | 27 SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode))->unref(); |
| 28 canvas.drawPaint(paint); | 28 canvas.drawPaint(paint); |
| 29 } | 29 } |
| 30 | 30 |
| 31 static SkShader* MakeBitmapShader(SkShader::TileMode tx, SkShader::TileMode ty, | |
| 32 int w, int h) { | |
| 33 static SkBitmap bmp; | |
| 34 if (bmp.isNull()) { | |
| 35 makebm(&bmp, w/2, h/4); | |
| 36 } | |
| 37 return SkShader::CreateBitmapShader(bmp, tx, ty); | |
| 38 } | |
| 39 | |
| 40 /////////////////////////////////////////////////////////////////////////////// | 31 /////////////////////////////////////////////////////////////////////////////// |
| 41 | 32 |
| 42 struct GradData { | 33 struct GradData { |
| 43 int fCount; | 34 int fCount; |
| 44 const SkColor* fColors; | 35 const SkColor* fColors; |
| 45 const SkScalar* fPos; | 36 const SkScalar* fPos; |
| 46 }; | 37 }; |
| 47 | 38 |
| 48 static const SkColor gColors[] = { | 39 static const SkColor gColors[] = { |
| 49 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK | 40 SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 return SkString("shadertext"); | 99 return SkString("shadertext"); |
| 109 } | 100 } |
| 110 | 101 |
| 111 SkISize onISize() { return SkISize::Make(1450, 500); } | 102 SkISize onISize() { return SkISize::Make(1450, 500); } |
| 112 | 103 |
| 113 virtual void onDraw(SkCanvas* canvas) { | 104 virtual void onDraw(SkCanvas* canvas) { |
| 114 const char text[] = "Shaded Text"; | 105 const char text[] = "Shaded Text"; |
| 115 const int textLen = SK_ARRAY_COUNT(text) - 1; | 106 const int textLen = SK_ARRAY_COUNT(text) - 1; |
| 116 const int pointSize = 36; | 107 const int pointSize = 36; |
| 117 | 108 |
| 118 int w = pointSize * textLen; | 109 const int w = pointSize * textLen; |
| 119 int h = pointSize; | 110 const int h = pointSize; |
| 120 | 111 |
| 121 SkPoint pts[2] = { | 112 SkPoint pts[2] = { |
| 122 { 0, 0 }, | 113 { 0, 0 }, |
| 123 { SkIntToScalar(w), SkIntToScalar(h) } | 114 { SkIntToScalar(w), SkIntToScalar(h) } |
| 124 }; | 115 }; |
| 125 SkScalar textBase = SkIntToScalar(h/2); | 116 SkScalar textBase = SkIntToScalar(h/2); |
| 126 | 117 |
| 127 SkShader::TileMode tileModes[] = { | 118 SkShader::TileMode tileModes[] = { |
| 128 SkShader::kClamp_TileMode, | 119 SkShader::kClamp_TileMode, |
| 129 SkShader::kRepeat_TileMode, | 120 SkShader::kRepeat_TileMode, |
| 130 SkShader::kMirror_TileMode | 121 SkShader::kMirror_TileMode |
| 131 }; | 122 }; |
| 132 | 123 |
| 133 static const int gradCount = SK_ARRAY_COUNT(gGradData) * | 124 static const int gradCount = SK_ARRAY_COUNT(gGradData) * |
| 134 SK_ARRAY_COUNT(gGradMakers); | 125 SK_ARRAY_COUNT(gGradMakers); |
| 135 static const int bmpCount = SK_ARRAY_COUNT(tileModes) * | 126 static const int bmpCount = SK_ARRAY_COUNT(tileModes) * |
| 136 SK_ARRAY_COUNT(tileModes); | 127 SK_ARRAY_COUNT(tileModes); |
| 137 SkShader* shaders[gradCount + bmpCount]; | 128 SkShader* shaders[gradCount + bmpCount]; |
| 138 | 129 |
| 139 int shdIdx = 0; | 130 int shdIdx = 0; |
| 140 for (size_t d = 0; d < SK_ARRAY_COUNT(gGradData); ++d) { | 131 for (size_t d = 0; d < SK_ARRAY_COUNT(gGradData); ++d) { |
| 141 for (size_t m = 0; m < SK_ARRAY_COUNT(gGradMakers); ++m) { | 132 for (size_t m = 0; m < SK_ARRAY_COUNT(gGradMakers); ++m) { |
| 142 shaders[shdIdx++] = gGradMakers[m](pts, | 133 shaders[shdIdx++] = gGradMakers[m](pts, |
| 143 gGradData[d], | 134 gGradData[d], |
| 144 SkShader::kClamp_TileMode); | 135 SkShader::kClamp_TileMode); |
| 145 } | 136 } |
| 146 } | 137 } |
| 138 |
| 139 SkBitmap bm; |
| 140 makebm(&bm, w/16, h/4); |
| 147 for (size_t tx = 0; tx < SK_ARRAY_COUNT(tileModes); ++tx) { | 141 for (size_t tx = 0; tx < SK_ARRAY_COUNT(tileModes); ++tx) { |
| 148 for (size_t ty = 0; ty < SK_ARRAY_COUNT(tileModes); ++ty) { | 142 for (size_t ty = 0; ty < SK_ARRAY_COUNT(tileModes); ++ty) { |
| 149 shaders[shdIdx++] = MakeBitmapShader(tileModes[tx], | 143 shaders[shdIdx++] = SkShader::CreateBitmapShader(bm, tileModes[t
x], tileModes[ty]); |
| 150 tileModes[ty], | |
| 151 w/8, h); | |
| 152 } | 144 } |
| 153 } | 145 } |
| 154 | 146 |
| 155 SkPaint paint; | 147 SkPaint paint; |
| 156 paint.setDither(true); | 148 paint.setDither(true); |
| 157 paint.setAntiAlias(true); | 149 paint.setAntiAlias(true); |
| 158 sk_tool_utils::set_portable_typeface(&paint); | 150 sk_tool_utils::set_portable_typeface(&paint); |
| 159 paint.setTextSize(SkIntToScalar(pointSize)); | 151 paint.setTextSize(SkIntToScalar(pointSize)); |
| 160 | 152 |
| 161 canvas->save(); | 153 canvas->save(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 185 |
| 194 private: | 186 private: |
| 195 typedef GM INHERITED; | 187 typedef GM INHERITED; |
| 196 }; | 188 }; |
| 197 | 189 |
| 198 /////////////////////////////////////////////////////////////////////////////// | 190 /////////////////////////////////////////////////////////////////////////////// |
| 199 | 191 |
| 200 static GM* MyFactory(void*) { return new ShaderTextGM; } | 192 static GM* MyFactory(void*) { return new ShaderTextGM; } |
| 201 static GMRegistry reg(MyFactory); | 193 static GMRegistry reg(MyFactory); |
| 202 } | 194 } |
| OLD | NEW |