add localMatrix to gradient Descriptor
this consolidation will also help transisition to new flattening pattern, where we want to have a flatten/unflatten method on all of the common gradient params (i.e. Descriptor). BUG=skia: R=egdaniel@google.com Author: reed@google.com Review URL: https://codereview.chromium.org/461643002
This commit is contained in:
parent
6dff71f44b
commit
addf2edf3d
@ -12,8 +12,8 @@
|
||||
#include "SkTwoPointConicalGradient.h"
|
||||
#include "SkSweepGradient.h"
|
||||
|
||||
SkGradientShaderBase::SkGradientShaderBase(const Descriptor& desc, const SkMatrix* localMatrix)
|
||||
: INHERITED(localMatrix)
|
||||
SkGradientShaderBase::SkGradientShaderBase(const Descriptor& desc)
|
||||
: INHERITED(desc.fLocalMatrix)
|
||||
{
|
||||
SkASSERT(desc.fCount > 1);
|
||||
|
||||
@ -711,14 +711,14 @@ void SkGradientShaderBase::toString(SkString* str) const {
|
||||
} while (0)
|
||||
|
||||
static void desc_init(SkGradientShaderBase::Descriptor* desc,
|
||||
const SkColor colors[],
|
||||
const SkScalar pos[], int colorCount,
|
||||
SkShader::TileMode mode, uint32_t flags) {
|
||||
const SkColor colors[], const SkScalar pos[], int colorCount,
|
||||
SkShader::TileMode mode, uint32_t flags, const SkMatrix* localMatrix) {
|
||||
desc->fColors = colors;
|
||||
desc->fPos = pos;
|
||||
desc->fCount = colorCount;
|
||||
desc->fTileMode = mode;
|
||||
desc->fGradFlags = flags;
|
||||
desc->fLocalMatrix = localMatrix;
|
||||
}
|
||||
|
||||
SkShader* SkGradientShader::CreateLinear(const SkPoint pts[2],
|
||||
@ -733,8 +733,8 @@ SkShader* SkGradientShader::CreateLinear(const SkPoint pts[2],
|
||||
EXPAND_1_COLOR(colorCount);
|
||||
|
||||
SkGradientShaderBase::Descriptor desc;
|
||||
desc_init(&desc, colors, pos, colorCount, mode, flags);
|
||||
return SkNEW_ARGS(SkLinearGradient, (pts, desc, localMatrix));
|
||||
desc_init(&desc, colors, pos, colorCount, mode, flags, localMatrix);
|
||||
return SkNEW_ARGS(SkLinearGradient, (pts, desc));
|
||||
}
|
||||
|
||||
SkShader* SkGradientShader::CreateRadial(const SkPoint& center, SkScalar radius,
|
||||
@ -749,8 +749,8 @@ SkShader* SkGradientShader::CreateRadial(const SkPoint& center, SkScalar radius,
|
||||
EXPAND_1_COLOR(colorCount);
|
||||
|
||||
SkGradientShaderBase::Descriptor desc;
|
||||
desc_init(&desc, colors, pos, colorCount, mode, flags);
|
||||
return SkNEW_ARGS(SkRadialGradient, (center, radius, desc, localMatrix));
|
||||
desc_init(&desc, colors, pos, colorCount, mode, flags, localMatrix);
|
||||
return SkNEW_ARGS(SkRadialGradient, (center, radius, desc));
|
||||
}
|
||||
|
||||
SkShader* SkGradientShader::CreateTwoPointRadial(const SkPoint& start,
|
||||
@ -769,9 +769,9 @@ SkShader* SkGradientShader::CreateTwoPointRadial(const SkPoint& start,
|
||||
EXPAND_1_COLOR(colorCount);
|
||||
|
||||
SkGradientShaderBase::Descriptor desc;
|
||||
desc_init(&desc, colors, pos, colorCount, mode, flags);
|
||||
desc_init(&desc, colors, pos, colorCount, mode, flags, localMatrix);
|
||||
return SkNEW_ARGS(SkTwoPointRadialGradient,
|
||||
(start, startRadius, end, endRadius, desc, localMatrix));
|
||||
(start, startRadius, end, endRadius, desc));
|
||||
}
|
||||
|
||||
SkShader* SkGradientShader::CreateTwoPointConical(const SkPoint& start,
|
||||
@ -798,9 +798,9 @@ SkShader* SkGradientShader::CreateTwoPointConical(const SkPoint& start,
|
||||
SkGradientShaderBase::Descriptor desc;
|
||||
|
||||
if (!flipGradient) {
|
||||
desc_init(&desc, colors, pos, colorCount, mode, flags);
|
||||
desc_init(&desc, colors, pos, colorCount, mode, flags, localMatrix);
|
||||
return SkNEW_ARGS(SkTwoPointConicalGradient,
|
||||
(start, startRadius, end, endRadius, flipGradient, desc, localMatrix));
|
||||
(start, startRadius, end, endRadius, flipGradient, desc));
|
||||
} else {
|
||||
SkAutoSTArray<8, SkColor> colorsNew(colorCount);
|
||||
SkAutoSTArray<8, SkScalar> posNew(colorCount);
|
||||
@ -812,13 +812,13 @@ SkShader* SkGradientShader::CreateTwoPointConical(const SkPoint& start,
|
||||
for (int i = 0; i < colorCount; ++i) {
|
||||
posNew[i] = 1 - pos[colorCount - i - 1];
|
||||
}
|
||||
desc_init(&desc, colorsNew.get(), posNew.get(), colorCount, mode, flags);
|
||||
desc_init(&desc, colorsNew.get(), posNew.get(), colorCount, mode, flags, localMatrix);
|
||||
} else {
|
||||
desc_init(&desc, colorsNew.get(), NULL, colorCount, mode, flags);
|
||||
desc_init(&desc, colorsNew.get(), NULL, colorCount, mode, flags, localMatrix);
|
||||
}
|
||||
|
||||
return SkNEW_ARGS(SkTwoPointConicalGradient,
|
||||
(end, endRadius, start, startRadius, flipGradient, desc, localMatrix));
|
||||
(end, endRadius, start, startRadius, flipGradient, desc));
|
||||
}
|
||||
}
|
||||
|
||||
@ -834,8 +834,8 @@ SkShader* SkGradientShader::CreateSweep(SkScalar cx, SkScalar cy,
|
||||
EXPAND_1_COLOR(colorCount);
|
||||
|
||||
SkGradientShaderBase::Descriptor desc;
|
||||
desc_init(&desc, colors, pos, colorCount, SkShader::kClamp_TileMode, flags);
|
||||
return SkNEW_ARGS(SkSweepGradient, (cx, cy, desc, localMatrix));
|
||||
desc_init(&desc, colors, pos, colorCount, SkShader::kClamp_TileMode, flags, localMatrix);
|
||||
return SkNEW_ARGS(SkSweepGradient, (cx, cy, desc));
|
||||
}
|
||||
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkGradientShader)
|
||||
|
@ -89,6 +89,7 @@ public:
|
||||
fTileMode = SkShader::kClamp_TileMode;
|
||||
}
|
||||
|
||||
const SkMatrix* fLocalMatrix;
|
||||
const SkColor* fColors;
|
||||
const SkScalar* fPos;
|
||||
int fCount;
|
||||
@ -97,7 +98,7 @@ public:
|
||||
};
|
||||
|
||||
public:
|
||||
SkGradientShaderBase(const Descriptor& desc, const SkMatrix* localMatrix);
|
||||
SkGradientShaderBase(const Descriptor& desc);
|
||||
virtual ~SkGradientShaderBase();
|
||||
|
||||
// The cache is initialized on-demand when getCache16/32 is called.
|
||||
|
@ -52,11 +52,11 @@ static void pts_to_unit_matrix(const SkPoint pts[2], SkMatrix* matrix) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkLinearGradient::SkLinearGradient(const SkPoint pts[2], const Descriptor& desc,
|
||||
const SkMatrix* localMatrix)
|
||||
: SkGradientShaderBase(desc, localMatrix)
|
||||
SkLinearGradient::SkLinearGradient(const SkPoint pts[2], const Descriptor& desc)
|
||||
: SkGradientShaderBase(desc)
|
||||
, fStart(pts[0])
|
||||
, fEnd(pts[1]) {
|
||||
, fEnd(pts[1])
|
||||
{
|
||||
pts_to_unit_matrix(pts, &fPtsToUnit);
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
class SkLinearGradient : public SkGradientShaderBase {
|
||||
public:
|
||||
SkLinearGradient(const SkPoint pts[2], const Descriptor&, const SkMatrix* localMatrix);
|
||||
SkLinearGradient(const SkPoint pts[2], const Descriptor&);
|
||||
|
||||
virtual size_t contextSize() const SK_OVERRIDE;
|
||||
|
||||
|
@ -145,11 +145,10 @@ void shadeSpan16_radial_repeat(SkScalar fx, SkScalar dx, SkScalar fy, SkScalar d
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkRadialGradient::SkRadialGradient(const SkPoint& center, SkScalar radius,
|
||||
const Descriptor& desc, const SkMatrix* localMatrix)
|
||||
: SkGradientShaderBase(desc, localMatrix),
|
||||
fCenter(center),
|
||||
fRadius(radius)
|
||||
SkRadialGradient::SkRadialGradient(const SkPoint& center, SkScalar radius, const Descriptor& desc)
|
||||
: SkGradientShaderBase(desc)
|
||||
, fCenter(center)
|
||||
, fRadius(radius)
|
||||
{
|
||||
// make sure our table is insync with our current #define for kSQRT_TABLE_SIZE
|
||||
SkASSERT(sizeof(gSqrt8Table) == kSQRT_TABLE_SIZE);
|
||||
|
@ -13,8 +13,7 @@
|
||||
|
||||
class SkRadialGradient : public SkGradientShaderBase {
|
||||
public:
|
||||
SkRadialGradient(const SkPoint& center, SkScalar radius, const Descriptor&,
|
||||
const SkMatrix* localMatrix);
|
||||
SkRadialGradient(const SkPoint& center, SkScalar radius, const Descriptor&);
|
||||
|
||||
virtual size_t contextSize() const SK_OVERRIDE;
|
||||
|
||||
|
@ -8,9 +8,8 @@
|
||||
|
||||
#include "SkSweepGradient.h"
|
||||
|
||||
SkSweepGradient::SkSweepGradient(SkScalar cx, SkScalar cy,
|
||||
const Descriptor& desc, const SkMatrix* localMatrix)
|
||||
: SkGradientShaderBase(desc, localMatrix)
|
||||
SkSweepGradient::SkSweepGradient(SkScalar cx, SkScalar cy, const Descriptor& desc)
|
||||
: SkGradientShaderBase(desc)
|
||||
, fCenter(SkPoint::Make(cx, cy))
|
||||
{
|
||||
fPtsToUnit.setTranslate(-cx, -cy);
|
||||
|
@ -13,8 +13,7 @@
|
||||
|
||||
class SkSweepGradient : public SkGradientShaderBase {
|
||||
public:
|
||||
SkSweepGradient(SkScalar cx, SkScalar cy, const Descriptor&,
|
||||
const SkMatrix* localMatrix);
|
||||
SkSweepGradient(SkScalar cx, SkScalar cy, const Descriptor&);
|
||||
|
||||
virtual size_t contextSize() const SK_OVERRIDE;
|
||||
|
||||
|
@ -196,14 +196,14 @@ void SkTwoPointConicalGradient::init() {
|
||||
SkTwoPointConicalGradient::SkTwoPointConicalGradient(
|
||||
const SkPoint& start, SkScalar startRadius,
|
||||
const SkPoint& end, SkScalar endRadius,
|
||||
bool flippedGrad, const Descriptor& desc,
|
||||
const SkMatrix* localMatrix)
|
||||
: SkGradientShaderBase(desc, localMatrix),
|
||||
fCenter1(start),
|
||||
fCenter2(end),
|
||||
fRadius1(startRadius),
|
||||
fRadius2(endRadius),
|
||||
fFlippedGrad(flippedGrad) {
|
||||
bool flippedGrad, const Descriptor& desc)
|
||||
: SkGradientShaderBase(desc)
|
||||
, fCenter1(start)
|
||||
, fCenter2(end)
|
||||
, fRadius1(startRadius)
|
||||
, fRadius2(endRadius)
|
||||
, fFlippedGrad(flippedGrad)
|
||||
{
|
||||
// this is degenerate, and should be caught by our caller
|
||||
SkASSERT(fCenter1 != fCenter2 || fRadius1 != fRadius2);
|
||||
this->init();
|
||||
|
@ -44,8 +44,7 @@ class SkTwoPointConicalGradient : public SkGradientShaderBase {
|
||||
public:
|
||||
SkTwoPointConicalGradient(const SkPoint& start, SkScalar startRadius,
|
||||
const SkPoint& end, SkScalar endRadius,
|
||||
bool flippedGrad, const Descriptor&,
|
||||
const SkMatrix* localMatrix);
|
||||
bool flippedGrad, const Descriptor&);
|
||||
|
||||
|
||||
virtual size_t contextSize() const SK_OVERRIDE;
|
||||
|
@ -167,15 +167,15 @@ void shadeSpan_twopoint_repeat(SkScalar fx, SkScalar dx,
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkTwoPointRadialGradient::SkTwoPointRadialGradient(
|
||||
const SkPoint& start, SkScalar startRadius,
|
||||
const SkPoint& end, SkScalar endRadius,
|
||||
const Descriptor& desc, const SkMatrix* localMatrix)
|
||||
: SkGradientShaderBase(desc, localMatrix),
|
||||
fCenter1(start),
|
||||
fCenter2(end),
|
||||
fRadius1(startRadius),
|
||||
fRadius2(endRadius) {
|
||||
SkTwoPointRadialGradient::SkTwoPointRadialGradient(const SkPoint& start, SkScalar startRadius,
|
||||
const SkPoint& end, SkScalar endRadius,
|
||||
const Descriptor& desc)
|
||||
: SkGradientShaderBase(desc)
|
||||
, fCenter1(start)
|
||||
, fCenter2(end)
|
||||
, fRadius1(startRadius)
|
||||
, fRadius2(endRadius)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@ class SkTwoPointRadialGradient : public SkGradientShaderBase {
|
||||
public:
|
||||
SkTwoPointRadialGradient(const SkPoint& start, SkScalar startRadius,
|
||||
const SkPoint& end, SkScalar endRadius,
|
||||
const Descriptor&, const SkMatrix* localMatrix);
|
||||
const Descriptor&);
|
||||
|
||||
virtual BitmapType asABitmap(SkBitmap* bitmap,
|
||||
SkMatrix* matrix,
|
||||
|
Loading…
Reference in New Issue
Block a user