SkMatrix tm;
tm = vm;
tm.postIDiv(2*S, 2*S);
- paint.colorStage(0)->setEffect(SkNEW_ARGS(GrSingleTextureEffect,
- (texture, tm)))->unref();
+ paint.colorStage(0)->setEffect(GrSingleTextureEffect::Create(texture, tm))->unref();
ctx->drawRect(paint, GrRect::MakeWH(2*S, 2*S));
#include "SkXfermode.h"
class SkBitmap;
-class GrEffect;
+class GrEffectRef;
class GrContext;
class SK_API SkColorFilter : public SkFlattenable {
/** 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.
*/
- virtual GrEffect* asNewEffect(GrContext*) const;
+ virtual GrEffectRef* asNewEffect(GrContext*) const;
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
protected:
struct SkIPoint;
struct SkIRect;
struct SkRect;
-class GrEffect;
+class GrEffectRef;
class GrTexture;
/**
* The effect can assume its vertexCoords space maps 1-to-1 with texels
* 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
///////////////////////////////////////////////////////////////////////////////
#ifndef SkNEW
- #define SkNEW(type_name) new type_name
- #define SkNEW_ARGS(type_name, args) new type_name args
- #define SkNEW_ARRAY(type_name, count) new type_name[count]
- #define SkNEW_PLACEMENT(buf, type_name) new (buf) type_name
+ #define SkNEW(type_name) (new type_name)
+ #define SkNEW_ARGS(type_name, args) (new type_name args)
+ #define SkNEW_ARRAY(type_name, count) (new type_name[(count)])
+ #define SkNEW_PLACEMENT(buf, type_name) (new (buf) type_name)
#define SkNEW_PLACEMENT_ARGS(buf, type_name, args) \
- new (buf) type_name args
- #define SkDELETE(obj) delete obj
- #define SkDELETE_ARRAY(array) delete[] array
+ (new (buf) type_name args)
+ #define SkDELETE(obj) (delete (obj))
+ #define SkDELETE_ARRAY(array) (delete[] (array))
#endif
#ifndef SK_CRASH
class SkPath;
class GrContext;
-class GrEffect;
-class GrEffectStage;
+class GrEffectRef;
/** \class SkShader
*
* 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.
*/
- virtual GrEffect* asNewEffect(GrContext* context, const SkPaint& paint) const;
+ virtual GrEffectRef* asNewEffect(GrContext* context, const SkPaint& paint) const;
//////////////////////////////////////////////////////////////////////////
// Factory methods for stock shaders
virtual uint32_t getFlags() const SK_OVERRIDE;
virtual bool asColorMatrix(SkScalar matrix[20]) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
- virtual GrEffect* asNewEffect(GrContext*) const SK_OVERRIDE;
+ virtual GrEffectRef* asNewEffect(GrContext*) const SK_OVERRIDE;
#endif
struct State {
public:
SkMagnifierImageFilter(SkRect srcRect, SkScalar inset);
- virtual bool asNewEffect(GrEffect** effect,
- GrTexture* texture) const SK_OVERRIDE;
+ virtual bool asNewEffect(GrEffectRef** effect, GrTexture* texture) const SK_OVERRIDE;
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkMagnifierImageFilter)
SkBitmap* result, SkIPoint* loc) SK_OVERRIDE;
#if SK_SUPPORT_GPU
- virtual bool asNewEffect(GrEffect**, GrTexture*) const SK_OVERRIDE;
+ virtual bool asNewEffect(GrEffectRef**, GrTexture*) const SK_OVERRIDE;
#endif
private:
class GrBackendEffectFactory;
class GrContext;
+class GrEffect;
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
Ganesh shading pipeline.
Subclasses must have a function that produces a human-readable name:
static const char* Name();
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 {
public:
SK_DECLARE_INST_COUNT(GrEffect)
- GrEffect() {};
virtual ~GrEffect();
/**
*/
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:
- 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;
};
+inline GrEffectRef::GrEffectRef(GrEffect* effect) {
+ GrAssert(NULL != effect);
+ effect->ref();
+ fEffect = effect;
+}
+
#endif
public:
GrEffectStage()
- : fEffect (NULL) {
+ : fEffectPtr (NULL) {
GR_DEBUGCODE(fSavedCoordChangeCnt = 0;)
}
~GrEffectStage() {
- GrSafeUnref(fEffect);
+ GrSafeUnref(fEffectPtr);
GrAssert(0 == fSavedCoordChangeCnt);
}
bool operator ==(const GrEffectStage& other) const {
// first handle cases where one or the other has no effect
- if (NULL == fEffect) {
- return NULL == other.fEffect;
- } else if (NULL == other.fEffect) {
+ if (NULL == fEffectPtr) {
+ return NULL == other.fEffectPtr;
+ } else if (NULL == other.fEffectPtr) {
return false;
}
- if (fEffect->getFactory() != other.fEffect->getFactory()) {
+ if (this->getEffect()->getFactory() != other.getEffect()->getFactory()) {
return false;
}
- if (!fEffect->isEqual(*other.fEffect)) {
+ if (!this->getEffect()->isEqual(*other.getEffect())) {
return false;
}
bool operator !=(const GrEffectStage& s) const { return !(*this == s); }
GrEffectStage& operator =(const GrEffectStage& other) {
- GrSafeAssign(fEffect, other.fEffect);
- if (NULL != fEffect) {
+ GrSafeAssign(fEffectPtr, other.fEffectPtr);
+ if (NULL != fEffectPtr) {
fCoordChangeMatrix = other.fCoordChangeMatrix;
}
return *this;
class SavedCoordChange {
private:
SkMatrix fCoordChangeMatrix;
- GR_DEBUGCODE(mutable SkAutoTUnref<const GrEffect> fEffect;)
+ GR_DEBUGCODE(mutable SkAutoTUnref<const GrEffectRef> fEffectPtr;)
friend class GrEffectStage;
};
*/
void saveCoordChange(SavedCoordChange* savedCoordChange) const {
savedCoordChange->fCoordChangeMatrix = fCoordChangeMatrix;
- GrAssert(NULL == savedCoordChange->fEffect.get());
- GR_DEBUGCODE(GrSafeRef(fEffect);)
- GR_DEBUGCODE(savedCoordChange->fEffect.reset(fEffect);)
+ GrAssert(NULL == savedCoordChange->fEffectPtr.get());
+ GR_DEBUGCODE(GrSafeRef(fEffectPtr);)
+ GR_DEBUGCODE(savedCoordChange->fEffectPtr.reset(fEffectPtr);)
GR_DEBUGCODE(++fSavedCoordChangeCnt);
}
*/
void restoreCoordChange(const SavedCoordChange& savedCoordChange) {
fCoordChangeMatrix = savedCoordChange.fCoordChangeMatrix;
- GrAssert(savedCoordChange.fEffect.get() == fEffect);
+ GrAssert(savedCoordChange.fEffectPtr.get() == fEffectPtr);
GR_DEBUGCODE(--fSavedCoordChangeCnt);
- GR_DEBUGCODE(savedCoordChange.fEffect.reset(NULL);)
+ GR_DEBUGCODE(savedCoordChange.fEffectPtr.reset(NULL);)
}
/**
const SkMatrix& getCoordChangeMatrix() const { return fCoordChangeMatrix; }
void reset() {
- GrSafeSetNull(fEffect);
+ GrSafeSetNull(fEffectPtr);
}
- const GrEffect* setEffect(const GrEffect* effect) {
+ const GrEffectRef* setEffect(const GrEffectRef* effectPtr) {
GrAssert(0 == fSavedCoordChangeCnt);
- GrSafeAssign(fEffect, effect);
+ GrSafeAssign(fEffectPtr, effectPtr);
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:
SkMatrix fCoordChangeMatrix;
- const GrEffect* fEffect;
+ const GrEffectRef* fEffectPtr;
GR_DEBUGCODE(mutable int fSavedCoordChangeCnt;)
};
#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
class GrContext;
-class GrEffect;
+class GrEffectRef;
class GrTexture;
class GrEffectTestFactory : GrNoncopyable {
public:
- typedef GrEffect* (*CreateProc)(SkRandom*, GrContext*, GrTexture* dummyTextures[]);
+ typedef GrEffectRef* (*CreateProc)(SkRandom*, GrContext*, GrTexture* dummyTextures[]);
GrEffectTestFactory(CreateProc createProc) {
fCreateProc = createProc;
GetFactories()->push_back(this);
}
- static GrEffect* CreateStage(SkRandom* random,
- GrContext* context,
- GrTexture* dummyTextures[]) {
+ static GrEffectRef* CreateStage(SkRandom* random,
+ GrContext* context,
+ GrTexture* dummyTextures[]) {
uint32_t idx = random->nextRangeU(0, GetFactories()->count() - 1);
GrEffectTestFactory* factory = (*GetFactories())[idx];
return factory->fCreateProc(random, context, dummyTextures);
*/
#define GR_DECLARE_EFFECT_TEST \
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
* also implement this static function:
#include "effects/GrSingleTextureEffect.h"
#include "SkGr.h"
-GrEffect* SkBitmapProcShader::asNewEffect(GrContext* context, const SkPaint& paint) const {
+GrEffectRef* SkBitmapProcShader::asNewEffect(GrContext* context, const SkPaint& paint) const {
SkMatrix matrix;
matrix.setIDiv(fRawBitmap.width(), fRawBitmap.height());
return NULL;
}
- GrEffect* effect = SkNEW_ARGS(GrSingleTextureEffect, (texture, matrix, params));
+ GrEffectRef* effect = GrSingleTextureEffect::Create(texture, matrix, params);
GrUnlockCachedBitmapTexture(texture);
return effect;
}
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader)
#if SK_SUPPORT_GPU
- GrEffect* asNewEffect(GrContext*, const SkPaint&) const SK_OVERRIDE;
+ GrEffectRef* asNewEffect(GrContext*, const SkPaint&) const SK_OVERRIDE;
#endif
protected:
return SkUnPreMultiply::PMColorToColor(dst);
}
-GrEffect* SkColorFilter::asNewEffect(GrContext*) const {
+GrEffectRef* SkColorFilter::asNewEffect(GrContext*) const {
return NULL;
}
return true;
}
-bool SkImageFilter::asNewEffect(GrEffect**, GrTexture*) const {
+bool SkImageFilter::asNewEffect(GrEffectRef**, GrTexture*) const {
return false;
}
return kNone_GradientType;
}
-GrEffect* SkShader::asNewEffect(GrContext*, const SkPaint&) const {
+GrEffectRef* SkShader::asNewEffect(GrContext*, const SkPaint&) const {
return NULL;
}
class GrBlendEffect : public GrEffect {
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 bool isEqual(const GrEffect&) const SK_OVERRIDE;
void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
private:
+ GrBlendEffect(SkBlendImageFilter::Mode mode, GrTexture* foreground, GrTexture* background);
GrTextureAccess fForegroundAccess;
GrTextureAccess fBackgroundAccess;
SkBlendImageFilter::Mode fMode;
GrPaint paint;
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);
return dst;
}
class ColorMatrixEffect : public GrEffect {
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 {
return GrTBackendEffectFactory<ColorMatrixEffect>::getInstance();
};
private:
+ ColorMatrixEffect(const SkColorMatrix& matrix) : fMatrix(matrix) {}
+
SkColorMatrix fMatrix;
typedef GrGLEffect INHERITED;
GR_DEFINE_EFFECT_TEST(ColorMatrixEffect);
-GrEffect* ColorMatrixEffect::TestCreate(SkRandom* random,
- GrContext*,
- GrTexture* dummyTextures[2]) {
+GrEffectRef* ColorMatrixEffect::TestCreate(SkRandom* random,
+ GrContext*,
+ GrTexture* dummyTextures[2]) {
SkColorMatrix colorMatrix;
for (size_t i = 0; i < SK_ARRAY_COUNT(colorMatrix.fMat); ++i) {
colorMatrix.fMat[i] = random->nextSScalar1();
}
- return SkNEW_ARGS(ColorMatrixEffect, (colorMatrix));
+ return ColorMatrixEffect::Create(colorMatrix);
}
-GrEffect* SkColorMatrixFilter::asNewEffect(GrContext*) const {
- return SkNEW_ARGS(ColorMatrixEffect, (fMatrix));
+GrEffectRef* SkColorMatrixFilter::asNewEffect(GrContext*) const {
+ return ColorMatrixEffect::Create(fMatrix);
}
#endif
class GrDisplacementMapEffect : public GrEffect {
public:
- GrDisplacementMapEffect(SkDisplacementMapEffect::ChannelSelectorType xChannelSelector,
- SkDisplacementMapEffect::ChannelSelectorType yChannelSelector,
- SkScalar scale, GrTexture* displacement, GrTexture* color);
+ static GrEffectRef* Create(SkDisplacementMapEffect::ChannelSelectorType xChannelSelector,
+ SkDisplacementMapEffect::ChannelSelectorType yChannelSelector,
+ SkScalar scale, GrTexture* displacement, GrTexture* color) {
+ SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrDisplacementMapEffect, (xChannelSelector,
+ yChannelSelector,
+ scale,
+ displacement,
+ color)));
+ return CreateEffectPtr(effect);
+ }
+
virtual ~GrDisplacementMapEffect();
virtual bool isEqual(const GrEffect&) const SK_OVERRIDE;
void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE;
private:
+ GrDisplacementMapEffect(SkDisplacementMapEffect::ChannelSelectorType xChannelSelector,
+ SkDisplacementMapEffect::ChannelSelectorType yChannelSelector,
+ SkScalar scale, GrTexture* displacement, GrTexture* color);
+
GR_DECLARE_EFFECT_TEST;
GrTextureAccess fDisplacementAccess;
GrPaint paint;
paint.colorStage(0)->setEffect(
- SkNEW_ARGS(GrDisplacementMapEffect, (fXChannelSelector, fYChannelSelector, fScale,
- displacement.get(), color.get())))->unref();
+ GrDisplacementMapEffect::Create(fXChannelSelector,
+ fYChannelSelector,
+ fScale,
+ displacement.get(),
+ color.get()))->unref();
context->drawRect(paint, rect);
return dst;
}
GR_DEFINE_EFFECT_TEST(GrDisplacementMapEffect);
-GrEffect* GrDisplacementMapEffect::TestCreate(SkRandom* random,
- GrContext* context,
- GrTexture* textures[]) {
+GrEffectRef* GrDisplacementMapEffect::TestCreate(SkRandom* random,
+ GrContext* context,
+ GrTexture* textures[]) {
int texIdxDispl = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
GrEffectUnitTest::kAlphaTextureIdx;
int texIdxColor = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
random->nextRangeU(1, kMaxComponent));
SkScalar scale = random->nextUScalar1();
- return SkNEW_ARGS(GrDisplacementMapEffect, (xChannelSelector, yChannelSelector, scale,
- textures[texIdxDispl], textures[texIdxColor]));
+ return GrDisplacementMapEffect::Create(xChannelSelector, yChannelSelector, scale,
+ textures[texIdxDispl], textures[texIdxColor]);
}
///////////////////////////////////////////////////////////////////////////////
SkScalar kd, SkImageFilter* input);
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; }
protected:
SkSpecularLightingImageFilter(SkLight* light, SkScalar surfaceScale, SkScalar ks, SkScalar shininess, SkImageFilter* input);
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 shininess() const { return fShininess; }
class GrDiffuseLightingEffect : public GrLightingEffect {
public:
- GrDiffuseLightingEffect(GrTexture* texture,
- const SkLight* light,
- SkScalar surfaceScale,
- SkScalar kd);
+ static GrEffectRef* Create(GrTexture* texture,
+ const SkLight* light,
+ SkScalar surfaceScale,
+ SkScalar kd) {
+ SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrDiffuseLightingEffect, (texture,
+ light,
+ surfaceScale,
+ kd)));
+ return CreateEffectPtr(effect);
+ }
static const char* Name() { return "DiffuseLighting"; }
virtual bool isEqual(const GrEffect&) const SK_OVERRIDE;
SkScalar kd() const { return fKD; }
private:
+ GrDiffuseLightingEffect(GrTexture* texture,
+ const SkLight* light,
+ SkScalar surfaceScale,
+ SkScalar kd);
+
GR_DECLARE_EFFECT_TEST;
typedef GrLightingEffect INHERITED;
SkScalar fKD;
class GrSpecularLightingEffect : public GrLightingEffect {
public:
- GrSpecularLightingEffect(GrTexture* texture,
- const SkLight* light,
- SkScalar surfaceScale,
- SkScalar ks,
- SkScalar shininess);
-
+ static GrEffectRef* Create(GrTexture* texture,
+ const SkLight* light,
+ SkScalar surfaceScale,
+ SkScalar ks,
+ SkScalar shininess) {
+ SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSpecularLightingEffect, (texture,
+ light,
+ surfaceScale,
+ ks,
+ shininess)));
+ return CreateEffectPtr(effect);
+ }
static const char* Name() { return "SpecularLighting"; }
typedef GrGLSpecularLightingEffect GLEffect;
SkScalar shininess() const { return fShininess; }
private:
+ GrSpecularLightingEffect(GrTexture* texture,
+ const SkLight* light,
+ SkScalar surfaceScale,
+ SkScalar ks,
+ SkScalar shininess);
+
GR_DECLARE_EFFECT_TEST;
typedef GrLightingEffect INHERITED;
SkScalar fKS;
return true;
}
-bool SkDiffuseLightingImageFilter::asNewEffect(GrEffect** effect,
+bool SkDiffuseLightingImageFilter::asNewEffect(GrEffectRef** effect,
GrTexture* texture) const {
#if SK_SUPPORT_GPU
if (effect) {
SkScalar scale = SkScalarMul(surfaceScale(), SkIntToScalar(255));
- *effect = SkNEW_ARGS(GrDiffuseLightingEffect, (texture, light(), scale, kd()));
+ *effect = GrDiffuseLightingEffect::Create(texture, light(), scale, kd());
}
return true;
#else
return true;
}
-bool SkSpecularLightingImageFilter::asNewEffect(GrEffect** effect,
+bool SkSpecularLightingImageFilter::asNewEffect(GrEffectRef** effect,
GrTexture* texture) const {
#if SK_SUPPORT_GPU
if (effect) {
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;
#else
GR_DEFINE_EFFECT_TEST(GrDiffuseLightingEffect);
-GrEffect* GrDiffuseLightingEffect::TestCreate(SkRandom* random,
- GrContext* context,
- GrTexture* textures[]) {
+GrEffectRef* GrDiffuseLightingEffect::TestCreate(SkRandom* random,
+ GrContext* context,
+ GrTexture* textures[]) {
SkScalar surfaceScale = random->nextSScalar1();
SkScalar kd = random->nextUScalar1();
SkAutoTUnref<SkLight> light(create_random_light(random));
- return SkNEW_ARGS(GrDiffuseLightingEffect, (textures[GrEffectUnitTest::kAlphaTextureIdx],
- light, surfaceScale, kd));
+ return GrDiffuseLightingEffect::Create(textures[GrEffectUnitTest::kAlphaTextureIdx],
+ light, surfaceScale, kd);
}
GR_DEFINE_EFFECT_TEST(GrSpecularLightingEffect);
-GrEffect* GrSpecularLightingEffect::TestCreate(SkRandom* random,
- GrContext* context,
- GrTexture* textures[]) {
+GrEffectRef* GrSpecularLightingEffect::TestCreate(SkRandom* random,
+ GrContext* context,
+ GrTexture* textures[]) {
SkScalar surfaceScale = random->nextSScalar1();
SkScalar ks = random->nextUScalar1();
SkScalar shininess = random->nextUScalar1();
SkAutoTUnref<SkLight> light(create_random_light(random));
- return SkNEW_ARGS(GrSpecularLightingEffect, (textures[GrEffectUnitTest::kAlphaTextureIdx],
- light, surfaceScale, ks, shininess));
+ return GrSpecularLightingEffect::Create(textures[GrEffectUnitTest::kAlphaTextureIdx],
+ light, surfaceScale, ks, shininess);
}
///////////////////////////////////////////////////////////////////////////////
class GrMagnifierEffect : public GrSingleTextureEffect {
public:
- 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) {}
+ static GrEffectRef* Create(GrTexture* texture,
+ float xOffset,
+ float yOffset,
+ float xZoom,
+ float yZoom,
+ float xInset,
+ float yInset) {
+ SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrMagnifierEffect, (texture,
+ xOffset,
+ yOffset,
+ xZoom,
+ yZoom,
+ xInset,
+ yInset)));
+ return CreateEffectPtr(effect);
+ }
virtual ~GrMagnifierEffect() {};
typedef GrGLMagnifierEffect GLEffect;
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;
float fXOffset;
GR_DEFINE_EFFECT_TEST(GrMagnifierEffect);
-GrEffect* GrMagnifierEffect::TestCreate(SkRandom* random,
- GrContext* context,
- GrTexture** textures) {
+GrEffectRef* GrMagnifierEffect::TestCreate(SkRandom* random,
+ GrContext* context,
+ GrTexture** textures) {
const int kMaxWidth = 200;
const int kMaxHeight = 200;
const int kMaxInset = 20;
SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
SkIntToScalar(width), SkIntToScalar(height)),
inset));
- GrEffect* effect;
+ GrEffectRef* effect;
filter->asNewEffect(&effect, textures[0]);
GrAssert(NULL != effect);
return effect;
SkASSERT(srcRect.x() >= 0 && srcRect.y() >= 0 && inset >= 0);
}
-bool SkMagnifierImageFilter::asNewEffect(GrEffect** effect,
- GrTexture* texture) const {
+bool SkMagnifierImageFilter::asNewEffect(GrEffectRef** effect, GrTexture* texture) const {
#if SK_SUPPORT_GPU
if (effect) {
- *effect = SkNEW_ARGS(GrMagnifierEffect, (texture,
- fSrcRect.x() / texture->width(),
- fSrcRect.y() / texture->height(),
- texture->width() / fSrcRect.width(),
- texture->height() / fSrcRect.height(),
- fInset / texture->width(),
- fInset / texture->height()));
+ *effect = GrMagnifierEffect::Create(texture,
+ fSrcRect.x() / texture->width(),
+ fSrcRect.y() / texture->height(),
+ texture->width() / fSrcRect.width(),
+ texture->height() / fSrcRect.height(),
+ fInset / texture->width(),
+ fInset / texture->height());
}
return true;
#else
class GrMatrixConvolutionEffect : public GrSingleTextureEffect {
public:
typedef SkMatrixConvolutionImageFilter::TileMode TileMode;
- GrMatrixConvolutionEffect(GrTexture*,
- const SkISize& kernelSize,
- const SkScalar* kernel,
- SkScalar gain,
- SkScalar bias,
- const SkIPoint& target,
- TileMode tileMode,
- bool convolveAlpha);
+ static GrEffectRef* Create(GrTexture* texture,
+ const SkISize& kernelSize,
+ const SkScalar* kernel,
+ SkScalar gain,
+ SkScalar bias,
+ const SkIPoint& target,
+ TileMode tileMode,
+ bool convolveAlpha) {
+ SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrMatrixConvolutionEffect, (texture,
+ kernelSize,
+ kernel,
+ gain,
+ bias,
+ target,
+ tileMode,
+ convolveAlpha)));
+ return CreateEffectPtr(effect);
+ }
virtual ~GrMatrixConvolutionEffect();
virtual void getConstantColorComponents(GrColor* color,
virtual bool isEqual(const GrEffect&) const SK_OVERRIDE;
private:
+ GrMatrixConvolutionEffect(GrTexture*,
+ const SkISize& kernelSize,
+ const SkScalar* kernel,
+ SkScalar gain,
+ SkScalar bias,
+ const SkIPoint& target,
+ TileMode tileMode,
+ bool convolveAlpha);
+
SkISize fKernelSize;
float *fKernel;
float fGain;
// Allows for a 5x5 kernel (or 25x1, for that matter).
#define MAX_KERNEL_SIZE 25
-GrEffect* GrMatrixConvolutionEffect::TestCreate(SkRandom* random,
- GrContext* context,
- GrTexture* textures[]) {
+GrEffectRef* GrMatrixConvolutionEffect::TestCreate(SkRandom* random,
+ GrContext* context,
+ GrTexture* textures[]) {
int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
GrEffectUnitTest::kAlphaTextureIdx;
int width = random->nextRangeU(1, MAX_KERNEL_SIZE);
random->nextRangeU(0, kernelSize.height()));
TileMode tileMode = static_cast<TileMode>(random->nextRangeU(0, 2));
bool convolveAlpha = random->nextBool();
- return SkNEW_ARGS(GrMatrixConvolutionEffect, (textures[texIdx],
- kernelSize,
- kernel,
- gain,
- bias,
- target,
- tileMode,
- convolveAlpha));
+ return GrMatrixConvolutionEffect::Create(textures[texIdx],
+ kernelSize,
+ kernel,
+ gain,
+ bias,
+ target,
+ tileMode,
+ convolveAlpha);
}
-bool SkMatrixConvolutionImageFilter::asNewEffect(GrEffect** effect,
+bool SkMatrixConvolutionImageFilter::asNewEffect(GrEffectRef** effect,
GrTexture* texture) const {
bool ok = fKernelSize.width() * fKernelSize.height() <= MAX_KERNEL_SIZE;
if (ok && effect) {
- *effect = SkNEW_ARGS(GrMatrixConvolutionEffect, (texture,
- fKernelSize,
- fKernel,
- fGain,
- fBias,
- fTarget,
- fTileMode,
- fConvolveAlpha));
+ *effect = GrMatrixConvolutionEffect::Create(texture,
+ fKernelSize,
+ fKernel,
+ fGain,
+ fBias,
+ fTarget,
+ fTileMode,
+ fConvolveAlpha);
}
return ok;
}
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();
MorphologyType type() const { return fType; }
MorphologyType fType;
private:
+ GrMorphologyEffect(GrTexture*, Direction, int radius, MorphologyType);
+
GR_DECLARE_EFFECT_TEST;
typedef Gr1DKernelEffect INHERITED;
GR_DEFINE_EFFECT_TEST(GrMorphologyEffect);
-GrEffect* GrMorphologyEffect::TestCreate(SkRandom* random,
- GrContext* context,
- GrTexture* textures[]) {
+GrEffectRef* GrMorphologyEffect::TestCreate(SkRandom* random,
+ GrContext* context,
+ GrTexture* textures[]) {
int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
GrEffectUnitTest::kAlphaTextureIdx;
Direction dir = random->nextBool() ? kX_Direction : kY_Direction;
MorphologyType type = random->nextBool() ? GrMorphologyEffect::kErode_MorphologyType :
GrMorphologyEffect::kDilate_MorphologyType;
- return SkNEW_ARGS(GrMorphologyEffect, (textures[texIdx], dir, radius, type));
+ return GrMorphologyEffect::Create(textures[texIdx], dir, radius, type);
}
namespace {
GrMorphologyEffect::MorphologyType morphType,
Gr1DKernelEffect::Direction direction) {
GrPaint paint;
- paint.colorStage(0)->setEffect(SkNEW_ARGS(GrMorphologyEffect, (texture,
- direction,
- radius,
- morphType)))->unref();
+ paint.colorStage(0)->setEffect(GrMorphologyEffect::Create(texture,
+ direction,
+ radius,
+ morphType))->unref();
context->drawRect(paint, rect);
}
virtual bool asComponentTable(SkBitmap* table) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
- virtual GrEffect* asNewEffect(GrContext* context) const SK_OVERRIDE;
+ virtual GrEffectRef* asNewEffect(GrContext* context) const SK_OVERRIDE;
#endif
virtual void filterSpan(const SkPMColor src[], int count,
class ColorTableEffect : public GrEffect {
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();
static const char* Name() { return "ColorTable"; }
typedef GLColorTableEffect GLEffect;
private:
+ explicit ColorTableEffect(GrTexture* texture, unsigned flags);
+
GR_DECLARE_EFFECT_TEST;
GrTextureAccess fTextureAccess;
GR_DEFINE_EFFECT_TEST(ColorTableEffect);
-GrEffect* ColorTableEffect::TestCreate(SkRandom* random,
- GrContext* context,
- GrTexture* textures[]) {
+GrEffectRef* ColorTableEffect::TestCreate(SkRandom* random,
+ GrContext* context,
+ GrTexture* textures[]) {
static unsigned kAllFlags = SkTable_ColorFilter::kR_Flag | SkTable_ColorFilter::kG_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;
this->asComponentTable(&bitmap);
// passing NULL because this effect does no tiling or filtering.
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
// knowing when else to unlock it currently. TODO: Remove this when
class GrLinearGradient : public GrGradientEffect {
public:
- GrLinearGradient(GrContext* ctx,
- const SkLinearGradient& shader,
- const SkMatrix& matrix,
- SkShader::TileMode tm)
- : INHERITED(ctx, shader, matrix, tm) { }
+ static GrEffectRef* Create(GrContext* ctx,
+ const SkLinearGradient& shader,
+ const SkMatrix& matrix,
+ SkShader::TileMode tm) {
+ SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrLinearGradient, (ctx, shader, matrix, tm)));
+ return CreateEffectPtr(effect);
+ }
+
virtual ~GrLinearGradient() { }
static const char* Name() { return "Linear Gradient"; }
typedef GrGLLinearGradient GLEffect;
private:
+ GrLinearGradient(GrContext* ctx,
+ const SkLinearGradient& shader,
+ const SkMatrix& matrix,
+ SkShader::TileMode tm)
+ : INHERITED(ctx, shader, matrix, tm) { }
GR_DECLARE_EFFECT_TEST;
typedef GrGradientEffect INHERITED;
GR_DEFINE_EFFECT_TEST(GrLinearGradient);
-GrEffect* GrLinearGradient::TestCreate(SkRandom* random,
- GrContext* context,
- GrTexture**) {
+GrEffectRef* GrLinearGradient::TestCreate(SkRandom* random,
+ GrContext* context,
+ GrTexture**) {
SkPoint points[] = {{random->nextUScalar1(), random->nextUScalar1()},
{random->nextUScalar1(), random->nextUScalar1()}};
/////////////////////////////////////////////////////////////////////
-GrEffect* SkLinearGradient::asNewEffect(GrContext* context, const SkPaint&) const {
+GrEffectRef* SkLinearGradient::asNewEffect(GrContext* context, const SkPaint&) const {
SkASSERT(NULL != context);
SkMatrix matrix;
if (!this->getLocalMatrix().invert(&matrix)) {
return NULL;
}
matrix.postConcat(fPtsToUnit);
- return SkNEW_ARGS(GrLinearGradient, (context, *this, matrix, fTileMode));
+ return GrLinearGradient::Create(context, *this, matrix, fTileMode);
}
#else
virtual void shadeSpan16(int x, int y, uint16_t dstC[], int count) SK_OVERRIDE;
virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) 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_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLinearGradient)
class GrRadialGradient : public GrGradientEffect {
public:
-
- GrRadialGradient(GrContext* ctx,
- const SkRadialGradient& shader,
- const SkMatrix& matrix,
- SkShader::TileMode tm)
- : INHERITED(ctx, shader, matrix, tm) {
+ static GrEffectRef* Create(GrContext* ctx,
+ const SkRadialGradient& shader,
+ const SkMatrix& matrix,
+ SkShader::TileMode tm) {
+ SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrRadialGradient, (ctx, shader, matrix, tm)));
+ return CreateEffectPtr(effect);
}
virtual ~GrRadialGradient() { }
typedef GrGLRadialGradient GLEffect;
private:
+ GrRadialGradient(GrContext* ctx,
+ const SkRadialGradient& shader,
+ const SkMatrix& matrix,
+ SkShader::TileMode tm)
+ : INHERITED(ctx, shader, matrix, tm) {
+ }
+
GR_DECLARE_EFFECT_TEST;
typedef GrGradientEffect INHERITED;
GR_DEFINE_EFFECT_TEST(GrRadialGradient);
-GrEffect* GrRadialGradient::TestCreate(SkRandom* random,
- GrContext* context,
- GrTexture**) {
+GrEffectRef* GrRadialGradient::TestCreate(SkRandom* random,
+ GrContext* context,
+ GrTexture**) {
SkPoint center = {random->nextUScalar1(), random->nextUScalar1()};
SkScalar radius = random->nextUScalar1();
/////////////////////////////////////////////////////////////////////
-GrEffect* SkRadialGradient::asNewEffect(GrContext* context, const SkPaint&) const {
+GrEffectRef* SkRadialGradient::asNewEffect(GrContext* context, const SkPaint&) const {
SkASSERT(NULL != context);
SkMatrix matrix;
return NULL;
}
matrix.postConcat(fPtsToUnit);
- return SkNEW_ARGS(GrRadialGradient, (context, *this, matrix, fTileMode));
+ return GrRadialGradient::Create(context, *this, matrix, fTileMode);
}
#else
SkMatrix* matrix,
TileMode* xy) 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_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkRadialGradient)
class GrSweepGradient : public GrGradientEffect {
public:
-
- GrSweepGradient(GrContext* ctx,
- const SkSweepGradient& shader,
- const SkMatrix& matrix)
- : INHERITED(ctx, shader, matrix, SkShader::kClamp_TileMode) { }
+ static GrEffectRef* Create(GrContext* ctx,
+ const SkSweepGradient& shader,
+ const SkMatrix& matrix) {
+ SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSweepGradient, (ctx, shader, matrix)));
+ return CreateEffectPtr(effect);
+ }
virtual ~GrSweepGradient() { }
static const char* Name() { return "Sweep Gradient"; }
typedef GrGLSweepGradient GLEffect;
private:
+ GrSweepGradient(GrContext* ctx,
+ const SkSweepGradient& shader,
+ const SkMatrix& matrix)
+ : INHERITED(ctx, shader, matrix, SkShader::kClamp_TileMode) { }
GR_DECLARE_EFFECT_TEST;
typedef GrGradientEffect INHERITED;
GR_DEFINE_EFFECT_TEST(GrSweepGradient);
-GrEffect* GrSweepGradient::TestCreate(SkRandom* random,
- GrContext* context,
- GrTexture**) {
+GrEffectRef* GrSweepGradient::TestCreate(SkRandom* random,
+ GrContext* context,
+ GrTexture**) {
SkPoint center = {random->nextUScalar1(), random->nextUScalar1()};
SkColor colors[kMaxRandomGradientColors];
/////////////////////////////////////////////////////////////////////
-GrEffect* SkSweepGradient::asNewEffect(GrContext* context, const SkPaint&) const {
+GrEffectRef* SkSweepGradient::asNewEffect(GrContext* context, const SkPaint&) const {
SkMatrix matrix;
if (!this->getLocalMatrix().invert(&matrix)) {
return NULL;
}
matrix.postConcat(fPtsToUnit);
- return SkNEW_ARGS(GrSweepGradient, (context, *this, matrix));
+ return GrSweepGradient::Create(context, *this, matrix);
}
#else
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_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkSweepGradient)
class GrConical2Gradient : public GrGradientEffect {
public:
- 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()) { }
+ static GrEffectRef* Create(GrContext* ctx,
+ const SkTwoPointConicalGradient& shader,
+ const SkMatrix& matrix,
+ SkShader::TileMode tm) {
+ SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrConical2Gradient, (ctx, shader, matrix, tm)));
+ return CreateEffectPtr(effect);
+ }
virtual ~GrConical2Gradient() { }
typedef GrGLConical2Gradient GLEffect;
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_DEFINE_EFFECT_TEST(GrConical2Gradient);
-GrEffect* GrConical2Gradient::TestCreate(SkRandom* random,
- GrContext* context,
- GrTexture**) {
+GrEffectRef* GrConical2Gradient::TestCreate(SkRandom* random,
+ GrContext* context,
+ GrTexture**) {
SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()};
SkScalar radius1 = random->nextUScalar1();
SkPoint center2;
/////////////////////////////////////////////////////////////////////
-GrEffect* SkTwoPointConicalGradient::asNewEffect(GrContext* context, const SkPaint&) const {
+GrEffectRef* SkTwoPointConicalGradient::asNewEffect(GrContext* context, const SkPaint&) const {
SkASSERT(NULL != context);
SkASSERT(fPtsToUnit.isIdentity());
// invert the localM, translate to center1, rotate so center2 is on x axis.
matrix.postConcat(rot);
}
- return SkNEW_ARGS(GrConical2Gradient, (context, *this, matrix, fTileMode));
+ return GrConical2Gradient::Create(context, *this, matrix, fTileMode);
}
#else
SkMatrix* matrix,
TileMode* xy) const;
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 getStartRadius() const { return fRadius1; }
class GrRadial2Gradient : public GrGradientEffect {
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() { }
static const char* Name() { return "Two-Point Radial Gradient"; }
typedef GrGLRadial2Gradient GLEffect;
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_DEFINE_EFFECT_TEST(GrRadial2Gradient);
-GrEffect* GrRadial2Gradient::TestCreate(SkRandom* random,
- GrContext* context,
- GrTexture**) {
+GrEffectRef* GrRadial2Gradient::TestCreate(SkRandom* random,
+ GrContext* context,
+ GrTexture**) {
SkPoint center1 = {random->nextUScalar1(), random->nextUScalar1()};
SkScalar radius1 = random->nextUScalar1();
SkPoint center2;
/////////////////////////////////////////////////////////////////////
-GrEffect* SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint&) const {
+GrEffectRef* SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint&) const {
SkASSERT(NULL != context);
// invert the localM, translate to center1 (fPtsToUni), rotate so center2 is on x axis.
SkMatrix matrix;
matrix.postConcat(rot);
}
- return SkNEW_ARGS(GrRadial2Gradient, (context, *this, matrix, fTileMode));
+ return GrRadial2Gradient::Create(context, *this, matrix, fTileMode);
}
#else
SkMatrix* matrix,
TileMode* xy) 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,
int count) SK_OVERRIDE;
GrDrawTarget::AutoStateRestore asr(target, GrDrawTarget::kReset_ASRInit);
GrDrawState* drawState = target->drawState();
drawState->setRenderTarget(rt);
- SkAutoTUnref<GrConvolutionEffect> conv(SkNEW_ARGS(GrConvolutionEffect,
- (texture, direction, radius,
- sigma)));
+ SkAutoTUnref<GrEffectRef> conv(GrConvolutionEffect::Create(texture,
+ direction,
+ radius,
+ sigma));
drawState->stage(0)->setEffect(conv);
target->drawSimpleRect(rect, NULL);
}
scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f,
i < scaleFactorY ? 0.5f : 1.0f);
- paint.colorStage(0)->setEffect(SkNEW_ARGS(GrSingleTextureEffect,
- (srcTexture, matrix, true)))->unref();
+ paint.colorStage(0)->setEffect(GrSingleTextureEffect::Create(srcTexture,
+ matrix,
+ true))->unref();
this->drawRectToRect(paint, dstRect, srcRect);
srcRect = dstRect;
srcTexture = dstTexture;
// FIXME: This should be mitchell, not bilinear.
matrix.setIDiv(srcTexture->width(), srcTexture->height());
this->setRenderTarget(dstTexture->asRenderTarget());
- paint.colorStage(0)->setEffect(SkNEW_ARGS(GrSingleTextureEffect,(srcTexture,
- matrix, true)))->unref();
+ paint.colorStage(0)->setEffect(GrSingleTextureEffect::Create(srcTexture,
+ matrix,
+ true))->unref();
SkRect dstRect(srcRect);
scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY);
this->drawRectToRect(paint, dstRect, srcRect);
/**
* 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) {
GrAssert(!this->getStage(stageIdx).getEffect());
- GrEffect* effect = SkNEW_ARGS(GrSingleTextureEffect, (texture, matrix));
+ GrEffectRef* effect = GrSingleTextureEffect::Create(texture, matrix);
this->stage(stageIdx)->setEffect(effect)->unref();
}
void createTextureEffect(int stageIdx,
const SkMatrix& matrix,
const GrTextureParams& params) {
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();
}
-
bool stagesDisabled() {
for (int i = 0; i < kNumStages; ++i) {
if (NULL != fStages[i].getEffect()) {
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() {
+ GrAssert(NULL == fEffectPtr);
}
const char* GrEffect::name() const {
fTextureAccesses.push_back(access);
}
-void * GrEffect::operator new(size_t size) {
+void* GrEffect::operator new(size_t size) {
return GrEffect_Globals::GetTLS()->allocate(size);
}
};
GrAssert(!drawState->isStageEnabled(kPathMaskStage));
drawState->stage(kPathMaskStage)->reset();
- drawState->createTextureEffect(kPathMaskStage, texture);
+ drawState->createTextureEffect(kPathMaskStage, texture, SkMatrix::I());
SkScalar w = SkIntToScalar(rect.width());
SkScalar h = SkIntToScalar(rect.height());
GrRect maskRect = GrRect::MakeWH(w / texture->width(),
GrTexture* texture = fRenderTarget->asTexture();
if (NULL != texture) {
paint->colorStage(kBitmapTextureIdx)->setEffect(
- SkNEW_ARGS(GrSingleTextureEffect, (texture)))->unref();
+ GrSingleTextureEffect::Create(texture, SkMatrix::I()))->unref();
return true;
}
return false;
SkColor filtered = colorFilter->filterColor(skPaint.getColor());
grPaint->setColor(SkColor2GrColor(filtered));
} else {
- SkAutoTUnref<GrEffect> effect(colorFilter->asNewEffect(dev->context()));
+ SkAutoTUnref<GrEffectRef> effect(colorFilter->asNewEffect(dev->context()));
if (NULL != effect.get()) {
grPaint->colorStage(kColorFilterTextureIdx)->setEffect(effect);
} else {
return false;
}
- SkAutoTUnref<GrEffect> effect(shader->asNewEffect(dev->context(), skPaint));
+ SkAutoTUnref<GrEffectRef> effect(shader->asNewEffect(dev->context(), skPaint));
if (NULL != effect.get()) {
grPaint->colorStage(kShaderTextureIdx)->setEffect(effect);
return true;
matrix.setIDiv(pathTexture->width(), pathTexture->height());
// Blend pathTexture over blurTexture.
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) {
// inner: dst = dst * src
paint.setBlendFunc(kDC_GrBlendCoeff, kZero_GrBlendCoeff);
matrix.postIDiv(blurTexture->width(), blurTexture->height());
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);
return true;
}
m.setTranslate(-dstM.fBounds.fLeft*SK_Scalar1, -dstM.fBounds.fTop*SK_Scalar1);
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;
d.setLTRB(SkIntToScalar(dstM.fBounds.fLeft),
SkIntToScalar(dstM.fBounds.fTop),
}
GrRect textureDomain = GrRect::MakeEmpty();
- SkAutoTUnref<GrEffect> effect;
+ SkAutoTUnref<GrEffectRef> effect;
if (needsTextureDomain) {
// Use a constrained texture domain to avoid color bleeding
SkScalar left, top, right, bottom;
GrTextureDomainEffect::kClamp_WrapMode,
params.isBilerp()));
} else {
- effect.reset(SkNEW_ARGS(GrSingleTextureEffect, (texture, params)));
+ effect.reset(GrSingleTextureEffect::Create(texture, SkMatrix::I(), params));
}
grPaint->colorStage(kBitmapTextureIdx)->setEffect(effect);
fContext->drawRectToRect(*grPaint, dstRect, paintRect, &m);
GrTexture* srcTexture,
GrTexture* dstTexture,
const GrRect& rect,
- GrEffect* effect) {
+ GrEffectRef* effect) {
SkASSERT(srcTexture && srcTexture->getContext() == context);
GrContext::AutoMatrix am;
am.setIdentity(context);
desc.fWidth = SkScalarCeilToInt(rect.width());
desc.fHeight = SkScalarCeilToInt(rect.height());
desc.fConfig = kRGBA_8888_GrPixelConfig;
- GrEffect* effect;
+ GrEffectRef* effect;
if (filter->canFilterImageGPU()) {
// Save the render target and set it to NULL, so we don't accidentally draw to it in the
stage->reset();
// draw sprite uses the default texture params
SkAutoCachedTexture act(this, bitmap, NULL, &texture);
- grPaint.colorStage(kBitmapTextureIdx)->setEffect(SkNEW_ARGS
- (GrSingleTextureEffect, (texture)))->unref();
+ grPaint.colorStage(kBitmapTextureIdx)->setEffect(
+ GrSingleTextureEffect::Create(texture, SkMatrix::I()))->unref();
SkImageFilter* filter = paint.getImageFilter();
if (NULL != filter) {
GrTexture* filteredTexture = filter_texture(this, fContext, texture, filter,
GrRect::MakeWH(SkIntToScalar(w), SkIntToScalar(h)));
if (filteredTexture) {
- grPaint.colorStage(kBitmapTextureIdx)->setEffect(SkNEW_ARGS
- (GrSingleTextureEffect, (filteredTexture)))->unref();
+ grPaint.colorStage(kBitmapTextureIdx)->setEffect(
+ GrSingleTextureEffect::Create(filteredTexture, SkMatrix::I()))->unref();
texture = filteredTexture;
filteredTexture->unref();
}
SkIntToScalar(devTex->height()));
GrTexture* filteredTexture = filter_texture(this, fContext, devTex, filter, rect);
if (filteredTexture) {
- grPaint.colorStage(kBitmapTextureIdx)->setEffect(SkNEW_ARGS
- (GrSingleTextureEffect, (filteredTexture)))->unref();
+ grPaint.colorStage(kBitmapTextureIdx)->setEffect(
+ GrSingleTextureEffect::Create(filteredTexture, SkMatrix::I()))->unref();
devTex = filteredTexture;
filteredTexture->unref();
}
GR_DEFINE_EFFECT_TEST(GrConfigConversionEffect);
-GrEffect* GrConfigConversionEffect::TestCreate(SkRandom* random,
- GrContext* context,
- GrTexture* textures[]) {
+GrEffectRef* GrConfigConversionEffect::TestCreate(SkRandom* random,
+ GrContext* context,
+ GrTexture* textures[]) {
PMConversion pmConv = static_cast<PMConversion>(random->nextULessThan(kPMConversionCnt));
bool swapRB;
if (kNone_PMConversion == pmConv) {
} else {
swapRB = random->nextBool();
}
- return SkNEW_ARGS(GrConfigConversionEffect, (textures[GrEffectUnitTest::kSkiaPMTextureIdx],
- swapRB,
- pmConv,
- GrEffectUnitTest::TestMatrix(random)));
+ SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrConfigConversionEffect,
+ (textures[GrEffectUnitTest::kSkiaPMTextureIdx],
+ swapRB,
+ pmConv,
+ GrEffectUnitTest::TestMatrix(random))));
+ return CreateEffectPtr(effect);
}
///////////////////////////////////////////////////////////////////////////////
// We then verify that two reads produced the same values.
GrPaint paint;
- SkAutoTUnref<GrEffect> pmToUPMEffect1(SkNEW_ARGS(GrConfigConversionEffect,
- (dataTex,
- false,
- *pmToUPMRule,
- SkMatrix::I())));
- SkAutoTUnref<GrEffect> upmToPMEffect(SkNEW_ARGS(GrConfigConversionEffect,
- (readTex,
- false,
- *upmToPMRule,
- SkMatrix::I())));
- SkAutoTUnref<GrEffect> pmToUPMEffect2(SkNEW_ARGS(GrConfigConversionEffect,
- (tempTex,
- false,
- *pmToUPMRule,
- SkMatrix::I())));
+ SkAutoTUnref<GrEffect> pmToUPM1(SkNEW_ARGS(GrConfigConversionEffect, (dataTex,
+ false,
+ *pmToUPMRule,
+ SkMatrix::I())));
+ SkAutoTUnref<GrEffect> upmToPM(SkNEW_ARGS(GrConfigConversionEffect, (readTex,
+ false,
+ *upmToPMRule,
+ SkMatrix::I())));
+ SkAutoTUnref<GrEffect> pmToUPM2(SkNEW_ARGS(GrConfigConversionEffect, (tempTex,
+ false,
+ *pmToUPMRule,
+ SkMatrix::I())));
+
+ SkAutoTUnref<GrEffectRef> pmToUPMEffect1(CreateEffectPtr(pmToUPM1));
+ SkAutoTUnref<GrEffectRef> upmToPMEffect(CreateEffectPtr(upmToPM));
+ SkAutoTUnref<GrEffectRef> pmToUPMEffect2(CreateEffectPtr(pmToUPM2));
context->setRenderTarget(readTex->asRenderTarget());
paint.colorStage(0)->setEffect(pmToUPMEffect1);
// 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
// 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;
} else {
if (kRGBA_8888_GrPixelConfig != texture->config() &&
// The PM conversions assume colors are 0..255
return false;
}
- stage->setEffect(SkNEW_ARGS(GrConfigConversionEffect, (texture,
- swapRedAndBlue,
- pmConversion, matrix)))->unref();
+ SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrConfigConversionEffect, (texture,
+ swapRedAndBlue,
+ pmConversion,
+ matrix)));
+ stage->setEffect(CreateEffectPtr(effect))->unref();
return true;
}
}
#include "GrSingleTextureEffect.h"
+class GrEffectStage;
class GrGLConfigConversionEffect;
/**
GR_DEFINE_EFFECT_TEST(GrConvolutionEffect);
-GrEffect* GrConvolutionEffect::TestCreate(SkRandom* random,
- GrContext* context,
- GrTexture* textures[]) {
+GrEffectRef* GrConvolutionEffect::TestCreate(SkRandom* random,
+ GrContext* context,
+ GrTexture* textures[]) {
int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
GrEffectUnitTest::kAlphaTextureIdx;
Direction dir = random->nextBool() ? kX_Direction : kY_Direction;
kernel[i] = random->nextSScalar1();
}
- return SkNEW_ARGS(GrConvolutionEffect, (textures[texIdx], dir, radius, kernel));
+ return GrConvolutionEffect::Create(textures[texIdx], dir, radius,kernel);
}
public:
/// Convolve with an arbitrary user-specified kernel
- GrConvolutionEffect(GrTexture*, Direction,
- int halfWidth, const float* kernel);
+ static GrEffectRef* Create(GrTexture* tex, Direction dir, int halfWidth, const float* kernel) {
+ SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrConvolutionEffect, (tex,
+ dir,
+ halfWidth,
+ kernel)));
+ return CreateEffectPtr(effect);
+ }
/// Convolve with a Gaussian kernel
- GrConvolutionEffect(GrTexture*, Direction,
- int halfWidth,
- float gaussianSigma);
+ static GrEffectRef* Create(GrTexture* tex,
+ Direction dir,
+ int halfWidth,
+ float gaussianSigma) {
+ SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrConvolutionEffect, (tex,
+ dir,
+ halfWidth,
+ gaussianSigma)));
+ return CreateEffectPtr(effect);
+ }
+
virtual ~GrConvolutionEffect();
const float* kernel() const { return fKernel; }
float fKernel[kMaxKernelWidth];
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;
typedef Gr1DKernelEffect INHERITED;
///////////////////////////////////////////////////////////////////////////////
-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)
: fTextureAccess(texture)
, fMatrix(m) {
GR_DEFINE_EFFECT_TEST(GrSingleTextureEffect);
-GrEffect* GrSingleTextureEffect::TestCreate(SkRandom* random,
- GrContext* context,
- GrTexture* textures[]) {
+GrEffectRef* GrSingleTextureEffect::TestCreate(SkRandom* random,
+ GrContext* context,
+ GrTexture* textures[]) {
int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
GrEffectUnitTest::kAlphaTextureIdx;
const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random);
- return SkNEW_ARGS(GrSingleTextureEffect, (textures[texIdx], matrix));
+ return GrSingleTextureEffect::Create(textures[texIdx], matrix);
}
* output color is the texture color is modulated against the input color.
*/
class GrSingleTextureEffect : public GrEffect {
-
public:
- /** These three constructors assume an identity matrix. TODO: Remove these.*/
- GrSingleTextureEffect(GrTexture* texture); /* unfiltered, clamp mode */
- GrSingleTextureEffect(GrTexture* texture, bool bilerp); /* clamp mode */
- GrSingleTextureEffect(GrTexture* texture, const GrTextureParams&);
+ /* unfiltered, clamp mode */
+ static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix) {
+ SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSingleTextureEffect, (tex, matrix)));
+ return CreateEffectPtr(effect);
+ }
- /** These three constructors take an explicit matrix */
- GrSingleTextureEffect(GrTexture*, const SkMatrix&); /* unfiltered, clamp mode */
- GrSingleTextureEffect(GrTexture*, const SkMatrix&, bool bilerp); /* clamp mode */
- GrSingleTextureEffect(GrTexture*, const SkMatrix&, const GrTextureParams&);
+ /* clamp mode */
+ static GrEffectRef* Create(GrTexture* tex, const SkMatrix& matrix, bool bilerp) {
+ SkAutoTUnref<GrEffect> effect(SkNEW_ARGS(GrSingleTextureEffect, (tex, matrix, bilerp)));
+ 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();
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:
+
GR_DECLARE_EFFECT_TEST;
GrTextureAccess fTextureAccess;
///////////////////////////////////////////////////////////////////////////////
-GrEffect* GrTextureDomainEffect::Create(GrTexture* texture,
- const SkMatrix& matrix,
- const GrRect& domain,
- WrapMode wrapMode,
- bool bilerp) {
+GrEffectRef* GrTextureDomainEffect::Create(GrTexture* texture,
+ const SkMatrix& matrix,
+ const GrRect& domain,
+ WrapMode wrapMode,
+ bool bilerp) {
static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1};
if (kClamp_WrapMode == wrapMode && domain.contains(kFullRect)) {
- return SkNEW_ARGS(GrSingleTextureEffect, (texture, matrix, bilerp));
+ return GrSingleTextureEffect::Create(texture, matrix, bilerp);
} else {
SkRect clippedDomain;
// We don't currently handle domains that are empty or don't intersect the texture.
clippedDomain.fBottom = SkMinScalar(domain.fBottom, kFullRect.fBottom);
GrAssert(clippedDomain.fLeft <= clippedDomain.fRight);
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);
+
}
}
GR_DEFINE_EFFECT_TEST(GrTextureDomainEffect);
-GrEffect* GrTextureDomainEffect::TestCreate(SkRandom* random,
- GrContext* context,
- GrTexture* textures[]) {
+GrEffectRef* GrTextureDomainEffect::TestCreate(SkRandom* random,
+ GrContext* context,
+ GrTexture* textures[]) {
int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx :
GrEffectUnitTest::kAlphaTextureIdx;
GrRect domain;
kDecal_WrapMode,
};
- static GrEffect* Create(GrTexture*,
- const SkMatrix&,
- const SkRect& domain,
- WrapMode,
- bool bilerp = false);
+ static GrEffectRef* Create(GrTexture*,
+ const SkMatrix&,
+ const SkRect& domain,
+ WrapMode,
+ bool bilerp = false);
virtual ~GrTextureDomainEffect();
return r->nextF() > .5f;
}
-const GrEffect* create_random_effect(SkRandom* random,
- GrContext* context,
- GrTexture* dummyTextures[]) {
+const GrEffectRef* create_random_effect(SkRandom* random,
+ GrContext* context,
+ GrTexture* dummyTextures[]) {
SkRandom sk_random;
sk_random.setSeed(random->nextU());
- GrEffect* effect = GrEffectTestFactory::CreateStage(&sk_random, context, dummyTextures);
+ GrEffectRef* effect = GrEffectTestFactory::CreateStage(&sk_random, context, dummyTextures);
GrAssert(effect);
return effect;
}
}
GrTexture* dummyTextures[] = {dummyTexture1.get(), dummyTexture2.get()};
- SkAutoTUnref<const GrEffect> effect(create_random_effect(&random,
+ SkAutoTUnref<const GrEffectRef> effect(create_random_effect(&random,
getContext(),
dummyTextures));
stages[s].setEffect(effect.get());