Change signature of SkShader::asNewEffect(), implement for SkBitmapProcShader.
Review URL: https://codereview.appspot.com/7086051 git-svn-id: http://skia.googlecode.com/svn/trunk@7153 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
ff06af20fd
commit
e197cbf9a3
@ -93,6 +93,12 @@
|
|||||||
'../src/core/SkUtilsArm.h',
|
'../src/core/SkUtilsArm.h',
|
||||||
],
|
],
|
||||||
}],
|
}],
|
||||||
|
['skia_gpu == 1', {
|
||||||
|
'include_dirs': [
|
||||||
|
'../include/gpu',
|
||||||
|
'../src/gpu',
|
||||||
|
],
|
||||||
|
}],
|
||||||
],
|
],
|
||||||
'direct_dependent_settings': {
|
'direct_dependent_settings': {
|
||||||
'include_dirs': [
|
'include_dirs': [
|
||||||
|
@ -319,11 +319,10 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* If the shader subclass has a GrEffect implementation, this installs an effect on the stage.
|
* If the shader subclass has a GrEffect implementation, this installs an effect on the stage.
|
||||||
* A GrContext pointer is required since effects may need to create textures. The stage
|
* The GrContext may be used by the effect to create textures. The GPU device does not call
|
||||||
* parameter is necessary to set a texture matrix. It will eventually be removed and this
|
* setContext. Instead we pass the paint here in case the shader needs paint info.
|
||||||
* function will operate as a GrEffect factory.
|
|
||||||
*/
|
*/
|
||||||
virtual bool asNewEffect(GrContext* context, GrEffectStage* stage) const;
|
virtual GrEffect* asNewEffect(GrContext* context, const SkPaint& paint) const;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
// Factory methods for stock shaders
|
// Factory methods for stock shaders
|
||||||
|
@ -336,4 +336,41 @@ bool SkBitmapProcShader::toDumpString(SkString* str) const {
|
|||||||
gTileModeName[fState.fTileModeY]);
|
gTileModeName[fState.fTileModeY]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#if SK_SUPPORT_GPU
|
||||||
|
|
||||||
|
#include "GrTextureAccess.h"
|
||||||
|
#include "effects/GrSingleTextureEffect.h"
|
||||||
|
#include "SkGr.h"
|
||||||
|
|
||||||
|
GrEffect* SkBitmapProcShader::asNewEffect(GrContext* context, const SkPaint& paint) const {
|
||||||
|
SkMatrix matrix;
|
||||||
|
matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height());
|
||||||
|
|
||||||
|
if (this->hasLocalMatrix()) {
|
||||||
|
SkMatrix inverse;
|
||||||
|
if (!this->getLocalMatrix().invert(&inverse)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
matrix.preConcat(inverse);
|
||||||
|
}
|
||||||
|
SkShader::TileMode tm[] = {
|
||||||
|
(TileMode)fState.fTileModeX,
|
||||||
|
(TileMode)fState.fTileModeY,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Must set wrap and filter on the sampler before requesting a texture.
|
||||||
|
GrTextureParams params(tm, paint.isFilterBitmap());
|
||||||
|
GrTexture* texture = GrLockCachedBitmapTexture(context, fRawBitmap, ¶ms);
|
||||||
|
|
||||||
|
if (NULL == texture) {
|
||||||
|
SkDebugf("Couldn't convert bitmap to texture.\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
GrEffect* effect = SkNEW_ARGS(GrSingleTextureEffect, (texture, matrix, params));
|
||||||
|
GrUnlockCachedBitmapTexture(texture);
|
||||||
|
return effect;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
@ -33,6 +33,10 @@ public:
|
|||||||
virtual bool toDumpString(SkString* str) const;
|
virtual bool toDumpString(SkString* str) const;
|
||||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader)
|
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader)
|
||||||
|
|
||||||
|
#if SK_SUPPORT_GPU
|
||||||
|
GrEffect* asNewEffect(GrContext*, const SkPaint&) const SK_OVERRIDE;
|
||||||
|
#endif
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
SkBitmapProcShader(SkFlattenableReadBuffer& );
|
SkBitmapProcShader(SkFlattenableReadBuffer& );
|
||||||
virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
|
virtual void flatten(SkFlattenableWriteBuffer&) const SK_OVERRIDE;
|
||||||
|
@ -173,7 +173,7 @@ SkShader::GradientType SkShader::asAGradient(GradientInfo* info) const {
|
|||||||
return kNone_GradientType;
|
return kNone_GradientType;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SkShader::asNewEffect(GrContext*, GrEffectStage*) const {
|
GrEffect* SkShader::asNewEffect(GrContext*, const SkPaint&) const {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -522,12 +522,8 @@ GrEffect* GrLinearGradient::TestCreate(SkRandom* random,
|
|||||||
SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(points,
|
SkAutoTUnref<SkShader> shader(SkGradientShader::CreateLinear(points,
|
||||||
colors, stops, colorCount,
|
colors, stops, colorCount,
|
||||||
tm));
|
tm));
|
||||||
GrEffectStage stage;
|
SkPaint paint;
|
||||||
shader->asNewEffect(context, &stage);
|
return shader->asNewEffect(context, paint);
|
||||||
GrAssert(NULL != stage.getEffect());
|
|
||||||
// const_cast and ref is a hack! Will remove when asNewEffect returns GrEffect*
|
|
||||||
stage.getEffect()->ref();
|
|
||||||
return const_cast<GrEffect*>(stage.getEffect());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
@ -550,22 +546,21 @@ void GrGLLinearGradient::emitCode(GrGLShaderBuilder* builder,
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool SkLinearGradient::asNewEffect(GrContext* context, GrEffectStage* stage) const {
|
GrEffect* SkLinearGradient::asNewEffect(GrContext* context, const SkPaint&) const {
|
||||||
SkASSERT(NULL != context && NULL != stage);
|
SkASSERT(NULL != context && NULL != stage);
|
||||||
SkMatrix matrix;
|
SkMatrix matrix;
|
||||||
if (!this->getLocalMatrix().invert(&matrix)) {
|
if (!this->getLocalMatrix().invert(&matrix)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
matrix.postConcat(fPtsToUnit);
|
matrix.postConcat(fPtsToUnit);
|
||||||
stage->setEffect(SkNEW_ARGS(GrLinearGradient, (context, *this, matrix, fTileMode)))->unref();
|
return SkNEW_ARGS(GrLinearGradient, (context, *this, matrix, fTileMode));
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
bool SkLinearGradient::asNewEffect(GrContext*, GrEffectStage*) const {
|
GrEffect* SkLinearGradient::asNewEffect(GrContext* context, const SkPaint&) const {
|
||||||
SkDEBUGFAIL("Should not call in GPU-less build");
|
SkDEBUGFAIL("Should not call in GPU-less build");
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -22,7 +22,7 @@ public:
|
|||||||
virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OVERRIDE;
|
virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OVERRIDE;
|
||||||
virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) const SK_OVERRIDE;
|
virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) const SK_OVERRIDE;
|
||||||
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
|
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
|
||||||
virtual bool asNewEffect(GrContext* context, GrEffectStage* stage) const SK_OVERRIDE;
|
virtual GrEffect* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE;
|
||||||
|
|
||||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLinearGradient)
|
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLinearGradient)
|
||||||
|
|
||||||
|
@ -545,12 +545,8 @@ GrEffect* GrRadialGradient::TestCreate(SkRandom* random,
|
|||||||
SkAutoTUnref<SkShader> shader(SkGradientShader::CreateRadial(center, radius,
|
SkAutoTUnref<SkShader> shader(SkGradientShader::CreateRadial(center, radius,
|
||||||
colors, stops, colorCount,
|
colors, stops, colorCount,
|
||||||
tm));
|
tm));
|
||||||
GrEffectStage stage;
|
SkPaint paint;
|
||||||
shader->asNewEffect(context, &stage);
|
return shader->asNewEffect(context, paint);
|
||||||
GrAssert(NULL != stage.getEffect());
|
|
||||||
// const_cast and ref is a hack! Will remove when asNewEffect returns GrEffect*
|
|
||||||
stage.getEffect()->ref();
|
|
||||||
return const_cast<GrEffect*>(stage.getEffect());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
@ -573,7 +569,7 @@ void GrGLRadialGradient::emitCode(GrGLShaderBuilder* builder,
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool SkRadialGradient::asNewEffect(GrContext* context, GrEffectStage* stage) const {
|
GrEffect* SkRadialGradient::asNewEffect(GrContext* context, const SkPaint&) const {
|
||||||
SkASSERT(NULL != context && NULL != stage);
|
SkASSERT(NULL != context && NULL != stage);
|
||||||
|
|
||||||
SkMatrix matrix;
|
SkMatrix matrix;
|
||||||
@ -581,15 +577,14 @@ bool SkRadialGradient::asNewEffect(GrContext* context, GrEffectStage* stage) con
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
matrix.postConcat(fPtsToUnit);
|
matrix.postConcat(fPtsToUnit);
|
||||||
stage->setEffect(SkNEW_ARGS(GrRadialGradient, (context, *this, matrix, fTileMode)))->unref();
|
return SkNEW_ARGS(GrRadialGradient, (context, *this, matrix, fTileMode));
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
bool SkRadialGradient::asNewEffect(GrContext*, GrEffectStage*) const {
|
GrEffect* SkRadialGradient::asNewEffect(GrContext* context, const SkPaint&) const {
|
||||||
SkDEBUGFAIL("Should not call in GPU-less build");
|
SkDEBUGFAIL("Should not call in GPU-less build");
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -24,7 +24,7 @@ public:
|
|||||||
SkMatrix* matrix,
|
SkMatrix* matrix,
|
||||||
TileMode* xy) const SK_OVERRIDE;
|
TileMode* xy) const SK_OVERRIDE;
|
||||||
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
|
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
|
||||||
virtual bool asNewEffect(GrContext* context, GrEffectStage* stage) const SK_OVERRIDE;
|
virtual GrEffect* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE;
|
||||||
|
|
||||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkRadialGradient)
|
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkRadialGradient)
|
||||||
|
|
||||||
|
@ -449,12 +449,8 @@ GrEffect* GrSweepGradient::TestCreate(SkRandom* random,
|
|||||||
int colorCount = RandomGradientParams(random, colors, &stops, &tmIgnored);
|
int colorCount = RandomGradientParams(random, colors, &stops, &tmIgnored);
|
||||||
SkAutoTUnref<SkShader> shader(SkGradientShader::CreateSweep(center.fX, center.fY,
|
SkAutoTUnref<SkShader> shader(SkGradientShader::CreateSweep(center.fX, center.fY,
|
||||||
colors, stops, colorCount));
|
colors, stops, colorCount));
|
||||||
GrEffectStage stage;
|
SkPaint paint;
|
||||||
shader->asNewEffect(context, &stage);
|
return shader->asNewEffect(context, paint);
|
||||||
GrAssert(NULL != stage.getEffect());
|
|
||||||
// const_cast and ref is a hack! Will remove when asNewEffect returns GrEffect*
|
|
||||||
stage.getEffect()->ref();
|
|
||||||
return const_cast<GrEffect*>(stage.getEffect());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
@ -476,21 +472,20 @@ void GrGLSweepGradient::emitCode(GrGLShaderBuilder* builder,
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool SkSweepGradient::asNewEffect(GrContext* context, GrEffectStage* stage) const {
|
GrEffect* SkSweepGradient::asNewEffect(GrContext* context, const SkPaint&) const {
|
||||||
SkMatrix matrix;
|
SkMatrix matrix;
|
||||||
if (!this->getLocalMatrix().invert(&matrix)) {
|
if (!this->getLocalMatrix().invert(&matrix)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
matrix.postConcat(fPtsToUnit);
|
matrix.postConcat(fPtsToUnit);
|
||||||
stage->setEffect(SkNEW_ARGS(GrSweepGradient, (context, *this, matrix)))->unref();
|
return SkNEW_ARGS(GrSweepGradient, (context, *this, matrix));
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
bool SkSweepGradient::asNewEffect(GrContext*, GrEffectStage*) const {
|
GrEffect* SkSweepGradient::asNewEffect(GrContext* context, const SkPaint&) const {
|
||||||
SkDEBUGFAIL("Should not call in GPU-less build");
|
SkDEBUGFAIL("Should not call in GPU-less build");
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -24,7 +24,7 @@ public:
|
|||||||
|
|
||||||
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
|
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
|
||||||
|
|
||||||
virtual bool asNewEffect(GrContext* context, GrEffectStage* stage) const SK_OVERRIDE;
|
virtual GrEffect* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE;
|
||||||
|
|
||||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSweepGradient)
|
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSweepGradient)
|
||||||
|
|
||||||
|
@ -440,12 +440,8 @@ GrEffect* GrConical2Gradient::TestCreate(SkRandom* random,
|
|||||||
center2, radius2,
|
center2, radius2,
|
||||||
colors, stops, colorCount,
|
colors, stops, colorCount,
|
||||||
tm));
|
tm));
|
||||||
GrEffectStage stage;
|
SkPaint paint;
|
||||||
shader->asNewEffect(context, &stage);
|
return shader->asNewEffect(context, paint);
|
||||||
GrAssert(NULL != stage.getEffect());
|
|
||||||
// const_cast and ref is a hack! Will remove when asNewEffect returns GrEffect*
|
|
||||||
stage.getEffect()->ref();
|
|
||||||
return const_cast<GrEffect*>(stage.getEffect());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -688,8 +684,7 @@ GrGLEffect::EffectKey GrGLConical2Gradient::GenKey(const GrEffectStage& s, const
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool SkTwoPointConicalGradient::asNewEffect(GrContext* context,
|
GrEffect* SkTwoPointConicalGradient::asNewEffect(GrContext* context, const SkPaint&) const {
|
||||||
GrEffectStage* stage) const {
|
|
||||||
SkASSERT(NULL != context && NULL != stage);
|
SkASSERT(NULL != context && NULL != stage);
|
||||||
SkASSERT(fPtsToUnit.isIdentity());
|
SkASSERT(fPtsToUnit.isIdentity());
|
||||||
// invert the localM, translate to center1, rotate so center2 is on x axis.
|
// invert the localM, translate to center1, rotate so center2 is on x axis.
|
||||||
@ -709,16 +704,14 @@ bool SkTwoPointConicalGradient::asNewEffect(GrContext* context,
|
|||||||
matrix.postConcat(rot);
|
matrix.postConcat(rot);
|
||||||
}
|
}
|
||||||
|
|
||||||
stage->setEffect(SkNEW_ARGS(GrConical2Gradient, (context, *this, matrix, fTileMode)))->unref();
|
return SkNEW_ARGS(GrConical2Gradient, (context, *this, matrix, fTileMode));
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
bool SkTwoPointConicalGradient::asNewEffect(GrContext*, GrEffectStage*) const {
|
GrEffect* SkTwoPointConicalGradient::asNewEffect(GrContext* context, const SkPaint&) const {
|
||||||
SkDEBUGFAIL("Should not call in GPU-less build");
|
SkDEBUGFAIL("Should not call in GPU-less build");
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -61,7 +61,7 @@ public:
|
|||||||
SkMatrix* matrix,
|
SkMatrix* matrix,
|
||||||
TileMode* xy) const;
|
TileMode* xy) const;
|
||||||
virtual SkShader::GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
|
virtual SkShader::GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
|
||||||
virtual bool asNewEffect(GrContext* context, GrEffectStage* stage) const SK_OVERRIDE;
|
virtual GrEffect* asNewEffect(GrContext* context, const SkPaint& paint) const SK_OVERRIDE;
|
||||||
|
|
||||||
SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2); }
|
SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2); }
|
||||||
SkScalar getStartRadius() const { return fRadius1; }
|
SkScalar getStartRadius() const { return fRadius1; }
|
||||||
|
@ -463,7 +463,7 @@ GrEffect* GrRadial2Gradient::TestCreate(SkRandom* random,
|
|||||||
do {
|
do {
|
||||||
center2.set(random->nextUScalar1(), random->nextUScalar1());
|
center2.set(random->nextUScalar1(), random->nextUScalar1());
|
||||||
radius2 = random->nextUScalar1 ();
|
radius2 = random->nextUScalar1 ();
|
||||||
// There is a bug in two point radial gradients with idenitical radii
|
// There is a bug in two point radial gradients with identical radii
|
||||||
} while (radius1 == radius2);
|
} while (radius1 == radius2);
|
||||||
|
|
||||||
SkColor colors[kMaxRandomGradientColors];
|
SkColor colors[kMaxRandomGradientColors];
|
||||||
@ -475,12 +475,8 @@ GrEffect* GrRadial2Gradient::TestCreate(SkRandom* random,
|
|||||||
center2, radius2,
|
center2, radius2,
|
||||||
colors, stops, colorCount,
|
colors, stops, colorCount,
|
||||||
tm));
|
tm));
|
||||||
GrEffectStage stage;
|
SkPaint paint;
|
||||||
shader->asNewEffect(context, &stage);
|
return shader->asNewEffect(context, paint);
|
||||||
GrAssert(NULL != stage.getEffect());
|
|
||||||
// const_cast and ref is a hack! Will remove when asNewEffect returns GrEffect*
|
|
||||||
stage.getEffect()->ref();
|
|
||||||
return const_cast<GrEffect*>(stage.getEffect());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
@ -661,8 +657,7 @@ GrGLEffect::EffectKey GrGLRadial2Gradient::GenKey(const GrEffectStage& s, const
|
|||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
bool SkTwoPointRadialGradient::asNewEffect(GrContext* context,
|
GrEffect* SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint&) const {
|
||||||
GrEffectStage* stage) const {
|
|
||||||
SkASSERT(NULL != context && NULL != stage);
|
SkASSERT(NULL != context && NULL != stage);
|
||||||
// invert the localM, translate to center1 (fPtsToUni), rotate so center2 is on x axis.
|
// invert the localM, translate to center1 (fPtsToUni), rotate so center2 is on x axis.
|
||||||
SkMatrix matrix;
|
SkMatrix matrix;
|
||||||
@ -680,15 +675,14 @@ bool SkTwoPointRadialGradient::asNewEffect(GrContext* context,
|
|||||||
matrix.postConcat(rot);
|
matrix.postConcat(rot);
|
||||||
}
|
}
|
||||||
|
|
||||||
stage->setEffect(SkNEW_ARGS(GrRadial2Gradient, (context, *this, matrix, fTileMode)))->unref();
|
return SkNEW_ARGS(GrRadial2Gradient, (context, *this, matrix, fTileMode));
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
bool SkTwoPointRadialGradient::asNewEffect(GrContext*, GrEffectStage*) const {
|
GrEffect* SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint&) const {
|
||||||
SkDEBUGFAIL("Should not call in GPU-less build");
|
SkDEBUGFAIL("Should not call in GPU-less build");
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -23,7 +23,7 @@ public:
|
|||||||
SkMatrix* matrix,
|
SkMatrix* matrix,
|
||||||
TileMode* xy) const SK_OVERRIDE;
|
TileMode* xy) const SK_OVERRIDE;
|
||||||
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
|
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
|
||||||
virtual bool asNewEffect(GrContext* context, GrEffectStage* stage) const SK_OVERRIDE;
|
virtual GrEffect* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE;
|
||||||
|
|
||||||
virtual void shadeSpan(int x, int y, SkPMColor* dstCParam,
|
virtual void shadeSpan(int x, int y, SkPMColor* dstCParam,
|
||||||
int count) SK_OVERRIDE;
|
int count) SK_OVERRIDE;
|
||||||
|
@ -474,7 +474,6 @@ inline bool skPaint2GrPaintNoShader(SkGpuDevice* dev,
|
|||||||
const SkPaint& skPaint,
|
const SkPaint& skPaint,
|
||||||
bool justAlpha,
|
bool justAlpha,
|
||||||
bool constantColor,
|
bool constantColor,
|
||||||
SkGpuDevice::SkAutoCachedTexture* act,
|
|
||||||
GrPaint* grPaint) {
|
GrPaint* grPaint) {
|
||||||
|
|
||||||
grPaint->setDither(skPaint.isDither());
|
grPaint->setDither(skPaint.isDither());
|
||||||
@ -537,81 +536,36 @@ inline bool skPaint2GrPaintNoShader(SkGpuDevice* dev,
|
|||||||
inline bool skPaint2GrPaintShader(SkGpuDevice* dev,
|
inline bool skPaint2GrPaintShader(SkGpuDevice* dev,
|
||||||
const SkPaint& skPaint,
|
const SkPaint& skPaint,
|
||||||
bool constantColor,
|
bool constantColor,
|
||||||
SkGpuDevice::SkAutoCachedTexture textures[GrPaint::kMaxColorStages],
|
|
||||||
GrPaint* grPaint) {
|
GrPaint* grPaint) {
|
||||||
SkShader* shader = skPaint.getShader();
|
SkShader* shader = skPaint.getShader();
|
||||||
if (NULL == shader) {
|
if (NULL == shader) {
|
||||||
return skPaint2GrPaintNoShader(dev,
|
return skPaint2GrPaintNoShader(dev, skPaint, false, constantColor, grPaint);
|
||||||
skPaint,
|
} else if (!skPaint2GrPaintNoShader(dev, skPaint, true, false, grPaint)) {
|
||||||
false,
|
|
||||||
constantColor,
|
|
||||||
&textures[kColorFilterTextureIdx],
|
|
||||||
grPaint);
|
|
||||||
} else if (!skPaint2GrPaintNoShader(dev, skPaint, true, false,
|
|
||||||
&textures[kColorFilterTextureIdx], grPaint)) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
GrEffectStage* stage = grPaint->colorStage(kShaderTextureIdx);
|
SkAutoTUnref<GrEffect> effect(shader->asNewEffect(dev->context(), skPaint));
|
||||||
if (shader->asNewEffect(dev->context(), stage)) {
|
if (NULL != effect.get()) {
|
||||||
|
grPaint->colorStage(kShaderTextureIdx)->setEffect(effect);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkBitmap bitmap;
|
// We still don't have SkColorShader::asNewEffect() implemented.
|
||||||
SkMatrix matrix;
|
SkShader::GradientInfo info;
|
||||||
SkShader::TileMode tileModes[2];
|
SkColor color;
|
||||||
SkShader::BitmapType bmptype = shader->asABitmap(&bitmap, &matrix, tileModes);
|
|
||||||
|
|
||||||
if (SkShader::kNone_BitmapType == bmptype) {
|
info.fColors = &color;
|
||||||
SkShader::GradientInfo info;
|
info.fColorOffsets = NULL;
|
||||||
SkColor color;
|
info.fColorCount = 1;
|
||||||
|
if (SkShader::kColor_GradientType == shader->asAGradient(&info)) {
|
||||||
info.fColors = &color;
|
SkPaint copy(skPaint);
|
||||||
info.fColorOffsets = NULL;
|
copy.setShader(NULL);
|
||||||
info.fColorCount = 1;
|
// modulate the paint alpha by the shader's solid color alpha
|
||||||
if (SkShader::kColor_GradientType == shader->asAGradient(&info)) {
|
U8CPU newA = SkMulDiv255Round(SkColorGetA(color), copy.getAlpha());
|
||||||
SkPaint copy(skPaint);
|
copy.setColor(SkColorSetA(color, newA));
|
||||||
copy.setShader(NULL);
|
return skPaint2GrPaintNoShader(dev, copy, false, constantColor, grPaint);
|
||||||
// modulate the paint alpha by the shader's solid color alpha
|
|
||||||
U8CPU newA = SkMulDiv255Round(SkColorGetA(color), copy.getAlpha());
|
|
||||||
copy.setColor(SkColorSetA(color, newA));
|
|
||||||
return skPaint2GrPaintNoShader(dev,
|
|
||||||
copy,
|
|
||||||
false,
|
|
||||||
constantColor,
|
|
||||||
&textures[kColorFilterTextureIdx],
|
|
||||||
grPaint);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
// since our texture coords will be in local space, we whack the texture
|
|
||||||
// matrix to map them back into 0...1 before we load it
|
|
||||||
if (shader->hasLocalMatrix()) {
|
|
||||||
SkMatrix inverse;
|
|
||||||
if (!shader->getLocalMatrix().invert(&inverse)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
matrix.preConcat(inverse);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Must set wrap and filter on the sampler before requesting a texture.
|
|
||||||
GrTextureParams params(tileModes, skPaint.isFilterBitmap());
|
|
||||||
GrTexture* texture = textures[kShaderTextureIdx].set(dev, bitmap, ¶ms);
|
|
||||||
|
|
||||||
if (NULL == texture) {
|
|
||||||
SkDebugf("Couldn't convert bitmap to texture.\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SkShader::kDefault_BitmapType == bmptype) {
|
|
||||||
SkScalar sx = SkFloatToScalar(1.f / bitmap.width());
|
|
||||||
SkScalar sy = SkFloatToScalar(1.f / bitmap.height());
|
|
||||||
matrix.postScale(sx, sy);
|
|
||||||
}
|
|
||||||
stage->setEffect(SkNEW_ARGS(GrSingleTextureEffect, (texture, matrix, params)))->unref();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -625,12 +579,7 @@ void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
|
|||||||
CHECK_SHOULD_DRAW(draw, false);
|
CHECK_SHOULD_DRAW(draw, false);
|
||||||
|
|
||||||
GrPaint grPaint;
|
GrPaint grPaint;
|
||||||
SkAutoCachedTexture textures[GrPaint::kMaxColorStages];
|
if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
|
||||||
if (!skPaint2GrPaintShader(this,
|
|
||||||
paint,
|
|
||||||
true,
|
|
||||||
textures,
|
|
||||||
&grPaint)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -661,12 +610,7 @@ void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
GrPaint grPaint;
|
GrPaint grPaint;
|
||||||
SkAutoCachedTexture textures[GrPaint::kMaxColorStages];
|
if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
|
||||||
if (!skPaint2GrPaintShader(this,
|
|
||||||
paint,
|
|
||||||
true,
|
|
||||||
textures,
|
|
||||||
&grPaint)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -723,12 +667,7 @@ void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect,
|
|||||||
}
|
}
|
||||||
|
|
||||||
GrPaint grPaint;
|
GrPaint grPaint;
|
||||||
SkAutoCachedTexture textures[GrPaint::kMaxColorStages];
|
if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
|
||||||
if (!skPaint2GrPaintShader(this,
|
|
||||||
paint,
|
|
||||||
true,
|
|
||||||
textures,
|
|
||||||
&grPaint)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fContext->drawRect(grPaint, rect, doStroke ? width : -1);
|
fContext->drawRect(grPaint, rect, doStroke ? width : -1);
|
||||||
@ -966,12 +905,7 @@ void SkGpuDevice::drawPath(const SkDraw& draw, const SkPath& origSrcPath,
|
|||||||
CHECK_SHOULD_DRAW(draw, false);
|
CHECK_SHOULD_DRAW(draw, false);
|
||||||
|
|
||||||
GrPaint grPaint;
|
GrPaint grPaint;
|
||||||
SkAutoCachedTexture textures[GrPaint::kMaxColorStages];
|
if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
|
||||||
if (!skPaint2GrPaintShader(this,
|
|
||||||
paint,
|
|
||||||
true,
|
|
||||||
textures,
|
|
||||||
&grPaint)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1199,10 +1133,9 @@ void SkGpuDevice::drawBitmapCommon(const SkDraw& draw,
|
|||||||
}
|
}
|
||||||
|
|
||||||
GrPaint grPaint;
|
GrPaint grPaint;
|
||||||
SkAutoCachedTexture colorLutTexture;
|
|
||||||
|
|
||||||
bool alphaOnly = !(SkBitmap::kA8_Config == bitmap.config());
|
bool alphaOnly = !(SkBitmap::kA8_Config == bitmap.config());
|
||||||
if (!skPaint2GrPaintNoShader(this, paint, alphaOnly, false, &colorLutTexture, &grPaint)) {
|
if (!skPaint2GrPaintNoShader(this, paint, alphaOnly, false, &grPaint)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GrTextureParams params;
|
GrTextureParams params;
|
||||||
@ -1472,8 +1405,7 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
|
|||||||
int h = bitmap.height();
|
int h = bitmap.height();
|
||||||
|
|
||||||
GrPaint grPaint;
|
GrPaint grPaint;
|
||||||
SkAutoCachedTexture colorLutTexture;
|
if(!skPaint2GrPaintNoShader(this, paint, true, false, &grPaint)) {
|
||||||
if(!skPaint2GrPaintNoShader(this, paint, true, false, &colorLutTexture, &grPaint)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1550,10 +1482,9 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkDevice* device,
|
|||||||
CHECK_SHOULD_DRAW(draw, true);
|
CHECK_SHOULD_DRAW(draw, true);
|
||||||
|
|
||||||
GrPaint grPaint;
|
GrPaint grPaint;
|
||||||
SkAutoCachedTexture colorLutTexture;
|
|
||||||
grPaint.colorStage(kBitmapTextureIdx)->reset();
|
grPaint.colorStage(kBitmapTextureIdx)->reset();
|
||||||
if (!dev->bindDeviceAsTexture(&grPaint) ||
|
if (!dev->bindDeviceAsTexture(&grPaint) ||
|
||||||
!skPaint2GrPaintNoShader(this, paint, true, false, &colorLutTexture, &grPaint)) {
|
!skPaint2GrPaintNoShader(this, paint, true, false, &grPaint)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1648,23 +1579,13 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
|
|||||||
CHECK_SHOULD_DRAW(draw, false);
|
CHECK_SHOULD_DRAW(draw, false);
|
||||||
|
|
||||||
GrPaint grPaint;
|
GrPaint grPaint;
|
||||||
SkAutoCachedTexture textures[GrPaint::kMaxColorStages];
|
|
||||||
// we ignore the shader if texs is null.
|
// we ignore the shader if texs is null.
|
||||||
if (NULL == texs) {
|
if (NULL == texs) {
|
||||||
if (!skPaint2GrPaintNoShader(this,
|
if (!skPaint2GrPaintNoShader(this, paint, false, NULL == colors, &grPaint)) {
|
||||||
paint,
|
|
||||||
false,
|
|
||||||
NULL == colors,
|
|
||||||
&textures[kColorFilterTextureIdx],
|
|
||||||
&grPaint)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (!skPaint2GrPaintShader(this,
|
if (!skPaint2GrPaintShader(this, paint, NULL == colors, &grPaint)) {
|
||||||
paint,
|
|
||||||
NULL == colors,
|
|
||||||
textures,
|
|
||||||
&grPaint)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1763,12 +1684,7 @@ void SkGpuDevice::drawText(const SkDraw& draw, const void* text,
|
|||||||
SkDraw myDraw(draw);
|
SkDraw myDraw(draw);
|
||||||
|
|
||||||
GrPaint grPaint;
|
GrPaint grPaint;
|
||||||
SkAutoCachedTexture textures[GrPaint::kMaxColorStages];
|
if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
|
||||||
if (!skPaint2GrPaintShader(this,
|
|
||||||
paint,
|
|
||||||
true,
|
|
||||||
textures,
|
|
||||||
&grPaint)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GrTextContext context(fContext, grPaint);
|
GrTextContext context(fContext, grPaint);
|
||||||
@ -1791,12 +1707,7 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text,
|
|||||||
SkDraw myDraw(draw);
|
SkDraw myDraw(draw);
|
||||||
|
|
||||||
GrPaint grPaint;
|
GrPaint grPaint;
|
||||||
SkAutoCachedTexture textures[GrPaint::kMaxColorStages];
|
if (!skPaint2GrPaintShader(this, paint, true, &grPaint)) {
|
||||||
if (!skPaint2GrPaintShader(this,
|
|
||||||
paint,
|
|
||||||
true,
|
|
||||||
textures,
|
|
||||||
&grPaint)) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GrTextContext context(fContext, grPaint);
|
GrTextContext context(fContext, grPaint);
|
||||||
|
Loading…
Reference in New Issue
Block a user