remove unused (by clients) SkUnitMapper
BUG=skia: R=robertphillips@google.com, scroggo@google.com, george@mozilla.com Author: reed@google.com Review URL: https://codereview.chromium.org/283273002 git-svn-id: http://skia.googlecode.com/svn/trunk@14761 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
61744ec1d2
commit
ee0cac336c
@ -13,7 +13,6 @@
|
|||||||
#include "SkPaint.h"
|
#include "SkPaint.h"
|
||||||
#include "SkShader.h"
|
#include "SkShader.h"
|
||||||
#include "SkString.h"
|
#include "SkString.h"
|
||||||
#include "SkUnitMapper.h"
|
|
||||||
|
|
||||||
struct GradData {
|
struct GradData {
|
||||||
int fCount;
|
int fCount;
|
||||||
@ -45,38 +44,33 @@ static const GradData gGradData[] = {
|
|||||||
|
|
||||||
/// Ignores scale
|
/// Ignores scale
|
||||||
static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, float scale) {
|
||||||
float scale) {
|
return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCount, tm);
|
||||||
return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos,
|
|
||||||
data.fCount, tm, mapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, float scale) {
|
||||||
float scale) {
|
|
||||||
SkPoint center;
|
SkPoint center;
|
||||||
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
return SkGradientShader::CreateRadial(center, center.fX * scale,
|
return SkGradientShader::CreateRadial(center, center.fX * scale,
|
||||||
data.fColors,
|
data.fColors,
|
||||||
data.fPos, data.fCount, tm, mapper);
|
data.fPos, data.fCount, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ignores scale
|
/// Ignores scale
|
||||||
static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, float scale) {
|
||||||
float scale) {
|
|
||||||
SkPoint center;
|
SkPoint center;
|
||||||
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors,
|
return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors,
|
||||||
data.fPos, data.fCount, mapper);
|
data.fPos, data.fCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ignores scale
|
/// Ignores scale
|
||||||
static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, float scale) {
|
||||||
float scale) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
@ -85,13 +79,12 @@ static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
|
|||||||
return SkGradientShader::CreateTwoPointRadial(
|
return SkGradientShader::CreateTwoPointRadial(
|
||||||
center1, (pts[1].fX - pts[0].fX) / 7,
|
center1, (pts[1].fX - pts[0].fX) / 7,
|
||||||
center0, (pts[1].fX - pts[0].fX) / 2,
|
center0, (pts[1].fX - pts[0].fX) / 2,
|
||||||
data.fColors, data.fPos, data.fCount, tm, mapper);
|
data.fColors, data.fPos, data.fCount, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ignores scale
|
/// Ignores scale
|
||||||
static SkShader* MakeConical(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeConical(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, float scale) {
|
||||||
float scale) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
@ -99,13 +92,12 @@ static SkShader* MakeConical(const SkPoint pts[2], const GradData& data,
|
|||||||
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
||||||
return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
|
return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
|
||||||
center0, (pts[1].fX - pts[0].fX) / 2,
|
center0, (pts[1].fX - pts[0].fX) / 2,
|
||||||
data.fColors, data.fPos, data.fCount, tm, mapper);
|
data.fColors, data.fPos, data.fCount, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ignores scale
|
/// Ignores scale
|
||||||
static SkShader* MakeConicalZeroRad(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeConicalZeroRad(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, float scale) {
|
||||||
float scale) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
@ -113,13 +105,12 @@ static SkShader* MakeConicalZeroRad(const SkPoint pts[2], const GradData& data,
|
|||||||
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
||||||
return SkGradientShader::CreateTwoPointConical(center1, 0.0,
|
return SkGradientShader::CreateTwoPointConical(center1, 0.0,
|
||||||
center0, (pts[1].fX - pts[0].fX) / 2,
|
center0, (pts[1].fX - pts[0].fX) / 2,
|
||||||
data.fColors, data.fPos, data.fCount, tm, mapper);
|
data.fColors, data.fPos, data.fCount, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ignores scale
|
/// Ignores scale
|
||||||
static SkShader* MakeConicalOutside(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeConicalOutside(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, float scale) {
|
||||||
float scale) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
|
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
|
||||||
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
||||||
@ -128,13 +119,12 @@ static SkShader* MakeConicalOutside(const SkPoint pts[2], const GradData& data,
|
|||||||
return SkGradientShader::CreateTwoPointConical(center0, radius0,
|
return SkGradientShader::CreateTwoPointConical(center0, radius0,
|
||||||
center1, radius1,
|
center1, radius1,
|
||||||
data.fColors, data.fPos,
|
data.fColors, data.fPos,
|
||||||
data.fCount, tm, mapper);
|
data.fCount, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Ignores scale
|
/// Ignores scale
|
||||||
static SkShader* MakeConicalOutsideZeroRad(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeConicalOutsideZeroRad(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, float scale) {
|
||||||
float scale) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
|
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
|
||||||
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
||||||
@ -143,12 +133,11 @@ static SkShader* MakeConicalOutsideZeroRad(const SkPoint pts[2], const GradData&
|
|||||||
return SkGradientShader::CreateTwoPointConical(center0, 0.0,
|
return SkGradientShader::CreateTwoPointConical(center0, 0.0,
|
||||||
center1, radius1,
|
center1, radius1,
|
||||||
data.fColors, data.fPos,
|
data.fColors, data.fPos,
|
||||||
data.fCount, tm, mapper);
|
data.fCount, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
|
typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, float scale);
|
||||||
float scale);
|
|
||||||
|
|
||||||
static const struct {
|
static const struct {
|
||||||
GradMaker fMaker;
|
GradMaker fMaker;
|
||||||
@ -240,7 +229,7 @@ public:
|
|||||||
{ SkIntToScalar(W), SkIntToScalar(H) }
|
{ SkIntToScalar(W), SkIntToScalar(H) }
|
||||||
};
|
};
|
||||||
|
|
||||||
fShader = gGrads[gradType].fMaker(pts, data, tm, NULL, scale);
|
fShader = gGrads[gradType].fMaker(pts, data, tm, scale);
|
||||||
fGeomType = geomType;
|
fGeomType = geomType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,3 +41,16 @@ canvas-layer-state
|
|||||||
# bsalomon: https://codereview.chromium.org/264303008/
|
# bsalomon: https://codereview.chromium.org/264303008/
|
||||||
# bsalomon@ will rebaseline this test
|
# bsalomon@ will rebaseline this test
|
||||||
ninepatch-stretch
|
ninepatch-stretch
|
||||||
|
|
||||||
|
|
||||||
|
# These are part of picture-version 27 -- removal of SkUnitMapp
|
||||||
|
# just need to be rebaselined
|
||||||
|
scaled_tilemode_bitmap
|
||||||
|
scaled_tilemodes_npot
|
||||||
|
scaled_tilemodes
|
||||||
|
tilemode_bitmap
|
||||||
|
tilemodes_npot
|
||||||
|
tilemodes
|
||||||
|
shadertext3
|
||||||
|
shadertext
|
||||||
|
shadertext2
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
#include "SkDraw.h"
|
#include "SkDraw.h"
|
||||||
#include "SkGradientShader.h"
|
#include "SkGradientShader.h"
|
||||||
#include "SkGraphics.h"
|
#include "SkGraphics.h"
|
||||||
#include "SkUnitMappers.h"
|
|
||||||
|
|
||||||
class HelloSkia : public SkExample {
|
class HelloSkia : public SkExample {
|
||||||
public:
|
public:
|
||||||
@ -50,12 +49,9 @@ protected:
|
|||||||
};
|
};
|
||||||
SkColor linearColors[] = {SK_ColorGREEN, SK_ColorBLACK};
|
SkColor linearColors[] = {SK_ColorGREEN, SK_ColorBLACK};
|
||||||
|
|
||||||
SkUnitMapper* linearMapper = new SkDiscreteMapper(100);
|
|
||||||
SkAutoUnref lm_deleter(linearMapper);
|
|
||||||
|
|
||||||
SkShader* shader = SkGradientShader::CreateLinear(
|
SkShader* shader = SkGradientShader::CreateLinear(
|
||||||
linearPoints, linearColors, NULL, 2,
|
linearPoints, linearColors, NULL, 2,
|
||||||
SkShader::kMirror_TileMode, linearMapper);
|
SkShader::kMirror_TileMode);
|
||||||
SkAutoUnref shader_deleter(shader);
|
SkAutoUnref shader_deleter(shader);
|
||||||
|
|
||||||
paint.setShader(shader);
|
paint.setShader(shader);
|
||||||
|
@ -150,7 +150,6 @@
|
|||||||
#include "SkTSearch.h"
|
#include "SkTSearch.h"
|
||||||
#include "SkTypeface.h"
|
#include "SkTypeface.h"
|
||||||
#include "SkTypes.h"
|
#include "SkTypes.h"
|
||||||
#include "SkUnitMapper.h"
|
|
||||||
#include "SkUnPreMultiply.h"
|
#include "SkUnPreMultiply.h"
|
||||||
#include "SkUtils.h"
|
#include "SkUtils.h"
|
||||||
#include "SkWeakRefCnt.h"
|
#include "SkWeakRefCnt.h"
|
||||||
|
@ -29,8 +29,7 @@ protected:
|
|||||||
SkPaint paint;
|
SkPaint paint;
|
||||||
uint32_t flags = doPreMul ? SkGradientShader::kInterpolateColorsInPremul_Flag : 0;
|
uint32_t flags = doPreMul ? SkGradientShader::kInterpolateColorsInPremul_Flag : 0;
|
||||||
SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, 2,
|
SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, 2,
|
||||||
SkShader::kClamp_TileMode,
|
SkShader::kClamp_TileMode, flags, NULL);
|
||||||
NULL, flags);
|
|
||||||
paint.setShader(s)->unref();
|
paint.setShader(s)->unref();
|
||||||
canvas->drawRect(r, paint);
|
canvas->drawRect(r, paint);
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ public:
|
|||||||
SkMatrix local;
|
SkMatrix local;
|
||||||
local.setRotate(180);
|
local.setRotate(180);
|
||||||
SkShader* s = SkGradientShader::CreateSweep(0,0, colors, NULL,
|
SkShader* s = SkGradientShader::CreateSweep(0,0, colors, NULL,
|
||||||
SK_ARRAY_COUNT(colors), NULL, 0, &local);
|
SK_ARRAY_COUNT(colors), 0, &local);
|
||||||
|
|
||||||
SkPaint paint;
|
SkPaint paint;
|
||||||
paint.setAntiAlias(true);
|
paint.setAntiAlias(true);
|
||||||
|
@ -46,7 +46,7 @@ static SkBitmap make_bmp(int w, int h) {
|
|||||||
colors, pos,
|
colors, pos,
|
||||||
SK_ARRAY_COUNT(colors),
|
SK_ARRAY_COUNT(colors),
|
||||||
SkShader::kRepeat_TileMode,
|
SkShader::kRepeat_TileMode,
|
||||||
NULL, 0, &mat))->unref();
|
0, &mat))->unref();
|
||||||
canvas.drawRect(rect, paint);
|
canvas.drawRect(rect, paint);
|
||||||
rect.inset(wScalar / 8, hScalar / 8);
|
rect.inset(wScalar / 8, hScalar / 8);
|
||||||
mat.preTranslate(6 * wScalar, 6 * hScalar);
|
mat.preTranslate(6 * wScalar, 6 * hScalar);
|
||||||
|
@ -63,7 +63,7 @@ static void makebm(SkBitmap* bm, int w, int h) {
|
|||||||
colors, pos,
|
colors, pos,
|
||||||
SK_ARRAY_COUNT(colors),
|
SK_ARRAY_COUNT(colors),
|
||||||
SkShader::kRepeat_TileMode,
|
SkShader::kRepeat_TileMode,
|
||||||
NULL, 0, &mat))->unref();
|
0, &mat))->unref();
|
||||||
canvas.drawRect(rect, paint);
|
canvas.drawRect(rect, paint);
|
||||||
rect.inset(wScalar / 8, hScalar / 8);
|
rect.inset(wScalar / 8, hScalar / 8);
|
||||||
mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4);
|
mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4);
|
||||||
|
@ -35,33 +35,28 @@ static const GradData gGradData[] = {
|
|||||||
// { 2, gCol2, NULL },
|
// { 2, gCol2, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCount, tm);
|
||||||
return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos,
|
|
||||||
data.fCount, tm, mapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
|
||||||
SkPoint center;
|
SkPoint center;
|
||||||
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
|
return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
|
||||||
data.fPos, data.fCount, tm, mapper);
|
data.fPos, data.fCount, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader::TileMode) {
|
||||||
SkShader::TileMode, SkUnitMapper* mapper) {
|
|
||||||
SkPoint center;
|
SkPoint center;
|
||||||
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors,
|
return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount);
|
||||||
data.fPos, data.fCount, mapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
|
typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm);
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper);
|
|
||||||
static const GradMaker gGradMakers[] = {
|
static const GradMaker gGradMakers[] = {
|
||||||
MakeLinear, MakeRadial, MakeSweep,
|
MakeLinear, MakeRadial, MakeSweep,
|
||||||
};
|
};
|
||||||
@ -95,7 +90,7 @@ protected:
|
|||||||
for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
|
||||||
canvas->save();
|
canvas->save();
|
||||||
for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) {
|
for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) {
|
||||||
SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, NULL);
|
SkShader* shader = gGradMakers[j](pts, gGradData[i], tm);
|
||||||
paint.setShader(shader)->unref();
|
paint.setShader(shader)->unref();
|
||||||
canvas->drawRect(r, paint);
|
canvas->drawRect(r, paint);
|
||||||
canvas->translate(0, SkIntToScalar(120));
|
canvas->translate(0, SkIntToScalar(120));
|
||||||
|
@ -63,7 +63,7 @@ static const int IMAGES_X = 4; // number of images per row
|
|||||||
|
|
||||||
static SkShader* make_linear_gradient(const SkPoint pts[2], const SkMatrix& localMatrix) {
|
static SkShader* make_linear_gradient(const SkPoint pts[2], const SkMatrix& localMatrix) {
|
||||||
return SkGradientShader::CreateLinear(pts, gColors, NULL, SK_ARRAY_COUNT(gColors),
|
return SkGradientShader::CreateLinear(pts, gColors, NULL, SK_ARRAY_COUNT(gColors),
|
||||||
SkShader::kClamp_TileMode, NULL, 0, &localMatrix);
|
SkShader::kClamp_TileMode, 0, &localMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* make_radial_gradient(const SkPoint pts[2], const SkMatrix& localMatrix) {
|
static SkShader* make_radial_gradient(const SkPoint pts[2], const SkMatrix& localMatrix) {
|
||||||
@ -72,7 +72,7 @@ static SkShader* make_radial_gradient(const SkPoint pts[2], const SkMatrix& loca
|
|||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
float radius = (center - pts[0]).length();
|
float radius = (center - pts[0]).length();
|
||||||
return SkGradientShader::CreateRadial(center, radius, gColors, NULL, SK_ARRAY_COUNT(gColors),
|
return SkGradientShader::CreateRadial(center, radius, gColors, NULL, SK_ARRAY_COUNT(gColors),
|
||||||
SkShader::kClamp_TileMode, NULL, 0, &localMatrix);
|
SkShader::kClamp_TileMode, 0, &localMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw_gradients(SkCanvas* canvas,
|
static void draw_gradients(SkCanvas* canvas,
|
||||||
|
@ -40,35 +40,31 @@ static const GradData gGradData[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix) {
|
||||||
const SkMatrix& localMatrix) {
|
|
||||||
return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos,
|
return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos,
|
||||||
data.fCount, tm, mapper, 0, &localMatrix);
|
data.fCount, tm, 0, &localMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix) {
|
||||||
const SkMatrix& localMatrix) {
|
|
||||||
SkPoint center;
|
SkPoint center;
|
||||||
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
|
return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
|
||||||
data.fPos, data.fCount, tm, mapper, 0, &localMatrix);
|
data.fPos, data.fCount, tm, 0, &localMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode, SkUnitMapper* mapper,
|
SkShader::TileMode, const SkMatrix& localMatrix) {
|
||||||
const SkMatrix& localMatrix) {
|
|
||||||
SkPoint center;
|
SkPoint center;
|
||||||
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors,
|
return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors,
|
||||||
data.fPos, data.fCount, mapper, 0, &localMatrix);
|
data.fPos, data.fCount, 0, &localMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix) {
|
||||||
const SkMatrix& localMatrix) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
@ -77,13 +73,12 @@ static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
|
|||||||
return SkGradientShader::CreateTwoPointRadial(
|
return SkGradientShader::CreateTwoPointRadial(
|
||||||
center1, (pts[1].fX - pts[0].fX) / 7,
|
center1, (pts[1].fX - pts[0].fX) / 7,
|
||||||
center0, (pts[1].fX - pts[0].fX) / 2,
|
center0, (pts[1].fX - pts[0].fX) / 2,
|
||||||
data.fColors, data.fPos, data.fCount, tm, mapper,
|
data.fColors, data.fPos, data.fCount, tm,
|
||||||
0, &localMatrix);
|
0, &localMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix) {
|
||||||
const SkMatrix& localMatrix) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
|
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
|
||||||
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
||||||
@ -92,13 +87,11 @@ static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data,
|
|||||||
return SkGradientShader::CreateTwoPointConical(center1, radius1,
|
return SkGradientShader::CreateTwoPointConical(center1, radius1,
|
||||||
center0, radius0,
|
center0, radius0,
|
||||||
data.fColors, data.fPos,
|
data.fColors, data.fPos,
|
||||||
data.fCount, tm, mapper,
|
data.fCount, tm, 0, &localMatrix);
|
||||||
0, &localMatrix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
|
typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix);
|
||||||
const SkMatrix& localMatrix);
|
|
||||||
static const GradMaker gGradMakers[] = {
|
static const GradMaker gGradMakers[] = {
|
||||||
MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2Conical
|
MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2Conical
|
||||||
};
|
};
|
||||||
@ -144,7 +137,7 @@ protected:
|
|||||||
scale.postTranslate(25.f, 25.f);
|
scale.postTranslate(25.f, 25.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, NULL, scale);
|
SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, scale);
|
||||||
|
|
||||||
paint.setShader(shader);
|
paint.setShader(shader);
|
||||||
canvas->drawRect(r, paint);
|
canvas->drawRect(r, paint);
|
||||||
@ -202,7 +195,7 @@ protected:
|
|||||||
perspective.setSkewX(SkScalarDiv(SkIntToScalar((unsigned) i+1),
|
perspective.setSkewX(SkScalarDiv(SkIntToScalar((unsigned) i+1),
|
||||||
SkIntToScalar(10)));
|
SkIntToScalar(10)));
|
||||||
|
|
||||||
SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, NULL, perspective);
|
SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, perspective);
|
||||||
|
|
||||||
paint.setShader(shader);
|
paint.setShader(shader);
|
||||||
canvas->drawRect(r, paint);
|
canvas->drawRect(r, paint);
|
||||||
@ -327,7 +320,7 @@ protected:
|
|||||||
SkShader* shader = SkGradientShader::CreateRadial(
|
SkShader* shader = SkGradientShader::CreateRadial(
|
||||||
SkPoint(center),
|
SkPoint(center),
|
||||||
SkIntToScalar(200), gColors, NULL, 5,
|
SkIntToScalar(200), gColors, NULL, 5,
|
||||||
SkShader::kClamp_TileMode, NULL);
|
SkShader::kClamp_TileMode);
|
||||||
paint.setShader(shader);
|
paint.setShader(shader);
|
||||||
canvas->drawRect(r, paint);
|
canvas->drawRect(r, paint);
|
||||||
shader->unref();
|
shader->unref();
|
||||||
@ -422,17 +415,17 @@ protected:
|
|||||||
SkAutoTUnref<SkShader> sweep(
|
SkAutoTUnref<SkShader> sweep(
|
||||||
SkGradientShader::CreateSweep(cx, cy, sweep_colors,
|
SkGradientShader::CreateSweep(cx, cy, sweep_colors,
|
||||||
NULL, SK_ARRAY_COUNT(sweep_colors),
|
NULL, SK_ARRAY_COUNT(sweep_colors),
|
||||||
NULL, flags[i]));
|
flags[i], NULL));
|
||||||
SkAutoTUnref<SkShader> radial1(
|
SkAutoTUnref<SkShader> radial1(
|
||||||
SkGradientShader::CreateRadial(center, radius, colors1,
|
SkGradientShader::CreateRadial(center, radius, colors1,
|
||||||
NULL, SK_ARRAY_COUNT(colors1),
|
NULL, SK_ARRAY_COUNT(colors1),
|
||||||
SkShader::kClamp_TileMode,
|
SkShader::kClamp_TileMode,
|
||||||
NULL, flags[i]));
|
flags[i], NULL));
|
||||||
SkAutoTUnref<SkShader> radial2(
|
SkAutoTUnref<SkShader> radial2(
|
||||||
SkGradientShader::CreateRadial(center, radius, colors2,
|
SkGradientShader::CreateRadial(center, radius, colors2,
|
||||||
NULL, SK_ARRAY_COUNT(colors2),
|
NULL, SK_ARRAY_COUNT(colors2),
|
||||||
SkShader::kClamp_TileMode,
|
SkShader::kClamp_TileMode,
|
||||||
NULL, flags[i]));
|
flags[i], NULL));
|
||||||
paint1.setShader(sweep);
|
paint1.setShader(sweep);
|
||||||
paint2.setShader(radial1);
|
paint2.setShader(radial1);
|
||||||
paint3.setShader(radial2);
|
paint3.setShader(radial2);
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2014 Google Inc.
|
* Copyright 2014 Google Inc.
|
||||||
*
|
*
|
||||||
* Use of this source code is governed by a BSD-style license that can be
|
* Use of this source code is governed by a BSD-style license that can be
|
||||||
* found in the LICENSE file.
|
* found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gm.h"
|
#include "gm.h"
|
||||||
#include "SkGradientShader.h"
|
#include "SkGradientShader.h"
|
||||||
|
|
||||||
@ -38,8 +38,7 @@ static const GradData gGradData[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static SkShader* Make2ConicalOutside(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2ConicalOutside(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix) {
|
||||||
const SkMatrix& localMatrix) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
|
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
|
||||||
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
||||||
@ -48,13 +47,11 @@ static SkShader* Make2ConicalOutside(const SkPoint pts[2], const GradData& data,
|
|||||||
return SkGradientShader::CreateTwoPointConical(center0, radius0,
|
return SkGradientShader::CreateTwoPointConical(center0, radius0,
|
||||||
center1, radius1,
|
center1, radius1,
|
||||||
data.fColors, data.fPos,
|
data.fColors, data.fPos,
|
||||||
data.fCount, tm, mapper,
|
data.fCount, tm, 0, &localMatrix);
|
||||||
0, &localMatrix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix) {
|
||||||
const SkMatrix& localMatrix) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
|
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
|
||||||
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
||||||
@ -63,13 +60,11 @@ static SkShader* Make2ConicalOutsideFlip(const SkPoint pts[2], const GradData& d
|
|||||||
return SkGradientShader::CreateTwoPointConical(center1, radius1,
|
return SkGradientShader::CreateTwoPointConical(center1, radius1,
|
||||||
center0, radius0,
|
center0, radius0,
|
||||||
data.fColors, data.fPos,
|
data.fColors, data.fPos,
|
||||||
data.fCount, tm, mapper,
|
data.fCount, tm, 0, &localMatrix);
|
||||||
0, &localMatrix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2ConicalInside(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2ConicalInside(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix) {
|
||||||
const SkMatrix& localMatrix) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
@ -77,13 +72,12 @@ static SkShader* Make2ConicalInside(const SkPoint pts[2], const GradData& data,
|
|||||||
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
||||||
return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
|
return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
|
||||||
center0, (pts[1].fX - pts[0].fX) / 2,
|
center0, (pts[1].fX - pts[0].fX) / 2,
|
||||||
data.fColors, data.fPos, data.fCount, tm, mapper,
|
data.fColors, data.fPos, data.fCount, tm,
|
||||||
0, &localMatrix);
|
0, &localMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2ConicalInsideFlip(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2ConicalInsideFlip(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix) {
|
||||||
const SkMatrix& localMatrix) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
@ -91,13 +85,12 @@ static SkShader* Make2ConicalInsideFlip(const SkPoint pts[2], const GradData& da
|
|||||||
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
||||||
return SkGradientShader::CreateTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 2,
|
return SkGradientShader::CreateTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 2,
|
||||||
center1, (pts[1].fX - pts[0].fX) / 7,
|
center1, (pts[1].fX - pts[0].fX) / 7,
|
||||||
data.fColors, data.fPos, data.fCount, tm, mapper,
|
data.fColors, data.fPos, data.fCount, tm,
|
||||||
0, &localMatrix);
|
0, &localMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2ConicalInsideCenter(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2ConicalInsideCenter(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix) {
|
||||||
const SkMatrix& localMatrix) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
@ -105,13 +98,12 @@ static SkShader* Make2ConicalInsideCenter(const SkPoint pts[2], const GradData&
|
|||||||
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
||||||
return SkGradientShader::CreateTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 7,
|
return SkGradientShader::CreateTwoPointConical(center0, (pts[1].fX - pts[0].fX) / 7,
|
||||||
center0, (pts[1].fX - pts[0].fX) / 2,
|
center0, (pts[1].fX - pts[0].fX) / 2,
|
||||||
data.fColors, data.fPos, data.fCount, tm, mapper,
|
data.fColors, data.fPos, data.fCount, tm,
|
||||||
0, &localMatrix);
|
0, &localMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2ConicalZeroRad(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2ConicalZeroRad(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix) {
|
||||||
const SkMatrix& localMatrix) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
@ -119,13 +111,12 @@ static SkShader* Make2ConicalZeroRad(const SkPoint pts[2], const GradData& data,
|
|||||||
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
||||||
return SkGradientShader::CreateTwoPointConical(center1, 0.f,
|
return SkGradientShader::CreateTwoPointConical(center1, 0.f,
|
||||||
center0, (pts[1].fX - pts[0].fX) / 2,
|
center0, (pts[1].fX - pts[0].fX) / 2,
|
||||||
data.fColors, data.fPos, data.fCount, tm, mapper,
|
data.fColors, data.fPos, data.fCount, tm,
|
||||||
0, &localMatrix);
|
0, &localMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2ConicalZeroRadFlip(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2ConicalZeroRadFlip(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix) {
|
||||||
const SkMatrix& localMatrix) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
@ -133,13 +124,12 @@ static SkShader* Make2ConicalZeroRadFlip(const SkPoint pts[2], const GradData& d
|
|||||||
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
||||||
return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 2,
|
return SkGradientShader::CreateTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 2,
|
||||||
center0, 0.f,
|
center0, 0.f,
|
||||||
data.fColors, data.fPos, data.fCount, tm, mapper,
|
data.fColors, data.fPos, data.fCount, tm,
|
||||||
0, &localMatrix);
|
0, &localMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2ConicalZeroRadCenter(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2ConicalZeroRadCenter(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix) {
|
||||||
const SkMatrix& localMatrix) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
@ -147,13 +137,12 @@ static SkShader* Make2ConicalZeroRadCenter(const SkPoint pts[2], const GradData&
|
|||||||
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
||||||
return SkGradientShader::CreateTwoPointConical(center0, 0.f,
|
return SkGradientShader::CreateTwoPointConical(center0, 0.f,
|
||||||
center0, (pts[1].fX - pts[0].fX) / 2,
|
center0, (pts[1].fX - pts[0].fX) / 2,
|
||||||
data.fColors, data.fPos, data.fCount, tm, mapper,
|
data.fColors, data.fPos, data.fCount, tm,
|
||||||
0, &localMatrix);
|
0, &localMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2ConicalZeroRadOutside(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2ConicalZeroRadOutside(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix) {
|
||||||
const SkMatrix& localMatrix) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
SkScalar radius0 = 0.f;
|
SkScalar radius0 = 0.f;
|
||||||
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
||||||
@ -162,13 +151,11 @@ static SkShader* Make2ConicalZeroRadOutside(const SkPoint pts[2], const GradData
|
|||||||
return SkGradientShader::CreateTwoPointConical(center0, radius0,
|
return SkGradientShader::CreateTwoPointConical(center0, radius0,
|
||||||
center1, radius1,
|
center1, radius1,
|
||||||
data.fColors, data.fPos,
|
data.fColors, data.fPos,
|
||||||
data.fCount, tm, mapper,
|
data.fCount, tm, 0, &localMatrix);
|
||||||
0, &localMatrix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix) {
|
||||||
const SkMatrix& localMatrix) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
SkScalar radius0 = 0.f;
|
SkScalar radius0 = 0.f;
|
||||||
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
||||||
@ -177,13 +164,11 @@ static SkShader* Make2ConicalZeroRadFlipOutside(const SkPoint pts[2], const Grad
|
|||||||
return SkGradientShader::CreateTwoPointConical(center1, radius1,
|
return SkGradientShader::CreateTwoPointConical(center1, radius1,
|
||||||
center0, radius0,
|
center0, radius0,
|
||||||
data.fColors, data.fPos,
|
data.fColors, data.fPos,
|
||||||
data.fCount, tm, mapper,
|
data.fCount, tm, 0, &localMatrix);
|
||||||
0, &localMatrix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2ConicalEdgeX(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2ConicalEdgeX(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix) {
|
||||||
const SkMatrix& localMatrix) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7);
|
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7);
|
||||||
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
||||||
@ -193,13 +178,11 @@ static SkShader* Make2ConicalEdgeX(const SkPoint pts[2], const GradData& data,
|
|||||||
return SkGradientShader::CreateTwoPointConical(center0, radius0,
|
return SkGradientShader::CreateTwoPointConical(center0, radius0,
|
||||||
center1, radius1,
|
center1, radius1,
|
||||||
data.fColors, data.fPos,
|
data.fColors, data.fPos,
|
||||||
data.fCount, tm, mapper,
|
data.fCount, tm, 0, &localMatrix);
|
||||||
0, &localMatrix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2ConicalEdgeY(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2ConicalEdgeY(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix) {
|
||||||
const SkMatrix& localMatrix) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7);
|
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7);
|
||||||
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
||||||
@ -209,12 +192,10 @@ static SkShader* Make2ConicalEdgeY(const SkPoint pts[2], const GradData& data,
|
|||||||
return SkGradientShader::CreateTwoPointConical(center0, radius0,
|
return SkGradientShader::CreateTwoPointConical(center0, radius0,
|
||||||
center1, radius1,
|
center1, radius1,
|
||||||
data.fColors, data.fPos,
|
data.fColors, data.fPos,
|
||||||
data.fCount, tm, mapper,
|
data.fCount, tm, 0, &localMatrix);
|
||||||
0, &localMatrix);
|
|
||||||
}
|
}
|
||||||
static SkShader* Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix) {
|
||||||
const SkMatrix& localMatrix) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
SkScalar radius0 = 0.f;
|
SkScalar radius0 = 0.f;
|
||||||
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
||||||
@ -224,13 +205,11 @@ static SkShader* Make2ConicalZeroRadEdgeX(const SkPoint pts[2], const GradData&
|
|||||||
return SkGradientShader::CreateTwoPointConical(center0, radius0,
|
return SkGradientShader::CreateTwoPointConical(center0, radius0,
|
||||||
center1, radius1,
|
center1, radius1,
|
||||||
data.fColors, data.fPos,
|
data.fColors, data.fPos,
|
||||||
data.fCount, tm, mapper,
|
data.fCount, tm, 0, &localMatrix);
|
||||||
0, &localMatrix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix) {
|
||||||
const SkMatrix& localMatrix) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
SkScalar radius0 = 0.f;
|
SkScalar radius0 = 0.f;
|
||||||
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
||||||
@ -240,13 +219,11 @@ static SkShader* Make2ConicalZeroRadEdgeY(const SkPoint pts[2], const GradData&
|
|||||||
return SkGradientShader::CreateTwoPointConical(center0, radius0,
|
return SkGradientShader::CreateTwoPointConical(center0, radius0,
|
||||||
center1, radius1,
|
center1, radius1,
|
||||||
data.fColors, data.fPos,
|
data.fColors, data.fPos,
|
||||||
data.fCount, tm, mapper,
|
data.fCount, tm, 0, &localMatrix);
|
||||||
0, &localMatrix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2ConicalTouchX(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2ConicalTouchX(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix) {
|
||||||
const SkMatrix& localMatrix) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7);
|
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7);
|
||||||
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
||||||
@ -256,13 +233,11 @@ static SkShader* Make2ConicalTouchX(const SkPoint pts[2], const GradData& data,
|
|||||||
return SkGradientShader::CreateTwoPointConical(center0, radius0,
|
return SkGradientShader::CreateTwoPointConical(center0, radius0,
|
||||||
center1, radius1,
|
center1, radius1,
|
||||||
data.fColors, data.fPos,
|
data.fColors, data.fPos,
|
||||||
data.fCount, tm, mapper,
|
data.fCount, tm, 0, &localMatrix);
|
||||||
0, &localMatrix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2ConicalTouchY(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2ConicalTouchY(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix) {
|
||||||
const SkMatrix& localMatrix) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7);
|
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 7);
|
||||||
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
||||||
@ -272,13 +247,11 @@ static SkShader* Make2ConicalTouchY(const SkPoint pts[2], const GradData& data,
|
|||||||
return SkGradientShader::CreateTwoPointConical(center0, radius0,
|
return SkGradientShader::CreateTwoPointConical(center0, radius0,
|
||||||
center1, radius1,
|
center1, radius1,
|
||||||
data.fColors, data.fPos,
|
data.fColors, data.fPos,
|
||||||
data.fCount, tm, mapper,
|
data.fCount, tm, 0, &localMatrix);
|
||||||
0, &localMatrix);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2ConicalInsideSmallRad(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2ConicalInsideSmallRad(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix) {
|
||||||
const SkMatrix& localMatrix) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
@ -286,13 +259,12 @@ static SkShader* Make2ConicalInsideSmallRad(const SkPoint pts[2], const GradData
|
|||||||
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
|
||||||
return SkGradientShader::CreateTwoPointConical(center0, 0.0000000000000000001f,
|
return SkGradientShader::CreateTwoPointConical(center0, 0.0000000000000000001f,
|
||||||
center0, (pts[1].fX - pts[0].fX) / 2,
|
center0, (pts[1].fX - pts[0].fX) / 2,
|
||||||
data.fColors, data.fPos, data.fCount, tm, mapper,
|
data.fColors, data.fPos, data.fCount, tm,
|
||||||
0, &localMatrix);
|
0, &localMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
|
typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper,
|
SkShader::TileMode tm, const SkMatrix& localMatrix);
|
||||||
const SkMatrix& localMatrix);
|
|
||||||
|
|
||||||
static const GradMaker gGradMakersOutside[] = {
|
static const GradMaker gGradMakersOutside[] = {
|
||||||
Make2ConicalOutside, Make2ConicalOutsideFlip,
|
Make2ConicalOutside, Make2ConicalOutsideFlip,
|
||||||
@ -378,7 +350,7 @@ protected:
|
|||||||
scale.postTranslate(25.f, 25.f);
|
scale.postTranslate(25.f, 25.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
SkShader* shader = gradMaker[j](pts, gGradData[i], tm, NULL, scale);
|
SkShader* shader = gradMaker[j](pts, gGradData[i], tm, scale);
|
||||||
paint.setShader(shader);
|
paint.setShader(shader);
|
||||||
canvas->drawRect(r, paint);
|
canvas->drawRect(r, paint);
|
||||||
shader->unref();
|
shader->unref();
|
||||||
|
@ -26,32 +26,26 @@ static const GradData gGradData[] = {
|
|||||||
{ 4, gColors, NULL },
|
{ 4, gColors, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCount, tm);
|
||||||
return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos,
|
|
||||||
data.fCount, tm, mapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
|
||||||
SkPoint center;
|
SkPoint center;
|
||||||
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
|
return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
|
||||||
data.fPos, data.fCount, tm, mapper);
|
data.fPos, data.fCount, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader::TileMode) {
|
||||||
SkShader::TileMode, SkUnitMapper* mapper) {
|
|
||||||
SkPoint center;
|
SkPoint center;
|
||||||
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors,
|
return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount);
|
||||||
data.fPos, data.fCount, mapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
@ -60,11 +54,10 @@ static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
|
|||||||
return SkGradientShader::CreateTwoPointRadial(
|
return SkGradientShader::CreateTwoPointRadial(
|
||||||
center1, (pts[1].fX - pts[0].fX) / 7,
|
center1, (pts[1].fX - pts[0].fX) / 7,
|
||||||
center0, (pts[1].fX - pts[0].fX) / 2,
|
center0, (pts[1].fX - pts[0].fX) / 2,
|
||||||
data.fColors, data.fPos, data.fCount, tm, mapper);
|
data.fColors, data.fPos, data.fCount, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
|
SkScalar radius0 = SkScalarDiv(pts[1].fX - pts[0].fX, 10);
|
||||||
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
SkScalar radius1 = SkScalarDiv(pts[1].fX - pts[0].fX, 3);
|
||||||
@ -73,12 +66,12 @@ static SkShader* Make2Conical(const SkPoint pts[2], const GradData& data,
|
|||||||
return SkGradientShader::CreateTwoPointConical(center1, radius1,
|
return SkGradientShader::CreateTwoPointConical(center1, radius1,
|
||||||
center0, radius0,
|
center0, radius0,
|
||||||
data.fColors, data.fPos,
|
data.fColors, data.fPos,
|
||||||
data.fCount, tm, mapper);
|
data.fCount, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
|
typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm);
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper);
|
|
||||||
static const GradMaker gGradMakers[] = {
|
static const GradMaker gGradMakers[] = {
|
||||||
MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2Conical,
|
MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2Conical,
|
||||||
};
|
};
|
||||||
@ -113,7 +106,7 @@ protected:
|
|||||||
for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); ++i) {
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); ++i) {
|
||||||
canvas->save();
|
canvas->save();
|
||||||
for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); ++j) {
|
for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); ++j) {
|
||||||
SkShader* shader = gGradMakers[j](kPts, gGradData[i], kTM, NULL);
|
SkShader* shader = gGradMakers[j](kPts, gGradData[i], kTM);
|
||||||
paint.setShader(shader)->unref();
|
paint.setShader(shader)->unref();
|
||||||
paint.setAlpha(kAlphas[a]);
|
paint.setAlpha(kAlphas[a]);
|
||||||
canvas->drawRect(kRect, paint);
|
canvas->drawRect(kRect, paint);
|
||||||
|
@ -19,7 +19,7 @@ static SkShader* MakeLinear(SkScalar width, SkScalar height, bool alternate,
|
|||||||
colors[1] = SK_ColorYELLOW;
|
colors[1] = SK_ColorYELLOW;
|
||||||
}
|
}
|
||||||
return SkGradientShader::CreateLinear(pts, colors, NULL, 2,
|
return SkGradientShader::CreateLinear(pts, colors, NULL, 2,
|
||||||
SkShader::kClamp_TileMode, NULL, 0, &localMatrix);
|
SkShader::kClamp_TileMode, 0, &localMatrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011 Google Inc.
|
* Copyright 2011 Google Inc.
|
||||||
*
|
*
|
||||||
* Use of this source code is governed by a BSD-style license that can be
|
* Use of this source code is governed by a BSD-style license that can be
|
||||||
* found in the LICENSE file.
|
* found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gm.h"
|
#include "gm.h"
|
||||||
#include "SkCanvas.h"
|
#include "SkCanvas.h"
|
||||||
#include "SkGradientShader.h"
|
#include "SkGradientShader.h"
|
||||||
#include "SkUnitMappers.h"
|
|
||||||
|
|
||||||
namespace skiagm {
|
namespace skiagm {
|
||||||
|
|
||||||
@ -23,15 +22,9 @@ static void makebm(SkBitmap* bm, int w, int h) {
|
|||||||
SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
|
SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
|
||||||
SkPaint paint;
|
SkPaint paint;
|
||||||
|
|
||||||
SkUnitMapper* um = NULL;
|
|
||||||
|
|
||||||
um = new SkCosineMapper;
|
|
||||||
|
|
||||||
SkAutoUnref au(um);
|
|
||||||
|
|
||||||
paint.setDither(true);
|
paint.setDither(true);
|
||||||
paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos,
|
paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos,
|
||||||
SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode, um))->unref();
|
SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode))->unref();
|
||||||
canvas.drawPaint(paint);
|
canvas.drawPaint(paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,32 +54,26 @@ static const GradData gGradData[] = {
|
|||||||
{ 5, gColors, NULL },
|
{ 5, gColors, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCount, tm);
|
||||||
return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos,
|
|
||||||
data.fCount, tm, mapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
|
||||||
SkPoint center;
|
SkPoint center;
|
||||||
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
|
return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
|
||||||
data.fPos, data.fCount, tm, mapper);
|
data.fPos, data.fCount, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader::TileMode) {
|
||||||
SkShader::TileMode, SkUnitMapper* mapper) {
|
|
||||||
SkPoint center;
|
SkPoint center;
|
||||||
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors,
|
return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount);
|
||||||
data.fPos, data.fCount, mapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
@ -95,11 +82,11 @@ static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
|
|||||||
return SkGradientShader::CreateTwoPointRadial(
|
return SkGradientShader::CreateTwoPointRadial(
|
||||||
center1, (pts[1].fX - pts[0].fX) / 7,
|
center1, (pts[1].fX - pts[0].fX) / 7,
|
||||||
center0, (pts[1].fX - pts[0].fX) / 2,
|
center0, (pts[1].fX - pts[0].fX) / 2,
|
||||||
data.fColors, data.fPos, data.fCount, tm, mapper);
|
data.fColors, data.fPos, data.fCount, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
|
typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm);
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper);
|
|
||||||
static const GradMaker gGradMakers[] = {
|
static const GradMaker gGradMakers[] = {
|
||||||
MakeLinear, MakeRadial, MakeSweep, Make2Radial
|
MakeLinear, MakeRadial, MakeSweep, Make2Radial
|
||||||
};
|
};
|
||||||
@ -154,8 +141,7 @@ protected:
|
|||||||
for (size_t m = 0; m < SK_ARRAY_COUNT(gGradMakers); ++m) {
|
for (size_t m = 0; m < SK_ARRAY_COUNT(gGradMakers); ++m) {
|
||||||
shaders[shdIdx++] = gGradMakers[m](pts,
|
shaders[shdIdx++] = gGradMakers[m](pts,
|
||||||
gGradData[d],
|
gGradData[d],
|
||||||
SkShader::kClamp_TileMode,
|
SkShader::kClamp_TileMode);
|
||||||
NULL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (size_t tx = 0; tx < SK_ARRAY_COUNT(tileModes); ++tx) {
|
for (size_t tx = 0; tx < SK_ARRAY_COUNT(tileModes); ++tx) {
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
#include "gm.h"
|
#include "gm.h"
|
||||||
#include "SkCanvas.h"
|
#include "SkCanvas.h"
|
||||||
#include "SkGradientShader.h"
|
#include "SkGradientShader.h"
|
||||||
#include "SkUnitMappers.h"
|
|
||||||
|
|
||||||
namespace skiagm {
|
namespace skiagm {
|
||||||
|
|
||||||
@ -26,14 +25,8 @@ static void makebm(SkBitmap* bm, int w, int h) {
|
|||||||
|
|
||||||
SkPaint paint;
|
SkPaint paint;
|
||||||
|
|
||||||
SkUnitMapper* um = NULL;
|
|
||||||
|
|
||||||
um = new SkCosineMapper;
|
|
||||||
|
|
||||||
SkAutoUnref au(um);
|
|
||||||
|
|
||||||
paint.setShader(SkGradientShader::CreateLinear(kPts0, kColors0, kPos,
|
paint.setShader(SkGradientShader::CreateLinear(kPts0, kColors0, kPos,
|
||||||
SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode, um))->unref();
|
SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode))->unref();
|
||||||
canvas.drawPaint(paint);
|
canvas.drawPaint(paint);
|
||||||
paint.setShader(SkGradientShader::CreateLinear(kPts1, kColors1, kPos,
|
paint.setShader(SkGradientShader::CreateLinear(kPts1, kColors1, kPos,
|
||||||
SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode))->unref();
|
SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode))->unref();
|
||||||
|
@ -4,10 +4,10 @@
|
|||||||
* Use of this source code is governed by a BSD-style license that can be
|
* Use of this source code is governed by a BSD-style license that can be
|
||||||
* found in the LICENSE file.
|
* found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gm.h"
|
#include "gm.h"
|
||||||
#include "SkCanvas.h"
|
#include "SkCanvas.h"
|
||||||
#include "SkGradientShader.h"
|
#include "SkGradientShader.h"
|
||||||
#include "SkUnitMappers.h"
|
|
||||||
|
|
||||||
namespace skiagm {
|
namespace skiagm {
|
||||||
|
|
||||||
@ -26,14 +26,8 @@ static void makebm(SkBitmap* bm, int w, int h) {
|
|||||||
|
|
||||||
SkPaint paint;
|
SkPaint paint;
|
||||||
|
|
||||||
SkUnitMapper* um = NULL;
|
|
||||||
|
|
||||||
um = new SkCosineMapper;
|
|
||||||
|
|
||||||
SkAutoUnref au(um);
|
|
||||||
|
|
||||||
paint.setShader(SkGradientShader::CreateLinear(kPts0, kColors0, kPos,
|
paint.setShader(SkGradientShader::CreateLinear(kPts0, kColors0, kPos,
|
||||||
SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode, um))->unref();
|
SK_ARRAY_COUNT(kColors0), SkShader::kClamp_TileMode))->unref();
|
||||||
canvas.drawPaint(paint);
|
canvas.drawPaint(paint);
|
||||||
paint.setShader(SkGradientShader::CreateLinear(kPts1, kColors1, kPos,
|
paint.setShader(SkGradientShader::CreateLinear(kPts1, kColors1, kPos,
|
||||||
SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode))->unref();
|
SK_ARRAY_COUNT(kColors1), SkShader::kClamp_TileMode))->unref();
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
// effects
|
// effects
|
||||||
#include "SkGradientShader.h"
|
#include "SkGradientShader.h"
|
||||||
#include "SkUnitMappers.h"
|
|
||||||
#include "SkBlurDrawLooper.h"
|
#include "SkBlurDrawLooper.h"
|
||||||
|
|
||||||
static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
|
static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
|
||||||
@ -29,16 +28,9 @@ static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
|
|||||||
SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
|
SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
|
||||||
SkPaint paint;
|
SkPaint paint;
|
||||||
|
|
||||||
SkUnitMapper* um = NULL;
|
|
||||||
|
|
||||||
um = new SkCosineMapper;
|
|
||||||
// um = new SkDiscreteMapper(12);
|
|
||||||
|
|
||||||
SkAutoUnref au(um);
|
|
||||||
|
|
||||||
paint.setDither(true);
|
paint.setDither(true);
|
||||||
paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos,
|
paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos,
|
||||||
SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode, um))->unref();
|
SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode))->unref();
|
||||||
canvas.drawPaint(paint);
|
canvas.drawPaint(paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
|
|
||||||
// effects
|
// effects
|
||||||
#include "SkGradientShader.h"
|
#include "SkGradientShader.h"
|
||||||
#include "SkUnitMappers.h"
|
|
||||||
#include "SkBlurDrawLooper.h"
|
#include "SkBlurDrawLooper.h"
|
||||||
|
|
||||||
static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
|
static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
|
||||||
@ -30,16 +29,9 @@ static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
|
|||||||
SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
|
SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
|
||||||
SkPaint paint;
|
SkPaint paint;
|
||||||
|
|
||||||
SkUnitMapper* um = NULL;
|
|
||||||
|
|
||||||
um = new SkCosineMapper;
|
|
||||||
// um = new SkDiscreteMapper(12);
|
|
||||||
|
|
||||||
SkAutoUnref au(um);
|
|
||||||
|
|
||||||
paint.setDither(true);
|
paint.setDither(true);
|
||||||
paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos,
|
paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos,
|
||||||
SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode, um))->unref();
|
SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode))->unref();
|
||||||
canvas.drawPaint(paint);
|
canvas.drawPaint(paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +106,6 @@
|
|||||||
'../samplecode/SampleTextureDomain.cpp',
|
'../samplecode/SampleTextureDomain.cpp',
|
||||||
'../samplecode/SampleTiling.cpp',
|
'../samplecode/SampleTiling.cpp',
|
||||||
'../samplecode/SampleTinyBitmap.cpp',
|
'../samplecode/SampleTinyBitmap.cpp',
|
||||||
'../samplecode/SampleUnitMapper.cpp',
|
|
||||||
'../samplecode/SampleUnpremul.cpp',
|
'../samplecode/SampleUnpremul.cpp',
|
||||||
'../samplecode/SampleVertices.cpp',
|
'../samplecode/SampleVertices.cpp',
|
||||||
'../samplecode/SampleXfermodesBlur.cpp',
|
'../samplecode/SampleXfermodesBlur.cpp',
|
||||||
@ -273,7 +272,6 @@
|
|||||||
[ 'skia_os == "android"', {
|
[ 'skia_os == "android"', {
|
||||||
'sources!': [
|
'sources!': [
|
||||||
'../samplecode/SampleAnimator.cpp',
|
'../samplecode/SampleAnimator.cpp',
|
||||||
'../samplecode/SampleUnitMapper.cpp',
|
|
||||||
],
|
],
|
||||||
'dependencies!': [
|
'dependencies!': [
|
||||||
'animator.gyp:animator',
|
'animator.gyp:animator',
|
||||||
|
@ -307,7 +307,6 @@
|
|||||||
'<(skia_include_path)/core/SkTypeface.h',
|
'<(skia_include_path)/core/SkTypeface.h',
|
||||||
'<(skia_include_path)/core/SkTypes.h',
|
'<(skia_include_path)/core/SkTypes.h',
|
||||||
'<(skia_include_path)/core/SkUnPreMultiply.h',
|
'<(skia_include_path)/core/SkUnPreMultiply.h',
|
||||||
'<(skia_include_path)/core/SkUnitMapper.h',
|
|
||||||
'<(skia_include_path)/core/SkUtils.h',
|
'<(skia_include_path)/core/SkUtils.h',
|
||||||
'<(skia_include_path)/core/SkWeakRefCnt.h',
|
'<(skia_include_path)/core/SkWeakRefCnt.h',
|
||||||
'<(skia_include_path)/core/SkWriter32.h',
|
'<(skia_include_path)/core/SkWriter32.h',
|
||||||
|
@ -117,7 +117,6 @@
|
|||||||
'utils/win/SkIStream.h',
|
'utils/win/SkIStream.h',
|
||||||
'utils/win/SkTScopedComPtr.h',
|
'utils/win/SkTScopedComPtr.h',
|
||||||
'utils/SkBoundaryPatch.h',
|
'utils/SkBoundaryPatch.h',
|
||||||
'utils/SkUnitMappers.h',
|
|
||||||
'utils/SkPictureUtils.h',
|
'utils/SkPictureUtils.h',
|
||||||
'utils/SkRandom.h',
|
'utils/SkRandom.h',
|
||||||
'utils/SkMeshUtils.h',
|
'utils/SkMeshUtils.h',
|
||||||
@ -258,7 +257,6 @@
|
|||||||
'core/SkWriter32.h',
|
'core/SkWriter32.h',
|
||||||
'core/SkError.h',
|
'core/SkError.h',
|
||||||
'core/SkPath.h',
|
'core/SkPath.h',
|
||||||
'core/SkUnitMapper.h',
|
|
||||||
'core/SkFlattenable.h',
|
'core/SkFlattenable.h',
|
||||||
'core/SkTSearch.h',
|
'core/SkTSearch.h',
|
||||||
'core/SkRect.h',
|
'core/SkRect.h',
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
# If these become 'permanent', they should be moved into skia_common.gypi
|
# If these become 'permanent', they should be moved into skia_common.gypi
|
||||||
#
|
#
|
||||||
'skia_for_chromium_defines': [
|
'skia_for_chromium_defines': [
|
||||||
|
'SK_SUPPORT_LEGACY_DEADUNITMAPPERTYPE',
|
||||||
'SK_SUPPORT_LEGACY_GETTOPDEVICE',
|
'SK_SUPPORT_LEGACY_GETTOPDEVICE',
|
||||||
'SK_SUPPORT_LEGACY_N32_NAME',
|
'SK_SUPPORT_LEGACY_N32_NAME',
|
||||||
'SK_SUPPORT_LEGACY_BUILDMIPMAP',
|
'SK_SUPPORT_LEGACY_BUILDMIPMAP',
|
||||||
|
@ -56,7 +56,6 @@
|
|||||||
'../include/utils/SkRandom.h',
|
'../include/utils/SkRandom.h',
|
||||||
'../include/utils/SkRTConf.h',
|
'../include/utils/SkRTConf.h',
|
||||||
'../include/utils/SkProxyCanvas.h',
|
'../include/utils/SkProxyCanvas.h',
|
||||||
'../include/utils/SkUnitMappers.h',
|
|
||||||
'../include/utils/SkWGL.h',
|
'../include/utils/SkWGL.h',
|
||||||
|
|
||||||
'../src/utils/SkBase64.cpp',
|
'../src/utils/SkBase64.cpp',
|
||||||
@ -110,7 +109,6 @@
|
|||||||
'../src/utils/SkThreadUtils_win.h',
|
'../src/utils/SkThreadUtils_win.h',
|
||||||
'../src/utils/SkTFitsIn.h',
|
'../src/utils/SkTFitsIn.h',
|
||||||
'../src/utils/SkTLogic.h',
|
'../src/utils/SkTLogic.h',
|
||||||
'../src/utils/SkUnitMappers.cpp',
|
|
||||||
|
|
||||||
#mac
|
#mac
|
||||||
'../include/utils/mac/SkCGUtils.h',
|
'../include/utils/mac/SkCGUtils.h',
|
||||||
|
@ -61,7 +61,7 @@ public:
|
|||||||
kSkPixelRef_Type,
|
kSkPixelRef_Type,
|
||||||
kSkRasterizer_Type,
|
kSkRasterizer_Type,
|
||||||
kSkShader_Type,
|
kSkShader_Type,
|
||||||
kSkUnitMapper_Type,
|
kSkUnused_Type, // used to be SkUnitMapper
|
||||||
kSkXfermode_Type,
|
kSkXfermode_Type,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -327,13 +327,14 @@ protected:
|
|||||||
// V24: SkTwoPointConicalGradient now has fFlipped flag for gradient flipping
|
// V24: SkTwoPointConicalGradient now has fFlipped flag for gradient flipping
|
||||||
// V25: SkDashPathEffect now only writes phase and interval array when flattening
|
// V25: SkDashPathEffect now only writes phase and interval array when flattening
|
||||||
// V26: Removed boolean from SkColorShader for inheriting color from SkPaint.
|
// V26: Removed boolean from SkColorShader for inheriting color from SkPaint.
|
||||||
|
// V27: Remove SkUnitMapper from gradients (and skia).
|
||||||
|
|
||||||
// Note: If the picture version needs to be increased then please follow the
|
// Note: If the picture version needs to be increased then please follow the
|
||||||
// steps to generate new SKPs in (only accessible to Googlers): http://goo.gl/qATVcw
|
// steps to generate new SKPs in (only accessible to Googlers): http://goo.gl/qATVcw
|
||||||
|
|
||||||
// Only SKPs within the min/current picture version range (inclusive) can be read.
|
// Only SKPs within the min/current picture version range (inclusive) can be read.
|
||||||
static const uint32_t MIN_PICTURE_VERSION = 19;
|
static const uint32_t MIN_PICTURE_VERSION = 19;
|
||||||
static const uint32_t CURRENT_PICTURE_VERSION = 26;
|
static const uint32_t CURRENT_PICTURE_VERSION = 27;
|
||||||
|
|
||||||
mutable uint32_t fUniqueID;
|
mutable uint32_t fUniqueID;
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
#include "SkReader32.h"
|
#include "SkReader32.h"
|
||||||
#include "SkRefCnt.h"
|
#include "SkRefCnt.h"
|
||||||
#include "SkShader.h"
|
#include "SkShader.h"
|
||||||
#include "SkUnitMapper.h"
|
|
||||||
#include "SkWriteBuffer.h"
|
#include "SkWriteBuffer.h"
|
||||||
#include "SkXfermode.h"
|
#include "SkXfermode.h"
|
||||||
|
|
||||||
@ -110,9 +109,13 @@ public:
|
|||||||
SkPixelRef* readPixelRef() { return this->readFlattenable<SkPixelRef>(); }
|
SkPixelRef* readPixelRef() { return this->readFlattenable<SkPixelRef>(); }
|
||||||
SkRasterizer* readRasterizer() { return this->readFlattenable<SkRasterizer>(); }
|
SkRasterizer* readRasterizer() { return this->readFlattenable<SkRasterizer>(); }
|
||||||
SkShader* readShader() { return this->readFlattenable<SkShader>(); }
|
SkShader* readShader() { return this->readFlattenable<SkShader>(); }
|
||||||
SkUnitMapper* readUnitMapper() { return this->readFlattenable<SkUnitMapper>(); }
|
|
||||||
SkXfermode* readXfermode() { return this->readFlattenable<SkXfermode>(); }
|
SkXfermode* readXfermode() { return this->readFlattenable<SkXfermode>(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Like readFlattenable() but explicitly just skips the data that was written for the
|
||||||
|
* flattenable (or the sentinel that there wasn't one).
|
||||||
|
*/
|
||||||
|
virtual void skipFlattenable();
|
||||||
|
|
||||||
// binary data and arrays
|
// binary data and arrays
|
||||||
virtual bool readByteArray(void* value, size_t size);
|
virtual bool readByteArray(void* value, size_t size);
|
||||||
|
@ -21,6 +21,10 @@ class SkXfermode;
|
|||||||
class GrContext;
|
class GrContext;
|
||||||
class GrEffectRef;
|
class GrEffectRef;
|
||||||
|
|
||||||
|
#ifdef SK_SUPPORT_LEGACY_DEADUNITMAPPERTYPE
|
||||||
|
class SkDeadUnitMapperType;
|
||||||
|
#endif
|
||||||
|
|
||||||
/** \class SkShader
|
/** \class SkShader
|
||||||
*
|
*
|
||||||
* Shaders specify the source color(s) for what is being drawn. If a paint
|
* Shaders specify the source color(s) for what is being drawn. If a paint
|
||||||
|
@ -1,37 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
* Copyright 2006 The Android Open Source Project
|
|
||||||
*
|
|
||||||
* Use of this source code is governed by a BSD-style license that can be
|
|
||||||
* found in the LICENSE file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef SkUnitMapper_DEFINED
|
|
||||||
#define SkUnitMapper_DEFINED
|
|
||||||
|
|
||||||
#include "SkRefCnt.h"
|
|
||||||
#include "SkScalar.h"
|
|
||||||
|
|
||||||
#include "SkFlattenable.h"
|
|
||||||
|
|
||||||
class SkUnitMapper : public SkFlattenable {
|
|
||||||
public:
|
|
||||||
SK_DECLARE_INST_COUNT(SkUnitMapper)
|
|
||||||
|
|
||||||
SkUnitMapper() {}
|
|
||||||
|
|
||||||
/** Given a value in [0..0xFFFF], return a value in the same range.
|
|
||||||
*/
|
|
||||||
virtual uint16_t mapUnit16(uint16_t x) = 0;
|
|
||||||
|
|
||||||
SK_DEFINE_FLATTENABLE_TYPE(SkUnitMapper)
|
|
||||||
|
|
||||||
protected:
|
|
||||||
SkUnitMapper(SkReadBuffer& rb) : SkFlattenable(rb) {}
|
|
||||||
|
|
||||||
private:
|
|
||||||
typedef SkFlattenable INHERITED;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -10,8 +10,6 @@
|
|||||||
|
|
||||||
#include "SkShader.h"
|
#include "SkShader.h"
|
||||||
|
|
||||||
class SkUnitMapper;
|
|
||||||
|
|
||||||
/** \class SkGradientShader
|
/** \class SkGradientShader
|
||||||
|
|
||||||
SkGradientShader hosts factories for creating subclasses of SkShader that
|
SkGradientShader hosts factories for creating subclasses of SkShader that
|
||||||
@ -43,14 +41,28 @@ public:
|
|||||||
intermediate values must be strictly increasing.
|
intermediate values must be strictly increasing.
|
||||||
@param count Must be >=2. The number of colors (and pos if not NULL) entries.
|
@param count Must be >=2. The number of colors (and pos if not NULL) entries.
|
||||||
@param mode The tiling mode
|
@param mode The tiling mode
|
||||||
@param mapper May be NULL. Callback to modify the spread of the colors.
|
|
||||||
*/
|
*/
|
||||||
static SkShader* CreateLinear(const SkPoint pts[2],
|
static SkShader* CreateLinear(const SkPoint pts[2],
|
||||||
const SkColor colors[], const SkScalar pos[], int count,
|
const SkColor colors[], const SkScalar pos[], int count,
|
||||||
SkShader::TileMode mode,
|
SkShader::TileMode mode,
|
||||||
SkUnitMapper* mapper = NULL,
|
uint32_t flags, const SkMatrix* localMatrix);
|
||||||
uint32_t flags = 0,
|
|
||||||
const SkMatrix* localMatrix = NULL);
|
static SkShader* CreateLinear(const SkPoint pts[2],
|
||||||
|
const SkColor colors[], const SkScalar pos[], int count,
|
||||||
|
SkShader::TileMode mode) {
|
||||||
|
return CreateLinear(pts, colors, pos, count, mode, 0, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef SK_SUPPORT_LEGACY_DEADUNITMAPPERTYPE
|
||||||
|
static SkShader* CreateLinear(const SkPoint pts[2],
|
||||||
|
const SkColor colors[], const SkScalar pos[], int count,
|
||||||
|
SkShader::TileMode mode,
|
||||||
|
SkDeadUnitMapperType*, // this type is now gone
|
||||||
|
uint32_t flags,
|
||||||
|
const SkMatrix* localMatrix) {
|
||||||
|
return CreateLinear(pts, colors, pos, count, mode, flags, localMatrix);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/** Returns a shader that generates a radial gradient given the center and radius.
|
/** Returns a shader that generates a radial gradient given the center and radius.
|
||||||
<p />
|
<p />
|
||||||
@ -67,14 +79,27 @@ public:
|
|||||||
intermediate values must be strictly increasing.
|
intermediate values must be strictly increasing.
|
||||||
@param count Must be >= 2. The number of colors (and pos if not NULL) entries
|
@param count Must be >= 2. The number of colors (and pos if not NULL) entries
|
||||||
@param mode The tiling mode
|
@param mode The tiling mode
|
||||||
@param mapper May be NULL. Callback to modify the spread of the colors.
|
|
||||||
*/
|
*/
|
||||||
static SkShader* CreateRadial(const SkPoint& center, SkScalar radius,
|
static SkShader* CreateRadial(const SkPoint& center, SkScalar radius,
|
||||||
const SkColor colors[], const SkScalar pos[], int count,
|
const SkColor colors[], const SkScalar pos[], int count,
|
||||||
SkShader::TileMode mode,
|
SkShader::TileMode mode,
|
||||||
SkUnitMapper* mapper = NULL,
|
uint32_t flags, const SkMatrix* localMatrix);
|
||||||
uint32_t flags = 0,
|
|
||||||
const SkMatrix* localMatrix = NULL);
|
static SkShader* CreateRadial(const SkPoint& center, SkScalar radius,
|
||||||
|
const SkColor colors[], const SkScalar pos[], int count,
|
||||||
|
SkShader::TileMode mode) {
|
||||||
|
return CreateRadial(center, radius, colors, pos, count, mode, 0, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef SK_SUPPORT_LEGACY_DEADUNITMAPPERTYPE
|
||||||
|
static SkShader* CreateRadial(const SkPoint& center, SkScalar radius,
|
||||||
|
const SkColor colors[], const SkScalar pos[], int count,
|
||||||
|
SkShader::TileMode mode,
|
||||||
|
SkDeadUnitMapperType*,
|
||||||
|
uint32_t flags, const SkMatrix* localMatrix) {
|
||||||
|
return CreateRadial(center, radius, colors, pos, count, mode, flags, localMatrix);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/** Returns a shader that generates a radial gradient given the start position, start radius, end position and end radius.
|
/** Returns a shader that generates a radial gradient given the start position, start radius, end position and end radius.
|
||||||
<p />
|
<p />
|
||||||
@ -94,18 +119,32 @@ public:
|
|||||||
intermediate values must be strictly increasing.
|
intermediate values must be strictly increasing.
|
||||||
@param count Must be >= 2. The number of colors (and pos if not NULL) entries
|
@param count Must be >= 2. The number of colors (and pos if not NULL) entries
|
||||||
@param mode The tiling mode
|
@param mode The tiling mode
|
||||||
@param mapper May be NULL. Callback to modify the spread of the colors.
|
|
||||||
*/
|
*/
|
||||||
static SkShader* CreateTwoPointRadial(const SkPoint& start,
|
static SkShader* CreateTwoPointRadial(const SkPoint& start, SkScalar startRadius,
|
||||||
SkScalar startRadius,
|
const SkPoint& end, SkScalar endRadius,
|
||||||
const SkPoint& end,
|
const SkColor colors[], const SkScalar pos[], int count,
|
||||||
SkScalar endRadius,
|
|
||||||
const SkColor colors[],
|
|
||||||
const SkScalar pos[], int count,
|
|
||||||
SkShader::TileMode mode,
|
SkShader::TileMode mode,
|
||||||
SkUnitMapper* mapper = NULL,
|
uint32_t flags, const SkMatrix* localMatrix);
|
||||||
uint32_t flags = 0,
|
|
||||||
const SkMatrix* localMatrix = NULL);
|
static SkShader* CreateTwoPointRadial(const SkPoint& start, SkScalar startRadius,
|
||||||
|
const SkPoint& end, SkScalar endRadius,
|
||||||
|
const SkColor colors[], const SkScalar pos[], int count,
|
||||||
|
SkShader::TileMode mode) {
|
||||||
|
return CreateTwoPointRadial(start, startRadius, end, endRadius, colors, pos, count, mode,
|
||||||
|
0, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef SK_SUPPORT_LEGACY_DEADUNITMAPPERTYPE
|
||||||
|
static SkShader* CreateTwoPointRadial(const SkPoint& start, SkScalar startRadius,
|
||||||
|
const SkPoint& end, SkScalar endRadius,
|
||||||
|
const SkColor colors[], const SkScalar pos[], int count,
|
||||||
|
SkShader::TileMode mode,
|
||||||
|
SkDeadUnitMapperType*,
|
||||||
|
uint32_t flags, const SkMatrix* localMatrix) {
|
||||||
|
return CreateTwoPointRadial(start, startRadius, end, endRadius, colors, pos, count, mode,
|
||||||
|
flags, localMatrix);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a shader that generates a conical gradient given two circles, or
|
* Returns a shader that generates a conical gradient given two circles, or
|
||||||
@ -113,16 +152,31 @@ public:
|
|||||||
* two circles according to the following HTML spec.
|
* two circles according to the following HTML spec.
|
||||||
* http://dev.w3.org/html5/2dcontext/#dom-context-2d-createradialgradient
|
* http://dev.w3.org/html5/2dcontext/#dom-context-2d-createradialgradient
|
||||||
*/
|
*/
|
||||||
static SkShader* CreateTwoPointConical(const SkPoint& start,
|
static SkShader* CreateTwoPointConical(const SkPoint& start, SkScalar startRadius,
|
||||||
SkScalar startRadius,
|
const SkPoint& end, SkScalar endRadius,
|
||||||
const SkPoint& end,
|
const SkColor colors[], const SkScalar pos[], int count,
|
||||||
SkScalar endRadius,
|
|
||||||
const SkColor colors[],
|
|
||||||
const SkScalar pos[], int count,
|
|
||||||
SkShader::TileMode mode,
|
SkShader::TileMode mode,
|
||||||
SkUnitMapper* mapper = NULL,
|
uint32_t flags, const SkMatrix* localMatrix);
|
||||||
uint32_t flags = 0,
|
|
||||||
const SkMatrix* localMatrix = NULL);
|
static SkShader* CreateTwoPointConical(const SkPoint& start, SkScalar startRadius,
|
||||||
|
const SkPoint& end, SkScalar endRadius,
|
||||||
|
const SkColor colors[], const SkScalar pos[], int count,
|
||||||
|
SkShader::TileMode mode) {
|
||||||
|
return CreateTwoPointConical(start, startRadius, end, endRadius, colors, pos, count, mode,
|
||||||
|
0, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef SK_SUPPORT_LEGACY_DEADUNITMAPPERTYPE
|
||||||
|
static SkShader* CreateTwoPointConical(const SkPoint& start, SkScalar startRadius,
|
||||||
|
const SkPoint& end, SkScalar endRadius,
|
||||||
|
const SkColor colors[], const SkScalar pos[], int count,
|
||||||
|
SkShader::TileMode mode,
|
||||||
|
SkDeadUnitMapperType*,
|
||||||
|
uint32_t flags, const SkMatrix* localMatrix) {
|
||||||
|
return CreateTwoPointConical(start, startRadius, end, endRadius, colors, pos, count, mode,
|
||||||
|
flags, localMatrix);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/** Returns a shader that generates a sweep gradient given a center.
|
/** Returns a shader that generates a sweep gradient given a center.
|
||||||
<p />
|
<p />
|
||||||
@ -138,13 +192,24 @@ public:
|
|||||||
If this is not null, the values must begin with 0, end with 1.0, and
|
If this is not null, the values must begin with 0, end with 1.0, and
|
||||||
intermediate values must be strictly increasing.
|
intermediate values must be strictly increasing.
|
||||||
@param count Must be >= 2. The number of colors (and pos if not NULL) entries
|
@param count Must be >= 2. The number of colors (and pos if not NULL) entries
|
||||||
@param mapper May be NULL. Callback to modify the spread of the colors.
|
|
||||||
*/
|
*/
|
||||||
static SkShader* CreateSweep(SkScalar cx, SkScalar cy,
|
static SkShader* CreateSweep(SkScalar cx, SkScalar cy,
|
||||||
const SkColor colors[], const SkScalar pos[],
|
const SkColor colors[], const SkScalar pos[], int count,
|
||||||
int count, SkUnitMapper* mapper = NULL,
|
uint32_t flags, const SkMatrix* localMatrix);
|
||||||
uint32_t flags = 0,
|
|
||||||
const SkMatrix* localMatrix = NULL);
|
static SkShader* CreateSweep(SkScalar cx, SkScalar cy,
|
||||||
|
const SkColor colors[], const SkScalar pos[], int count) {
|
||||||
|
return CreateSweep(cx, cy, colors, pos, count, 0, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef SK_SUPPORT_LEGACY_DEADUNITMAPPERTYPE
|
||||||
|
static SkShader* CreateSweep(SkScalar cx, SkScalar cy,
|
||||||
|
const SkColor colors[], const SkScalar pos[], int count,
|
||||||
|
SkDeadUnitMapperType*,
|
||||||
|
uint32_t flags, const SkMatrix* localMatrix) {
|
||||||
|
return CreateSweep(cx, cy, colors, pos, count, flags, localMatrix);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
|
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
|
||||||
};
|
};
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
#include "SkRandom.h"
|
#include "SkRandom.h"
|
||||||
#include "SkTransparentShader.h"
|
#include "SkTransparentShader.h"
|
||||||
#include "SkTypeface.h"
|
#include "SkTypeface.h"
|
||||||
#include "SkUnitMappers.h"
|
|
||||||
#include "SkUtils.h"
|
#include "SkUtils.h"
|
||||||
#include "SkXfermode.h"
|
#include "SkXfermode.h"
|
||||||
|
|
||||||
@ -368,10 +367,8 @@ protected:
|
|||||||
SkScalar* linearPos = NULL;
|
SkScalar* linearPos = NULL;
|
||||||
int linearCount = 2;
|
int linearCount = 2;
|
||||||
SkShader::TileMode linearMode = SkShader::kMirror_TileMode;
|
SkShader::TileMode linearMode = SkShader::kMirror_TileMode;
|
||||||
SkUnitMapper* linearMapper = new SkDiscreteMapper(3);
|
|
||||||
SkAutoUnref unmapLinearMapper(linearMapper);
|
|
||||||
SkShader* linear = SkGradientShader::CreateLinear(linearPoints,
|
SkShader* linear = SkGradientShader::CreateLinear(linearPoints,
|
||||||
linearColors, linearPos, linearCount, linearMode, linearMapper);
|
linearColors, linearPos, linearCount, linearMode);
|
||||||
|
|
||||||
SkPoint radialCenter = { SkIntToScalar(25), SkIntToScalar(25) };
|
SkPoint radialCenter = { SkIntToScalar(25), SkIntToScalar(25) };
|
||||||
SkScalar radialRadius = SkIntToScalar(25);
|
SkScalar radialRadius = SkIntToScalar(25);
|
||||||
@ -379,11 +376,9 @@ protected:
|
|||||||
SkScalar radialPos[] = { 0, SkIntToScalar(3) / 5, SkIntToScalar(1)};
|
SkScalar radialPos[] = { 0, SkIntToScalar(3) / 5, SkIntToScalar(1)};
|
||||||
int radialCount = 3;
|
int radialCount = 3;
|
||||||
SkShader::TileMode radialMode = SkShader::kRepeat_TileMode;
|
SkShader::TileMode radialMode = SkShader::kRepeat_TileMode;
|
||||||
SkUnitMapper* radialMapper = new SkCosineMapper();
|
|
||||||
SkAutoUnref unmapRadialMapper(radialMapper);
|
|
||||||
SkShader* radial = SkGradientShader::CreateRadial(radialCenter,
|
SkShader* radial = SkGradientShader::CreateRadial(radialCenter,
|
||||||
radialRadius, radialColors, radialPos, radialCount,
|
radialRadius, radialColors, radialPos, radialCount,
|
||||||
radialMode, radialMapper);
|
radialMode);
|
||||||
|
|
||||||
SkTransparentShader* transparentShader = new SkTransparentShader();
|
SkTransparentShader* transparentShader = new SkTransparentShader();
|
||||||
SkEmbossMaskFilter::Light light;
|
SkEmbossMaskFilter::Light light;
|
||||||
|
@ -13,8 +13,7 @@
|
|||||||
static SkShader* setgrad(const SkRect& r, SkColor c0, SkColor c1) {
|
static SkShader* setgrad(const SkRect& r, SkColor c0, SkColor c1) {
|
||||||
SkColor colors[] = { c0, c1 };
|
SkColor colors[] = { c0, c1 };
|
||||||
SkPoint pts[] = { { r.fLeft, r.fTop }, { r.fRight, r.fTop } };
|
SkPoint pts[] = { { r.fLeft, r.fTop }, { r.fRight, r.fTop } };
|
||||||
return SkGradientShader::CreateLinear(pts, colors, NULL, 2,
|
return SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader::kClamp_TileMode);
|
||||||
SkShader::kClamp_TileMode, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_alphagradients(SkCanvas* canvas) {
|
static void test_alphagradients(SkCanvas* canvas) {
|
||||||
@ -64,32 +63,26 @@ static const GradData gGradData[] = {
|
|||||||
{ 5, gColors, gPos2 }
|
{ 5, gColors, gPos2 }
|
||||||
};
|
};
|
||||||
|
|
||||||
static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCount, tm);
|
||||||
return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos,
|
|
||||||
data.fCount, tm, mapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
|
||||||
SkPoint center;
|
SkPoint center;
|
||||||
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
|
return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
|
||||||
data.fPos, data.fCount, tm, mapper);
|
data.fPos, data.fCount, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
|
||||||
SkPoint center;
|
SkPoint center;
|
||||||
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors,
|
return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount);
|
||||||
data.fPos, data.fCount, mapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
@ -98,22 +91,22 @@ static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
|
|||||||
return SkGradientShader::CreateTwoPointRadial(
|
return SkGradientShader::CreateTwoPointRadial(
|
||||||
center1, (pts[1].fX - pts[0].fX) / 7,
|
center1, (pts[1].fX - pts[0].fX) / 7,
|
||||||
center0, (pts[1].fX - pts[0].fX) / 2,
|
center0, (pts[1].fX - pts[0].fX) / 2,
|
||||||
data.fColors, data.fPos, data.fCount, tm, mapper);
|
data.fColors, data.fPos, data.fCount, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2RadialConcentric(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2RadialConcentric(const SkPoint pts[2], const GradData& data,
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
SkShader::TileMode tm) {
|
||||||
SkPoint center;
|
SkPoint center;
|
||||||
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
return SkGradientShader::CreateTwoPointRadial(
|
return SkGradientShader::CreateTwoPointRadial(
|
||||||
center, (pts[1].fX - pts[0].fX) / 7,
|
center, (pts[1].fX - pts[0].fX) / 7,
|
||||||
center, (pts[1].fX - pts[0].fX) / 2,
|
center, (pts[1].fX - pts[0].fX) / 2,
|
||||||
data.fColors, data.fPos, data.fCount, tm, mapper);
|
data.fColors, data.fPos, data.fCount, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
|
typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm);
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper);
|
|
||||||
static const GradMaker gGradMakers[] = {
|
static const GradMaker gGradMakers[] = {
|
||||||
MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2RadialConcentric
|
MakeLinear, MakeRadial, MakeSweep, Make2Radial, Make2RadialConcentric
|
||||||
};
|
};
|
||||||
@ -154,7 +147,7 @@ protected:
|
|||||||
canvas->save();
|
canvas->save();
|
||||||
for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) {
|
for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) {
|
||||||
SkShader* shader;
|
SkShader* shader;
|
||||||
shader = gGradMakers[j](pts, gGradData[i], (SkShader::TileMode)tm, NULL);
|
shader = gGradMakers[j](pts, gGradData[i], (SkShader::TileMode)tm);
|
||||||
paint.setShader(shader)->unref();
|
paint.setShader(shader)->unref();
|
||||||
canvas->drawRect(r, paint);
|
canvas->drawRect(r, paint);
|
||||||
canvas->translate(0, SkIntToScalar(120));
|
canvas->translate(0, SkIntToScalar(120));
|
||||||
|
@ -31,7 +31,7 @@ static void make_paint(SkPaint* paint, const SkMatrix& localMatrix) {
|
|||||||
SkColor colors[] = { 0, SK_ColorWHITE };
|
SkColor colors[] = { 0, SK_ColorWHITE };
|
||||||
SkPoint pts[] = { { 0, 0 }, { 0, SK_Scalar1*20 } };
|
SkPoint pts[] = { { 0, 0 }, { 0, SK_Scalar1*20 } };
|
||||||
SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader::kClamp_TileMode,
|
SkShader* s = SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader::kClamp_TileMode,
|
||||||
NULL, 0, &localMatrix);
|
0, &localMatrix);
|
||||||
|
|
||||||
paint->setShader(s)->unref();
|
paint->setShader(s)->unref();
|
||||||
paint->setXfermodeMode(SkXfermode::kDstIn_Mode);
|
paint->setXfermodeMode(SkXfermode::kDstIn_Mode);
|
||||||
|
@ -42,7 +42,7 @@ static SkShader* make_shader1(const SkIPoint& size) {
|
|||||||
{ SkIntToScalar(size.fX), SkIntToScalar(size.fY) } };
|
{ SkIntToScalar(size.fX), SkIntToScalar(size.fY) } };
|
||||||
SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorRED };
|
SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorRED };
|
||||||
return SkGradientShader::CreateLinear(pts, colors, NULL,
|
return SkGradientShader::CreateLinear(pts, colors, NULL,
|
||||||
SK_ARRAY_COUNT(colors), SkShader::kMirror_TileMode, NULL);
|
SK_ARRAY_COUNT(colors), SkShader::kMirror_TileMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -1,15 +1,14 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2011 Google Inc.
|
* Copyright 2011 Google Inc.
|
||||||
*
|
*
|
||||||
* Use of this source code is governed by a BSD-style license that can be
|
* Use of this source code is governed by a BSD-style license that can be
|
||||||
* found in the LICENSE file.
|
* found in the LICENSE file.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "SampleCode.h"
|
#include "SampleCode.h"
|
||||||
#include "SkView.h"
|
#include "SkView.h"
|
||||||
#include "SkCanvas.h"
|
#include "SkCanvas.h"
|
||||||
#include "SkGradientShader.h"
|
#include "SkGradientShader.h"
|
||||||
#include "SkUnitMappers.h"
|
|
||||||
|
|
||||||
static void makebm(SkBitmap* bm, int w, int h) {
|
static void makebm(SkBitmap* bm, int w, int h) {
|
||||||
bm->allocN32Pixels(w, h);
|
bm->allocN32Pixels(w, h);
|
||||||
@ -22,15 +21,9 @@ static void makebm(SkBitmap* bm, int w, int h) {
|
|||||||
SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
|
SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
|
||||||
SkPaint paint;
|
SkPaint paint;
|
||||||
|
|
||||||
SkUnitMapper* um = NULL;
|
|
||||||
|
|
||||||
um = new SkCosineMapper;
|
|
||||||
|
|
||||||
SkAutoUnref au(um);
|
|
||||||
|
|
||||||
paint.setDither(true);
|
paint.setDither(true);
|
||||||
paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos,
|
paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos,
|
||||||
SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode, um))->unref();
|
SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode))->unref();
|
||||||
canvas.drawPaint(paint);
|
canvas.drawPaint(paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,32 +53,26 @@ static const GradData gGradData[] = {
|
|||||||
{ 5, gColors, NULL },
|
{ 5, gColors, NULL },
|
||||||
};
|
};
|
||||||
|
|
||||||
static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCount, tm);
|
||||||
return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos,
|
|
||||||
data.fCount, tm, mapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
|
||||||
SkPoint center;
|
SkPoint center;
|
||||||
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
|
return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
|
||||||
data.fPos, data.fCount, tm, mapper);
|
data.fPos, data.fCount, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
|
||||||
SkPoint center;
|
SkPoint center;
|
||||||
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors,
|
return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount);
|
||||||
data.fPos, data.fCount, mapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
@ -94,11 +81,11 @@ static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
|
|||||||
return SkGradientShader::CreateTwoPointRadial(
|
return SkGradientShader::CreateTwoPointRadial(
|
||||||
center1, (pts[1].fX - pts[0].fX) / 7,
|
center1, (pts[1].fX - pts[0].fX) / 7,
|
||||||
center0, (pts[1].fX - pts[0].fX) / 2,
|
center0, (pts[1].fX - pts[0].fX) / 2,
|
||||||
data.fColors, data.fPos, data.fCount, tm, mapper);
|
data.fColors, data.fPos, data.fCount, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
|
typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm);
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper);
|
|
||||||
static const GradMaker gGradMakers[] = {
|
static const GradMaker gGradMakers[] = {
|
||||||
MakeLinear, MakeRadial, MakeSweep, Make2Radial
|
MakeLinear, MakeRadial, MakeSweep, Make2Radial
|
||||||
};
|
};
|
||||||
@ -152,8 +139,7 @@ protected:
|
|||||||
for (size_t m = 0; m < SK_ARRAY_COUNT(gGradMakers); ++m) {
|
for (size_t m = 0; m < SK_ARRAY_COUNT(gGradMakers); ++m) {
|
||||||
shaders[shdIdx++] = gGradMakers[m](pts,
|
shaders[shdIdx++] = gGradMakers[m](pts,
|
||||||
gGradData[d],
|
gGradData[d],
|
||||||
SkShader::kClamp_TileMode,
|
SkShader::kClamp_TileMode);
|
||||||
NULL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (size_t tx = 0; tx < SK_ARRAY_COUNT(tileModes); ++tx) {
|
for (size_t tx = 0; tx < SK_ARRAY_COUNT(tileModes); ++tx) {
|
||||||
|
@ -178,32 +178,26 @@ static const GradData gGradData[] = {
|
|||||||
{ 5, gColors, gPos2 }
|
{ 5, gColors, gPos2 }
|
||||||
};
|
};
|
||||||
|
|
||||||
static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeLinear(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos, data.fCount, tm);
|
||||||
return SkGradientShader::CreateLinear(pts, data.fColors, data.fPos,
|
|
||||||
data.fCount, tm, mapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeRadial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
|
||||||
SkPoint center;
|
SkPoint center;
|
||||||
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
|
return SkGradientShader::CreateRadial(center, center.fX, data.fColors,
|
||||||
data.fPos, data.fCount, tm, mapper);
|
data.fPos, data.fCount, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data,
|
static SkShader* MakeSweep(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
|
||||||
SkPoint center;
|
SkPoint center;
|
||||||
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors,
|
return SkGradientShader::CreateSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount);
|
||||||
data.fPos, data.fCount, mapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
|
static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm) {
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper) {
|
|
||||||
SkPoint center0, center1;
|
SkPoint center0, center1;
|
||||||
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
|
||||||
SkScalarAve(pts[0].fY, pts[1].fY));
|
SkScalarAve(pts[0].fY, pts[1].fY));
|
||||||
@ -212,11 +206,10 @@ static SkShader* Make2Radial(const SkPoint pts[2], const GradData& data,
|
|||||||
return SkGradientShader::CreateTwoPointRadial(
|
return SkGradientShader::CreateTwoPointRadial(
|
||||||
center1, (pts[1].fX - pts[0].fX) / 7,
|
center1, (pts[1].fX - pts[0].fX) / 7,
|
||||||
center0, (pts[1].fX - pts[0].fX) / 2,
|
center0, (pts[1].fX - pts[0].fX) / 2,
|
||||||
data.fColors, data.fPos, data.fCount, tm, mapper);
|
data.fColors, data.fPos, data.fCount, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data,
|
typedef SkShader* (*GradMaker)(const SkPoint pts[2], const GradData& data, SkShader::TileMode tm);
|
||||||
SkShader::TileMode tm, SkUnitMapper* mapper);
|
|
||||||
static const GradMaker gGradMakers[] = {
|
static const GradMaker gGradMakers[] = {
|
||||||
MakeLinear, MakeRadial, MakeSweep, Make2Radial
|
MakeLinear, MakeRadial, MakeSweep, Make2Radial
|
||||||
};
|
};
|
||||||
@ -236,7 +229,7 @@ static void gradient_slide(SkCanvas* canvas) {
|
|||||||
for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
|
for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
|
||||||
canvas->save();
|
canvas->save();
|
||||||
for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) {
|
for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) {
|
||||||
SkShader* shader = gGradMakers[j](pts, gGradData[i], tm, NULL);
|
SkShader* shader = gGradMakers[j](pts, gGradData[i], tm);
|
||||||
paint.setShader(shader);
|
paint.setShader(shader);
|
||||||
canvas->drawRect(r, paint);
|
canvas->drawRect(r, paint);
|
||||||
shader->unref();
|
shader->unref();
|
||||||
@ -335,7 +328,7 @@ static SkShader* make_shader1(const SkIPoint& size) {
|
|||||||
{ SkIntToScalar(size.fX), SkIntToScalar(size.fY) } };
|
{ SkIntToScalar(size.fX), SkIntToScalar(size.fY) } };
|
||||||
SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorRED };
|
SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorRED };
|
||||||
return SkGradientShader::CreateLinear(pts, colors, NULL,
|
return SkGradientShader::CreateLinear(pts, colors, NULL,
|
||||||
SK_ARRAY_COUNT(colors), SkShader::kMirror_TileMode, NULL);
|
SK_ARRAY_COUNT(colors), SkShader::kMirror_TileMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
class Rec {
|
class Rec {
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
|
|
||||||
// effects
|
// effects
|
||||||
#include "SkGradientShader.h"
|
#include "SkGradientShader.h"
|
||||||
#include "SkUnitMappers.h"
|
|
||||||
#include "SkBlurMask.h"
|
#include "SkBlurMask.h"
|
||||||
#include "SkBlurDrawLooper.h"
|
#include "SkBlurDrawLooper.h"
|
||||||
|
|
||||||
@ -35,16 +34,9 @@ static void makebm(SkBitmap* bm, SkColorType ct, int w, int h) {
|
|||||||
SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
|
SkScalar pos[] = { 0, SK_Scalar1/2, SK_Scalar1 };
|
||||||
SkPaint paint;
|
SkPaint paint;
|
||||||
|
|
||||||
SkUnitMapper* um = NULL;
|
|
||||||
|
|
||||||
um = new SkCosineMapper;
|
|
||||||
// um = new SkDiscreteMapper(12);
|
|
||||||
|
|
||||||
SkAutoUnref au(um);
|
|
||||||
|
|
||||||
paint.setDither(true);
|
paint.setDither(true);
|
||||||
paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos,
|
paint.setShader(SkGradientShader::CreateLinear(pts, colors, pos,
|
||||||
SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode, um))->unref();
|
SK_ARRAY_COUNT(colors), SkShader::kClamp_TileMode))->unref();
|
||||||
canvas.drawPaint(paint);
|
canvas.drawPaint(paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,172 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
* 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 "SkDevice.h"
|
|
||||||
#include "SkPaint.h"
|
|
||||||
#include "SkUnitMappers.h"
|
|
||||||
#include "SkCubicInterval.h"
|
|
||||||
|
|
||||||
#include "SkWidgetViews.h"
|
|
||||||
|
|
||||||
static SkStaticTextView* make_textview(SkView* parent,
|
|
||||||
const SkRect& bounds,
|
|
||||||
const SkPaint& paint) {
|
|
||||||
SkStaticTextView* view = new SkStaticTextView;
|
|
||||||
view->setMode(SkStaticTextView::kFixedSize_Mode);
|
|
||||||
view->setPaint(paint);
|
|
||||||
view->setVisibleP(true);
|
|
||||||
view->setSize(bounds.width(), bounds.height());
|
|
||||||
view->setLoc(bounds.fLeft, bounds.fTop);
|
|
||||||
parent->attachChildToFront(view)->unref();
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void set_scalar(SkStaticTextView* view, SkScalar value) {
|
|
||||||
SkString str;
|
|
||||||
str.appendScalar(value);
|
|
||||||
view->setText(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
class UnitMapperView : public SampleView {
|
|
||||||
SkPoint fPts[4];
|
|
||||||
SkMatrix fMatrix;
|
|
||||||
SkStaticTextView* fViews[4];
|
|
||||||
|
|
||||||
void setViews() {
|
|
||||||
set_scalar(fViews[0], fPts[1].fX);
|
|
||||||
set_scalar(fViews[1], fPts[1].fY);
|
|
||||||
set_scalar(fViews[2], fPts[2].fX);
|
|
||||||
set_scalar(fViews[3], fPts[2].fY);
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
UnitMapperView() {
|
|
||||||
fPts[0].set(0, 0);
|
|
||||||
fPts[1].set(SK_Scalar1 / 3, SK_Scalar1 / 3);
|
|
||||||
fPts[2].set(SK_Scalar1 * 2 / 3, SK_Scalar1 * 2 / 3);
|
|
||||||
fPts[3].set(SK_Scalar1, SK_Scalar1);
|
|
||||||
|
|
||||||
fMatrix.setScale(SK_Scalar1 * 200, -SK_Scalar1 * 200);
|
|
||||||
fMatrix.postTranslate(SkIntToScalar(100), SkIntToScalar(300));
|
|
||||||
|
|
||||||
SkRect r = {
|
|
||||||
SkIntToScalar(350), SkIntToScalar(100),
|
|
||||||
SkIntToScalar(500), SkIntToScalar(130)
|
|
||||||
};
|
|
||||||
SkPaint paint;
|
|
||||||
paint.setAntiAlias(true);
|
|
||||||
paint.setTextSize(SkIntToScalar(25));
|
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
fViews[i] = make_textview(this, r, paint);
|
|
||||||
r.offset(0, r.height());
|
|
||||||
}
|
|
||||||
this->setViews();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
|
||||||
// overrides from SkEventSink
|
|
||||||
virtual bool onQuery(SkEvent* evt) {
|
|
||||||
if (SampleCode::TitleQ(*evt)) {
|
|
||||||
SampleCode::TitleR(evt, "UnitMapper");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return this->INHERITED::onQuery(evt);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void onDrawContent(SkCanvas* canvas) {
|
|
||||||
SkPaint paint;
|
|
||||||
paint.setAntiAlias(true);
|
|
||||||
paint.setColor(0xFF8888FF);
|
|
||||||
|
|
||||||
SkRect r = { 0, 0, SK_Scalar1, SK_Scalar1 };
|
|
||||||
|
|
||||||
canvas->concat(fMatrix);
|
|
||||||
canvas->drawRect(r, paint);
|
|
||||||
|
|
||||||
paint.setColor(SK_ColorBLACK);
|
|
||||||
paint.setStyle(SkPaint::kStroke_Style);
|
|
||||||
paint.setStrokeWidth(0);
|
|
||||||
paint.setStrokeCap(SkPaint::kRound_Cap);
|
|
||||||
|
|
||||||
SkPath path;
|
|
||||||
path.moveTo(fPts[0]);
|
|
||||||
path.cubicTo(fPts[1], fPts[2], fPts[3]);
|
|
||||||
canvas->drawPath(path, paint);
|
|
||||||
|
|
||||||
paint.setColor(SK_ColorRED);
|
|
||||||
paint.setStrokeWidth(0);
|
|
||||||
canvas->drawLine(0, 0, SK_Scalar1, SK_Scalar1, paint);
|
|
||||||
|
|
||||||
paint.setColor(SK_ColorBLUE);
|
|
||||||
paint.setStrokeWidth(SK_Scalar1 / 60);
|
|
||||||
for (int i = 0; i < 50; i++) {
|
|
||||||
SkScalar x = i * SK_Scalar1 / 49;
|
|
||||||
canvas->drawPoint(x, SkEvalCubicInterval(&fPts[1], x), paint);
|
|
||||||
}
|
|
||||||
|
|
||||||
paint.setStrokeWidth(SK_Scalar1 / 20);
|
|
||||||
paint.setColor(SK_ColorGREEN);
|
|
||||||
canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, &fPts[1], paint);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool invertPt(SkScalar x, SkScalar y, SkPoint* result) {
|
|
||||||
if (NULL == result)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
SkMatrix m;
|
|
||||||
if (!fMatrix.invert(&m)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
m.mapXY(x, y, result);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int hittest(SkScalar x, SkScalar y) {
|
|
||||||
SkPoint target = { x, y };
|
|
||||||
SkPoint pts[2] = { fPts[1], fPts[2] };
|
|
||||||
fMatrix.mapPoints(pts, 2);
|
|
||||||
for (int i = 0; i < 2; i++) {
|
|
||||||
if (SkPoint::Distance(pts[i], target) < SkIntToScalar(4)) {
|
|
||||||
return i + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual SkView::Click* onFindClickHandler(SkScalar x, SkScalar y, unsigned) SK_OVERRIDE {
|
|
||||||
fDragIndex = hittest(x, y);
|
|
||||||
return fDragIndex >= 0 ? new Click(this) : NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool onClick(Click* click) {
|
|
||||||
if (fDragIndex >= 0) {
|
|
||||||
if (!invertPt(click->fCurr.fX, click->fCurr.fY,
|
|
||||||
&fPts[fDragIndex])) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
this->setViews();
|
|
||||||
this->inval(NULL);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
int fDragIndex;
|
|
||||||
|
|
||||||
typedef SampleView INHERITED;
|
|
||||||
};
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
static SkView* MyFactory() { return new UnitMapperView; }
|
|
||||||
static SkViewRegister reg(MyFactory);
|
|
@ -47,7 +47,7 @@ static SkShader* make_shader1(const SkIPoint& size) {
|
|||||||
{ SkIntToScalar(size.fX), SkIntToScalar(size.fY) } };
|
{ SkIntToScalar(size.fX), SkIntToScalar(size.fY) } };
|
||||||
SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorRED };
|
SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorRED };
|
||||||
return SkGradientShader::CreateLinear(pts, colors, NULL,
|
return SkGradientShader::CreateLinear(pts, colors, NULL,
|
||||||
SK_ARRAY_COUNT(colors), SkShader::kMirror_TileMode, NULL);
|
SK_ARRAY_COUNT(colors), SkShader::kMirror_TileMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
class VerticesView : public SampleView {
|
class VerticesView : public SampleView {
|
||||||
|
@ -11,49 +11,6 @@
|
|||||||
#include "SkAnimateMaker.h"
|
#include "SkAnimateMaker.h"
|
||||||
#include "SkAnimatorScript.h"
|
#include "SkAnimatorScript.h"
|
||||||
#include "SkGradientShader.h"
|
#include "SkGradientShader.h"
|
||||||
#include "SkUnitMapper.h"
|
|
||||||
|
|
||||||
static SkScalar SkUnitToScalar(U16CPU x) {
|
|
||||||
return x / 65535.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
static U16CPU SkScalarToUnit(SkScalar x) {
|
|
||||||
SkScalar pin = SkScalarPin(x, 0, SK_Scalar1);
|
|
||||||
return (int) (pin * 65535.0f);
|
|
||||||
}
|
|
||||||
|
|
||||||
class SkDrawGradientUnitMapper : public SkUnitMapper {
|
|
||||||
public:
|
|
||||||
SkDrawGradientUnitMapper(SkAnimateMaker* maker, const char* script) : fMaker(maker), fScript(script) {
|
|
||||||
}
|
|
||||||
|
|
||||||
SK_DECLARE_UNFLATTENABLE_OBJECT()
|
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual uint16_t mapUnit16(uint16_t x) {
|
|
||||||
fUnit = SkUnitToScalar(x);
|
|
||||||
SkScriptValue value;
|
|
||||||
SkAnimatorScript engine(*fMaker, NULL, SkType_Float);
|
|
||||||
engine.propertyCallBack(GetUnitValue, &fUnit);
|
|
||||||
if (engine.evaluate(fScript, &value, SkType_Float))
|
|
||||||
x = SkScalarToUnit(value.fOperand.fScalar);
|
|
||||||
return x;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool GetUnitValue(const char* token, size_t len, void* unitPtr, SkScriptValue* value) {
|
|
||||||
if (SK_LITERAL_STR_EQUAL("unit", token, len)) {
|
|
||||||
value->fOperand.fScalar = *(SkScalar*) unitPtr;
|
|
||||||
value->fType = SkType_Float;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
SkAnimateMaker* fMaker;
|
|
||||||
const char* fScript;
|
|
||||||
SkScalar fUnit;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
#if SK_USE_CONDENSED_INFO == 0
|
#if SK_USE_CONDENSED_INFO == 0
|
||||||
|
|
||||||
@ -67,13 +24,12 @@ const SkMemberInfo SkDrawGradient::fInfo[] = {
|
|||||||
|
|
||||||
DEFINE_GET_MEMBER(SkDrawGradient);
|
DEFINE_GET_MEMBER(SkDrawGradient);
|
||||||
|
|
||||||
SkDrawGradient::SkDrawGradient() : fUnitMapper(NULL) {
|
SkDrawGradient::SkDrawGradient() {
|
||||||
}
|
}
|
||||||
|
|
||||||
SkDrawGradient::~SkDrawGradient() {
|
SkDrawGradient::~SkDrawGradient() {
|
||||||
for (int index = 0; index < fDrawColors.count(); index++)
|
for (int index = 0; index < fDrawColors.count(); index++)
|
||||||
delete fDrawColors[index];
|
delete fDrawColors[index];
|
||||||
delete fUnitMapper;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SkDrawGradient::addChild(SkAnimateMaker& , SkDisplayable* child) {
|
bool SkDrawGradient::addChild(SkAnimateMaker& , SkDisplayable* child) {
|
||||||
@ -138,8 +94,6 @@ void SkDrawGradient::onEndElement(SkAnimateMaker& maker) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (unitMapper.size() > 0)
|
|
||||||
fUnitMapper = new SkDrawGradientUnitMapper(&maker, unitMapper.c_str());
|
|
||||||
INHERITED::onEndElement(maker);
|
INHERITED::onEndElement(maker);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,7 +130,7 @@ SkShader* SkDrawLinearGradient::getShader() {
|
|||||||
return NULL;
|
return NULL;
|
||||||
SkShader* shader = SkGradientShader::CreateLinear((SkPoint*)points.begin(),
|
SkShader* shader = SkGradientShader::CreateLinear((SkPoint*)points.begin(),
|
||||||
fColors.begin(), offsets.begin(), fColors.count(), (SkShader::TileMode) tileMode,
|
fColors.begin(), offsets.begin(), fColors.count(), (SkShader::TileMode) tileMode,
|
||||||
fUnitMapper, 0, getMatrix());
|
0, getMatrix());
|
||||||
SkAutoTDelete<SkShader> autoDel(shader);
|
SkAutoTDelete<SkShader> autoDel(shader);
|
||||||
(void)autoDel.detach();
|
(void)autoDel.detach();
|
||||||
return shader;
|
return shader;
|
||||||
@ -211,7 +165,7 @@ SkShader* SkDrawRadialGradient::getShader() {
|
|||||||
return NULL;
|
return NULL;
|
||||||
SkShader* shader = SkGradientShader::CreateRadial(center,
|
SkShader* shader = SkGradientShader::CreateRadial(center,
|
||||||
radius, fColors.begin(), offsets.begin(), fColors.count(), (SkShader::TileMode) tileMode,
|
radius, fColors.begin(), offsets.begin(), fColors.count(), (SkShader::TileMode) tileMode,
|
||||||
fUnitMapper, 0, getMatrix());
|
0, getMatrix());
|
||||||
SkAutoTDelete<SkShader> autoDel(shader);
|
SkAutoTDelete<SkShader> autoDel(shader);
|
||||||
(void)autoDel.detach();
|
(void)autoDel.detach();
|
||||||
return shader;
|
return shader;
|
||||||
|
@ -14,8 +14,6 @@
|
|||||||
#include "SkDrawShader.h"
|
#include "SkDrawShader.h"
|
||||||
#include "SkIntArray.h"
|
#include "SkIntArray.h"
|
||||||
|
|
||||||
class SkUnitMapper;
|
|
||||||
|
|
||||||
class SkDrawGradient : public SkDrawShader {
|
class SkDrawGradient : public SkDrawShader {
|
||||||
DECLARE_PRIVATE_MEMBER_INFO(DrawGradient);
|
DECLARE_PRIVATE_MEMBER_INFO(DrawGradient);
|
||||||
SkDrawGradient();
|
SkDrawGradient();
|
||||||
@ -30,7 +28,6 @@ protected:
|
|||||||
SkString unitMapper;
|
SkString unitMapper;
|
||||||
SkTDColorArray fColors;
|
SkTDColorArray fColors;
|
||||||
SkTDDrawColorArray fDrawColors;
|
SkTDDrawColorArray fDrawColors;
|
||||||
SkUnitMapper* fUnitMapper;
|
|
||||||
int addPrelude();
|
int addPrelude();
|
||||||
private:
|
private:
|
||||||
typedef SkDrawShader INHERITED;
|
typedef SkDrawShader INHERITED;
|
||||||
|
@ -335,3 +335,25 @@ SkFlattenable* SkReadBuffer::readFlattenable(SkFlattenable::Type ft) {
|
|||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Needs to follow the same pattern as readFlattenable(), but explicitly skip whatever data
|
||||||
|
* has been written.
|
||||||
|
*/
|
||||||
|
void SkReadBuffer::skipFlattenable() {
|
||||||
|
if (fFactoryCount > 0) {
|
||||||
|
if (0 == fReader.readU32()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if (fFactoryTDArray) {
|
||||||
|
if (0 == fReader.readU32()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (NULL == this->readFunctionPtr()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
uint32_t sizeRecorded = fReader.readU32();
|
||||||
|
fReader.skip(sizeRecorded);
|
||||||
|
}
|
||||||
|
@ -273,3 +273,15 @@ SkFlattenable* SkValidatingReadBuffer::readFlattenable(SkFlattenable::Type type)
|
|||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SkValidatingReadBuffer::skipFlattenable() {
|
||||||
|
SkString name;
|
||||||
|
this->readString(&name);
|
||||||
|
if (fError) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
uint32_t sizeRecorded = this->readUInt();
|
||||||
|
this->skip(sizeRecorded);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ public:
|
|||||||
|
|
||||||
// common data structures
|
// common data structures
|
||||||
virtual SkFlattenable* readFlattenable(SkFlattenable::Type type) SK_OVERRIDE;
|
virtual SkFlattenable* readFlattenable(SkFlattenable::Type type) SK_OVERRIDE;
|
||||||
|
virtual void skipFlattenable() SK_OVERRIDE;
|
||||||
virtual void readPoint(SkPoint* point) SK_OVERRIDE;
|
virtual void readPoint(SkPoint* point) SK_OVERRIDE;
|
||||||
virtual void readMatrix(SkMatrix* matrix) SK_OVERRIDE;
|
virtual void readMatrix(SkMatrix* matrix) SK_OVERRIDE;
|
||||||
virtual void readIRect(SkIRect* rect) SK_OVERRIDE;
|
virtual void readIRect(SkIRect* rect) SK_OVERRIDE;
|
||||||
|
@ -17,8 +17,6 @@ SkGradientShaderBase::SkGradientShaderBase(const Descriptor& desc, const SkMatri
|
|||||||
{
|
{
|
||||||
SkASSERT(desc.fCount > 1);
|
SkASSERT(desc.fCount > 1);
|
||||||
|
|
||||||
fMapper = desc.fMapper;
|
|
||||||
SkSafeRef(fMapper);
|
|
||||||
fGradFlags = SkToU8(desc.fGradFlags);
|
fGradFlags = SkToU8(desc.fGradFlags);
|
||||||
|
|
||||||
SkASSERT((unsigned)desc.fTileMode < SkShader::kTileModeCount);
|
SkASSERT((unsigned)desc.fTileMode < SkShader::kTileModeCount);
|
||||||
@ -142,7 +140,10 @@ static uint32_t unpack_flags(uint32_t packed) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SkGradientShaderBase::SkGradientShaderBase(SkReadBuffer& buffer) : INHERITED(buffer) {
|
SkGradientShaderBase::SkGradientShaderBase(SkReadBuffer& buffer) : INHERITED(buffer) {
|
||||||
fMapper = buffer.readUnitMapper();
|
if (0 != buffer.pictureVersion() && buffer.pictureVersion() < 27) {
|
||||||
|
// skip the old SkUnitMapper slot
|
||||||
|
buffer.skipFlattenable();
|
||||||
|
}
|
||||||
|
|
||||||
int colorCount = fColorCount = buffer.getArrayCount();
|
int colorCount = fColorCount = buffer.getArrayCount();
|
||||||
if (colorCount > kColorStorageCount) {
|
if (colorCount > kColorStorageCount) {
|
||||||
@ -181,7 +182,6 @@ SkGradientShaderBase::~SkGradientShaderBase() {
|
|||||||
if (fOrigColors != fStorage) {
|
if (fOrigColors != fStorage) {
|
||||||
sk_free(fOrigColors);
|
sk_free(fOrigColors);
|
||||||
}
|
}
|
||||||
SkSafeUnref(fMapper);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkGradientShaderBase::initCommon() {
|
void SkGradientShaderBase::initCommon() {
|
||||||
@ -194,7 +194,6 @@ void SkGradientShaderBase::initCommon() {
|
|||||||
|
|
||||||
void SkGradientShaderBase::flatten(SkWriteBuffer& buffer) const {
|
void SkGradientShaderBase::flatten(SkWriteBuffer& buffer) const {
|
||||||
this->INHERITED::flatten(buffer);
|
this->INHERITED::flatten(buffer);
|
||||||
buffer.writeFlattenable(fMapper);
|
|
||||||
buffer.writeColorArray(fOrigColors, fColorCount);
|
buffer.writeColorArray(fOrigColors, fColorCount);
|
||||||
buffer.writeUInt(pack_mode_flags(fTileMode, fGradFlags));
|
buffer.writeUInt(pack_mode_flags(fTileMode, fGradFlags));
|
||||||
if (fColorCount > 2) {
|
if (fColorCount > 2) {
|
||||||
@ -528,20 +527,6 @@ void SkGradientShaderBase::GradientShaderCache::initCache16(GradientShaderCache*
|
|||||||
prevIndex = nextIndex;
|
prevIndex = nextIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cache->fShader.fMapper) {
|
|
||||||
cache->fCache16Storage = (uint16_t*)sk_malloc_throw(allocSize);
|
|
||||||
uint16_t* linear = cache->fCache16; // just computed linear data
|
|
||||||
uint16_t* mapped = cache->fCache16Storage; // storage for mapped data
|
|
||||||
SkUnitMapper* map = cache->fShader.fMapper;
|
|
||||||
for (int i = 0; i < kCache16Count; i++) {
|
|
||||||
int index = map->mapUnit16(bitsTo16(i, kCache16Bits)) >> kCache16Shift;
|
|
||||||
mapped[i] = linear[index];
|
|
||||||
mapped[i + kCache16Count] = linear[index + kCache16Count];
|
|
||||||
}
|
|
||||||
sk_free(cache->fCache16);
|
|
||||||
cache->fCache16 = cache->fCache16Storage;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const SkPMColor* SkGradientShaderBase::GradientShaderCache::getCache32() {
|
const SkPMColor* SkGradientShaderBase::GradientShaderCache::getCache32() {
|
||||||
@ -579,23 +564,6 @@ void SkGradientShaderBase::GradientShaderCache::initCache32(GradientShaderCache*
|
|||||||
prevIndex = nextIndex;
|
prevIndex = nextIndex;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cache->fShader.fMapper) {
|
|
||||||
SkMallocPixelRef* newPR = SkMallocPixelRef::NewAllocate(info, 0, NULL);
|
|
||||||
SkPMColor* linear = cache->fCache32; // just computed linear data
|
|
||||||
SkPMColor* mapped = (SkPMColor*)newPR->getAddr(); // storage for mapped data
|
|
||||||
SkUnitMapper* map = cache->fShader.fMapper;
|
|
||||||
for (int i = 0; i < kCache32Count; i++) {
|
|
||||||
int index = map->mapUnit16((i << 8) | i) >> 8;
|
|
||||||
mapped[i + kCache32Count*0] = linear[index + kCache32Count*0];
|
|
||||||
mapped[i + kCache32Count*1] = linear[index + kCache32Count*1];
|
|
||||||
mapped[i + kCache32Count*2] = linear[index + kCache32Count*2];
|
|
||||||
mapped[i + kCache32Count*3] = linear[index + kCache32Count*3];
|
|
||||||
}
|
|
||||||
cache->fCache32PixelRef->unref();
|
|
||||||
cache->fCache32PixelRef = newPR;
|
|
||||||
cache->fCache32 = (SkPMColor*)newPR->getAddr();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -627,15 +595,6 @@ void SkGradientShaderBase::getGradientTableBitmap(SkBitmap* bitmap) const {
|
|||||||
// built with 0xFF
|
// built with 0xFF
|
||||||
SkAutoTUnref<GradientShaderCache> cache(this->refCache(0xFF));
|
SkAutoTUnref<GradientShaderCache> cache(this->refCache(0xFF));
|
||||||
|
|
||||||
// don't have a way to put the mapper into our cache-key yet
|
|
||||||
if (fMapper) {
|
|
||||||
// force our cache32pixelref to be built
|
|
||||||
(void)cache->getCache32();
|
|
||||||
bitmap->setConfig(SkImageInfo::MakeN32Premul(kCache32Count, 1));
|
|
||||||
bitmap->setPixelRef(cache->getCache32PixelRef());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// build our key: [numColors + colors[] + {positions[]} + flags ]
|
// build our key: [numColors + colors[] + {positions[]} + flags ]
|
||||||
int count = 1 + fColorCount + 1;
|
int count = 1 + fColorCount + 1;
|
||||||
if (fColorCount > 2) {
|
if (fColorCount > 2) {
|
||||||
@ -744,8 +703,6 @@ void SkGradientShaderBase::toString(SkString* str) const {
|
|||||||
str->append(" ");
|
str->append(" ");
|
||||||
str->append(gTileModeName[fTileMode]);
|
str->append(gTileModeName[fTileMode]);
|
||||||
|
|
||||||
// TODO: add "fMapper->toString(str);" when SkUnitMapper::toString is added
|
|
||||||
|
|
||||||
this->INHERITED::toString(str);
|
this->INHERITED::toString(str);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -770,13 +727,11 @@ void SkGradientShaderBase::toString(SkString* str) const {
|
|||||||
static void desc_init(SkGradientShaderBase::Descriptor* desc,
|
static void desc_init(SkGradientShaderBase::Descriptor* desc,
|
||||||
const SkColor colors[],
|
const SkColor colors[],
|
||||||
const SkScalar pos[], int colorCount,
|
const SkScalar pos[], int colorCount,
|
||||||
SkShader::TileMode mode,
|
SkShader::TileMode mode, uint32_t flags) {
|
||||||
SkUnitMapper* mapper, uint32_t flags) {
|
|
||||||
desc->fColors = colors;
|
desc->fColors = colors;
|
||||||
desc->fPos = pos;
|
desc->fPos = pos;
|
||||||
desc->fCount = colorCount;
|
desc->fCount = colorCount;
|
||||||
desc->fTileMode = mode;
|
desc->fTileMode = mode;
|
||||||
desc->fMapper = mapper;
|
|
||||||
desc->fGradFlags = flags;
|
desc->fGradFlags = flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -784,7 +739,6 @@ SkShader* SkGradientShader::CreateLinear(const SkPoint pts[2],
|
|||||||
const SkColor colors[],
|
const SkColor colors[],
|
||||||
const SkScalar pos[], int colorCount,
|
const SkScalar pos[], int colorCount,
|
||||||
SkShader::TileMode mode,
|
SkShader::TileMode mode,
|
||||||
SkUnitMapper* mapper,
|
|
||||||
uint32_t flags,
|
uint32_t flags,
|
||||||
const SkMatrix* localMatrix) {
|
const SkMatrix* localMatrix) {
|
||||||
if (NULL == pts || NULL == colors || colorCount < 1) {
|
if (NULL == pts || NULL == colors || colorCount < 1) {
|
||||||
@ -793,7 +747,7 @@ SkShader* SkGradientShader::CreateLinear(const SkPoint pts[2],
|
|||||||
EXPAND_1_COLOR(colorCount);
|
EXPAND_1_COLOR(colorCount);
|
||||||
|
|
||||||
SkGradientShaderBase::Descriptor desc;
|
SkGradientShaderBase::Descriptor desc;
|
||||||
desc_init(&desc, colors, pos, colorCount, mode, mapper, flags);
|
desc_init(&desc, colors, pos, colorCount, mode, flags);
|
||||||
return SkNEW_ARGS(SkLinearGradient, (pts, desc, localMatrix));
|
return SkNEW_ARGS(SkLinearGradient, (pts, desc, localMatrix));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -801,7 +755,6 @@ SkShader* SkGradientShader::CreateRadial(const SkPoint& center, SkScalar radius,
|
|||||||
const SkColor colors[],
|
const SkColor colors[],
|
||||||
const SkScalar pos[], int colorCount,
|
const SkScalar pos[], int colorCount,
|
||||||
SkShader::TileMode mode,
|
SkShader::TileMode mode,
|
||||||
SkUnitMapper* mapper,
|
|
||||||
uint32_t flags,
|
uint32_t flags,
|
||||||
const SkMatrix* localMatrix) {
|
const SkMatrix* localMatrix) {
|
||||||
if (radius <= 0 || NULL == colors || colorCount < 1) {
|
if (radius <= 0 || NULL == colors || colorCount < 1) {
|
||||||
@ -810,7 +763,7 @@ SkShader* SkGradientShader::CreateRadial(const SkPoint& center, SkScalar radius,
|
|||||||
EXPAND_1_COLOR(colorCount);
|
EXPAND_1_COLOR(colorCount);
|
||||||
|
|
||||||
SkGradientShaderBase::Descriptor desc;
|
SkGradientShaderBase::Descriptor desc;
|
||||||
desc_init(&desc, colors, pos, colorCount, mode, mapper, flags);
|
desc_init(&desc, colors, pos, colorCount, mode, flags);
|
||||||
return SkNEW_ARGS(SkRadialGradient, (center, radius, desc, localMatrix));
|
return SkNEW_ARGS(SkRadialGradient, (center, radius, desc, localMatrix));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -822,7 +775,6 @@ SkShader* SkGradientShader::CreateTwoPointRadial(const SkPoint& start,
|
|||||||
const SkScalar pos[],
|
const SkScalar pos[],
|
||||||
int colorCount,
|
int colorCount,
|
||||||
SkShader::TileMode mode,
|
SkShader::TileMode mode,
|
||||||
SkUnitMapper* mapper,
|
|
||||||
uint32_t flags,
|
uint32_t flags,
|
||||||
const SkMatrix* localMatrix) {
|
const SkMatrix* localMatrix) {
|
||||||
if (startRadius < 0 || endRadius < 0 || NULL == colors || colorCount < 1) {
|
if (startRadius < 0 || endRadius < 0 || NULL == colors || colorCount < 1) {
|
||||||
@ -831,7 +783,7 @@ SkShader* SkGradientShader::CreateTwoPointRadial(const SkPoint& start,
|
|||||||
EXPAND_1_COLOR(colorCount);
|
EXPAND_1_COLOR(colorCount);
|
||||||
|
|
||||||
SkGradientShaderBase::Descriptor desc;
|
SkGradientShaderBase::Descriptor desc;
|
||||||
desc_init(&desc, colors, pos, colorCount, mode, mapper, flags);
|
desc_init(&desc, colors, pos, colorCount, mode, flags);
|
||||||
return SkNEW_ARGS(SkTwoPointRadialGradient,
|
return SkNEW_ARGS(SkTwoPointRadialGradient,
|
||||||
(start, startRadius, end, endRadius, desc, localMatrix));
|
(start, startRadius, end, endRadius, desc, localMatrix));
|
||||||
}
|
}
|
||||||
@ -844,7 +796,6 @@ SkShader* SkGradientShader::CreateTwoPointConical(const SkPoint& start,
|
|||||||
const SkScalar pos[],
|
const SkScalar pos[],
|
||||||
int colorCount,
|
int colorCount,
|
||||||
SkShader::TileMode mode,
|
SkShader::TileMode mode,
|
||||||
SkUnitMapper* mapper,
|
|
||||||
uint32_t flags,
|
uint32_t flags,
|
||||||
const SkMatrix* localMatrix) {
|
const SkMatrix* localMatrix) {
|
||||||
if (startRadius < 0 || endRadius < 0 || NULL == colors || colorCount < 1) {
|
if (startRadius < 0 || endRadius < 0 || NULL == colors || colorCount < 1) {
|
||||||
@ -861,7 +812,7 @@ SkShader* SkGradientShader::CreateTwoPointConical(const SkPoint& start,
|
|||||||
SkGradientShaderBase::Descriptor desc;
|
SkGradientShaderBase::Descriptor desc;
|
||||||
|
|
||||||
if (!flipGradient) {
|
if (!flipGradient) {
|
||||||
desc_init(&desc, colors, pos, colorCount, mode, mapper, flags);
|
desc_init(&desc, colors, pos, colorCount, mode, flags);
|
||||||
return SkNEW_ARGS(SkTwoPointConicalGradient,
|
return SkNEW_ARGS(SkTwoPointConicalGradient,
|
||||||
(start, startRadius, end, endRadius, flipGradient, desc, localMatrix));
|
(start, startRadius, end, endRadius, flipGradient, desc, localMatrix));
|
||||||
} else {
|
} else {
|
||||||
@ -875,9 +826,9 @@ SkShader* SkGradientShader::CreateTwoPointConical(const SkPoint& start,
|
|||||||
for (int i = 0; i < colorCount; ++i) {
|
for (int i = 0; i < colorCount; ++i) {
|
||||||
posNew[i] = 1 - pos[colorCount - i - 1];
|
posNew[i] = 1 - pos[colorCount - i - 1];
|
||||||
}
|
}
|
||||||
desc_init(&desc, colorsNew.get(), posNew.get(), colorCount, mode, mapper, flags);
|
desc_init(&desc, colorsNew.get(), posNew.get(), colorCount, mode, flags);
|
||||||
} else {
|
} else {
|
||||||
desc_init(&desc, colorsNew.get(), NULL, colorCount, mode, mapper, flags);
|
desc_init(&desc, colorsNew.get(), NULL, colorCount, mode, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
return SkNEW_ARGS(SkTwoPointConicalGradient,
|
return SkNEW_ARGS(SkTwoPointConicalGradient,
|
||||||
@ -888,7 +839,7 @@ SkShader* SkGradientShader::CreateTwoPointConical(const SkPoint& start,
|
|||||||
SkShader* SkGradientShader::CreateSweep(SkScalar cx, SkScalar cy,
|
SkShader* SkGradientShader::CreateSweep(SkScalar cx, SkScalar cy,
|
||||||
const SkColor colors[],
|
const SkColor colors[],
|
||||||
const SkScalar pos[],
|
const SkScalar pos[],
|
||||||
int colorCount, SkUnitMapper* mapper,
|
int colorCount,
|
||||||
uint32_t flags,
|
uint32_t flags,
|
||||||
const SkMatrix* localMatrix) {
|
const SkMatrix* localMatrix) {
|
||||||
if (NULL == colors || colorCount < 1) {
|
if (NULL == colors || colorCount < 1) {
|
||||||
@ -897,7 +848,7 @@ SkShader* SkGradientShader::CreateSweep(SkScalar cx, SkScalar cy,
|
|||||||
EXPAND_1_COLOR(colorCount);
|
EXPAND_1_COLOR(colorCount);
|
||||||
|
|
||||||
SkGradientShaderBase::Descriptor desc;
|
SkGradientShaderBase::Descriptor desc;
|
||||||
desc_init(&desc, colors, pos, colorCount, SkShader::kClamp_TileMode, mapper, flags);
|
desc_init(&desc, colors, pos, colorCount, SkShader::kClamp_TileMode, flags);
|
||||||
return SkNEW_ARGS(SkSweepGradient, (cx, cy, desc, localMatrix));
|
return SkNEW_ARGS(SkSweepGradient, (cx, cy, desc, localMatrix));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
#include "SkReadBuffer.h"
|
#include "SkReadBuffer.h"
|
||||||
#include "SkWriteBuffer.h"
|
#include "SkWriteBuffer.h"
|
||||||
#include "SkMallocPixelRef.h"
|
#include "SkMallocPixelRef.h"
|
||||||
#include "SkUnitMapper.h"
|
|
||||||
#include "SkUtils.h"
|
#include "SkUtils.h"
|
||||||
#include "SkTemplates.h"
|
#include "SkTemplates.h"
|
||||||
#include "SkBitmapCache.h"
|
#include "SkBitmapCache.h"
|
||||||
@ -94,7 +93,6 @@ public:
|
|||||||
const SkScalar* fPos;
|
const SkScalar* fPos;
|
||||||
int fCount;
|
int fCount;
|
||||||
SkShader::TileMode fTileMode;
|
SkShader::TileMode fTileMode;
|
||||||
SkUnitMapper* fMapper;
|
|
||||||
uint32_t fGradFlags;
|
uint32_t fGradFlags;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -201,7 +199,6 @@ protected:
|
|||||||
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
|
virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
|
||||||
SK_TO_STRING_OVERRIDE()
|
SK_TO_STRING_OVERRIDE()
|
||||||
|
|
||||||
SkUnitMapper* fMapper;
|
|
||||||
SkMatrix fPtsToUnit; // set by subclass
|
SkMatrix fPtsToUnit; // set by subclass
|
||||||
TileMode fTileMode;
|
TileMode fTileMode;
|
||||||
TileProc fTileProc;
|
TileProc fTileProc;
|
||||||
|
@ -1,61 +0,0 @@
|
|||||||
|
|
||||||
/*
|
|
||||||
* 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 "SkUnitMappers.h"
|
|
||||||
#include "SkReadBuffer.h"
|
|
||||||
#include "SkWriteBuffer.h"
|
|
||||||
|
|
||||||
|
|
||||||
SkDiscreteMapper::SkDiscreteMapper(int segments) {
|
|
||||||
if (segments < 2) {
|
|
||||||
fSegments = 0;
|
|
||||||
fScale = 0;
|
|
||||||
} else {
|
|
||||||
if (segments > 0xFFFF) {
|
|
||||||
segments = 0xFFFF;
|
|
||||||
}
|
|
||||||
fSegments = segments;
|
|
||||||
fScale = (1 << 30) / (segments - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint16_t SkDiscreteMapper::mapUnit16(uint16_t input) {
|
|
||||||
SkFixed x = input * fSegments >> 16;
|
|
||||||
x = x * fScale >> 14;
|
|
||||||
x += x << 15 >> 31; // map 0x10000 to 0xFFFF
|
|
||||||
return SkToU16(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
SkDiscreteMapper::SkDiscreteMapper(SkReadBuffer& rb)
|
|
||||||
: SkUnitMapper(rb) {
|
|
||||||
fSegments = rb.readInt();
|
|
||||||
fScale = rb.read32();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SkDiscreteMapper::flatten(SkWriteBuffer& wb) const {
|
|
||||||
this->INHERITED::flatten(wb);
|
|
||||||
|
|
||||||
wb.writeInt(fSegments);
|
|
||||||
wb.write32(fScale);
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
uint16_t SkCosineMapper::mapUnit16(uint16_t input)
|
|
||||||
{
|
|
||||||
/* we want to call cosine(input * pi/2) treating input as [0...1)
|
|
||||||
however, the straight multitply would overflow 32bits since input is
|
|
||||||
16bits and pi/2 is 17bits, so we shift down our pi const before we mul
|
|
||||||
*/
|
|
||||||
SkFixed rads = (unsigned)(input * (SK_FixedPI >> 2)) >> 15;
|
|
||||||
SkFixed x = SkFixedCos(rads);
|
|
||||||
x += x << 15 >> 31; // map 0x10000 to 0xFFFF
|
|
||||||
return SkToU16(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
SkCosineMapper::SkCosineMapper(SkReadBuffer& rb)
|
|
||||||
: SkUnitMapper(rb) {}
|
|
@ -359,7 +359,7 @@ static void TestDeferredCanvasFreshFrame(skiatest::Reporter* reporter) {
|
|||||||
const SkColor colors[2] = {SK_ColorWHITE, SK_ColorWHITE};
|
const SkColor colors[2] = {SK_ColorWHITE, SK_ColorWHITE};
|
||||||
const SkScalar pos[2] = {0, SK_Scalar1};
|
const SkScalar pos[2] = {0, SK_Scalar1};
|
||||||
SkShader* shader = SkGradientShader::CreateTwoPointConical(
|
SkShader* shader = SkGradientShader::CreateTwoPointConical(
|
||||||
pt1, r1, pt2, r2, colors, pos, 2, SkShader::kClamp_TileMode, NULL);
|
pt1, r1, pt2, r2, colors, pos, 2, SkShader::kClamp_TileMode);
|
||||||
paint.setShader(shader)->unref();
|
paint.setShader(shader)->unref();
|
||||||
canvas->drawRect(fullRect, paint);
|
canvas->drawRect(fullRect, paint);
|
||||||
REPORTER_ASSERT(reporter, !canvas->isFreshFrame());
|
REPORTER_ASSERT(reporter, !canvas->isFreshFrame());
|
||||||
|
Loading…
Reference in New Issue
Block a user