Index: samplecode/SampleShaderText.cpp |
diff --git a/samplecode/SampleShaderText.cpp b/samplecode/SampleShaderText.cpp |
index 6f23a0b6b31df4ee5d5b452207ce860e2993cdb1..c7048ab401c37c5a928c8206ffc9ab5e08167303 100644 |
--- a/samplecode/SampleShaderText.cpp |
+++ b/samplecode/SampleShaderText.cpp |
@@ -1,14 +1,15 @@ |
+ |
/* |
* Copyright 2011 Google Inc. |
* |
* Use of this source code is governed by a BSD-style license that can be |
* found in the LICENSE file. |
*/ |
- |
#include "SampleCode.h" |
#include "SkView.h" |
#include "SkCanvas.h" |
#include "SkGradientShader.h" |
+#include "SkUnitMappers.h" |
static void makebm(SkBitmap* bm, int w, int h) { |
bm->allocN32Pixels(w, h); |
@@ -21,9 +22,15 @@ |
SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 }; |
SkPaint paint; |
+ SkUnitMapper* um = NULL; |
+ |
+ um = new SkCosineMapper; |
+ |
+ SkAutoUnref au(um); |
+ |
paint.setDither(true); |
paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos, |
- SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode))->unref(); |
+ SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode, um))->unref(); |
canvas.drawPaint(paint); |
} |
@@ -53,26 +60,32 @@ |
{ 5, gColors, NULL }, |
}; |
-static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) { |
- return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCount, tm); |
-} |
- |
-static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) { |
+static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, |
+ SkShader::TileMode tm, SkUnitMapper* mapper) { |
+ return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, |
+ data.fCount, tm, mapper); |
+} |
+ |
+static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, |
+ SkShader::TileMode tm, SkUnitMapper* mapper) { |
SkPoint center; |
center.set(SkScalarAve(pts[0].fX, pts[1].fX), |
SkScalarAve(pts[0].fY, pts[1].fY)); |
return SkGradientShader::CreateRadial(center, center.fX, data.fColors, |
- data.fPos, data.fCount, tm); |
-} |
- |
-static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) { |
+ data.fPos, data.fCount, tm, mapper); |
+} |
+ |
+static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, |
+ SkShader::TileMode tm, SkUnitMapper* mapper) { |
SkPoint center; |
center.set(SkScalarAve(pts[0].fX, pts[1].fX), |
SkScalarAve(pts[0].fY, pts[1].fY)); |
- return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount); |
-} |
- |
-static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) { |
+ return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, |
+ data.fPos, data.fCount, mapper); |
+} |
+ |
+static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data, |
+ SkShader::TileMode tm, SkUnitMapper* mapper) { |
SkPoint center0, center1; |
center0.set(SkScalarAve(pts[0].fX, pts[1].fX), |
SkScalarAve(pts[0].fY, pts[1].fY)); |
@@ -81,11 +94,11 @@ |
return SkGradientShader::CreateTwoPointRadial( |
center1, (pts[1].fX - pts[0].fX) / 7, |
center0, (pts[1].fX - pts[0].fX) / 2, |
- data.fColors, data.fPos, data.fCount, tm); |
-} |
- |
-typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm); |
- |
+ data.fColors, data.fPos, data.fCount, tm, mapper); |
+} |
+ |
+typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, |
+ SkShader::TileMode tm, SkUnitMapper* mapper); |
static const GradMaker gGradMakers[] = { |
MakeLinear, MakeRadial, MakeSweep, Make2Radial |
}; |
@@ -139,7 +152,8 @@ |
for (size_t m = 0; m < SK_ARRAY_COUNT(gGradMakers); ++m) { |
shaders[shdIdx++] = gGradMakers[m](pts, |
gGradData[d], |
- SkShader::kClamp_TileMode); |
+ SkShader::kClamp_TileMode, |
+ NULL); |
} |
} |
for (size_t tx = 0; tx < SK_ARRAY_COUNT(tileModes); ++tx) { |