add localmatrix parameter to shader's asNewEffect

BUG=skia:
R=bsalomon@google.com, dominikg@chromium.org

Author: reed@google.com

Review URL: https://codereview.chromium.org/278963002

git-svn-id: http://skia.googlecode.com/svn/trunk@14686 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
commit-bot@chromium.org 2014-05-09 20:28:11 +00:00
parent 68867b3db2
commit 96fb7489ba
22 changed files with 102 additions and 38 deletions

View File

@ -360,7 +360,8 @@ public:
* color. The GrContext may be used by the effect to create textures. The GPU device does not
* call createContext. Instead we pass the SkPaint here in case the shader needs paint info.
*/
virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint& paint) const;
virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint& paint,
const SkMatrix* localMatrixOrNull) const;
//////////////////////////////////////////////////////////////////////////
// Factory methods for stock shaders

View File

@ -95,7 +95,8 @@ public:
typedef SkShader::Context INHERITED;
};
virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE;
virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint&,
const SkMatrix*) const SK_OVERRIDE;
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPerlinNoiseShader)

View File

@ -393,7 +393,8 @@ static SkScalar get_combined_min_stretch(const SkMatrix& viewMatrix, const SkMat
}
}
GrEffectRef* SkBitmapProcShader::asNewEffect(GrContext* context, const SkPaint& paint) const {
GrEffectRef* SkBitmapProcShader::asNewEffect(GrContext* context, const SkPaint& paint,
const SkMatrix* localMatrix) const {
SkMatrix matrix;
matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height());
@ -401,6 +402,13 @@ GrEffectRef* SkBitmapProcShader::asNewEffect(GrContext* context, const SkPaint&
if (!this->getLocalMatrix().invert(&lmInverse)) {
return NULL;
}
if (localMatrix) {
SkMatrix inv;
if (!localMatrix->invert(&inv)) {
return NULL;
}
lmInverse.postConcat(inv);
}
matrix.preConcat(lmInverse);
SkShader::TileMode tm[] = {

View File

@ -31,7 +31,7 @@ public:
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader)
#if SK_SUPPORT_GPU
GrEffectRef* asNewEffect(GrContext*, const SkPaint&) const SK_OVERRIDE;
GrEffectRef* asNewEffect(GrContext*, const SkPaint&, const SkMatrix*) const SK_OVERRIDE;
#endif
class BitmapProcShaderContext : public SkShader::Context {

View File

@ -30,8 +30,13 @@ public:
}
// TODO: need to augment this API to pass in a localmatrix (which we can augment)
virtual GrEffectRef* asNewEffect(GrContext* ctx, const SkPaint& paint) const SK_OVERRIDE {
return fProxyShader->asNewEffect(ctx, paint);
virtual GrEffectRef* asNewEffect(GrContext* ctx, const SkPaint& paint,
const SkMatrix* localMatrix) const SK_OVERRIDE {
SkMatrix tmp = fProxyLocalMatrix;
if (localMatrix) {
tmp.preConcat(*localMatrix);
}
return fProxyShader->asNewEffect(ctx, paint, &tmp);
}
virtual SkShader* refAsALocalMatrixShader(SkMatrix* localMatrix) const SK_OVERRIDE {

View File

@ -192,11 +192,12 @@ void SkPictureShader::toString(SkString* str) const {
#endif
#if SK_SUPPORT_GPU
GrEffectRef* SkPictureShader::asNewEffect(GrContext* context, const SkPaint& paint) const {
SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(context->getMatrix(), NULL));
GrEffectRef* SkPictureShader::asNewEffect(GrContext* context, const SkPaint& paint,
const SkMatrix* localMatrix) const {
SkAutoTUnref<SkShader> bitmapShader(this->refBitmapShader(context->getMatrix(), localMatrix));
if (!bitmapShader) {
return NULL;
}
return bitmapShader->asNewEffect(context, paint);
return bitmapShader->asNewEffect(context, paint, NULL);
}
#endif

View File

@ -30,7 +30,7 @@ public:
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureShader)
#if SK_SUPPORT_GPU
GrEffectRef* asNewEffect(GrContext*, const SkPaint&) const SK_OVERRIDE;
GrEffectRef* asNewEffect(GrContext*, const SkPaint&, const SkMatrix*) const SK_OVERRIDE;
#endif
protected:

View File

@ -211,7 +211,7 @@ SkShader::GradientType SkShader::asAGradient(GradientInfo* info) const {
return kNone_GradientType;
}
GrEffectRef* SkShader::asNewEffect(GrContext*, const SkPaint&) const {
GrEffectRef* SkShader::asNewEffect(GrContext*, const SkPaint&, const SkMatrix*) const {
return NULL;
}

View File

@ -723,7 +723,7 @@ GrEffectRef* GrPerlinNoiseEffect::TestCreate(SkRandom* random,
stitchTiles ? &tileSize : NULL);
SkPaint paint;
GrEffectRef* effect = shader->asNewEffect(context, paint);
GrEffectRef* effect = shader->asNewEffect(context, paint, NULL);
SkDELETE(shader);
@ -1275,9 +1275,15 @@ void GrGLSimplexNoise::setData(const GrGLUniformManager& uman, const GrDrawEffec
/////////////////////////////////////////////////////////////////////
GrEffectRef* SkPerlinNoiseShader::asNewEffect(GrContext* context, const SkPaint& paint) const {
GrEffectRef* SkPerlinNoiseShader::asNewEffect(GrContext* context, const SkPaint& paint,
const SkMatrix* externalLocalMatrix) const {
SkASSERT(NULL != context);
SkMatrix localMatrix = this->getLocalMatrix();
if (externalLocalMatrix) {
localMatrix.preConcat(*externalLocalMatrix);
}
if (0 == fNumOctaves) {
SkColor clearColor = 0;
if (kFractalNoise_Type == fType) {
@ -1309,7 +1315,7 @@ GrEffectRef* SkPerlinNoiseShader::asNewEffect(GrContext* context, const SkPaint&
fNumOctaves, fStitchTiles,
fPaintingData->fStitchDataInit,
permutationsTexture, noiseTexture,
this->getLocalMatrix(), paint.getAlpha()) :
localMatrix, paint.getAlpha()) :
NULL;
// Unlock immediately, this is not great, but we don't have a way of
@ -1328,7 +1334,7 @@ GrEffectRef* SkPerlinNoiseShader::asNewEffect(GrContext* context, const SkPaint&
#else
GrEffectRef* SkPerlinNoiseShader::asNewEffect(GrContext*, const SkPaint&) const {
GrEffectRef* SkPerlinNoiseShader::asNewEffect(GrContext*, const SkPaint&, const SkMatrix*) const {
SkDEBUGFAIL("Should not call in GPU-less build");
return NULL;
}

View File

@ -527,7 +527,7 @@ GrEffectRef* GrLinearGradient::TestCreate(SkRandom* random,
colors, stops, colorCount,
tm));
SkPaint paint;
return shader->asNewEffect(context, paint);
return shader->asNewEffect(context, paint, NULL);
}
/////////////////////////////////////////////////////////////////////
@ -547,12 +547,20 @@ void GrGLLinearGradient::emitCode(GrGLShaderBuilder* builder,
/////////////////////////////////////////////////////////////////////
GrEffectRef* SkLinearGradient::asNewEffect(GrContext* context, const SkPaint&) const {
GrEffectRef* SkLinearGradient::asNewEffect(GrContext* context, const SkPaint&,
const SkMatrix* localMatrix) const {
SkASSERT(NULL != context);
SkMatrix matrix;
if (!this->getLocalMatrix().invert(&matrix)) {
return NULL;
}
if (localMatrix) {
SkMatrix inv;
if (!localMatrix->invert(&inv)) {
return NULL;
}
matrix.postConcat(inv);
}
matrix.postConcat(fPtsToUnit);
return GrLinearGradient::Create(context, *this, matrix, fTileMode);
}

View File

@ -30,7 +30,7 @@ public:
virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) const SK_OVERRIDE;
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE;
virtual GrEffectRef* asNewEffect(GrContext*, const SkPaint&, const SkMatrix*) const SK_OVERRIDE;
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLinearGradient)

View File

@ -538,7 +538,7 @@ GrEffectRef* GrRadialGradient::TestCreate(SkRandom* random,
colors, stops, colorCount,
tm));
SkPaint paint;
return shader->asNewEffect(context, paint);
return shader->asNewEffect(context, paint, NULL);
}
/////////////////////////////////////////////////////////////////////
@ -559,13 +559,21 @@ void GrGLRadialGradient::emitCode(GrGLShaderBuilder* builder,
/////////////////////////////////////////////////////////////////////
GrEffectRef* SkRadialGradient::asNewEffect(GrContext* context, const SkPaint&) const {
GrEffectRef* SkRadialGradient::asNewEffect(GrContext* context, const SkPaint&,
const SkMatrix* localMatrix) const {
SkASSERT(NULL != context);
SkMatrix matrix;
if (!this->getLocalMatrix().invert(&matrix)) {
return NULL;
}
if (localMatrix) {
SkMatrix inv;
if (!localMatrix->invert(&inv)) {
return NULL;
}
matrix.postConcat(inv);
}
matrix.postConcat(fPtsToUnit);
return GrRadialGradient::Create(context, *this, matrix, fTileMode);
}

View File

@ -33,7 +33,7 @@ public:
SkMatrix* matrix,
TileMode* xy) const SK_OVERRIDE;
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE;
virtual GrEffectRef* asNewEffect(GrContext*, const SkPaint&, const SkMatrix*) const SK_OVERRIDE;
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkRadialGradient)

View File

@ -247,7 +247,7 @@ GrEffectRef* GrSweepGradient::TestCreate(SkRandom* random,
SkAutoTUnref<SkShader> shader(SkGradientShader::CreateSweep(center.fX, center.fY,
colors, stops, colorCount));
SkPaint paint;
return shader->asNewEffect(context, paint);
return shader->asNewEffect(context, paint, NULL);
}
/////////////////////////////////////////////////////////////////////
@ -279,11 +279,19 @@ void GrGLSweepGradient::emitCode(GrGLShaderBuilder* builder,
/////////////////////////////////////////////////////////////////////
GrEffectRef* SkSweepGradient::asNewEffect(GrContext* context, const SkPaint&) const {
GrEffectRef* SkSweepGradient::asNewEffect(GrContext* context, const SkPaint&,
const SkMatrix* localMatrix) const {
SkMatrix matrix;
if (!this->getLocalMatrix().invert(&matrix)) {
return NULL;
}
if (localMatrix) {
SkMatrix inv;
if (!localMatrix->invert(&inv)) {
return NULL;
}
matrix.postConcat(inv);
}
matrix.postConcat(fPtsToUnit);
return GrSweepGradient::Create(context, *this, matrix);
}

View File

@ -35,7 +35,7 @@ public:
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE;
virtual GrEffectRef* asNewEffect(GrContext*, const SkPaint&, const SkMatrix*) const SK_OVERRIDE;
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSweepGradient)

View File

@ -380,11 +380,12 @@ void SkTwoPointConicalGradient::flatten(
#if SK_SUPPORT_GPU
GrEffectRef* SkTwoPointConicalGradient::asNewEffect(GrContext* context, const SkPaint&) const {
GrEffectRef* SkTwoPointConicalGradient::asNewEffect(GrContext* context, const SkPaint&,
const SkMatrix* localMatrix) const {
SkASSERT(NULL != context);
SkASSERT(fPtsToUnit.isIdentity());
return Gr2PtConicalGradientEffect::Create(context, *this, fTileMode);
return Gr2PtConicalGradientEffect::Create(context, *this, fTileMode, localMatrix);
}
#else

View File

@ -65,7 +65,7 @@ public:
SkMatrix* matrix,
TileMode* xy) const;
virtual SkShader::GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint& paint) const SK_OVERRIDE;
virtual GrEffectRef* asNewEffect(GrContext*, const SkPaint&, const SkMatrix*) const SK_OVERRIDE;
virtual bool isOpaque() const SK_OVERRIDE;
SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2); }

View File

@ -199,7 +199,7 @@ GrEffectRef* Edge2PtConicalEffect::TestCreate(SkRandom* random,
colors, stops, colorCount,
tm));
SkPaint paint;
return shader->asNewEffect(context, paint);
return shader->asNewEffect(context, paint, NULL);
}
GLEdge2PtConicalEffect::GLEdge2PtConicalEffect(const GrBackendEffectFactory& factory,
@ -470,7 +470,7 @@ GrEffectRef* FocalOutside2PtConicalEffect::TestCreate(SkRandom* random,
colors, stops, colorCount,
tm));
SkPaint paint;
return shader->asNewEffect(context, paint);
return shader->asNewEffect(context, paint, NULL);
}
GLFocalOutside2PtConicalEffect::GLFocalOutside2PtConicalEffect(const GrBackendEffectFactory& factory,
@ -679,7 +679,7 @@ GrEffectRef* FocalInside2PtConicalEffect::TestCreate(SkRandom* random,
colors, stops, colorCount,
tm));
SkPaint paint;
return shader->asNewEffect(context, paint);
return shader->asNewEffect(context, paint, NULL);
}
GLFocalInside2PtConicalEffect::GLFocalInside2PtConicalEffect(const GrBackendEffectFactory& factory,
@ -920,7 +920,7 @@ GrEffectRef* CircleInside2PtConicalEffect::TestCreate(SkRandom* random,
colors, stops, colorCount,
tm));
SkPaint paint;
return shader->asNewEffect(context, paint);
return shader->asNewEffect(context, paint, NULL);
}
GLCircleInside2PtConicalEffect::GLCircleInside2PtConicalEffect(const GrBackendEffectFactory& factory,
@ -1148,7 +1148,7 @@ GrEffectRef* CircleOutside2PtConicalEffect::TestCreate(SkRandom* random,
colors, stops, colorCount,
tm));
SkPaint paint;
return shader->asNewEffect(context, paint);
return shader->asNewEffect(context, paint, NULL);
}
GLCircleOutside2PtConicalEffect::GLCircleOutside2PtConicalEffect(const GrBackendEffectFactory& factory,
@ -1267,11 +1267,19 @@ GrGLEffect::EffectKey GLCircleOutside2PtConicalEffect::GenKey(const GrDrawEffect
GrEffectRef* Gr2PtConicalGradientEffect::Create(GrContext* ctx,
const SkTwoPointConicalGradient& shader,
SkShader::TileMode tm) {
SkShader::TileMode tm,
const SkMatrix* localMatrix) {
SkMatrix matrix;
if (!shader.getLocalMatrix().invert(&matrix)) {
return NULL;
}
if (localMatrix) {
SkMatrix inv;
if (!localMatrix->invert(&inv)) {
return NULL;
}
matrix.postConcat(inv);
}
if (shader.getStartRadius() < kErrorTol) {
SkScalar focalX;

View File

@ -19,7 +19,7 @@ namespace Gr2PtConicalGradientEffect {
* shader passed in.
*/
GrEffectRef* Create(GrContext* ctx, const SkTwoPointConicalGradient& shader,
SkShader::TileMode tm);
SkShader::TileMode tm, const SkMatrix* localMatrix);
};
#endif

View File

@ -530,7 +530,7 @@ GrEffectRef* GrRadial2Gradient::TestCreate(SkRandom* random,
colors, stops, colorCount,
tm));
SkPaint paint;
return shader->asNewEffect(context, paint);
return shader->asNewEffect(context, paint, NULL);
}
/////////////////////////////////////////////////////////////////////
@ -670,13 +670,21 @@ GrGLEffect::EffectKey GrGLRadial2Gradient::GenKey(const GrDrawEffect& drawEffect
/////////////////////////////////////////////////////////////////////
GrEffectRef* SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint&) const {
GrEffectRef* SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint&,
const SkMatrix* localMatrix) const {
SkASSERT(NULL != context);
// invert the localM, translate to center1 (fPtsToUni), rotate so center2 is on x axis.
SkMatrix matrix;
if (!this->getLocalMatrix().invert(&matrix)) {
return NULL;
}
if (localMatrix) {
SkMatrix inv;
if (!localMatrix->invert(&inv)) {
return NULL;
}
matrix.postConcat(inv);
}
matrix.postConcat(fPtsToUnit);
SkScalar diffLen = fDiff.length();

View File

@ -21,7 +21,8 @@ public:
SkMatrix* matrix,
TileMode* xy) const SK_OVERRIDE;
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE;
virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint&,
const SkMatrix*) const SK_OVERRIDE;
virtual size_t contextSize() const SK_OVERRIDE;

View File

@ -463,7 +463,7 @@ inline bool skPaint2GrPaintShader(SkGpuDevice* dev,
GrContext::AutoWideOpenIdentityDraw awo(dev->context(), NULL);
// setup the shader as the first color effect on the paint
SkAutoTUnref<GrEffectRef> effect(shader->asNewEffect(dev->context(), skPaint));
SkAutoTUnref<GrEffectRef> effect(shader->asNewEffect(dev->context(), skPaint, NULL));
if (NULL != effect.get()) {
grPaint->addColorEffect(effect);
// Now setup the rest of the paint.