Wrap GrEffects in GrEffectPtr.

This is the first step towards automatic recycling of scratch resouces in the cache via ref-cnts.

R=robertphillips@google.com
Review URL: https://codereview.appspot.com/7092061

git-svn-id: http://skia.googlecode.com/svn/trunk@7222 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
bsalomon@google.com 2013-01-16 15:16:18 +00:00
parent 6f54724c11
commit 0ac6af4997
48 changed files with 598 additions and 354 deletions

View File

@ -113,8 +113,7 @@ protected:
SkMatrix tm; SkMatrix tm;
tm = vm; tm = vm;
tm.postIDiv(2*S, 2*S); tm.postIDiv(2*S, 2*S);
paint.colorStage(0)->setEffect(SkNEW_ARGS(GrSingleTextureEffect, paint.colorStage(0)->setEffect(GrSingleTextureEffect::Create(texture, tm))->unref();
(texture, tm)))->unref();
ctx->drawRect(paint, GrRect::MakeWH(2*S, 2*S)); ctx->drawRect(paint, GrRect::MakeWH(2*S, 2*S));

View File

@ -15,7 +15,7 @@
#include "SkXfermode.h" #include "SkXfermode.h"
class SkBitmap; class SkBitmap;
class GrEffect; class GrEffectRef;
class GrContext; class GrContext;
class SK_API SkColorFilter : public SkFlattenable { class SK_API SkColorFilter : public SkFlattenable {
@ -118,7 +118,7 @@ public:
/** A subclass may implement this factory function to work with the GPU backend. If the return /** A subclass may implement this factory function to work with the GPU backend. If the return
is non-NULL then the caller owns a ref on the returned object. is non-NULL then the caller owns a ref on the returned object.
*/ */
virtual GrEffect* asNewEffect(GrContext*) const; virtual GrEffectRef* asNewEffect(GrContext*) const;
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP() SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
protected: protected:

View File

@ -17,7 +17,7 @@ class SkMatrix;
struct SkIPoint; struct SkIPoint;
struct SkIRect; struct SkIRect;
struct SkRect; struct SkRect;
class GrEffect; class GrEffectRef;
class GrTexture; class GrTexture;
/** /**
@ -93,7 +93,7 @@ public:
* The effect can assume its vertexCoords space maps 1-to-1 with texels * The effect can assume its vertexCoords space maps 1-to-1 with texels
* in the texture. * in the texture.
*/ */
virtual bool asNewEffect(GrEffect** effect, GrTexture*) const; virtual bool asNewEffect(GrEffectRef** effect, GrTexture*) const;
/** /**
* Returns true if the filter can be processed on the GPU. This is most * Returns true if the filter can be processed on the GPU. This is most

View File

@ -92,14 +92,14 @@
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#ifndef SkNEW #ifndef SkNEW
#define SkNEW(type_name) new type_name #define SkNEW(type_name) (new type_name)
#define SkNEW_ARGS(type_name, args) new type_name args #define SkNEW_ARGS(type_name, args) (new type_name args)
#define SkNEW_ARRAY(type_name, count) new type_name[count] #define SkNEW_ARRAY(type_name, count) (new type_name[(count)])
#define SkNEW_PLACEMENT(buf, type_name) new (buf) type_name #define SkNEW_PLACEMENT(buf, type_name) (new (buf) type_name)
#define SkNEW_PLACEMENT_ARGS(buf, type_name, args) \ #define SkNEW_PLACEMENT_ARGS(buf, type_name, args) \
new (buf) type_name args (new (buf) type_name args)
#define SkDELETE(obj) delete obj #define SkDELETE(obj) (delete (obj))
#define SkDELETE_ARRAY(array) delete[] array #define SkDELETE_ARRAY(array) (delete[] (array))
#endif #endif
#ifndef SK_CRASH #ifndef SK_CRASH

View File

@ -18,8 +18,7 @@
class SkPath; class SkPath;
class GrContext; class GrContext;
class GrEffect; class GrEffectRef;
class GrEffectStage;
/** \class SkShader /** \class SkShader
* *
@ -322,7 +321,7 @@ public:
* The GrContext may be used by the effect to create textures. The GPU device does not call * The GrContext may be used by the effect to create textures. The GPU device does not call
* setContext. Instead we pass the paint here in case the shader needs paint info. * setContext. Instead we pass the paint here in case the shader needs paint info.
*/ */
virtual GrEffect* asNewEffect(GrContext* context, const SkPaint& paint) const; virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint& paint) const;
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// Factory methods for stock shaders // Factory methods for stock shaders

View File

@ -22,7 +22,7 @@ public:
virtual uint32_t getFlags() const SK_OVERRIDE; virtual uint32_t getFlags() const SK_OVERRIDE;
virtual bool asColorMatrix(SkScalar matrix[20]) const SK_OVERRIDE; virtual bool asColorMatrix(SkScalar matrix[20]) const SK_OVERRIDE;
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
virtual GrEffect* asNewEffect(GrContext*) const SK_OVERRIDE; virtual GrEffectRef* asNewEffect(GrContext*) const SK_OVERRIDE;
#endif #endif
struct State { struct State {

View File

@ -16,8 +16,7 @@ class SK_API SkMagnifierImageFilter : public SkImageFilter {
public: public:
SkMagnifierImageFilter(SkRect srcRect, SkScalar inset); SkMagnifierImageFilter(SkRect srcRect, SkScalar inset);
virtual bool asNewEffect(GrEffect** effect, virtual bool asNewEffect(GrEffectRef** effect, GrTexture* texture) const SK_OVERRIDE;
GrTexture* texture) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMagnifierImageFilter) SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMagnifierImageFilter)

View File

@ -62,7 +62,7 @@ protected:
SkBitmap* result, SkIPoint* loc) SK_OVERRIDE; SkBitmap* result, SkIPoint* loc) SK_OVERRIDE;
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
virtual bool asNewEffect(GrEffect**, GrTexture*) const SK_OVERRIDE; virtual bool asNewEffect(GrEffectRef**, GrTexture*) const SK_OVERRIDE;
#endif #endif
private: private:

View File

@ -17,19 +17,52 @@
class GrBackendEffectFactory; class GrBackendEffectFactory;
class GrContext; class GrContext;
class GrEffect;
class SkString; class SkString;
/**
* A Wrapper class for GrEffect. Its ref-count will track owners that may use effects to enqueue
* new draw operations separately from ownership within a deferred drawing queue. When the
* GrEffectRef ref count reaches zero the scratch GrResources owned by the effect can be recycled
* in service of later draws. However, the deferred draw queue may still own direct references to
* the underlying GrEffect.
*/
class GrEffectRef : public SkRefCnt {
public:
SK_DECLARE_INST_COUNT(GrEffectRef);
GrEffect* get() { return fEffect; }
const GrEffect* get() const { return fEffect; }
void* operator new(size_t size);
void operator delete(void* target);
private:
friend GrEffect; // to construct these
explicit GrEffectRef(GrEffect* effect);
virtual ~GrEffectRef();
GrEffect* fEffect;
typedef SkRefCnt INHERITED;
};
/** Provides custom vertex shader, fragment shader, uniform data for a particular stage of the /** Provides custom vertex shader, fragment shader, uniform data for a particular stage of the
Ganesh shading pipeline. Ganesh shading pipeline.
Subclasses must have a function that produces a human-readable name: Subclasses must have a function that produces a human-readable name:
static const char* Name(); static const char* Name();
GrEffect objects *must* be immutable: after being constructed, their fields may not change. GrEffect objects *must* be immutable: after being constructed, their fields may not change.
GrEffect subclass objects should be created by factory functions that return GrEffectRef.
There is no public way to wrap a GrEffect in a GrEffectRef. Thus, a factory should be a static
member function of a GrEffect subclass.
*/ */
class GrEffect : public GrRefCnt { class GrEffect : public GrRefCnt {
public: public:
SK_DECLARE_INST_COUNT(GrEffect) SK_DECLARE_INST_COUNT(GrEffect)
GrEffect() {};
virtual ~GrEffect(); virtual ~GrEffect();
/** /**
@ -120,9 +153,36 @@ protected:
*/ */
void addTextureAccess(const GrTextureAccess* textureAccess); void addTextureAccess(const GrTextureAccess* textureAccess);
GrEffect() : fEffectPtr(NULL) {};
/** This should be called by GrEffect subclass factories */
static GrEffectRef* CreateEffectPtr(GrEffect* effect) {
if (NULL == effect->fEffectPtr) {
effect->fEffectPtr = SkNEW_ARGS(GrEffectRef, (effect));
} else {
effect->fEffectPtr->ref();
GrCrash("This function should only be called once per effect currently.");
}
return effect->fEffectPtr;
}
private: private:
SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses; void effectPtrDestroyed() {
fEffectPtr = NULL;
}
friend GrEffectRef; // to call GrEffectRef destroyed
SkSTArray<4, const GrTextureAccess*, true> fTextureAccesses;
GrEffectRef* fEffectPtr;
typedef GrRefCnt INHERITED; typedef GrRefCnt INHERITED;
}; };
inline GrEffectRef::GrEffectRef(GrEffect* effect) {
GrAssert(NULL != effect);
effect->ref();
fEffect = effect;
}
#endif #endif

View File

