* 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
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)
}
}
-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());
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[] = {
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 {
}
// 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 {
#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
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:
return kNone_GradientType;
}
-GrEffectRef* SkShader::asNewEffect(GrContext*, const SkPaint&) const {
+GrEffectRef* SkShader::asNewEffect(GrContext*, const SkPaint&, const SkMatrix*) const {
return NULL;
}
stitchTiles ? &tileSize : NULL);
SkPaint paint;
- GrEffectRef* effect = shader->asNewEffect(context, paint);
+ GrEffectRef* effect = shader->asNewEffect(context, paint, NULL);
SkDELETE(shader);
/////////////////////////////////////////////////////////////////////
-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) {
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
#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;
}
colors, stops, colorCount,
tm));
SkPaint paint;
- return shader->asNewEffect(context, paint);
+ return shader->asNewEffect(context, paint, NULL);
}
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
-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);
}
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)
colors, stops, colorCount,
tm));
SkPaint paint;
- return shader->asNewEffect(context, paint);
+ return shader->asNewEffect(context, paint, NULL);
}
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
-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);
}
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)
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);
}
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
-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);
}
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)
#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
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); }
colors, stops, colorCount,
tm));
SkPaint paint;
- return shader->asNewEffect(context, paint);
+ return shader->asNewEffect(context, paint, NULL);
}
GLEdge2PtConicalEffect::GLEdge2PtConicalEffect(const GrBackendEffectFactory& factory,
colors, stops, colorCount,
tm));
SkPaint paint;
- return shader->asNewEffect(context, paint);
+ return shader->asNewEffect(context, paint, NULL);
}
GLFocalOutside2PtConicalEffect::GLFocalOutside2PtConicalEffect(const GrBackendEffectFactory& factory,
colors, stops, colorCount,
tm));
SkPaint paint;
- return shader->asNewEffect(context, paint);
+ return shader->asNewEffect(context, paint, NULL);
}
GLFocalInside2PtConicalEffect::GLFocalInside2PtConicalEffect(const GrBackendEffectFactory& factory,
colors, stops, colorCount,
tm));
SkPaint paint;
- return shader->asNewEffect(context, paint);
+ return shader->asNewEffect(context, paint, NULL);
}
GLCircleInside2PtConicalEffect::GLCircleInside2PtConicalEffect(const GrBackendEffectFactory& factory,
colors, stops, colorCount,
tm));
SkPaint paint;
- return shader->asNewEffect(context, paint);
+ return shader->asNewEffect(context, paint, NULL);
}
GLCircleOutside2PtConicalEffect::GLCircleOutside2PtConicalEffect(const GrBackendEffectFactory& factory,
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;
* shader passed in.
*/
GrEffectRef* Create(GrContext* ctx, const SkTwoPointConicalGradient& shader,
- SkShader::TileMode tm);
+ SkShader::TileMode tm, const SkMatrix* localMatrix);
};
#endif
colors, stops, colorCount,
tm));
SkPaint paint;
- return shader->asNewEffect(context, paint);
+ return shader->asNewEffect(context, paint, NULL);
}
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
-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();
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;
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.