@ -22,28 +22,28 @@ class GrEffectStage {
public: public:
GrEffectStage() GrEffectStage()
: fEffect (NULL) { : fEffectPtr (NULL) {
GR_DEBUGCODE(fSavedCoordChangeCnt = 0;) GR_DEBUGCODE(fSavedCoordChangeCnt = 0;)
} }
~GrEffectStage() { ~GrEffectStage() {
GrSafeUnref(fEffect); GrSafeUnref(fEffectPtr);
GrAssert(0 == fSavedCoordChangeCnt); GrAssert(0 == fSavedCoordChangeCnt);
} }
bool operator ==(const GrEffectStage& other) const { bool operator ==(const GrEffectStage& other) const {
// first handle cases where one or the other has no effect // first handle cases where one or the other has no effect
if (NULL == fEffect) { if (NULL == fEffectPtr) {
return NULL == other.fEffect; return NULL == other.fEffectPtr;
} else if (NULL == other.fEffect) { } else if (NULL == other.fEffectPtr) {
return false; return false;
} }
if (fEffect->getFactory() != other.fEffect->getFactory()) { if (this->getEffect()->getFactory() != other.getEffect()->getFactory()) {
return false; return false;
} }
if (!fEffect->isEqual(*other.fEffect)) { if (!this->getEffect()->isEqual(*other.getEffect())) {
return false; return false;
} }
@ -53,8 +53,8 @@ public:
bool operator !=(const GrEffectStage& s) const { return !(*this == s); } bool operator !=(const GrEffectStage& s) const { return !(*this == s); }
GrEffectStage& operator =(const GrEffectStage& other) { GrEffectStage& operator =(const GrEffectStage& other) {
GrSafeAssign(fEffect, other.fEffect); GrSafeAssign(fEffectPtr, other.fEffectPtr);
if (NULL != fEffect) { if (NULL != fEffectPtr) {
fCoordChangeMatrix = other.fCoordChangeMatrix; fCoordChangeMatrix = other.fCoordChangeMatrix;
} }
return *this; return *this;
@ -70,7 +70,7 @@ public:
class SavedCoordChange { class SavedCoordChange {
private: private:
SkMatrix fCoordChangeMatrix; SkMatrix fCoordChangeMatrix;
GR_DEBUGCODE(mutable SkAutoTUnref<const GrEffect> fEffect;) GR_DEBUGCODE(mutable SkAutoTUnref<const GrEffectRef> fEffectPtr;)
friend class GrEffectStage; friend class GrEffectStage;
}; };
@ -83,9 +83,9 @@ public:
*/ */
void saveCoordChange(SavedCoordChange* savedCoordChange) const { void saveCoordChange(SavedCoordChange* savedCoordChange) const {
savedCoordChange->fCoordChangeMatrix = fCoordChangeMatrix; savedCoordChange->fCoordChangeMatrix = fCoordChangeMatrix;
GrAssert(NULL == savedCoordChange->fEffect.get()); GrAssert(NULL == savedCoordChange->fEffectPtr.get());
GR_DEBUGCODE(GrSafeRef(fEffect);) GR_DEBUGCODE(GrSafeRef(fEffectPtr);)
GR_DEBUGCODE(savedCoordChange->fEffect.reset(fEffect);) GR_DEBUGCODE(savedCoordChange->fEffectPtr.reset(fEffectPtr);)
GR_DEBUGCODE(++fSavedCoordChangeCnt); GR_DEBUGCODE(++fSavedCoordChangeCnt);
} }
@ -94,9 +94,9 @@ public:
*/ */
void restoreCoordChange(const SavedCoordChange& savedCoordChange) { void restoreCoordChange(const SavedCoordChange& savedCoordChange) {
fCoordChangeMatrix = savedCoordChange.fCoordChangeMatrix; fCoordChangeMatrix = savedCoordChange.fCoordChangeMatrix;
GrAssert(savedCoordChange.fEffect.get() == fEffect); GrAssert(savedCoordChange.fEffectPtr.get() == fEffectPtr);
GR_DEBUGCODE(--fSavedCoordChangeCnt); GR_DEBUGCODE(--fSavedCoordChangeCnt);
GR_DEBUGCODE(savedCoordChange.fEffect.reset(NULL);) GR_DEBUGCODE(savedCoordChange.fEffectPtr.reset(NULL);)
} }
/** /**
@ -106,21 +106,28 @@ public:
const SkMatrix& getCoordChangeMatrix() const { return fCoordChangeMatrix; } const SkMatrix& getCoordChangeMatrix() const { return fCoordChangeMatrix; }
void reset() { void reset() {
GrSafeSetNull(fEffect); GrSafeSetNull(fEffectPtr);
} }
const GrEffect* setEffect(const GrEffect* effect) { const GrEffectRef* setEffect(const GrEffectRef* effectPtr) {
GrAssert(0 == fSavedCoordChangeCnt); GrAssert(0 == fSavedCoordChangeCnt);
GrSafeAssign(fEffect, effect); GrSafeAssign(fEffectPtr, effectPtr);
fCoordChangeMatrix.reset(); fCoordChangeMatrix.reset();
return effect; return effectPtr;
} }
const GrEffect* getEffect() const { return fEffect; } // TODO: Push GrEffectRef deeper and make this getter return it rather than GrEffect.
const GrEffect* getEffect() const {
if (NULL != fEffectPtr) {
return fEffectPtr->get();
} else {
return NULL;
}
}
private: private:
SkMatrix fCoordChangeMatrix; SkMatrix fCoordChangeMatrix;
const GrEffect* fEffect; const GrEffectRef* fEffectPtr;
GR_DEBUGCODE(mutable int fSavedCoordChangeCnt;) GR_DEBUGCODE(mutable int fSavedCoordChangeCnt;)
}; };

View File

@ -31,22 +31,22 @@ const SkMatrix& TestMatrix(SkRandom*);
#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
class GrContext; class GrContext;
class GrEffect; class GrEffectRef;
class GrTexture; class GrTexture;
class GrEffectTestFactory : GrNoncopyable { class GrEffectTestFactory : GrNoncopyable {
public: public:
typedef GrEffect* (*CreateProc)(SkRandom*, GrContext*, GrTexture* dummyTextures[]); typedef GrEffectRef* (*CreateProc)(SkRandom*, GrContext*, GrTexture* dummyTextures[]);
GrEffectTestFactory(CreateProc createProc) { GrEffectTestFactory(CreateProc createProc) {
fCreateProc = createProc; fCreateProc = createProc;
GetFactories()->push_back(this); GetFactories()->push_back(this);
} }
static GrEffect* CreateStage(SkRandom* random, static GrEffectRef* CreateStage(SkRandom* random,
GrContext* context, GrContext* context,
GrTexture* dummyTextures[]) { GrTexture* dummyTextures[]) {
uint32_t idx = random->nextRangeU(0, GetFactories()->count() - 1); uint32_t idx = random->nextRangeU(0, GetFactories()->count() - 1);
GrEffectTestFactory* factory = (*GetFactories())[idx]; GrEffectTestFactory* factory = (*GetFactories())[idx];
return factory->fCreateProc(random, context, dummyTextures); return factory->fCreateProc(random, context, dummyTextures);
@ -62,7 +62,7 @@ private:
*/ */
#define GR_DECLARE_EFFECT_TEST \ #define GR_DECLARE_EFFECT_TEST \
static GrEffectTestFactory gTestFactory; \ static GrEffectTestFactory gTestFactory; \
static GrEffect* TestCreate(SkRandom*, GrContext*, GrTexture* dummyTextures[2]) static GrEffectRef* TestCreate(SkRandom*, GrContext*, GrTexture* dummyTextures[2])
/** GrEffect subclasses should insert this macro in their implementation file. They must then /** GrEffect subclasses should insert this macro in their implementation file. They must then
* also implement this static function: * also implement this static function:

View File

@ -335,7 +335,7 @@ void SkBitmapProcShader::toString(SkString* str) const {
#include "effects/GrSingleTextureEffect.h" #include "effects/GrSingleTextureEffect.h"
#include "SkGr.h" #include "SkGr.h"
GrEffect* SkBitmapProcShader::asNewEffect(GrContext* context, const SkPaint& paint) const { GrEffectRef* SkBitmapProcShader::asNewEffect(GrContext* context, const SkPaint& paint) const {
SkMatrix matrix; SkMatrix matrix;
matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height()); matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height());
@ -360,7 +360,7 @@ GrEffect* SkBitmapProcShader::asNewEffect(GrContext* context, const SkPaint& pai
return NULL; return NULL;
} }
GrEffect* effect = SkNEW_ARGS(GrSingleTextureEffect, (texture, matrix, params)); GrEffectRef* effect = GrSingleTextureEffect::Create(texture, matrix, params);
GrUnlockCachedBitmapTexture(texture); GrUnlockCachedBitmapTexture(texture);
return effect; return effect;
} }

View File

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

View File

@ -41,7 +41,7 @@ SkColor SkColorFilter::filterColor(SkColor c) const {
return SkUnPreMultiply::PMColorToColor(dst); return SkUnPreMultiply::PMColorToColor(dst);
} }
GrEffect* SkColorFilter::asNewEffect(GrContext*) const { GrEffectRef* SkColorFilter::asNewEffect(GrContext*) const {
return NULL; return NULL;
} }

View File

@ -117,7 +117,7 @@ bool SkImageFilter::onFilterBounds(const SkIRect& src, const SkMatrix& ctm,
return true; return true;
} }
bool SkImageFilter::asNewEffect(GrEffect**, GrTexture*) const { bool SkImageFilter::asNewEffect(GrEffectRef**, GrTexture*) const {
return false; return false;
} }

View File

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

View File

@ -143,7 +143,13 @@ private:
class GrBlendEffect : public GrEffect { class GrBlendEffect : public GrEffect {
public: public:
GrBlendEffect(SkBlendImageFilter::Mode mode, GrTexture* foreground, GrTexture* background); static GrEffectRef* Create(SkBlendImageFilter::Mode mode,
GrTexture* foreground,
GrTexture* background) {
SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrBlendEffect, (mode, foreground, background)));
return CreateEffectPtr(effect);
}
virtual ~GrBlendEffect(); virtual ~GrBlendEffect();
virtual bool isEqual(const GrEffect&) const SK_OVERRIDE; virtual bool isEqual(const GrEffect&) const SK_OVERRIDE;
@ -156,6 +162,7 @@ public:
void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
private: private:
GrBlendEffect(SkBlendImageFilter::Mode mode, GrTexture* foreground, GrTexture* background);
GrTextureAccess fForegroundAccess; GrTextureAccess fForegroundAccess;
GrTextureAccess fBackgroundAccess; GrTextureAccess fBackgroundAccess;
SkBlendImageFilter::Mode fMode; SkBlendImageFilter::Mode fMode;
@ -218,7 +225,7 @@ GrTexture* SkBlendImageFilter::filterImageGPU(Proxy* proxy, GrTexture* src, cons
GrPaint paint; GrPaint paint;
paint.colorStage(0)->setEffect( paint.colorStage(0)->setEffect(
SkNEW_ARGS(GrBlendEffect, (fMode, foreground.get(), background.get())))->unref(); GrBlendEffect::Create(fMode, foreground.get(), background.get()))->unref();
context->drawRect(paint, rect); context->drawRect(paint, rect);
return dst; return dst;
} }

View File

@ -325,9 +325,12 @@ bool SkColorMatrixFilter::asColorMatrix(SkScalar matrix[20]) const {
class ColorMatrixEffect : public GrEffect { class ColorMatrixEffect : public GrEffect {
public: public:
static const char* Name() { return "Color Matrix"; } static GrEffectRef* Create(const SkColorMatrix& matrix) {
SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(ColorMatrixEffect, (matrix)));
return CreateEffectPtr(effect);
}
ColorMatrixEffect(const SkColorMatrix& matrix) : fMatrix(matrix) {} static const char* Name() { return "Color Matrix"; }
virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE { virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE {
return GrTBackendEffectFactory<ColorMatrixEffect>::getInstance(); return GrTBackendEffectFactory<ColorMatrixEffect>::getInstance();
@ -451,6 +454,8 @@ public:
}; };
private: private:
ColorMatrixEffect(const SkColorMatrix& matrix) : fMatrix(matrix) {}
SkColorMatrix fMatrix; SkColorMatrix fMatrix;
typedef GrGLEffect INHERITED; typedef GrGLEffect INHERITED;
@ -458,18 +463,18 @@ private:
GR_DEFINE_EFFECT_TEST(ColorMatrixEffect); GR_DEFINE_EFFECT_TEST(ColorMatrixEffect);
GrEffect* ColorMatrixEffect::TestCreate(SkRandom* random, GrEffectRef* ColorMatrixEffect::TestCreate(SkRandom* random,
GrContext*, GrContext*,
GrTexture* dummyTextures[2]) { GrTexture* dummyTextures[2]) {
SkColorMatrix colorMatrix; SkColorMatrix colorMatrix;
for (size_t i = 0; i < SK_ARRAY_COUNT(colorMatrix.fMat); ++i) { for (size_t i = 0; i < SK_ARRAY_COUNT(colorMatrix.fMat); ++i) {
colorMatrix.fMat[i] = random->nextSScalar1(); colorMatrix.fMat[i] = random->nextSScalar1();
} }
return SkNEW_ARGS(ColorMatrixEffect, (colorMatrix)); return ColorMatrixEffect::Create(colorMatrix);
} }
GrEffect* SkColorMatrixFilter::asNewEffect(GrContext*) const { GrEffectRef* SkColorMatrixFilter::asNewEffect(GrContext*) const {
return SkNEW_ARGS(ColorMatrixEffect, (fMatrix)); return ColorMatrixEffect::Create(fMatrix);
} }
#endif #endif

View File

@ -232,9 +232,17 @@ private:
class GrDisplacementMapEffect : public GrEffect { class GrDisplacementMapEffect : public GrEffect {
public: public:
GrDisplacementMapEffect(SkDisplacementMapEffect::ChannelSelectorType xChannelSelector, static GrEffectRef* Create(SkDisplacementMapEffect::ChannelSelectorType xChannelSelector,
SkDisplacementMapEffect::ChannelSelectorType yChannelSelector, SkDisplacementMapEffect::ChannelSelectorType yChannelSelector,
SkScalar scale, GrTexture* displacement, GrTexture* color); SkScalar scale, GrTexture* displacement, GrTexture* color) {
SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrDisplacementMapEffect, (xChannelSelector,
yChannelSelector,
scale,
displacement,
color)));
return CreateEffectPtr(effect);
}
virtual ~GrDisplacementMapEffect(); virtual ~GrDisplacementMapEffect();
virtual bool isEqual(const GrEffect&) const SK_OVERRIDE; virtual bool isEqual(const GrEffect&) const SK_OVERRIDE;
@ -251,6 +259,10 @@ public:
void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
private: private:
GrDisplacementMapEffect(SkDisplacementMapEffect::ChannelSelectorType xChannelSelector,
SkDisplacementMapEffect::ChannelSelectorType yChannelSelector,
SkScalar scale, GrTexture* displacement, GrTexture* color);
GR_DECLARE_EFFECT_TEST; GR_DECLARE_EFFECT_TEST;
GrTextureAccess fDisplacementAccess; GrTextureAccess fDisplacementAccess;
@ -319,8 +331,11 @@ GrTexture* SkDisplacementMapEffect::filterImageGPU(Proxy* proxy, GrTexture* src,
GrPaint paint; GrPaint paint;
paint.colorStage(0)->setEffect( paint.colorStage(0)->setEffect(
SkNEW_ARGS(GrDisplacementMapEffect, (fXChannelSelector, fYChannelSelector, fScale, GrDisplacementMapEffect::Create(fXChannelSelector,
displacement.get(), color.get())))->unref(); fYChannelSelector,
fScale,
displacement.get(),
color.get()))->unref();
context->drawRect(paint, rect); context->drawRect(paint, rect);
return dst; return dst;
} }
@ -369,9 +384,9 @@ void GrDisplacementMapEffect::getConstantColorComponents(GrColor* color,
GR_DEFINE_EFFECT_TEST(GrDisplacementMapEffect); GR_DEFINE_EFFECT_TEST(GrDisplacementMapEffect);
GrEffect* GrDisplacementMapEffect::TestCreate(SkRandom* random, GrEffectRef* GrDisplacementMapEffect::TestCreate(SkRandom* random,
GrContext* context, GrContext* context,
GrTexture* textures[]) { GrTexture* textures[]) {
int texIdxDispl = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : int texIdxDispl = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
GrEffectUnitTest::kAlphaTextureIdx; GrEffectUnitTest::kAlphaTextureIdx;
int texIdxColor = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : int texIdxColor = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
@ -385,8 +400,8 @@ GrEffect* GrDisplacementMapEffect::TestCreate(SkRandom* random,
random->nextRangeU(1, kMaxComponent)); random->nextRangeU(1, kMaxComponent));
SkScalar scale = random->nextUScalar1(); SkScalar scale = random->nextUScalar1();
return SkNEW_ARGS(GrDisplacementMapEffect, (xChannelSelector, yChannelSelector, scale, return GrDisplacementMapEffect::Create(xChannelSelector, yChannelSelector, scale,
textures[texIdxDispl], textures[texIdxColor])); textures[texIdxDispl], textures[texIdxColor]);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -264,7 +264,7 @@ public:
SkScalar kd, SkImageFilter* input); SkScalar kd, SkImageFilter* input);
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFilter) SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkDiffuseLightingImageFilter)
virtual bool asNewEffect(GrEffect** effect, GrTexture*) const SK_OVERRIDE; virtual bool asNewEffect(GrEffectRef** effect, GrTexture*) const SK_OVERRIDE;
SkScalar kd() const { return fKD; } SkScalar kd() const { return fKD; }
protected: protected:
@ -284,7 +284,7 @@ public:
SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScalar ks, SkScalar shininess, SkImageFilter* input); SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScalar ks, SkScalar shininess, SkImageFilter* input);
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageFilter) SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSpecularLightingImageFilter)
virtual bool asNewEffect(GrEffect** effect, GrTexture*) const SK_OVERRIDE; virtual bool asNewEffect(GrEffectRef** effect, GrTexture*) const SK_OVERRIDE;
SkScalar ks() const { return fKS; } SkScalar ks() const { return fKS; }
SkScalar shininess() const { return fShininess; } SkScalar shininess() const { return fShininess; }
@ -326,10 +326,16 @@ private:
class GrDiffuseLightingEffect : public GrLightingEffect { class GrDiffuseLightingEffect : public GrLightingEffect {
public: public:
GrDiffuseLightingEffect(GrTexture* texture, static GrEffectRef* Create(GrTexture* texture,
const SkLight* light, const SkLight* light,
SkScalar surfaceScale, SkScalar surfaceScale,
SkScalar kd); SkScalar kd) {
SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrDiffuseLightingEffect, (texture,
light,
surfaceScale,
kd)));
return CreateEffectPtr(effect);
}
static const char* Name() { return "DiffuseLighting"; } static const char* Name() { return "DiffuseLighting"; }
@ -339,6 +345,11 @@ public:
virtual bool isEqual(const GrEffect&) const SK_OVERRIDE; virtual bool isEqual(const GrEffect&) const SK_OVERRIDE;
SkScalar kd() const { return fKD; } SkScalar kd() const { return fKD; }
private: private:
GrDiffuseLightingEffect(GrTexture* texture,
const SkLight* light,
SkScalar surfaceScale,
SkScalar kd);
GR_DECLARE_EFFECT_TEST; GR_DECLARE_EFFECT_TEST;
typedef GrLightingEffect INHERITED; typedef GrLightingEffect INHERITED;
SkScalar fKD; SkScalar fKD;
@ -346,12 +357,18 @@ private:
class GrSpecularLightingEffect : public GrLightingEffect { class GrSpecularLightingEffect : public GrLightingEffect {
public: public:
GrSpecularLightingEffect(GrTexture* texture, static GrEffectRef* Create(GrTexture* texture,
const SkLight* light, const SkLight* light,
SkScalar surfaceScale, SkScalar surfaceScale,
SkScalar ks, SkScalar ks,
SkScalar shininess); SkScalar shininess) {
SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSpecularLightingEffect, (texture,
light,
surfaceScale,
ks,
shininess)));
return CreateEffectPtr(effect);
}
static const char* Name() { return "SpecularLighting"; } static const char* Name() { return "SpecularLighting"; }
typedef GrGLSpecularLightingEffect GLEffect; typedef GrGLSpecularLightingEffect GLEffect;
@ -362,6 +379,12 @@ public:
SkScalar shininess() const { return fShininess; } SkScalar shininess() const { return fShininess; }
private: private:
GrSpecularLightingEffect(GrTexture* texture,
const SkLight* light,
SkScalar surfaceScale,
SkScalar ks,
SkScalar shininess);
GR_DECLARE_EFFECT_TEST; GR_DECLARE_EFFECT_TEST;
typedef GrLightingEffect INHERITED; typedef GrLightingEffect INHERITED;
SkScalar fKS; SkScalar fKS;
@ -832,12 +855,12 @@ bool SkDiffuseLightingImageFilter::onFilterImage(Proxy*,
return true; return true;
} }
bool SkDiffuseLightingImageFilter::asNewEffect(GrEffect** effect, bool SkDiffuseLightingImageFilter::asNewEffect(GrEffectRef** effect,
GrTexture* texture) const { GrTexture* texture) const {
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
if (effect) { if (effect) {
SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255));
*effect = SkNEW_ARGS(GrDiffuseLightingEffect, (texture, light(), scale, kd())); *effect = GrDiffuseLightingEffect::Create(texture, light(), scale, kd());
} }
return true; return true;
#else #else
@ -901,12 +924,12 @@ bool SkSpecularLightingImageFilter::onFilterImage(Proxy*,
return true; return true;
} }
bool SkSpecularLightingImageFilter::asNewEffect(GrEffect** effect, bool SkSpecularLightingImageFilter::asNewEffect(GrEffectRef** effect,
GrTexture* texture) const { GrTexture* texture) const {
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
if (effect) { if (effect) {
SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255)); SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255));
*effect = SkNEW_ARGS(GrSpecularLightingEffect, (texture, light(), scale, ks(), shininess())); *effect = GrSpecularLightingEffect::Create(texture, light(), scale, ks(), shininess());
} }
return true; return true;
#else #else
@ -1054,14 +1077,14 @@ bool GrDiffuseLightingEffect::isEqual(const GrEffect& sBase) const {
GR_DEFINE_EFFECT_TEST(GrDiffuseLightingEffect); GR_DEFINE_EFFECT_TEST(GrDiffuseLightingEffect);
GrEffect* GrDiffuseLightingEffect::TestCreate(SkRandom* random, GrEffectRef* GrDiffuseLightingEffect::TestCreate(SkRandom* random,
GrContext* context, GrContext* context,
GrTexture* textures[]) { GrTexture* textures[]) {
SkScalar surfaceScale = random->nextSScalar1(); SkScalar surfaceScale = random->nextSScalar1();
SkScalar kd = random->nextUScalar1(); SkScalar kd = random->nextUScalar1();
SkAutoTUnref<SkLight> light(create_random_light(random)); SkAutoTUnref<SkLight> light(create_random_light(random));
return SkNEW_ARGS(GrDiffuseLightingEffect, (textures[GrEffectUnitTest::kAlphaTextureIdx], return GrDiffuseLightingEffect::Create(textures[GrEffectUnitTest::kAlphaTextureIdx],
light, surfaceScale, kd)); light, surfaceScale, kd);
} }
@ -1267,15 +1290,15 @@ bool GrSpecularLightingEffect::isEqual(const GrEffect& sBase) const {
GR_DEFINE_EFFECT_TEST(GrSpecularLightingEffect); GR_DEFINE_EFFECT_TEST(GrSpecularLightingEffect);
GrEffect* GrSpecularLightingEffect::TestCreate(SkRandom* random, GrEffectRef* GrSpecularLightingEffect::TestCreate(SkRandom* random,
GrContext* context, GrContext* context,
GrTexture* textures[]) { GrTexture* textures[]) {
SkScalar surfaceScale = random->nextSScalar1(); SkScalar surfaceScale = random->nextSScalar1();
SkScalar ks = random->nextUScalar1(); SkScalar ks = random->nextUScalar1();
SkScalar shininess = random->nextUScalar1(); SkScalar shininess = random->nextUScalar1();
SkAutoTUnref<SkLight> light(create_random_light(random)); SkAutoTUnref<SkLight> light(create_random_light(random));
return SkNEW_ARGS(GrSpecularLightingEffect, (textures[GrEffectUnitTest::kAlphaTextureIdx], return GrSpecularLightingEffect::Create(textures[GrEffectUnitTest::kAlphaTextureIdx],
light, surfaceScale, ks, shininess)); light, surfaceScale, ks, shininess);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -26,20 +26,22 @@ class GrGLMagnifierEffect;
class GrMagnifierEffect : public GrSingleTextureEffect { class GrMagnifierEffect : public GrSingleTextureEffect {
public: public:
GrMagnifierEffect(GrTexture* texture, static GrEffectRef* Create(GrTexture* texture,
float xOffset, float xOffset,
float yOffset, float yOffset,
float xZoom, float xZoom,
float yZoom, float yZoom,
float xInset, float xInset,
float yInset) float yInset) {
: GrSingleTextureEffect(texture, MakeDivByTextureWHMatrix(texture)) SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrMagnifierEffect, (texture,
, fXOffset(xOffset) xOffset,
, fYOffset(yOffset) yOffset,
, fXZoom(xZoom) xZoom,
, fYZoom(yZoom) yZoom,
, fXInset(xInset) xInset,
, fYInset(yInset) {} yInset)));
return CreateEffectPtr(effect);
}
virtual ~GrMagnifierEffect() {}; virtual ~GrMagnifierEffect() {};
@ -58,6 +60,21 @@ public:
typedef GrGLMagnifierEffect GLEffect; typedef GrGLMagnifierEffect GLEffect;
private: private:
GrMagnifierEffect(GrTexture* texture,
float xOffset,
float yOffset,
float xZoom,
float yZoom,
float xInset,
float yInset)
: GrSingleTextureEffect(texture, MakeDivByTextureWHMatrix(texture))
, fXOffset(xOffset)
, fYOffset(yOffset)
, fXZoom(xZoom)
, fYZoom(yZoom)
, fXInset(xInset)
, fYInset(yInset) {}
GR_DECLARE_EFFECT_TEST; GR_DECLARE_EFFECT_TEST;
float fXOffset; float fXOffset;
@ -184,9 +201,9 @@ GrGLEffect::EffectKey GrGLMagnifierEffect::GenKey(const GrEffectStage& stage, co
GR_DEFINE_EFFECT_TEST(GrMagnifierEffect); GR_DEFINE_EFFECT_TEST(GrMagnifierEffect);
GrEffect* GrMagnifierEffect::TestCreate(SkRandom* random, GrEffectRef* GrMagnifierEffect::TestCreate(SkRandom* random,
GrContext* context, GrContext* context,
GrTexture** textures) { GrTexture** textures) {
const int kMaxWidth = 200; const int kMaxWidth = 200;
const int kMaxHeight = 200; const int kMaxHeight = 200;
const int kMaxInset = 20; const int kMaxInset = 20;
@ -201,7 +218,7 @@ GrEffect* GrMagnifierEffect::TestCreate(SkRandom* random,
SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y), SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
SkIntToScalar(width), SkIntToScalar(height)), SkIntToScalar(width), SkIntToScalar(height)),
inset)); inset));
GrEffect* effect; GrEffectRef* effect;
filter->asNewEffect(&effect, textures[0]); filter->asNewEffect(&effect, textures[0]);
GrAssert(NULL != effect); GrAssert(NULL != effect);
return effect; return effect;
@ -243,17 +260,16 @@ SkMagnifierImageFilter::SkMagnifierImageFilter(SkRect srcRect, SkScalar inset)
SkASSERT(srcRect.x() >= 0 && srcRect.y() >= 0 && inset >= 0); SkASSERT(srcRect.x() >= 0 && srcRect.y() >= 0 && inset >= 0);
} }
bool SkMagnifierImageFilter::asNewEffect(GrEffect** effect, bool SkMagnifierImageFilter::asNewEffect(GrEffectRef** effect, GrTexture* texture) const {
GrTexture* texture) const {
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
if (effect) { if (effect) {
*effect = SkNEW_ARGS(GrMagnifierEffect, (texture, *effect = GrMagnifierEffect::Create(texture,
fSrcRect.x() / texture->width(), fSrcRect.x() / texture->width(),
fSrcRect.y() / texture->height(), fSrcRect.y() / texture->height(),
texture->width() / fSrcRect.width(), texture->width() / fSrcRect.width(),
texture->height() / fSrcRect.height(), texture->height() / fSrcRect.height(),
fInset / texture->width(), fInset / texture->width(),
fInset / texture->height())); fInset / texture->height());
} }
return true; return true;
#else #else

View File

@ -247,14 +247,24 @@ class GrGLMatrixConvolutionEffect;
class GrMatrixConvolutionEffect : public GrSingleTextureEffect { class GrMatrixConvolutionEffect : public GrSingleTextureEffect {
public: public:
typedef SkMatrixConvolutionImageFilter::TileMode TileMode; typedef SkMatrixConvolutionImageFilter::TileMode TileMode;
GrMatrixConvolutionEffect(GrTexture*, static GrEffectRef* Create(GrTexture* texture,
const SkISize& kernelSize, const SkISize& kernelSize,
const SkScalar* kernel, const SkScalar* kernel,
SkScalar gain, SkScalar gain,
SkScalar bias, SkScalar bias,
const SkIPoint& target, const SkIPoint& target,
TileMode tileMode, TileMode tileMode,
bool convolveAlpha); bool convolveAlpha) {
SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrMatrixConvolutionEffect, (texture,
kernelSize,
kernel,
gain,
bias,
target,
tileMode,
convolveAlpha)));
return CreateEffectPtr(effect);
}
virtual ~GrMatrixConvolutionEffect(); virtual ~GrMatrixConvolutionEffect();
virtual void getConstantColorComponents(GrColor* color, virtual void getConstantColorComponents(GrColor* color,
@ -280,6 +290,15 @@ public:
virtual bool isEqual(const GrEffect&) const SK_OVERRIDE; virtual bool isEqual(const GrEffect&) const SK_OVERRIDE;
private: private:
GrMatrixConvolutionEffect(GrTexture*,
const SkISize& kernelSize,
const SkScalar* kernel,
SkScalar gain,
SkScalar bias,
const SkIPoint& target,
TileMode tileMode,
bool convolveAlpha);
SkISize fKernelSize; SkISize fKernelSize;
float *fKernel; float *fKernel;
float fGain; float fGain;
@ -518,9 +537,9 @@ GR_DEFINE_EFFECT_TEST(GrMatrixConvolutionEffect);
// Allows for a 5x5 kernel (or 25x1, for that matter). // Allows for a 5x5 kernel (or 25x1, for that matter).
#define MAX_KERNEL_SIZE 25 #define MAX_KERNEL_SIZE 25
GrEffect* GrMatrixConvolutionEffect::TestCreate(SkRandom* random, GrEffectRef* GrMatrixConvolutionEffect::TestCreate(SkRandom* random,
GrContext* context, GrContext* context,
GrTexture* textures[]) { GrTexture* textures[]) {
int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
GrEffectUnitTest::kAlphaTextureIdx; GrEffectUnitTest::kAlphaTextureIdx;
int width = random->nextRangeU(1, MAX_KERNEL_SIZE); int width = random->nextRangeU(1, MAX_KERNEL_SIZE);
@ -536,29 +555,29 @@ GrEffect* GrMatrixConvolutionEffect::TestCreate(SkRandom* random,
random->nextRangeU(0, kernelSize.height())); random->nextRangeU(0, kernelSize.height()));
TileMode tileMode = static_cast<TileMode>(random->nextRangeU(0, 2)); TileMode tileMode = static_cast<TileMode>(random->nextRangeU(0, 2));
bool convolveAlpha = random->nextBool(); bool convolveAlpha = random->nextBool();
return SkNEW_ARGS(GrMatrixConvolutionEffect, (textures[texIdx], return GrMatrixConvolutionEffect::Create(textures[texIdx],
kernelSize, kernelSize,
kernel, kernel,
gain, gain,
bias, bias,
target, target,
tileMode, tileMode,
convolveAlpha)); convolveAlpha);
} }
bool SkMatrixConvolutionImageFilter::asNewEffect(GrEffect** effect, bool SkMatrixConvolutionImageFilter::asNewEffect(GrEffectRef** effect,
GrTexture* texture) const { GrTexture* texture) const {
bool ok = fKernelSize.width() * fKernelSize.height() <= MAX_KERNEL_SIZE; bool ok = fKernelSize.width() * fKernelSize.height() <= MAX_KERNEL_SIZE;
if (ok && effect) { if (ok && effect) {
*effect = SkNEW_ARGS(GrMatrixConvolutionEffect, (texture, *effect = GrMatrixConvolutionEffect::Create(texture,
fKernelSize, fKernelSize,
fKernel, fKernel,
fGain, fGain,
fBias, fBias,
fTarget, fTarget,
fTileMode, fTileMode,
fConvolveAlpha)); fConvolveAlpha);
} }
return ok; return ok;
} }

View File

@ -243,7 +243,11 @@ public:
kDilate_MorphologyType, kDilate_MorphologyType,
}; };
GrMorphologyEffect(GrTexture*, Direction, int radius, MorphologyType); static GrEffectRef* Create(GrTexture* tex, Direction dir, int radius, MorphologyType type) {
SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrMorphologyEffect, (tex, dir, radius, type)));
return CreateEffectPtr(effect);
}
virtual ~GrMorphologyEffect(); virtual ~GrMorphologyEffect();
MorphologyType type() const { return fType; } MorphologyType type() const { return fType; }
@ -260,6 +264,8 @@ protected:
MorphologyType fType; MorphologyType fType;
private: private:
GrMorphologyEffect(GrTexture*, Direction, int radius, MorphologyType);
GR_DECLARE_EFFECT_TEST; GR_DECLARE_EFFECT_TEST;
typedef Gr1DKernelEffect INHERITED; typedef Gr1DKernelEffect INHERITED;
@ -406,9 +412,9 @@ bool GrMorphologyEffect::isEqual(const GrEffect& sBase) const {
GR_DEFINE_EFFECT_TEST(GrMorphologyEffect); GR_DEFINE_EFFECT_TEST(GrMorphologyEffect);
GrEffect* GrMorphologyEffect::TestCreate(SkRandom* random, GrEffectRef* GrMorphologyEffect::TestCreate(SkRandom* random,
GrContext* context, GrContext* context,
GrTexture* textures[]) { GrTexture* textures[]) {
int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
GrEffectUnitTest::kAlphaTextureIdx; GrEffectUnitTest::kAlphaTextureIdx;
Direction dir = random->nextBool() ? kX_Direction : kY_Direction; Direction dir = random->nextBool() ? kX_Direction : kY_Direction;
@ -417,7 +423,7 @@ GrEffect* GrMorphologyEffect::TestCreate(SkRandom* random,
MorphologyType type = random->nextBool() ? GrMorphologyEffect::kErode_MorphologyType : MorphologyType type = random->nextBool() ? GrMorphologyEffect::kErode_MorphologyType :
GrMorphologyEffect::kDilate_MorphologyType; GrMorphologyEffect::kDilate_MorphologyType;
return SkNEW_ARGS(GrMorphologyEffect, (textures[texIdx], dir, radius, type)); return GrMorphologyEffect::Create(textures[texIdx], dir, radius, type);
} }
namespace { namespace {
@ -429,10 +435,10 @@ void apply_morphology_pass(GrContext* context,
GrMorphologyEffect::MorphologyType morphType, GrMorphologyEffect::MorphologyType morphType,
Gr1DKernelEffect::Direction direction) { Gr1DKernelEffect::Direction direction) {
GrPaint paint; GrPaint paint;
paint.colorStage(0)->setEffect(SkNEW_ARGS(GrMorphologyEffect, (texture, paint.colorStage(0)->setEffect(GrMorphologyEffect::Create(texture,
direction, direction,
radius, radius,
morphType)))->unref(); morphType))->unref();
context->drawRect(paint, rect); context->drawRect(paint, rect);
} }

View File

@ -41,7 +41,7 @@ public:
virtual bool asComponentTable(SkBitmap* table) const SK_OVERRIDE; virtual bool asComponentTable(SkBitmap* table) const SK_OVERRIDE;
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
virtual GrEffect* asNewEffect(GrContext* context) const SK_OVERRIDE; virtual GrEffectRef* asNewEffect(GrContext* context) const SK_OVERRIDE;
#endif #endif
virtual void filterSpan(const SkPMColor src[], int count, virtual void filterSpan(const SkPMColor src[], int count,
@ -226,8 +226,11 @@ class GLColorTableEffect;
class ColorTableEffect : public GrEffect { class ColorTableEffect : public GrEffect {
public: public:
static GrEffectRef* Create(GrTexture* texture, unsigned flags) {
SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(ColorTableEffect, (texture, flags)));
return CreateEffectPtr(effect);
}
explicit ColorTableEffect(GrTexture* texture, unsigned flags);
virtual ~ColorTableEffect(); virtual ~ColorTableEffect();
static const char* Name() { return "ColorTable"; } static const char* Name() { return "ColorTable"; }
@ -239,6 +242,8 @@ public:
typedef GLColorTableEffect GLEffect; typedef GLColorTableEffect GLEffect;
private: private:
explicit ColorTableEffect(GrTexture* texture, unsigned flags);
GR_DECLARE_EFFECT_TEST; GR_DECLARE_EFFECT_TEST;
GrTextureAccess fTextureAccess; GrTextureAccess fTextureAccess;
@ -365,20 +370,20 @@ void ColorTableEffect::getConstantColorComponents(GrColor* color, uint32_t* vali
GR_DEFINE_EFFECT_TEST(ColorTableEffect); GR_DEFINE_EFFECT_TEST(ColorTableEffect);
GrEffect* ColorTableEffect::TestCreate(SkRandom* random, GrEffectRef* ColorTableEffect::TestCreate(SkRandom* random,
GrContext* context, GrContext* context,
GrTexture* textures[]) { GrTexture* textures[]) {
static unsigned kAllFlags = SkTable_ColorFilter::kR_Flag | SkTable_ColorFilter::kG_Flag | static unsigned kAllFlags = SkTable_ColorFilter::kR_Flag | SkTable_ColorFilter::kG_Flag |
SkTable_ColorFilter::kB_Flag | SkTable_ColorFilter::kA_Flag; SkTable_ColorFilter::kB_Flag | SkTable_ColorFilter::kA_Flag;
return SkNEW_ARGS(ColorTableEffect, (textures[GrEffectUnitTest::kAlphaTextureIdx], kAllFlags)); return ColorTableEffect::Create(textures[GrEffectUnitTest::kAlphaTextureIdx], kAllFlags);
} }
GrEffect* SkTable_ColorFilter::asNewEffect(GrContext* context) const { GrEffectRef* SkTable_ColorFilter::asNewEffect(GrContext* context) const {
SkBitmap bitmap; SkBitmap bitmap;
this->asComponentTable(&bitmap); this->asComponentTable(&bitmap);
// passing NULL because this effect does no tiling or filtering. // passing NULL because this effect does no tiling or filtering.
GrTexture* texture = GrLockCachedBitmapTexture(context, bitmap, NULL); GrTexture* texture = GrLockCachedBitmapTexture(context, bitmap, NULL);
GrEffect* effect = SkNEW_ARGS(ColorTableEffect, (texture, fFlags)); GrEffectRef* effect = ColorTableEffect::Create(texture, fFlags);
// Unlock immediately, this is not great, but we don't have a way of // Unlock immediately, this is not great, but we don't have a way of
// knowing when else to unlock it currently. TODO: Remove this when // knowing when else to unlock it currently. TODO: Remove this when

View File

@ -484,11 +484,14 @@ private:
class GrLinearGradient : public GrGradientEffect { class GrLinearGradient : public GrGradientEffect {
public: public:
GrLinearGradient(GrContext* ctx, static GrEffectRef* Create(GrContext* ctx,
const SkLinearGradient& shader, const SkLinearGradient& shader,
const SkMatrix& matrix, const SkMatrix& matrix,
SkShader::TileMode tm) SkShader::TileMode tm) {
: INHERITED(ctx, shader, matrix, tm) { } SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrLinearGradient, (ctx, shader, matrix, tm)));
return CreateEffectPtr(effect);
}
virtual ~GrLinearGradient() { } virtual ~GrLinearGradient() { }
static const char* Name() { return "Linear Gradient"; } static const char* Name() { return "Linear Gradient"; }
@ -499,6 +502,11 @@ public:
typedef GrGLLinearGradient GLEffect; typedef GrGLLinearGradient GLEffect;
private: private:
GrLinearGradient(GrContext* ctx,
const SkLinearGradient& shader,
const SkMatrix& matrix,
SkShader::TileMode tm)
: INHERITED(ctx, shader, matrix, tm) { }
GR_DECLARE_EFFECT_TEST; GR_DECLARE_EFFECT_TEST;
typedef GrGradientEffect INHERITED; typedef GrGradientEffect INHERITED;
@ -508,9 +516,9 @@ private:
GR_DEFINE_EFFECT_TEST(GrLinearGradient); GR_DEFINE_EFFECT_TEST(GrLinearGradient);
GrEffect* GrLinearGradient::TestCreate(SkRandom* random, GrEffectRef* GrLinearGradient::TestCreate(SkRandom* random,
GrContext* context, GrContext* context,
GrTexture**) { GrTexture**) {
SkPoint points[] = {{random->nextUScalar1(), random->nextUScalar1()}, SkPoint points[] = {{random->nextUScalar1(), random->nextUScalar1()},
{random->nextUScalar1(), random->nextUScalar1()}}; {random->nextUScalar1(), random->nextUScalar1()}};
@ -546,14 +554,14 @@ void GrGLLinearGradient::emitCode(GrGLShaderBuilder* builder,
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
GrEffect* SkLinearGradient::asNewEffect(GrContext* context, const SkPaint&) const { GrEffectRef* SkLinearGradient::asNewEffect(GrContext* context, const SkPaint&) const {
SkASSERT(NULL != context); SkASSERT(NULL != context);
SkMatrix matrix; SkMatrix matrix;
if (!this->getLocalMatrix().invert(&matrix)) { if (!this->getLocalMatrix().invert(&matrix)) {
return NULL; return NULL;
} }
matrix.postConcat(fPtsToUnit); matrix.postConcat(fPtsToUnit);
return SkNEW_ARGS(GrLinearGradient, (context, *this, matrix, fTileMode)); return GrLinearGradient::Create(context, *this, matrix, fTileMode);
} }
#else #else

View File

@ -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 GrEffect* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE; virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE;
SK_DEVELOPER_TO_STRING() SK_DEVELOPER_TO_STRING()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLinearGradient) SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLinearGradient)

View File

@ -504,12 +504,12 @@ private:
class GrRadialGradient : public GrGradientEffect { class GrRadialGradient : public GrGradientEffect {
public: public:
static GrEffectRef* Create(GrContext* ctx,
GrRadialGradient(GrContext* ctx, const SkRadialGradient& shader,
const SkRadialGradient& shader, const SkMatrix& matrix,
const SkMatrix& matrix, SkShader::TileMode tm) {
SkShader::TileMode tm) SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrRadialGradient, (ctx, shader, matrix, tm)));
: INHERITED(ctx, shader, matrix, tm) { return CreateEffectPtr(effect);
} }
virtual ~GrRadialGradient() { } virtual ~GrRadialGradient() { }
@ -522,6 +522,13 @@ public:
typedef GrGLRadialGradient GLEffect; typedef GrGLRadialGradient GLEffect;
private: private:
GrRadialGradient(GrContext* ctx,
const SkRadialGradient& shader,
const SkMatrix& matrix,
SkShader::TileMode tm)
: INHERITED(ctx, shader, matrix, tm) {
}
GR_DECLARE_EFFECT_TEST; GR_DECLARE_EFFECT_TEST;
typedef GrGradientEffect INHERITED; typedef GrGradientEffect INHERITED;
@ -531,9 +538,9 @@ private:
GR_DEFINE_EFFECT_TEST(GrRadialGradient); GR_DEFINE_EFFECT_TEST(GrRadialGradient);
GrEffect* GrRadialGradient::TestCreate(SkRandom* random, GrEffectRef* GrRadialGradient::TestCreate(SkRandom* random,
GrContext* context, GrContext* context,
GrTexture**) { GrTexture**) {
SkPoint center = {random->nextUScalar1(), random->nextUScalar1()}; SkPoint center = {random->nextUScalar1(), random->nextUScalar1()};
SkScalar radius = random->nextUScalar1(); SkScalar radius = random->nextUScalar1();
@ -569,7 +576,7 @@ void GrGLRadialGradient::emitCode(GrGLShaderBuilder* builder,
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
GrEffect* SkRadialGradient::asNewEffect(GrContext* context, const SkPaint&) const { GrEffectRef* SkRadialGradient::asNewEffect(GrContext* context, const SkPaint&) const {
SkASSERT(NULL != context); SkASSERT(NULL != context);
SkMatrix matrix; SkMatrix matrix;
@ -577,7 +584,7 @@ GrEffect* SkRadialGradient::asNewEffect(GrContext* context, const SkPaint&) cons
return NULL; return NULL;
} }
matrix.postConcat(fPtsToUnit); matrix.postConcat(fPtsToUnit);
return SkNEW_ARGS(GrRadialGradient, (context, *this, matrix, fTileMode)); return GrRadialGradient::Create(context, *this, matrix, fTileMode);
} }
#else #else

View File

@ -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 GrEffect* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE; virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE;
SK_DEVELOPER_TO_STRING() SK_DEVELOPER_TO_STRING()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkRadialGradient) SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkRadialGradient)

View File

@ -413,11 +413,12 @@ private:
class GrSweepGradient : public GrGradientEffect { class GrSweepGradient : public GrGradientEffect {
public: public:
static GrEffectRef* Create(GrContext* ctx,
GrSweepGradient(GrContext* ctx, const SkSweepGradient& shader,
const SkSweepGradient& shader, const SkMatrix& matrix) {
const SkMatrix& matrix) SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSweepGradient, (ctx, shader, matrix)));
: INHERITED(ctx, shader, matrix, SkShader::kClamp_TileMode) { } return CreateEffectPtr(effect);
}
virtual ~GrSweepGradient() { } virtual ~GrSweepGradient() { }
static const char* Name() { return "Sweep Gradient"; } static const char* Name() { return "Sweep Gradient"; }
@ -428,6 +429,10 @@ public:
typedef GrGLSweepGradient GLEffect; typedef GrGLSweepGradient GLEffect;
private: private:
GrSweepGradient(GrContext* ctx,
const SkSweepGradient& shader,
const SkMatrix& matrix)
: INHERITED(ctx, shader, matrix, SkShader::kClamp_TileMode) { }
GR_DECLARE_EFFECT_TEST; GR_DECLARE_EFFECT_TEST;
typedef GrGradientEffect INHERITED; typedef GrGradientEffect INHERITED;
@ -437,9 +442,9 @@ private:
GR_DEFINE_EFFECT_TEST(GrSweepGradient); GR_DEFINE_EFFECT_TEST(GrSweepGradient);
GrEffect* GrSweepGradient::TestCreate(SkRandom* random, GrEffectRef* GrSweepGradient::TestCreate(SkRandom* random,
GrContext* context, GrContext* context,
GrTexture**) { GrTexture**) {
SkPoint center = {random->nextUScalar1(), random->nextUScalar1()}; SkPoint center = {random->nextUScalar1(), random->nextUScalar1()};
SkColor colors[kMaxRandomGradientColors]; SkColor colors[kMaxRandomGradientColors];
@ -472,13 +477,13 @@ void GrGLSweepGradient::emitCode(GrGLShaderBuilder* builder,
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
GrEffect* SkSweepGradient::asNewEffect(GrContext* context, const SkPaint&) const { GrEffectRef* SkSweepGradient::asNewEffect(GrContext* context, const SkPaint&) const {
SkMatrix matrix; SkMatrix matrix;
if (!this->getLocalMatrix().invert(&matrix)) { if (!this->getLocalMatrix().invert(&matrix)) {
return NULL; return NULL;
} }
matrix.postConcat(fPtsToUnit); matrix.postConcat(fPtsToUnit);
return SkNEW_ARGS(GrSweepGradient, (context, *this, matrix)); return GrSweepGradient::Create(context, *this, matrix);
} }
#else #else

View File

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

View File

@ -369,14 +369,13 @@ private:
class GrConical2Gradient : public GrGradientEffect { class GrConical2Gradient : public GrGradientEffect {
public: public:
GrConical2Gradient(GrContext* ctx, static GrEffectRef* Create(GrContext* ctx,
const SkTwoPointConicalGradient& shader, const SkTwoPointConicalGradient& shader,
const SkMatrix& matrix, const SkMatrix& matrix,
SkShader::TileMode tm) SkShader::TileMode tm) {
: INHERITED(ctx, shader, matrix, tm) SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrConical2Gradient, (ctx, shader, matrix, tm)));
, fCenterX1(shader.getCenterX1()) return CreateEffectPtr(effect);
, fRadius0(shader.getStartRadius()) }
, fDiffRadius(shader.getDiffRadius()) { }
virtual ~GrConical2Gradient() { } virtual ~GrConical2Gradient() { }
@ -401,6 +400,15 @@ public:
typedef GrGLConical2Gradient GLEffect; typedef GrGLConical2Gradient GLEffect;
private: private:
GrConical2Gradient(GrContext* ctx,
const SkTwoPointConicalGradient& shader,
const SkMatrix& matrix,
SkShader::TileMode tm)
: INHERITED(ctx, shader, matrix, tm)
, fCenterX1(shader.getCenterX1())
, fRadius0(shader.getStartRadius())
, fDiffRadius(shader.getDiffRadius()) { }
GR_DECLARE_EFFECT_TEST; GR_DECLARE_EFFECT_TEST;
// @{ // @{
@ -418,9 +426,9 @@ private:
GR_DEFINE_EFFECT_TEST(GrConical2Gradient); GR_DEFINE_EFFECT_TEST(GrConical2Gradient);
GrEffect* GrConical2Gradient::TestCreate(SkRandom* random, GrEffectRef* GrConical2Gradient::TestCreate(SkRandom* random,
GrContext* context, GrContext* context,
GrTexture**) { GrTexture**) {
SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()};
SkScalar radius1 = random->nextUScalar1(); SkScalar radius1 = random->nextUScalar1();
SkPoint center2; SkPoint center2;
@ -684,7 +692,7 @@ GrGLEffect::EffectKey GrGLConical2Gradient::GenKey(const GrEffectStage& s, const
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
GrEffect* SkTwoPointConicalGradient::asNewEffect(GrContext* context, const SkPaint&) const { GrEffectRef* SkTwoPointConicalGradient::asNewEffect(GrContext* context, const SkPaint&) const {
SkASSERT(NULL != context); SkASSERT(NULL != context);
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.
@ -704,7 +712,7 @@ GrEffect* SkTwoPointConicalGradient::asNewEffect(GrContext* context, const SkPai
matrix.postConcat(rot); matrix.postConcat(rot);
} }
return SkNEW_ARGS(GrConical2Gradient, (context, *this, matrix, fTileMode)); return GrConical2Gradient::Create(context, *this, matrix, fTileMode);
} }
#else #else

View File

@ -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 GrEffect* asNewEffect(GrContext* context, const SkPaint& paint) const SK_OVERRIDE; virtual GrEffectRef* 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; }

View File

@ -428,15 +428,14 @@ private:
class GrRadial2Gradient : public GrGradientEffect { class GrRadial2Gradient : public GrGradientEffect {
public: public:
static GrEffectRef* Create(GrContext* ctx,
const SkTwoPointRadialGradient& shader,
const SkMatrix& matrix,
SkShader::TileMode tm) {
SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrRadial2Gradient, (ctx, shader, matrix, tm)));
return CreateEffectPtr(effect);
}
GrRadial2Gradient(GrContext* ctx,
const SkTwoPointRadialGradient& shader,
const SkMatrix& matrix,
SkShader::TileMode tm)
: INHERITED(ctx, shader, matrix, tm)
, fCenterX1(shader.getCenterX1())
, fRadius0(shader.getStartRadius())
, fPosRoot(shader.getDiffRadius() < 0) { }
virtual ~GrRadial2Gradient() { } virtual ~GrRadial2Gradient() { }
static const char* Name() { return "Two-Point Radial Gradient"; } static const char* Name() { return "Two-Point Radial Gradient"; }
@ -460,6 +459,15 @@ public:
typedef GrGLRadial2Gradient GLEffect; typedef GrGLRadial2Gradient GLEffect;
private: private:
GrRadial2Gradient(GrContext* ctx,
const SkTwoPointRadialGradient& shader,
const SkMatrix& matrix,
SkShader::TileMode tm)
: INHERITED(ctx, shader, matrix, tm)
, fCenterX1(shader.getCenterX1())
, fRadius0(shader.getStartRadius())
, fPosRoot(shader.getDiffRadius() < 0) { }
GR_DECLARE_EFFECT_TEST; GR_DECLARE_EFFECT_TEST;
// @{ // @{
@ -479,9 +487,9 @@ private:
GR_DEFINE_EFFECT_TEST(GrRadial2Gradient); GR_DEFINE_EFFECT_TEST(GrRadial2Gradient);
GrEffect* GrRadial2Gradient::TestCreate(SkRandom* random, GrEffectRef* GrRadial2Gradient::TestCreate(SkRandom* random,
GrContext* context, GrContext* context,
GrTexture**) { GrTexture**) {
SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()}; SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()};
SkScalar radius1 = random->nextUScalar1(); SkScalar radius1 = random->nextUScalar1();
SkPoint center2; SkPoint center2;
@ -683,7 +691,7 @@ GrGLEffect::EffectKey GrGLRadial2Gradient::GenKey(const GrEffectStage& s, const
///////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////
GrEffect* SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint&) const { GrEffectRef* SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint&) const {
SkASSERT(NULL != context); SkASSERT(NULL != context);
// 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;
@ -701,7 +709,7 @@ GrEffect* SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPain
matrix.postConcat(rot); matrix.postConcat(rot);
} }
return SkNEW_ARGS(GrRadial2Gradient, (context, *this, matrix, fTileMode)); return GrRadial2Gradient::Create(context, *this, matrix, fTileMode);
} }
#else #else

View File

@ -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 GrEffect* asNewEffect(GrContext* context, const SkPaint&) const SK_OVERRIDE; virtual GrEffectRef* 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;

View File

@ -200,9 +200,10 @@ void convolve_gaussian(GrDrawTarget* target,
GrDrawTarget::AutoStateRestore asr(target, GrDrawTarget::kReset_ASRInit); GrDrawTarget::AutoStateRestore asr(target, GrDrawTarget::kReset_ASRInit);
GrDrawState* drawState = target->drawState(); GrDrawState* drawState = target->drawState();
drawState->setRenderTarget(rt); drawState->setRenderTarget(rt);
SkAutoTUnref<GrConvolutionEffect> conv(SkNEW_ARGS(GrConvolutionEffect, SkAutoTUnref<GrEffectRef> conv(GrConvolutionEffect::Create(texture,
(texture, direction, radius, direction,
sigma))); radius,
sigma));
drawState->stage(0)->setEffect(conv); drawState->stage(0)->setEffect(conv);
target->drawSimpleRect(rect, NULL); target->drawSimpleRect(rect, NULL);
} }
@ -1859,8 +1860,9 @@ GrTexture* GrContext::gaussianBlur(GrTexture* srcTexture,
scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f, scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f,
i < scaleFactorY ? 0.5f : 1.0f); i < scaleFactorY ? 0.5f : 1.0f);
paint.colorStage(0)->setEffect(SkNEW_ARGS(GrSingleTextureEffect, paint.colorStage(0)->setEffect(GrSingleTextureEffect::Create(srcTexture,
(srcTexture, matrix, true)))->unref(); matrix,
true))->unref();
this->drawRectToRect(paint, dstRect, srcRect); this->drawRectToRect(paint, dstRect, srcRect);
srcRect = dstRect; srcRect = dstRect;
srcTexture = dstTexture; srcTexture = dstTexture;
@ -1917,8 +1919,9 @@ GrTexture* GrContext::gaussianBlur(GrTexture* srcTexture,
// FIXME: This should be mitchell, not bilinear. // FIXME: This should be mitchell, not bilinear.
matrix.setIDiv(srcTexture->width(), srcTexture->height()); matrix.setIDiv(srcTexture->width(), srcTexture->height());
this->setRenderTarget(dstTexture->asRenderTarget()); this->setRenderTarget(dstTexture->asRenderTarget());
paint.colorStage(0)->setEffect(SkNEW_ARGS(GrSingleTextureEffect,(srcTexture, paint.colorStage(0)->setEffect(GrSingleTextureEffect::Create(srcTexture,
matrix, true)))->unref(); matrix,
true))->unref();
SkRect dstRect(srcRect); SkRect dstRect(srcRect);
scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY);
this->drawRectToRect(paint, dstRect, srcRect); this->drawRectToRect(paint, dstRect, srcRect);

View File

@ -195,13 +195,9 @@ public:
/** /**
* Creates a GrSingleTextureEffect. * Creates a GrSingleTextureEffect.
*/ */
void createTextureEffect(int stageIdx, GrTexture* texture) {
GrAssert(!this->getStage(stageIdx).getEffect());
this->stage(stageIdx)->setEffect(SkNEW_ARGS(GrSingleTextureEffect, (texture)))->unref();
}
void createTextureEffect(int stageIdx, GrTexture* texture, const SkMatrix& matrix) { void createTextureEffect(int stageIdx, GrTexture* texture, const SkMatrix& matrix) {
GrAssert(!this->getStage(stageIdx).getEffect()); GrAssert(!this->getStage(stageIdx).getEffect());
GrEffect* effect = SkNEW_ARGS(GrSingleTextureEffect, (texture, matrix)); GrEffectRef* effect = GrSingleTextureEffect::Create(texture, matrix);
this->stage(stageIdx)->setEffect(effect)->unref(); this->stage(stageIdx)->setEffect(effect)->unref();
} }
void createTextureEffect(int stageIdx, void createTextureEffect(int stageIdx,
@ -209,11 +205,10 @@ public:
const SkMatrix& matrix, const SkMatrix& matrix,
const GrTextureParams& params) { const GrTextureParams& params) {
GrAssert(!this->getStage(stageIdx).getEffect()); GrAssert(!this->getStage(stageIdx).getEffect());
GrEffect* effect = SkNEW_ARGS(GrSingleTextureEffect, (texture, matrix, params)); GrEffectRef* effect = GrSingleTextureEffect::Create(texture, matrix, params);
this->stage(stageIdx)->setEffect(effect)->unref(); this->stage(stageIdx)->setEffect(effect)->unref();
} }
bool stagesDisabled() { bool stagesDisabled() {
for (int i = 0; i < kNumStages; ++i) { for (int i = 0; i < kNumStages; ++i) {
if (NULL != fStages[i].getEffect()) { if (NULL != fStages[i].getEffect()) {

View File

@ -58,7 +58,28 @@ private:
int32_t GrBackendEffectFactory::fCurrEffectClassID = GrBackendEffectFactory::kIllegalEffectClassID; int32_t GrBackendEffectFactory::fCurrEffectClassID = GrBackendEffectFactory::kIllegalEffectClassID;
///////////////////////////////////////////////////////////////////////////////
SK_DEFINE_INST_COUNT(GrEffectRef)
GrEffectRef::~GrEffectRef() {
GrAssert(1 == this->getRefCnt());
fEffect->effectPtrDestroyed();
fEffect->unref();
}
void* GrEffectRef::operator new(size_t size) {
return GrEffect_Globals::GetTLS()->allocate(size);
}
void GrEffectRef::operator delete(void* target) {
GrEffect_Globals::GetTLS()->release(target);
}
///////////////////////////////////////////////////////////////////////////////
GrEffect::~GrEffect() { GrEffect::~GrEffect() {
GrAssert(NULL == fEffectPtr);
} }
const char* GrEffect::name() const { const char* GrEffect::name() const {
@ -81,7 +102,7 @@ void GrEffect::addTextureAccess(const GrTextureAccess* access) {
fTextureAccesses.push_back(access); fTextureAccesses.push_back(access);
} }
void * GrEffect::operator new(size_t size) { void* GrEffect::operator new(size_t size) {
return GrEffect_Globals::GetTLS()->allocate(size); return GrEffect_Globals::GetTLS()->allocate(size);
} }

View File

@ -198,7 +198,7 @@ void GrSWMaskHelper::DrawToTargetWithPathMask(GrTexture* texture,
}; };
GrAssert(!drawState->isStageEnabled(kPathMaskStage)); GrAssert(!drawState->isStageEnabled(kPathMaskStage));
drawState->stage(kPathMaskStage)->reset(); drawState->stage(kPathMaskStage)->reset();
drawState->createTextureEffect(kPathMaskStage, texture); drawState->createTextureEffect(kPathMaskStage, texture, SkMatrix::I());
SkScalar w = SkIntToScalar(rect.width()); SkScalar w = SkIntToScalar(rect.width());
SkScalar h = SkIntToScalar(rect.height()); SkScalar h = SkIntToScalar(rect.height());
GrRect maskRect = GrRect::MakeWH(w / texture->width(), GrRect maskRect = GrRect::MakeWH(w / texture->width(),

View File

@ -443,7 +443,7 @@ bool SkGpuDevice::bindDeviceAsTexture(GrPaint* paint) {
GrTexture* texture = fRenderTarget->asTexture(); GrTexture* texture = fRenderTarget->asTexture();
if (NULL != texture) { if (NULL != texture) {
paint->colorStage(kBitmapTextureIdx)->setEffect( paint->colorStage(kBitmapTextureIdx)->setEffect(
SkNEW_ARGS(GrSingleTextureEffect, (texture)))->unref(); GrSingleTextureEffect::Create(texture, SkMatrix::I()))->unref();
return true; return true;
} }
return false; return false;
@ -512,7 +512,7 @@ inline bool skPaint2GrPaintNoShader(SkGpuDevice* dev,
SkColor filtered = colorFilter->filterColor(skPaint.getColor()); SkColor filtered = colorFilter->filterColor(skPaint.getColor());
grPaint->setColor(SkColor2GrColor(filtered)); grPaint->setColor(SkColor2GrColor(filtered));
} else { } else {
SkAutoTUnref<GrEffect> effect(colorFilter->asNewEffect(dev->context())); SkAutoTUnref<GrEffectRef> effect(colorFilter->asNewEffect(dev->context()));
if (NULL != effect.get()) { if (NULL != effect.get()) {
grPaint->colorStage(kColorFilterTextureIdx)->setEffect(effect); grPaint->colorStage(kColorFilterTextureIdx)->setEffect(effect);
} else { } else {
@ -544,7 +544,7 @@ inline bool skPaint2GrPaintShader(SkGpuDevice* dev,
return false; return false;
} }
SkAutoTUnref<GrEffect> effect(shader->asNewEffect(dev->context(), skPaint)); SkAutoTUnref<GrEffectRef> effect(shader->asNewEffect(dev->context(), skPaint));
if (NULL != effect.get()) { if (NULL != effect.get()) {
grPaint->colorStage(kShaderTextureIdx)->setEffect(effect); grPaint->colorStage(kShaderTextureIdx)->setEffect(effect);
return true; return true;
@ -796,7 +796,8 @@ bool drawWithGPUMaskFilter(GrContext* context, const SkPath& devPath, const SkSt
matrix.setIDiv(pathTexture->width(), pathTexture->height()); matrix.setIDiv(pathTexture->width(), pathTexture->height());
// Blend pathTexture over blurTexture. // Blend pathTexture over blurTexture.
context->setRenderTarget(blurTexture->asRenderTarget()); context->setRenderTarget(blurTexture->asRenderTarget());
paint.colorStage(0)->setEffect(SkNEW_ARGS(GrSingleTextureEffect, (pathTexture, matrix)))->unref(); paint.colorStage(0)->setEffect(
GrSingleTextureEffect::Create(pathTexture, matrix))->unref();
if (SkMaskFilter::kInner_BlurType == blurType) { if (SkMaskFilter::kInner_BlurType == blurType) {
// inner: dst = dst * src // inner: dst = dst * src
paint.setBlendFunc(kDC_GrBlendCoeff, kZero_GrBlendCoeff); paint.setBlendFunc(kDC_GrBlendCoeff, kZero_GrBlendCoeff);
@ -827,7 +828,8 @@ bool drawWithGPUMaskFilter(GrContext* context, const SkPath& devPath, const SkSt
matrix.postIDiv(blurTexture->width(), blurTexture->height()); matrix.postIDiv(blurTexture->width(), blurTexture->height());
grp->coverageStage(MASK_IDX)->reset(); grp->coverageStage(MASK_IDX)->reset();
grp->coverageStage(MASK_IDX)->setEffect(SkNEW_ARGS(GrSingleTextureEffect, (blurTexture, matrix)))->unref(); grp->coverageStage(MASK_IDX)->setEffect(
GrSingleTextureEffect::Create(blurTexture, matrix))->unref();
context->drawRect(*grp, finalRect); context->drawRect(*grp, finalRect);
return true; return true;
} }
@ -883,7 +885,7 @@ bool drawWithMaskFilter(GrContext* context, const SkPath& devPath,
m.setTranslate(-dstM.fBounds.fLeft*SK_Scalar1, -dstM.fBounds.fTop*SK_Scalar1); m.setTranslate(-dstM.fBounds.fLeft*SK_Scalar1, -dstM.fBounds.fTop*SK_Scalar1);
m.postIDiv(texture->width(), texture->height()); m.postIDiv(texture->width(), texture->height());
grp->coverageStage(MASK_IDX)->setEffect(SkNEW_ARGS(GrSingleTextureEffect, (texture, m)))->unref(); grp->coverageStage(MASK_IDX)->setEffect(GrSingleTextureEffect::Create(texture, m))->unref();
GrRect d; GrRect d;
d.setLTRB(SkIntToScalar(dstM.fBounds.fLeft), d.setLTRB(SkIntToScalar(dstM.fBounds.fLeft),
SkIntToScalar(dstM.fBounds.fTop), SkIntToScalar(dstM.fBounds.fTop),
@ -1313,7 +1315,7 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
} }
GrRect textureDomain = GrRect::MakeEmpty(); GrRect textureDomain = GrRect::MakeEmpty();
SkAutoTUnref<GrEffect> effect; SkAutoTUnref<GrEffectRef> effect;
if (needsTextureDomain) { if (needsTextureDomain) {
// Use a constrained texture domain to avoid color bleeding // Use a constrained texture domain to avoid color bleeding
SkScalar left, top, right, bottom; SkScalar left, top, right, bottom;
@ -1338,7 +1340,7 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
GrTextureDomainEffect::kClamp_WrapMode, GrTextureDomainEffect::kClamp_WrapMode,
params.isBilerp())); params.isBilerp()));
} else { } else {
effect.reset(SkNEW_ARGS(GrSingleTextureEffect, (texture, params))); effect.reset(GrSingleTextureEffect::Create(texture, SkMatrix::I(), params));
} }
grPaint->colorStage(kBitmapTextureIdx)->setEffect(effect); grPaint->colorStage(kBitmapTextureIdx)->setEffect(effect);
fContext->drawRectToRect(*grPaint, dstRect, paintRect, &m); fContext->drawRectToRect(*grPaint, dstRect, paintRect, &m);
@ -1350,7 +1352,7 @@ void apply_effect(GrContext* context,
GrTexture* srcTexture, GrTexture* srcTexture,
GrTexture* dstTexture, GrTexture* dstTexture,
const GrRect& rect, const GrRect& rect,
GrEffect* effect) { GrEffectRef* effect) {
SkASSERT(srcTexture && srcTexture->getContext() == context); SkASSERT(srcTexture && srcTexture->getContext() == context);
GrContext::AutoMatrix am; GrContext::AutoMatrix am;
am.setIdentity(context); am.setIdentity(context);
@ -1375,7 +1377,7 @@ static GrTexture* filter_texture(SkDevice* device, GrContext* context,
desc.fWidth = SkScalarCeilToInt(rect.width()); desc.fWidth = SkScalarCeilToInt(rect.width());
desc.fHeight = SkScalarCeilToInt(rect.height()); desc.fHeight = SkScalarCeilToInt(rect.height());
desc.fConfig = kRGBA_8888_GrPixelConfig; desc.fConfig = kRGBA_8888_GrPixelConfig;
GrEffect* effect; GrEffectRef* effect;
if (filter->canFilterImageGPU()) { if (filter->canFilterImageGPU()) {
// Save the render target and set it to NULL, so we don't accidentally draw to it in the // Save the render target and set it to NULL, so we don't accidentally draw to it in the
@ -1415,16 +1417,16 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
stage->reset(); stage->reset();
// draw sprite uses the default texture params // draw sprite uses the default texture params
SkAutoCachedTexture act(this, bitmap, NULL, &texture); SkAutoCachedTexture act(this, bitmap, NULL, &texture);
grPaint.colorStage(kBitmapTextureIdx)->setEffect(SkNEW_ARGS grPaint.colorStage(kBitmapTextureIdx)->setEffect(
(GrSingleTextureEffect, (texture)))->unref(); GrSingleTextureEffect::Create(texture, SkMatrix::I()))->unref();
SkImageFilter* filter = paint.getImageFilter(); SkImageFilter* filter = paint.getImageFilter();
if (NULL != filter) { if (NULL != filter) {
GrTexture* filteredTexture = filter_texture(this, fContext, texture, filter, GrTexture* filteredTexture = filter_texture(this, fContext, texture, filter,
GrRect::MakeWH(SkIntToScalar(w), SkIntToScalar(h))); GrRect::MakeWH(SkIntToScalar(w), SkIntToScalar(h)));
if (filteredTexture) { if (filteredTexture) {
grPaint.colorStage(kBitmapTextureIdx)->setEffect(SkNEW_ARGS grPaint.colorStage(kBitmapTextureIdx)->setEffect(
(GrSingleTextureEffect, (filteredTexture)))->unref(); GrSingleTextureEffect::Create(filteredTexture, SkMatrix::I()))->unref();
texture = filteredTexture; texture = filteredTexture;
filteredTexture->unref(); filteredTexture->unref();
} }
@ -1497,8 +1499,8 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkDevice* device,
SkIntToScalar(devTex->height())); SkIntToScalar(devTex->height()));
GrTexture* filteredTexture = filter_texture(this, fContext, devTex, filter, rect); GrTexture* filteredTexture = filter_texture(this, fContext, devTex, filter, rect);
if (filteredTexture) { if (filteredTexture) {
grPaint.colorStage(kBitmapTextureIdx)->setEffect(SkNEW_ARGS grPaint.colorStage(kBitmapTextureIdx)->setEffect(
(GrSingleTextureEffect, (filteredTexture)))->unref(); GrSingleTextureEffect::Create(filteredTexture, SkMatrix::I()))->unref();
devTex = filteredTexture; devTex = filteredTexture;
filteredTexture->unref(); filteredTexture->unref();
} }

View File

@ -124,9 +124,9 @@ bool GrConfigConversionEffect::isEqual(const GrEffect& s) const {
GR_DEFINE_EFFECT_TEST(GrConfigConversionEffect); GR_DEFINE_EFFECT_TEST(GrConfigConversionEffect);
GrEffect* GrConfigConversionEffect::TestCreate(SkRandom* random, GrEffectRef* GrConfigConversionEffect::TestCreate(SkRandom* random,
GrContext* context, GrContext* context,
GrTexture* textures[]) { GrTexture* textures[]) {
PMConversion pmConv = static_cast<PMConversion>(random->nextULessThan(kPMConversionCnt)); PMConversion pmConv = static_cast<PMConversion>(random->nextULessThan(kPMConversionCnt));
bool swapRB; bool swapRB;
if (kNone_PMConversion == pmConv) { if (kNone_PMConversion == pmConv) {
@ -134,10 +134,12 @@ GrEffect* GrConfigConversionEffect::TestCreate(SkRandom* random,
} else { } else {
swapRB = random->nextBool(); swapRB = random->nextBool();
} }
return SkNEW_ARGS(GrConfigConversionEffect, (textures[GrEffectUnitTest::kSkiaPMTextureIdx], SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrConfigConversionEffect,
swapRB, (textures[GrEffectUnitTest::kSkiaPMTextureIdx],
pmConv, swapRB,
GrEffectUnitTest::TestMatrix(random))); pmConv,
GrEffectUnitTest::TestMatrix(random))));
return CreateEffectPtr(effect);
} }
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@ -204,21 +206,22 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context
// We then verify that two reads produced the same values. // We then verify that two reads produced the same values.
GrPaint paint; GrPaint paint;
SkAutoTUnref<GrEffect> pmToUPMEffect1(SkNEW_ARGS(GrConfigConversionEffect, SkAutoTUnref<GrEffect> pmToUPM1(SkNEW_ARGS(GrConfigConversionEffect, (dataTex,
(dataTex, false,
false, *pmToUPMRule,
*pmToUPMRule, SkMatrix::I())));
SkMatrix::I()))); SkAutoTUnref<GrEffect> upmToPM(SkNEW_ARGS(GrConfigConversionEffect, (readTex,
SkAutoTUnref<GrEffect> upmToPMEffect(SkNEW_ARGS(GrConfigConversionEffect, false,
(readTex, *upmToPMRule,
false, SkMatrix::I())));
*upmToPMRule, SkAutoTUnref<GrEffect> pmToUPM2(SkNEW_ARGS(GrConfigConversionEffect, (tempTex,
SkMatrix::I()))); false,
SkAutoTUnref<GrEffect> pmToUPMEffect2(SkNEW_ARGS(GrConfigConversionEffect, *pmToUPMRule,
(tempTex, SkMatrix::I())));
false,
*pmToUPMRule, SkAutoTUnref<GrEffectRef> pmToUPMEffect1(CreateEffectPtr(pmToUPM1));
SkMatrix::I()))); SkAutoTUnref<GrEffectRef> upmToPMEffect(CreateEffectPtr(upmToPM));
SkAutoTUnref<GrEffectRef> pmToUPMEffect2(CreateEffectPtr(pmToUPM2));
context->setRenderTarget(readTex->asRenderTarget()); context->setRenderTarget(readTex->asRenderTarget());
paint.colorStage(0)->setEffect(pmToUPMEffect1); paint.colorStage(0)->setEffect(pmToUPMEffect1);
@ -260,7 +263,7 @@ bool GrConfigConversionEffect::InstallEffect(GrTexture* texture,
// If we returned a GrConfigConversionEffect that was equivalent to a GrSingleTextureEffect // If we returned a GrConfigConversionEffect that was equivalent to a GrSingleTextureEffect
// then we may pollute our texture cache with redundant shaders. So in the case that no // then we may pollute our texture cache with redundant shaders. So in the case that no
// conversions were requested we instead return a GrSingleTextureEffect. // conversions were requested we instead return a GrSingleTextureEffect.
stage->setEffect(SkNEW_ARGS(GrSingleTextureEffect, (texture, matrix)))->unref(); stage->setEffect(GrSingleTextureEffect::Create(texture, matrix))->unref();
return true; return true;
} else { } else {
if (kRGBA_8888_GrPixelConfig != texture->config() && if (kRGBA_8888_GrPixelConfig != texture->config() &&
@ -269,9 +272,11 @@ bool GrConfigConversionEffect::InstallEffect(GrTexture* texture,
// The PM conversions assume colors are 0..255 // The PM conversions assume colors are 0..255
return false; return false;
} }
stage->setEffect(SkNEW_ARGS(GrConfigConversionEffect, (texture, SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrConfigConversionEffect, (texture,
swapRedAndBlue, swapRedAndBlue,
pmConversion, matrix)))->unref(); pmConversion,
matrix)));
stage->setEffect(CreateEffectPtr(effect))->unref();
return true; return true;
} }
} }

View File

@ -10,6 +10,7 @@
#include "GrSingleTextureEffect.h" #include "GrSingleTextureEffect.h"
class GrEffectStage;
class GrGLConfigConversionEffect; class GrGLConfigConversionEffect;
/** /**

View File

@ -180,9 +180,9 @@ bool GrConvolutionEffect::isEqual(const GrEffect& sBase) const {
GR_DEFINE_EFFECT_TEST(GrConvolutionEffect); GR_DEFINE_EFFECT_TEST(GrConvolutionEffect);
GrEffect* GrConvolutionEffect::TestCreate(SkRandom* random, GrEffectRef* GrConvolutionEffect::TestCreate(SkRandom* random,
GrContext* context, GrContext* context,
GrTexture* textures[]) { GrTexture* textures[]) {
int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
GrEffectUnitTest::kAlphaTextureIdx; GrEffectUnitTest::kAlphaTextureIdx;
Direction dir = random->nextBool() ? kX_Direction : kY_Direction; Direction dir = random->nextBool() ? kX_Direction : kY_Direction;
@ -192,6 +192,6 @@ GrEffect* GrConvolutionEffect::TestCreate(SkRandom* random,
kernel[i] = random->nextSScalar1(); kernel[i] = random->nextSScalar1();
} }
return SkNEW_ARGS(GrConvolutionEffect, (textures[texIdx], dir, radius, kernel)); return GrConvolutionEffect::Create(textures[texIdx], dir, radius,kernel);
} }

View File

@ -22,13 +22,26 @@ class GrConvolutionEffect : public Gr1DKernelEffect {
public: public:
/// Convolve with an arbitrary user-specified kernel /// Convolve with an arbitrary user-specified kernel
GrConvolutionEffect(GrTexture*, Direction, static GrEffectRef* Create(GrTexture* tex, Direction dir, int halfWidth, const float* kernel) {
int halfWidth, const float* kernel); SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrConvolutionEffect, (tex,
dir,
halfWidth,
kernel)));
return CreateEffectPtr(effect);
}
/// Convolve with a Gaussian kernel /// Convolve with a Gaussian kernel
GrConvolutionEffect(GrTexture*, Direction, static GrEffectRef* Create(GrTexture* tex,
int halfWidth, Direction dir,
float gaussianSigma); int halfWidth,
float gaussianSigma) {
SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrConvolutionEffect, (tex,
dir,
halfWidth,
gaussianSigma)));
return CreateEffectPtr(effect);
}
virtual ~GrConvolutionEffect(); virtual ~GrConvolutionEffect();
const float* kernel() const { return fKernel; } const float* kernel() const { return fKernel; }
@ -56,6 +69,14 @@ protected:
float fKernel[kMaxKernelWidth]; float fKernel[kMaxKernelWidth];
private: private:
GrConvolutionEffect(GrTexture*, Direction,
int halfWidth, const float* kernel);
/// Convolve with a Gaussian kernel
GrConvolutionEffect(GrTexture*, Direction,
int halfWidth,
float gaussianSigma);
GR_DECLARE_EFFECT_TEST; GR_DECLARE_EFFECT_TEST;
typedef Gr1DKernelEffect INHERITED; typedef Gr1DKernelEffect INHERITED;

View File

@ -57,24 +57,6 @@ private:
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture)
: fTextureAccess(texture) {
fMatrix.reset();
this->addTextureAccess(&fTextureAccess);
}
GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, bool bilerp)
: fTextureAccess(texture, bilerp) {
fMatrix.reset();
this->addTextureAccess(&fTextureAccess);
}
GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, const GrTextureParams& params)
: fTextureAccess(texture, params) {
fMatrix.reset();
this->addTextureAccess(&fTextureAccess);
}
GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, const SkMatrix& m) GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, const SkMatrix& m)
: fTextureAccess(texture) : fTextureAccess(texture)
, fMatrix(m) { , fMatrix(m) {
@ -117,11 +99,11 @@ const GrBackendEffectFactory& GrSingleTextureEffect::getFactory() const {
GR_DEFINE_EFFECT_TEST(GrSingleTextureEffect); GR_DEFINE_EFFECT_TEST(GrSingleTextureEffect);
GrEffect* GrSingleTextureEffect::TestCreate(SkRandom* random, GrEffectRef* GrSingleTextureEffect::TestCreate(SkRandom* random,
GrContext* context, GrContext* context,
GrTexture* textures[]) { GrTexture* textures[]) {
int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
GrEffectUnitTest::kAlphaTextureIdx; GrEffectUnitTest::kAlphaTextureIdx;
const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random);
return SkNEW_ARGS(GrSingleTextureEffect, (textures[texIdx], matrix)); return GrSingleTextureEffect::Create(textures[texIdx], matrix);
} }

View File

@ -19,17 +19,23 @@ class GrTexture;
* output color is the texture color is modulated against the input color. * output color is the texture color is modulated against the input color.
*/ */
class GrSingleTextureEffect : public GrEffect { class GrSingleTextureEffect : public GrEffect {
public: public:
/** These three constructors assume an identity matrix. TODO: Remove these.*/ /* unfiltered, clamp mode */
GrSingleTextureEffect(GrTexture* texture); /* unfiltered, clamp mode */ static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix) {
GrSingleTextureEffect(GrTexture* texture, bool bilerp); /* clamp mode */ SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSingleTextureEffect, (tex, matrix)));
GrSingleTextureEffect(GrTexture* texture, const GrTextureParams&); return CreateEffectPtr(effect);
}
/** These three constructors take an explicit matrix */ /* clamp mode */
GrSingleTextureEffect(GrTexture*, const SkMatrix&); /* unfiltered, clamp mode */ static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, bool bilerp) {
GrSingleTextureEffect(GrTexture*, const SkMatrix&, bool bilerp); /* clamp mode */ SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSingleTextureEffect, (tex, matrix, bilerp)));
GrSingleTextureEffect(GrTexture*, const SkMatrix&, const GrTextureParams&); return CreateEffectPtr(effect);
}
static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, const GrTextureParams& p) {
SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSingleTextureEffect, (tex, matrix, p)));
return CreateEffectPtr(effect);
}
virtual ~GrSingleTextureEffect(); virtual ~GrSingleTextureEffect();
@ -50,7 +56,13 @@ public:
return INHERITED::isEqual(effect) && fMatrix.cheapEqualTo(ste.getMatrix()); return INHERITED::isEqual(effect) && fMatrix.cheapEqualTo(ste.getMatrix());
} }
protected:
GrSingleTextureEffect(GrTexture*, const SkMatrix&); /* unfiltered, clamp mode */
GrSingleTextureEffect(GrTexture*, const SkMatrix&, bool bilerp); /* clamp mode */
GrSingleTextureEffect(GrTexture*, const SkMatrix&, const GrTextureParams&);
private: private:
GR_DECLARE_EFFECT_TEST; GR_DECLARE_EFFECT_TEST;
GrTextureAccess fTextureAccess; GrTextureAccess fTextureAccess;

View File

@ -121,14 +121,14 @@ GrGLEffect::EffectKey GrGLTextureDomainEffect::GenKey(const GrEffectStage& stage
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
GrEffect* GrTextureDomainEffect::Create(GrTexture* texture, GrEffectRef* GrTextureDomainEffect::Create(GrTexture* texture,
const SkMatrix& matrix, const SkMatrix& matrix,
const GrRect& domain, const GrRect& domain,
WrapMode wrapMode, WrapMode wrapMode,
bool bilerp) { bool bilerp) {
static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1}; static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1};
if (kClamp_WrapMode == wrapMode && domain.contains(kFullRect)) { if (kClamp_WrapMode == wrapMode && domain.contains(kFullRect)) {
return SkNEW_ARGS(GrSingleTextureEffect, (texture, matrix, bilerp)); return GrSingleTextureEffect::Create(texture, matrix, bilerp);
} else { } else {
SkRect clippedDomain; SkRect clippedDomain;
// We don't currently handle domains that are empty or don't intersect the texture. // We don't currently handle domains that are empty or don't intersect the texture.
@ -142,8 +142,14 @@ GrEffect* GrTextureDomainEffect::Create(GrTexture* texture,
clippedDomain.fBottom = SkMinScalar(domain.fBottom, kFullRect.fBottom); clippedDomain.fBottom = SkMinScalar(domain.fBottom, kFullRect.fBottom);
GrAssert(clippedDomain.fLeft <= clippedDomain.fRight); GrAssert(clippedDomain.fLeft <= clippedDomain.fRight);
GrAssert(clippedDomain.fTop <= clippedDomain.fBottom); GrAssert(clippedDomain.fTop <= clippedDomain.fBottom);
return SkNEW_ARGS(GrTextureDomainEffect,
(texture, matrix, clippedDomain, wrapMode, bilerp)); SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrTextureDomainEffect, (texture,
matrix,
clippedDomain,
wrapMode,
bilerp)));
return CreateEffectPtr(effect);
} }
} }
@ -174,9 +180,9 @@ bool GrTextureDomainEffect::isEqual(const GrEffect& sBase) const {
GR_DEFINE_EFFECT_TEST(GrTextureDomainEffect); GR_DEFINE_EFFECT_TEST(GrTextureDomainEffect);
GrEffect* GrTextureDomainEffect::TestCreate(SkRandom* random, GrEffectRef* GrTextureDomainEffect::TestCreate(SkRandom* random,
GrContext* context, GrContext* context,
GrTexture* textures[]) { GrTexture* textures[]) {
int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
GrEffectUnitTest::kAlphaTextureIdx; GrEffectUnitTest::kAlphaTextureIdx;
GrRect domain; GrRect domain;

View File

@ -34,11 +34,11 @@ public:
kDecal_WrapMode, kDecal_WrapMode,
}; };
static GrEffect* Create(GrTexture*, static GrEffectRef* Create(GrTexture*,
const SkMatrix&, const SkMatrix&,
const SkRect& domain, const SkRect& domain,
WrapMode, WrapMode,
bool bilerp = false); bool bilerp = false);
virtual ~GrTextureDomainEffect(); virtual ~GrTextureDomainEffect();

View File

@ -31,13 +31,13 @@ bool random_bool(SkRandom* r) {
return r->nextF() > .5f; return r->nextF() > .5f;
} }
const GrEffect* create_random_effect(SkRandom* random, const GrEffectRef* create_random_effect(SkRandom* random,
GrContext* context, GrContext* context,
GrTexture* dummyTextures[]) { GrTexture* dummyTextures[]) {
SkRandom sk_random; SkRandom sk_random;
sk_random.setSeed(random->nextU()); sk_random.setSeed(random->nextU());
GrEffect* effect = GrEffectTestFactory::CreateStage(&sk_random, context, dummyTextures); GrEffectRef* effect = GrEffectTestFactory::CreateStage(&sk_random, context, dummyTextures);
GrAssert(effect); GrAssert(effect);
return effect; return effect;
} }
@ -122,7 +122,7 @@ bool GrGpuGL::programUnitTest() {
} }
GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()}; GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()};
SkAutoTUnref<const GrEffect> effect(create_random_effect(&random, SkAutoTUnref<const GrEffectRef> effect(create_random_effect(&random,
getContext(), getContext(),
dummyTextures)); dummyTextures));
stages[s].setEffect(effect.get()); stages[s].setEffect(effect.get());