Revert of Make GrDrawState and GrPaint take GrEffect* instead of GrEffectRef*. (https://codereview.chromium.org/377503004/)
Reason for revert:
broke linux builders
Original issue's description:
> Make GrDrawState and GrPaint take GrEffect* instead of GrEffectRef*.
>
> Make Sk-effect virtuals produce GrEffect* rather than GrEffectRef*
>
> Make GrEffectRef a typedef for GrEffect.
>
> Committed: https://skia.googlesource.com/skia/+/2011fe9cdfa63b83489a146cea6a724cede352c8
R=robertphillips@google.com, bsalomon@google.com
TBR=bsalomon@google.com, robertphillips@google.com
NOTREECHECKS=true
NOTRY=true
Author: reed@google.com
Review URL: https://codereview.chromium.org/372053003
diff --git a/include/core/SkColorFilter.h b/include/core/SkColorFilter.h
index 25e6bbe..c26bc07 100644
--- a/include/core/SkColorFilter.h
+++ b/include/core/SkColorFilter.h
@@ -15,7 +15,7 @@
#include "SkXfermode.h"
class SkBitmap;
-class GrEffect;
+class GrEffectRef;
class GrContext;
/**
@@ -126,7 +126,7 @@
/** 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_TO_STRING_PUREVIRT()
diff --git a/include/core/SkColorShader.h b/include/core/SkColorShader.h
index ba17f6c..8603577 100644
--- a/include/core/SkColorShader.h
+++ b/include/core/SkColorShader.h
@@ -58,7 +58,7 @@
virtual bool asNewEffect(GrContext* context, const SkPaint& paint,
const SkMatrix* localMatrix, GrColor* grColor,
- GrEffect** grEffect) const SK_OVERRIDE;
+ GrEffectRef** grEffect) const SK_OVERRIDE;
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorShader)
diff --git a/include/core/SkImageFilter.h b/include/core/SkImageFilter.h
index 088719c..9cdd275 100644
--- a/include/core/SkImageFilter.h
+++ b/include/core/SkImageFilter.h
@@ -16,7 +16,7 @@
class SkColorFilter;
class SkBaseDevice;
struct SkIPoint;
-class GrEffect;
+class GrEffectRef;
class GrTexture;
/**
@@ -281,7 +281,7 @@
* will be called with (NULL, NULL, SkMatrix::I()) to query for support,
* so returning "true" indicates support for all possible matrices.
*/
- virtual bool asNewEffect(GrEffect** effect,
+ virtual bool asNewEffect(GrEffectRef** effect,
GrTexture*,
const SkMatrix& matrix,
const SkIRect& bounds) const;
diff --git a/include/core/SkMaskFilter.h b/include/core/SkMaskFilter.h
index 3992512..72f20af 100644
--- a/include/core/SkMaskFilter.h
+++ b/include/core/SkMaskFilter.h
@@ -72,7 +72,7 @@
* If effect is non-NULL, a new GrEffect instance is stored in it. The caller assumes ownership
* of the effect and must unref it.
*/
- virtual bool asNewEffect(GrEffect** effect,
+ virtual bool asNewEffect(GrEffectRef** effect,
GrTexture*,
const SkMatrix& ctm) const;
diff --git a/include/core/SkShader.h b/include/core/SkShader.h
index 2ed91f8..31f57cc 100644
--- a/include/core/SkShader.h
+++ b/include/core/SkShader.h
@@ -20,7 +20,7 @@
class SkPicture;
class SkXfermode;
class GrContext;
-class GrEffect;
+class GrEffectRef;
/** \class SkShader
*
@@ -384,7 +384,7 @@
*/
virtual bool asNewEffect(GrContext* context, const SkPaint& paint,
const SkMatrix* localMatrixOrNull, GrColor* grColor,
- GrEffect** grEffect) const;
+ GrEffectRef** grEffect) const;
#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
/**
diff --git a/include/core/SkXfermode.h b/include/core/SkXfermode.h
index 74fd9f8..c0a6572 100644
--- a/include/core/SkXfermode.h
+++ b/include/core/SkXfermode.h
@@ -13,7 +13,7 @@
#include "SkFlattenable.h"
#include "SkColor.h"
-class GrEffect;
+class GrEffectRef;
class GrTexture;
class SkString;
@@ -198,7 +198,7 @@
fragment shader. If NULL, the effect should request access to destination color
(setWillReadDstColor()), and use that in the fragment shader (builder->dstColor()).
*/
- virtual bool asNewEffect(GrEffect** effect, GrTexture* background = NULL) const;
+ virtual bool asNewEffect(GrEffectRef** effect, GrTexture* background = NULL) const;
/** Returns true if the xfermode can be expressed as coeffs (src, dst), or as an effect
(effect). This helper calls the asCoeff() and asNewEffect() virtuals. If the xfermode is
@@ -206,7 +206,7 @@
simply test the return value. effect, src, and dst must all be NULL or all non-NULL.
*/
static bool AsNewEffectOrCoeff(SkXfermode*,
- GrEffect** effect,
+ GrEffectRef** effect,
Coeff* src,
Coeff* dst,
GrTexture* background = NULL);
diff --git a/include/effects/SkColorMatrixFilter.h b/include/effects/SkColorMatrixFilter.h
index edbe07d..5cfa468 100644
--- a/include/effects/SkColorMatrixFilter.h
+++ b/include/effects/SkColorMatrixFilter.h
@@ -26,7 +26,7 @@
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 {
diff --git a/include/effects/SkLumaColorFilter.h b/include/effects/SkLumaColorFilter.h
index 06eb01a..f2cee29 100644
--- a/include/effects/SkLumaColorFilter.h
+++ b/include/effects/SkLumaColorFilter.h
@@ -28,7 +28,7 @@
virtual void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
- virtual GrEffect* asNewEffect(GrContext*) const SK_OVERRIDE;
+ virtual GrEffectRef* asNewEffect(GrContext*) const SK_OVERRIDE;
#endif
SK_TO_STRING_OVERRIDE()
diff --git a/include/effects/SkMagnifierImageFilter.h b/include/effects/SkMagnifierImageFilter.h
index b992e28..9d8a9b6 100644
--- a/include/effects/SkMagnifierImageFilter.h
+++ b/include/effects/SkMagnifierImageFilter.h
@@ -28,8 +28,7 @@
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
- virtual bool asNewEffect(GrEffect** effect, GrTexture* texture, const SkMatrix& matrix,
- const SkIRect& bounds) const SK_OVERRIDE;
+ virtual bool asNewEffect(GrEffectRef** effect, GrTexture* texture, const SkMatrix& matrix, const SkIRect& bounds) const SK_OVERRIDE;
#endif
private:
diff --git a/include/effects/SkMatrixConvolutionImageFilter.h b/include/effects/SkMatrixConvolutionImageFilter.h
index 6d4c826..606de57 100644
--- a/include/effects/SkMatrixConvolutionImageFilter.h
+++ b/include/effects/SkMatrixConvolutionImageFilter.h
@@ -86,7 +86,7 @@
#if SK_SUPPORT_GPU
- virtual bool asNewEffect(GrEffect** effect,
+ virtual bool asNewEffect(GrEffectRef** effect,
GrTexture*,
const SkMatrix& ctm,
const SkIRect& bounds) const SK_OVERRIDE;
diff --git a/include/effects/SkPerlinNoiseShader.h b/include/effects/SkPerlinNoiseShader.h
index 3355925..2d9dfdd 100644
--- a/include/effects/SkPerlinNoiseShader.h
+++ b/include/effects/SkPerlinNoiseShader.h
@@ -97,7 +97,7 @@
};
virtual bool asNewEffect(GrContext* context, const SkPaint&, const SkMatrix*, GrColor*,
- GrEffect**) const SK_OVERRIDE;
+ GrEffectRef**) const SK_OVERRIDE;
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPerlinNoiseShader)
diff --git a/include/gpu/GrBackendEffectFactory.h b/include/gpu/GrBackendEffectFactory.h
index af8d5c7..0fc981c 100644
--- a/include/gpu/GrBackendEffectFactory.h
+++ b/include/gpu/GrBackendEffectFactory.h
@@ -23,6 +23,7 @@
of GrGLEffect.
*/
+class GrEffectRef;
class GrGLEffect;
class GrGLCaps;
class GrDrawEffect;
diff --git a/include/gpu/GrEffect.h b/include/gpu/GrEffect.h
index 978ad3a..5fed532 100644
--- a/include/gpu/GrEffect.h
+++ b/include/gpu/GrEffect.h
@@ -21,17 +21,66 @@
class GrVertexEffect;
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.
+ *
+ * GrEffectRefs created by new are placed in a per-thread managed pool. The pool is destroyed when
+ * the thread ends. Therefore, all dynamically allocated GrEffectRefs must be unreffed before thread
+ * termination.
+ */
+class GrEffectRef : public SkRefCnt {
+public:
+ SK_DECLARE_INST_COUNT(GrEffectRef);
+ virtual ~GrEffectRef();
+
+ GrEffect* get() { return fEffect; }
+ const GrEffect* get() const { return fEffect; }
+
+ const GrEffect* operator-> () { return fEffect; }
+ const GrEffect* operator-> () const { return fEffect; }
+
+ void* operator new(size_t size);
+ void operator delete(void* target);
+
+ void* operator new(size_t size, void* placement) {
+ return ::operator new(size, placement);
+ }
+ void operator delete(void* target, void* placement) {
+ ::operator delete(target, placement);
+ }
+
+private:
+ friend class GrEffect; // to construct these
+
+ explicit GrEffectRef(GrEffect* effect);
+
+ 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.
- Dynamically allocated GrEffects are managed by a per-thread memory pool. The ref count of an
- effect must reach 0 before the thread terminates and the pool is destroyed. To create a static
- effect use the macro GR_CREATE_STATIC_EFFECT declared below.
+ 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.
+
+ Because almost no code should ever handle a GrEffect directly outside of a GrEffectRef, we
+ privately inherit from SkRefCnt to help prevent accidental direct ref'ing/unref'ing of effects.
+
+ Dynamically allocated GrEffects and their corresponding GrEffectRefs are managed by a per-thread
+ memory pool. The ref count of an effect must reach 0 before the thread terminates and the pool
+ is destroyed. To create a static effect use the macro GR_CREATE_STATIC_EFFECT declared below.
*/
-class GrEffect : public SkRefCnt {
+class GrEffect : private SkRefCnt {
public:
SK_DECLARE_INST_COUNT(GrEffect)
@@ -75,17 +124,8 @@
computed by the GrBackendEffectFactory:
effectA.getFactory().glEffectKey(effectA) == effectB.getFactory().glEffectKey(effectB).
*/
- bool isEqual(const GrEffect& other) const {
- if (&this->getFactory() != &other.getFactory()) {
- return false;
- }
- bool result = this->onIsEqual(other);
-#ifdef SK_DEBUG
- if (result) {
- this->assertEquality(other);
- }
-#endif
- return result;
+ bool isEqual(const GrEffectRef& other) const {
+ return this->isEqual(*other.get());
}
/** Human-meaningful string to identify this effect; may be embedded
@@ -145,6 +185,24 @@
::operator delete(target, placement);
}
+ /** These functions are used when recording effects into a deferred drawing queue. The inc call
+ keeps the effect alive outside of GrEffectRef while allowing any resources owned by the
+ effect to be returned to the cache for reuse. The dec call must balance the inc call. */
+ void incDeferredRefCounts() const {
+ this->ref();
+ int count = fTextureAccesses.count();
+ for (int t = 0; t < count; ++t) {
+ fTextureAccesses[t]->getTexture()->incDeferredRefCount();
+ }
+ }
+ void decDeferredRefCounts() const {
+ int count = fTextureAccesses.count();
+ for (int t = 0; t < count; ++t) {
+ fTextureAccesses[t]->getTexture()->decDeferredRefCount();
+ }
+ this->unref();
+ }
+
protected:
/**
* Subclasses call this from their constructor to register coordinate transformations. The
@@ -167,18 +225,32 @@
: fWillReadDstColor(false)
, fWillReadFragmentPosition(false)
, fWillUseInputColor(true)
- , fHasVertexCode(false) {}
+ , fHasVertexCode(false)
+ , fEffectRef(NULL) {}
/** This should be called by GrEffect subclass factories. See the comment on AutoEffectUnref for
an example factory function. */
- static GrEffect* CreateEffectRef(GrEffect* effect) {
- return SkRef(effect);
+ static GrEffectRef* CreateEffectRef(GrEffect* effect) {
+ if (NULL == effect->fEffectRef) {
+ effect->fEffectRef = SkNEW_ARGS(GrEffectRef, (effect));
+ } else {
+ effect->fEffectRef->ref();
+ }
+ return effect->fEffectRef;
}
- static const GrEffect* CreateEffectRef(const GrEffect* effect) {
+ static const GrEffectRef* CreateEffectRef(const GrEffect* effect) {
return CreateEffectRef(const_cast<GrEffect*>(effect));
}
+ /** Used by GR_CREATE_STATIC_EFFECT below */
+ static GrEffectRef* CreateStaticEffectRef(void* refStorage, GrEffect* effect) {
+ SkASSERT(NULL == effect->fEffectRef);
+ effect->fEffectRef = SkNEW_PLACEMENT_ARGS(refStorage, GrEffectRef, (effect));
+ return effect->fEffectRef;
+ }
+
+
/** Helper used in subclass factory functions to unref the effect after it has been wrapped in a
GrEffectRef. E.g.:
@@ -189,7 +261,14 @@
return CreateEffectRef(effect);
}
*/
- typedef SkAutoTUnref<GrEffect> AutoEffectUnref;
+ class AutoEffectUnref {
+ public:
+ AutoEffectUnref(GrEffect* effect) : fEffect(effect) { }
+ ~AutoEffectUnref() { fEffect->unref(); }
+ operator GrEffect*() { return fEffect; }
+ private:
+ GrEffect* fEffect;
+ };
/** Helper for getting the GrEffect out of a GrEffectRef and down-casting to a GrEffect subclass
*/
@@ -220,6 +299,19 @@
void setWillNotUseInputColor() { fWillUseInputColor = false; }
private:
+ bool isEqual(const GrEffect& other) const {
+ if (&this->getFactory() != &other.getFactory()) {
+ return false;
+ }
+ bool result = this->onIsEqual(other);
+#ifdef SK_DEBUG
+ if (result) {
+ this->assertEquality(other);
+ }
+#endif
+ return result;
+ }
+
SkDEBUGCODE(void assertEquality(const GrEffect& other) const;)
/** Subclass implements this to support isEqual(). It will only be called if it is known that
@@ -227,6 +319,12 @@
getFactory()).*/
virtual bool onIsEqual(const GrEffect& other) const = 0;
+ void EffectRefDestroyed() { fEffectRef = NULL; }
+
+ friend class GrEffectRef; // to call EffectRefDestroyed()
+ friend class GrEffectStage; // to rewrap GrEffect in GrEffectRef when restoring an effect-stage
+ // from deferred state, to call isEqual on naked GrEffects, and
+ // to inc/dec deferred ref counts.
friend class GrVertexEffect; // to set fHasVertexCode and build fVertexAttribTypes.
SkSTArray<4, const GrCoordTransform*, true> fCoordTransforms;
@@ -236,20 +334,32 @@
bool fWillReadFragmentPosition;
bool fWillUseInputColor;
bool fHasVertexCode;
+ GrEffectRef* fEffectRef;
typedef SkRefCnt INHERITED;
};
-typedef GrEffect GrEffectRef;
+inline GrEffectRef::GrEffectRef(GrEffect* effect) {
+ SkASSERT(NULL != effect);
+ effect->ref();
+ fEffect = effect;
+}
/**
* This creates an effect outside of the effect memory pool. The effect's destructor will be called
- * at global destruction time. NAME will be the name of the created GrEffect.
+ * at global destruction time. NAME will be the name of the created GrEffectRef.
*/
#define GR_CREATE_STATIC_EFFECT(NAME, EFFECT_CLASS, ARGS) \
-static SkAlignedSStorage<sizeof(EFFECT_CLASS)> g_##NAME##_Storage; \
-static GrEffect* NAME SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLASS, ARGS); \
-static SkAutoTDestroy<GrEffect> NAME##_ad(NAME);
+enum { \
+ k_##NAME##_EffectRefOffset = GR_CT_ALIGN_UP(sizeof(EFFECT_CLASS), 8), \
+ k_##NAME##_StorageSize = k_##NAME##_EffectRefOffset + sizeof(GrEffectRef) \
+}; \
+static SkAlignedSStorage<k_##NAME##_StorageSize> g_##NAME##_Storage; \
+static void* NAME##_RefLocation = (char*)g_##NAME##_Storage.get() + k_##NAME##_EffectRefOffset; \
+static GrEffect* NAME##_Effect SkNEW_PLACEMENT_ARGS(g_##NAME##_Storage.get(), EFFECT_CLASS, ARGS);\
+static SkAutoTDestroy<GrEffect> NAME##_ad(NAME##_Effect); \
+static GrEffectRef* NAME(GrEffect::CreateStaticEffectRef(NAME##_RefLocation, NAME##_Effect)); \
+static SkAutoTDestroy<GrEffectRef> NAME##_Ref_ad(NAME)
#endif
diff --git a/include/gpu/GrEffectStage.h b/include/gpu/GrEffectStage.h
index fb0620d..84ccbbf 100644
--- a/include/gpu/GrEffectStage.h
+++ b/include/gpu/GrEffectStage.h
@@ -20,8 +20,8 @@
class GrEffectStage {
public:
- explicit GrEffectStage(const GrEffect* effect, int attrIndex0 = -1, int attrIndex1 = -1)
- : fEffect(SkRef(effect)) {
+ explicit GrEffectStage(const GrEffectRef* effectRef, int attrIndex0 = -1, int attrIndex1 = -1)
+ : fEffectRef(SkRef(effectRef)) {
fCoordChangeMatrixSet = false;
fVertexAttribIndices[0] = attrIndex0;
fVertexAttribIndices[1] = attrIndex1;
@@ -36,14 +36,14 @@
if (other.fCoordChangeMatrixSet) {
fCoordChangeMatrix = other.fCoordChangeMatrix;
}
- fEffect.reset(SkRef(other.fEffect.get()));
+ fEffectRef.reset(SkRef(other.fEffectRef.get()));
memcpy(fVertexAttribIndices, other.fVertexAttribIndices, sizeof(fVertexAttribIndices));
return *this;
}
bool operator== (const GrEffectStage& other) const {
- SkASSERT(NULL != fEffect.get());
- SkASSERT(NULL != other.fEffect.get());
+ SkASSERT(NULL != fEffectRef.get());
+ SkASSERT(NULL != other.fEffectRef.get());
if (!this->getEffect()->isEqual(*other.getEffect())) {
return false;
@@ -81,7 +81,7 @@
private:
bool fCoordChangeMatrixSet;
SkMatrix fCoordChangeMatrix;
- SkDEBUGCODE(mutable SkAutoTUnref<const GrEffect> fEffect;)
+ SkDEBUGCODE(mutable SkAutoTUnref<const GrEffectRef> fEffectRef;)
friend class GrEffectStage;
};
@@ -97,9 +97,9 @@
if (fCoordChangeMatrixSet) {
savedCoordChange->fCoordChangeMatrix = fCoordChangeMatrix;
}
- SkASSERT(NULL == savedCoordChange->fEffect.get());
- SkDEBUGCODE(SkRef(fEffect.get());)
- SkDEBUGCODE(savedCoordChange->fEffect.reset(fEffect.get());)
+ SkASSERT(NULL == savedCoordChange->fEffectRef.get());
+ SkDEBUGCODE(SkRef(fEffectRef.get());)
+ SkDEBUGCODE(savedCoordChange->fEffectRef.reset(fEffectRef.get());)
}
/**
@@ -110,8 +110,8 @@
if (fCoordChangeMatrixSet) {
fCoordChangeMatrix = savedCoordChange.fCoordChangeMatrix;
}
- SkASSERT(savedCoordChange.fEffect.get() == fEffect);
- SkDEBUGCODE(savedCoordChange.fEffect.reset(NULL);)
+ SkASSERT(savedCoordChange.fEffectRef.get() == fEffectRef);
+ SkDEBUGCODE(savedCoordChange.fEffectRef.reset(NULL);)
}
/**
@@ -126,15 +126,15 @@
}
}
- const GrEffect* getEffect() const { return fEffect.get(); }
+ const GrEffect* getEffect() const { return fEffectRef.get()->get(); }
const int* getVertexAttribIndices() const { return fVertexAttribIndices; }
- int getVertexAttribIndexCount() const { return fEffect->numVertexAttribs(); }
+ int getVertexAttribIndexCount() const { return fEffectRef->get()->numVertexAttribs(); }
private:
bool fCoordChangeMatrixSet;
SkMatrix fCoordChangeMatrix;
- SkAutoTUnref<const GrEffect> fEffect;
+ SkAutoTUnref<const GrEffectRef> fEffectRef;
int fVertexAttribIndices[2];
};
diff --git a/include/gpu/GrEffectUnitTest.h b/include/gpu/GrEffectUnitTest.h
index ffc64f2..f71ab54 100644
--- a/include/gpu/GrEffectUnitTest.h
+++ b/include/gpu/GrEffectUnitTest.h
@@ -32,26 +32,26 @@
#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
class GrContext;
-class GrEffect;
+class GrEffectRef;
class GrTexture;
class GrEffectTestFactory : SkNoncopyable {
public:
- typedef GrEffect* (*CreateProc)(SkRandom*,
- GrContext*,
- const GrDrawTargetCaps& caps,
- GrTexture* dummyTextures[]);
+ typedef GrEffectRef* (*CreateProc)(SkRandom*,
+ GrContext*,
+ const GrDrawTargetCaps& caps,
+ GrTexture* dummyTextures[]);
GrEffectTestFactory(CreateProc createProc) {
fCreateProc = createProc;
GetFactories()->push_back(this);
}
- static GrEffect* CreateStage(SkRandom* random,
- GrContext* context,
- const GrDrawTargetCaps& caps,
- GrTexture* dummyTextures[]) {
+ static GrEffectRef* CreateStage(SkRandom* random,
+ GrContext* context,
+ const GrDrawTargetCaps& caps,
+ GrTexture* dummyTextures[]) {
uint32_t idx = random->nextRangeU(0, GetFactories()->count() - 1);
GrEffectTestFactory* factory = (*GetFactories())[idx];
return factory->fCreateProc(random, context, caps, dummyTextures);
@@ -67,10 +67,10 @@
*/
#define GR_DECLARE_EFFECT_TEST \
static GrEffectTestFactory gTestFactory; \
- static GrEffect* TestCreate(SkRandom*, \
- GrContext*, \
- const GrDrawTargetCaps&, \
- GrTexture* dummyTextures[2])
+ static GrEffectRef* TestCreate(SkRandom*, \
+ GrContext*, \
+ const GrDrawTargetCaps&, \
+ GrTexture* dummyTextures[2])
/** GrEffect subclasses should insert this macro in their implementation file. They must then
* also implement this static function:
@@ -91,10 +91,10 @@
// The unit test relies on static initializers. Just declare the TestCreate function so that
// its definitions will compile.
#define GR_DECLARE_EFFECT_TEST \
- static GrEffect* TestCreate(SkRandom*, \
- GrContext*, \
- const GrDrawTargetCaps&, \
- GrTexture* dummyTextures[2])
+ static GrEffectRef* TestCreate(SkRandom*, \
+ GrContext*, \
+ const GrDrawTargetCaps&, \
+ GrTexture* dummyTextures[2])
#define GR_DEFINE_EFFECT_TEST(X)
#endif // !SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
diff --git a/include/gpu/GrPaint.h b/include/gpu/GrPaint.h
index 20dec35..db9b8cc 100644
--- a/include/gpu/GrPaint.h
+++ b/include/gpu/GrPaint.h
@@ -87,9 +87,9 @@
/**
* Appends an additional color effect to the color computation.
*/
- const GrEffect* addColorEffect(const GrEffect* effect, int attr0 = -1, int attr1 = -1) {
+ const GrEffectRef* addColorEffect(const GrEffectRef* effect, int attr0 = -1, int attr1 = -1) {
SkASSERT(NULL != effect);
- if (!effect->willUseInputColor()) {
+ if (!(*effect)->willUseInputColor()) {
fColorStages.reset();
}
SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, attr1));
@@ -99,9 +99,9 @@
/**
* Appends an additional coverage effect to the coverage computation.
*/
- const GrEffect* addCoverageEffect(const GrEffect* effect, int attr0 = -1, int attr1 = -1) {
+ const GrEffectRef* addCoverageEffect(const GrEffectRef* effect, int attr0 = -1, int attr1 = -1) {
SkASSERT(NULL != effect);
- if (!effect->willUseInputColor()) {
+ if (!(*effect)->willUseInputColor()) {
fCoverageStages.reset();
}
SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0, attr1));
diff --git a/src/core/SkBitmapProcShader.cpp b/src/core/SkBitmapProcShader.cpp
index 37ba540..8e03a80 100644
--- a/src/core/SkBitmapProcShader.cpp
+++ b/src/core/SkBitmapProcShader.cpp
@@ -471,7 +471,7 @@
bool SkBitmapProcShader::asNewEffect(GrContext* context, const SkPaint& paint,
const SkMatrix* localMatrix, GrColor* grColor,
- GrEffect** grEffect) const {
+ GrEffectRef** grEffect) const {
SkDEBUGFAIL("Should not call in GPU-less build");
return false;
}
diff --git a/src/core/SkBitmapProcShader.h b/src/core/SkBitmapProcShader.h
index 550d1d2..08e8397 100644
--- a/src/core/SkBitmapProcShader.h
+++ b/src/core/SkBitmapProcShader.h
@@ -31,7 +31,7 @@
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBitmapProcShader)
- bool asNewEffect(GrContext*, const SkPaint&, const SkMatrix*, GrColor*, GrEffect**)
+ bool asNewEffect(GrContext*, const SkPaint&, const SkMatrix*, GrColor*, GrEffectRef**)
const SK_OVERRIDE;
class BitmapProcShaderContext : public SkShader::Context {
diff --git a/src/core/SkColorFilter.cpp b/src/core/SkColorFilter.cpp
index a686f4c..8cf9fc0 100644
--- a/src/core/SkColorFilter.cpp
+++ b/src/core/SkColorFilter.cpp
@@ -40,6 +40,6 @@
return SkUnPreMultiply::PMColorToColor(dst);
}
-GrEffect* SkColorFilter::asNewEffect(GrContext*) const {
+GrEffectRef* SkColorFilter::asNewEffect(GrContext*) const {
return NULL;
}
diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp
index 5a5d5bd..4c4b56b 100644
--- a/src/core/SkImageFilter.cpp
+++ b/src/core/SkImageFilter.cpp
@@ -204,8 +204,9 @@
matrix.postTranslate(SkIntToScalar(-bounds.left()), SkIntToScalar(-bounds.top()));
this->asNewEffect(&effect, srcTexture, matrix, bounds);
SkASSERT(effect);
+ SkAutoUnref effectRef(effect);
GrPaint paint;
- paint.addColorEffect(effect)->unref();
+ paint.addColorEffect(effect);
context->drawRectToRect(paint, dstRect, srcRect);
SkAutoTUnref<GrTexture> resultTex(dst.detach());
@@ -298,7 +299,7 @@
return true;
}
-bool SkImageFilter::asNewEffect(GrEffect**, GrTexture*, const SkMatrix&, const SkIRect&) const {
+bool SkImageFilter::asNewEffect(GrEffectRef**, GrTexture*, const SkMatrix&, const SkIRect&) const {
return false;
}
diff --git a/src/core/SkLocalMatrixShader.h b/src/core/SkLocalMatrixShader.h
index b56cd47..1143f06 100644
--- a/src/core/SkLocalMatrixShader.h
+++ b/src/core/SkLocalMatrixShader.h
@@ -35,7 +35,7 @@
#if SK_SUPPORT_GPU
virtual bool asNewEffect(GrContext* context, const SkPaint& paint, const SkMatrix* localMatrix,
- GrColor* grColor, GrEffect** grEffect) const SK_OVERRIDE {
+ GrColor* grColor, GrEffectRef** grEffect) const SK_OVERRIDE {
SkMatrix tmp = fProxyLocalMatrix;
if (localMatrix) {
tmp.preConcat(*localMatrix);
@@ -46,7 +46,7 @@
#else
virtual bool asNewEffect(GrContext* context, const SkPaint& paint, const SkMatrix* localMatrix,
- GrColor* grColor, GrEffect** grEffect) const SK_OVERRIDE {
+ GrColor* grColor, GrEffectRef** grEffect) const SK_OVERRIDE {
SkDEBUGFAIL("Should not call in GPU-less build");
return false;
}
diff --git a/src/core/SkMaskFilter.cpp b/src/core/SkMaskFilter.cpp
index a2adc7c..2ab2843 100644
--- a/src/core/SkMaskFilter.cpp
+++ b/src/core/SkMaskFilter.cpp
@@ -298,7 +298,7 @@
}
#if SK_SUPPORT_GPU
-bool SkMaskFilter::asNewEffect(GrEffect** effect, GrTexture*, const SkMatrix&) const {
+bool SkMaskFilter::asNewEffect(GrEffectRef** effect, GrTexture*, const SkMatrix&) const {
return false;
}
diff --git a/src/core/SkPictureShader.cpp b/src/core/SkPictureShader.cpp
index e154131..2de8d4d 100644
--- a/src/core/SkPictureShader.cpp
+++ b/src/core/SkPictureShader.cpp
@@ -200,7 +200,7 @@
#else
bool SkPictureShader::asNewEffect(GrContext* context, const SkPaint& paint,
const SkMatrix* localMatrix, GrColor* grColor,
- GrEffect** grEffect) const {
+ GrEffectRef** grEffect) const {
SkDEBUGFAIL("Should not call in GPU-less build");
return false;
}
diff --git a/src/core/SkPictureShader.h b/src/core/SkPictureShader.h
index 4995d26..294ffcd 100644
--- a/src/core/SkPictureShader.h
+++ b/src/core/SkPictureShader.h
@@ -29,7 +29,7 @@
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureShader)
- bool asNewEffect(GrContext*, const SkPaint&, const SkMatrix*, GrColor*, GrEffect**)
+ bool asNewEffect(GrContext*, const SkPaint&, const SkMatrix*, GrColor*, GrEffectRef**)
const SK_OVERRIDE;
protected:
diff --git a/src/core/SkShader.cpp b/src/core/SkShader.cpp
index 71781ee..18fb0d2 100644
--- a/src/core/SkShader.cpp
+++ b/src/core/SkShader.cpp
@@ -210,7 +210,7 @@
bool SkShader::asNewEffect(GrContext* context, const SkPaint& paint,
const SkMatrix* localMatrixOrNull, GrColor* grColor,
- GrEffect** grEffect) const {
+ GrEffectRef** grEffect) const {
return false;
}
@@ -361,7 +361,7 @@
bool SkColorShader::asNewEffect(GrContext* context, const SkPaint& paint,
const SkMatrix* localMatrix, GrColor* grColor,
- GrEffect** grEffect) const {
+ GrEffectRef** grEffect) const {
SkDEBUGFAIL("Should not call in GPU-less build");
return false;
}
diff --git a/src/core/SkXfermode.cpp b/src/core/SkXfermode.cpp
index b3e2ed1..d62602e 100644
--- a/src/core/SkXfermode.cpp
+++ b/src/core/SkXfermode.cpp
@@ -676,12 +676,12 @@
return false;
}
-bool SkXfermode::asNewEffect(GrEffect** effect, GrTexture* background) const {
+bool SkXfermode::asNewEffect(GrEffectRef** effect, GrTexture* background) const {
return false;
}
bool SkXfermode::AsNewEffectOrCoeff(SkXfermode* xfermode,
- GrEffect** effect,
+ GrEffectRef** effect,
Coeff* src,
Coeff* dst,
GrTexture* background) {
diff --git a/src/core/SkXfermode_proccoeff.h b/src/core/SkXfermode_proccoeff.h
index b777f62..7edf665 100644
--- a/src/core/SkXfermode_proccoeff.h
+++ b/src/core/SkXfermode_proccoeff.h
@@ -31,7 +31,7 @@
virtual bool asCoeff(Coeff* sc, Coeff* dc) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
- virtual bool asNewEffect(GrEffect** effect,
+ virtual bool asNewEffect(GrEffectRef** effect,
GrTexture* background) const SK_OVERRIDE;
#endif
diff --git a/src/effects/SkAlphaThresholdFilter.cpp b/src/effects/SkAlphaThresholdFilter.cpp
index 0bc906d..6fcd2b4 100644
--- a/src/effects/SkAlphaThresholdFilter.cpp
+++ b/src/effects/SkAlphaThresholdFilter.cpp
@@ -24,7 +24,7 @@
virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&,
SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
#if SK_SUPPORT_GPU
- virtual bool asNewEffect(GrEffect** effect, GrTexture* texture,
+ virtual bool asNewEffect(GrEffectRef** effect, GrTexture* texture,
const SkMatrix& matrix, const SkIRect& bounds) const SK_OVERRIDE;
#endif
@@ -248,7 +248,7 @@
}
#if SK_SUPPORT_GPU
-bool SkAlphaThresholdFilterImpl::asNewEffect(GrEffect** effect, GrTexture* texture,
+bool SkAlphaThresholdFilterImpl::asNewEffect(GrEffectRef** effect, GrTexture* texture,
const SkMatrix& in_matrix, const SkIRect&) const {
if (effect) {
GrContext* context = texture->getContext();
diff --git a/src/effects/SkColorFilters.cpp b/src/effects/SkColorFilters.cpp
index bee3a50..81d70a7 100644
--- a/src/effects/SkColorFilters.cpp
+++ b/src/effects/SkColorFilters.cpp
@@ -87,7 +87,7 @@
#endif
#if SK_SUPPORT_GPU
- virtual GrEffect* asNewEffect(GrContext*) const SK_OVERRIDE;
+ virtual GrEffectRef* asNewEffect(GrContext*) const SK_OVERRIDE;
#endif
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkModeColorFilter)
@@ -409,7 +409,7 @@
return ModeColorFilterEffect::Create(color, mode);
}
-GrEffect* SkModeColorFilter::asNewEffect(GrContext*) const {
+GrEffectRef* SkModeColorFilter::asNewEffect(GrContext*) const {
if (SkXfermode::kDst_Mode != fMode) {
return ModeColorFilterEffect::Create(SkColor2GrColor(fColor), fMode);
}
diff --git a/src/effects/SkLumaColorFilter.cpp b/src/effects/SkLumaColorFilter.cpp
index 4c90f3d..ae8b905 100644
--- a/src/effects/SkLumaColorFilter.cpp
+++ b/src/effects/SkLumaColorFilter.cpp
@@ -121,7 +121,7 @@
}
};
-GrEffect* SkLumaColorFilter::asNewEffect(GrContext*) const {
+GrEffectRef* SkLumaColorFilter::asNewEffect(GrContext*) const {
return LumaColorFilterEffect::Create();
}
#endif
diff --git a/src/effects/SkPerlinNoiseShader.cpp b/src/effects/SkPerlinNoiseShader.cpp
index 502cc07..7f0127e 100644
--- a/src/effects/SkPerlinNoiseShader.cpp
+++ b/src/effects/SkPerlinNoiseShader.cpp
@@ -946,7 +946,7 @@
bool SkPerlinNoiseShader::asNewEffect(GrContext* context, const SkPaint& paint,
const SkMatrix* externalLocalMatrix, GrColor* grColor,
- GrEffect** grEffect) const {
+ GrEffectRef** grEffect) const {
SkASSERT(NULL != context);
*grColor = SkColor2GrColorJustAlpha(paint.getColor());
@@ -1011,7 +1011,7 @@
bool SkPerlinNoiseShader::asNewEffect(GrContext* context, const SkPaint& paint,
const SkMatrix* externalLocalMatrix, GrColor* grColor,
- GrEffect** grEffect) const {
+ GrEffectRef** grEffect) const {
SkDEBUGFAIL("Should not call in GPU-less build");
return false;
}
diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp
index 771d2fa..6a9ab10 100644
--- a/src/effects/SkTableColorFilter.cpp
+++ b/src/effects/SkTableColorFilter.cpp
@@ -43,7 +43,7 @@
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,
diff --git a/src/effects/gradients/SkLinearGradient.cpp b/src/effects/gradients/SkLinearGradient.cpp
index 768623a..72b9d47 100644
--- a/src/effects/gradients/SkLinearGradient.cpp
+++ b/src/effects/gradients/SkLinearGradient.cpp
@@ -579,7 +579,7 @@
bool SkLinearGradient::asNewEffect(GrContext* context, const SkPaint& paint,
const SkMatrix* localMatrix, GrColor* grColor,
- GrEffect** grEffect) const {
+ GrEffectRef** grEffect) const {
SkDEBUGFAIL("Should not call in GPU-less build");
return false;
}
diff --git a/src/effects/gradients/SkLinearGradient.h b/src/effects/gradients/SkLinearGradient.h
index bb64188..f412a68 100644
--- a/src/effects/gradients/SkLinearGradient.h
+++ b/src/effects/gradients/SkLinearGradient.h
@@ -31,7 +31,7 @@
virtual BitmapType asABitmap(SkBitmap*, SkMatrix*, TileMode*) const SK_OVERRIDE;
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
virtual bool asNewEffect(GrContext* context, const SkPaint& paint, const SkMatrix* localMatrix,
- GrColor* grColor, GrEffect** grEffect) const SK_OVERRIDE;
+ GrColor* grColor, GrEffectRef** grEffect) const SK_OVERRIDE;
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLinearGradient)
diff --git a/src/effects/gradients/SkRadialGradient.cpp b/src/effects/gradients/SkRadialGradient.cpp
index 38e6f33..f0cb161 100644
--- a/src/effects/gradients/SkRadialGradient.cpp
+++ b/src/effects/gradients/SkRadialGradient.cpp
@@ -591,7 +591,7 @@
bool SkRadialGradient::asNewEffect(GrContext* context, const SkPaint& paint,
const SkMatrix* localMatrix, GrColor* grColor,
- GrEffect** grEffect) const {
+ GrEffectRef** grEffect) const {
SkDEBUGFAIL("Should not call in GPU-less build");
return false;
}
diff --git a/src/effects/gradients/SkRadialGradient.h b/src/effects/gradients/SkRadialGradient.h
index ac79a57..197c967 100644
--- a/src/effects/gradients/SkRadialGradient.h
+++ b/src/effects/gradients/SkRadialGradient.h
@@ -33,7 +33,7 @@
SkMatrix* matrix,
TileMode* xy) const SK_OVERRIDE;
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
- virtual bool asNewEffect(GrContext*, const SkPaint&, const SkMatrix*, GrColor*, GrEffect**) const SK_OVERRIDE;
+ virtual bool asNewEffect(GrContext*, const SkPaint&, const SkMatrix*, GrColor*, GrEffectRef**) const SK_OVERRIDE;
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkRadialGradient)
diff --git a/src/effects/gradients/SkSweepGradient.cpp b/src/effects/gradients/SkSweepGradient.cpp
index 3b54ac8..154e3a2 100644
--- a/src/effects/gradients/SkSweepGradient.cpp
+++ b/src/effects/gradients/SkSweepGradient.cpp
@@ -310,7 +310,7 @@
bool SkSweepGradient::asNewEffect(GrContext* context, const SkPaint& paint,
const SkMatrix* localMatrix, GrColor* grColor,
- GrEffect** grEffect) const {
+ GrEffectRef** grEffect) const {
SkDEBUGFAIL("Should not call in GPU-less build");
return false;
}
diff --git a/src/effects/gradients/SkSweepGradient.h b/src/effects/gradients/SkSweepGradient.h
index 7404ac7..0b12e71 100644
--- a/src/effects/gradients/SkSweepGradient.h
+++ b/src/effects/gradients/SkSweepGradient.h
@@ -35,7 +35,7 @@
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
- virtual bool asNewEffect(GrContext*, const SkPaint&, const SkMatrix*, GrColor*, GrEffect**)
+ virtual bool asNewEffect(GrContext*, const SkPaint&, const SkMatrix*, GrColor*, GrEffectRef**)
const SK_OVERRIDE;
SK_TO_STRING_OVERRIDE()
diff --git a/src/effects/gradients/SkTwoPointConicalGradient.cpp b/src/effects/gradients/SkTwoPointConicalGradient.cpp
index 6678000..4421b90 100644
--- a/src/effects/gradients/SkTwoPointConicalGradient.cpp
+++ b/src/effects/gradients/SkTwoPointConicalGradient.cpp
@@ -396,7 +396,7 @@
bool SkTwoPointConicalGradient::asNewEffect(GrContext* context, const SkPaint& paint,
const SkMatrix* localMatrix, GrColor* grColor,
- GrEffect** grEffect) const {
+ GrEffectRef** grEffect) const {
SkDEBUGFAIL("Should not call in GPU-less build");
return false;
}
diff --git a/src/effects/gradients/SkTwoPointConicalGradient.h b/src/effects/gradients/SkTwoPointConicalGradient.h
index bff377e..f345d08 100644
--- a/src/effects/gradients/SkTwoPointConicalGradient.h
+++ b/src/effects/gradients/SkTwoPointConicalGradient.h
@@ -66,7 +66,7 @@
TileMode* xy) const;
virtual SkShader::GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
virtual bool asNewEffect(GrContext*, const SkPaint&, const SkMatrix*, GrColor* grColor,
- GrEffect**) const SK_OVERRIDE;
+ GrEffectRef**) const SK_OVERRIDE;
virtual bool isOpaque() const SK_OVERRIDE;
SkScalar getCenterX1() const { return SkPoint::Distance(fCenter1, fCenter2); }
diff --git a/src/effects/gradients/SkTwoPointConicalGradient_gpu.h b/src/effects/gradients/SkTwoPointConicalGradient_gpu.h
index 4471ffc..2b0f061 100644
--- a/src/effects/gradients/SkTwoPointConicalGradient_gpu.h
+++ b/src/effects/gradients/SkTwoPointConicalGradient_gpu.h
@@ -10,7 +10,7 @@
#include "SkGradientShaderPriv.h"
-class GrEffect;
+class GrEffectRef;
class SkTwoPointConicalGradient;
namespace Gr2PtConicalGradientEffect {
@@ -18,8 +18,8 @@
* Creates an effect that produces a two point conical gradient based on the
* shader passed in.
*/
- GrEffect* Create(GrContext* ctx, const SkTwoPointConicalGradient& shader,
- SkShader::TileMode tm, const SkMatrix* localMatrix);
+ GrEffectRef* Create(GrContext* ctx, const SkTwoPointConicalGradient& shader,
+ SkShader::TileMode tm, const SkMatrix* localMatrix);
};
#endif
diff --git a/src/effects/gradients/SkTwoPointRadialGradient.cpp b/src/effects/gradients/SkTwoPointRadialGradient.cpp
index 3507c89..e3d8996 100644
--- a/src/effects/gradients/SkTwoPointRadialGradient.cpp
+++ b/src/effects/gradients/SkTwoPointRadialGradient.cpp
@@ -712,7 +712,7 @@
bool SkTwoPointRadialGradient::asNewEffect(GrContext* context, const SkPaint& paint,
const SkMatrix* localMatrix, GrColor* grColor,
- GrEffect** grEffect) const {
+ GrEffectRef** grEffect) const {
SkDEBUGFAIL("Should not call in GPU-less build");
return false;
}
diff --git a/src/effects/gradients/SkTwoPointRadialGradient.h b/src/effects/gradients/SkTwoPointRadialGradient.h
index dc3a155..8916754 100644
--- a/src/effects/gradients/SkTwoPointRadialGradient.h
+++ b/src/effects/gradients/SkTwoPointRadialGradient.h
@@ -22,7 +22,7 @@
TileMode* xy) const SK_OVERRIDE;
virtual GradientType asAGradient(GradientInfo* info) const SK_OVERRIDE;
virtual bool asNewEffect(GrContext* context, const SkPaint&, const SkMatrix*, GrColor*,
- GrEffect**) const SK_OVERRIDE;
+ GrEffectRef**) const SK_OVERRIDE;
virtual size_t contextSize() const SK_OVERRIDE;
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index de14763..d2c60ea 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -340,13 +340,13 @@
/// the color / coverage distinction.
////
- const GrEffect* addColorEffect(const GrEffect* effect, int attr0 = -1, int attr1 = -1) {
+ const GrEffectRef* addColorEffect(const GrEffectRef* effect, int attr0 = -1, int attr1 = -1) {
SkASSERT(NULL != effect);
SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, attr1));
return effect;
}
- const GrEffect* addCoverageEffect(const GrEffect* effect, int attr0 = -1, int attr1 = -1) {
+ const GrEffectRef* addCoverageEffect(const GrEffectRef* effect, int attr0 = -1, int attr1 = -1) {
SkASSERT(NULL != effect);
SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0, attr1));
return effect;
@@ -356,23 +356,27 @@
* Creates a GrSimpleTextureEffect that uses local coords as texture coordinates.
*/
void addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) {
- this->addColorEffect(GrSimpleTextureEffect::Create(texture, matrix))->unref();
+ GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix);
+ this->addColorEffect(effect)->unref();
}
void addCoverageTextureEffect(GrTexture* texture, const SkMatrix& matrix) {
- this->addCoverageEffect(GrSimpleTextureEffect::Create(texture, matrix))->unref();
+ GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix);
+ this->addCoverageEffect(effect)->unref();
}
void addColorTextureEffect(GrTexture* texture,
const SkMatrix& matrix,
const GrTextureParams& params) {
- this->addColorEffect(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
+ GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, params);
+ this->addColorEffect(effect)->unref();
}
void addCoverageTextureEffect(GrTexture* texture,
const SkMatrix& matrix,
const GrTextureParams& params) {
- this->addCoverageEffect(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
+ GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, params);
+ this->addCoverageEffect(effect)->unref();
}
/**
diff --git a/src/gpu/GrEffect.cpp b/src/gpu/GrEffect.cpp
index f952483..986e80a 100644
--- a/src/gpu/GrEffect.cpp
+++ b/src/gpu/GrEffect.cpp
@@ -59,7 +59,25 @@
///////////////////////////////////////////////////////////////////////////////
-GrEffect::~GrEffect() {}
+GrEffectRef::~GrEffectRef() {
+ SkASSERT(this->unique());
+ fEffect->EffectRefDestroyed();
+ 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() {
+ SkASSERT(NULL == fEffectRef);
+}
const char* GrEffect::name() const {
return this->getFactory().name();
diff --git a/src/gpu/GrPaint.cpp b/src/gpu/GrPaint.cpp
index 328484b..ddce0ef 100644
--- a/src/gpu/GrPaint.cpp
+++ b/src/gpu/GrPaint.cpp
@@ -12,23 +12,27 @@
#include "effects/GrSimpleTextureEffect.h"
void GrPaint::addColorTextureEffect(GrTexture* texture, const SkMatrix& matrix) {
- this->addColorEffect(GrSimpleTextureEffect::Create(texture, matrix))->unref();
+ GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix);
+ this->addColorEffect(effect)->unref();
}
void GrPaint::addCoverageTextureEffect(GrTexture* texture, const SkMatrix& matrix) {
- this->addCoverageEffect(GrSimpleTextureEffect::Create(texture, matrix))->unref();
+ GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix);
+ this->addCoverageEffect(effect)->unref();
}
void GrPaint::addColorTextureEffect(GrTexture* texture,
const SkMatrix& matrix,
const GrTextureParams& params) {
- this->addColorEffect(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
+ GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, params);
+ this->addColorEffect(effect)->unref();
}
void GrPaint::addCoverageTextureEffect(GrTexture* texture,
const SkMatrix& matrix,
const GrTextureParams& params) {
- this->addCoverageEffect(GrSimpleTextureEffect::Create(texture, matrix, params))->unref();
+ GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, params);
+ this->addCoverageEffect(effect)->unref();
}
bool GrPaint::isOpaque() const {
diff --git a/src/gpu/effects/GrDashingEffect.h b/src/gpu/effects/GrDashingEffect.h
index 1a51e89..ced9671 100644
--- a/src/gpu/effects/GrDashingEffect.h
+++ b/src/gpu/effects/GrDashingEffect.h
@@ -35,8 +35,8 @@
* Bounding geometry is rendered and the effect computes coverage based on the fragment's
* position relative to the dashed line.
*/
- GrEffect* Create(GrEffectEdgeType edgeType, const SkPathEffect::DashInfo& info,
- SkScalar strokeWidth, DashCap cap);
+ GrEffectRef* Create(GrEffectEdgeType edgeType, const SkPathEffect::DashInfo& info,
+ SkScalar strokeWidth, DashCap cap);
}
#endif
diff --git a/src/gpu/effects/GrDitherEffect.h b/src/gpu/effects/GrDitherEffect.h
index 88e0a27..63036c0 100644
--- a/src/gpu/effects/GrDitherEffect.h
+++ b/src/gpu/effects/GrDitherEffect.h
@@ -11,13 +11,13 @@
#include "GrTypes.h"
#include "GrTypesPriv.h"
-class GrEffect;
+class GrEffectRef;
namespace GrDitherEffect {
/**
* Creates an effect that dithers the resulting color to an RGBA8 framebuffer
*/
- GrEffect* Create();
+ GrEffectRef* Create();
};
#endif
diff --git a/src/gpu/effects/GrOvalEffect.h b/src/gpu/effects/GrOvalEffect.h
index 37574ec..796ee5b 100644
--- a/src/gpu/effects/GrOvalEffect.h
+++ b/src/gpu/effects/GrOvalEffect.h
@@ -11,14 +11,14 @@
#include "GrTypes.h"
#include "GrTypesPriv.h"
-class GrEffect;
+class GrEffectRef;
struct SkRect;
namespace GrOvalEffect {
/**
* Creates an effect that performs clipping against an oval.
*/
- GrEffect* Create(GrEffectEdgeType, const SkRect&);
+ GrEffectRef* Create(GrEffectEdgeType, const SkRect&);
};
#endif
diff --git a/src/gpu/effects/GrRRectEffect.h b/src/gpu/effects/GrRRectEffect.h
index bcf4884..45ac5f4 100644
--- a/src/gpu/effects/GrRRectEffect.h
+++ b/src/gpu/effects/GrRRectEffect.h
@@ -11,7 +11,7 @@
#include "GrTypes.h"
#include "GrTypesPriv.h"
-class GrEffect;
+class GrEffectRef;
class SkRRect;
namespace GrRRectEffect {
@@ -19,7 +19,7 @@
* Creates an effect that performs anti-aliased clipping against a SkRRect. It doesn't support
* all varieties of SkRRect so the caller must check for a NULL return.
*/
- GrEffect* Create(GrEffectEdgeType, const SkRRect&);
+ GrEffectRef* Create(GrEffectEdgeType, const SkRRect&);
};
#endif
diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp
index 8ead5b8..64c8559 100644
--- a/tests/GLProgramsTest.cpp
+++ b/tests/GLProgramsTest.cpp
@@ -172,7 +172,7 @@
*this->caps(),
dummyTextures));
SkASSERT(effect);
- int numAttribs = effect->numVertexAttribs();
+ int numAttribs = (*effect)->numVertexAttribs();
// If adding this effect would exceed the max attrib count then generate a
// new random effect.
@@ -183,15 +183,15 @@
// If adding this effect would exceed the max texture coord set count then generate a
// new random effect.
- if (useFixedFunctionTexturing && !effect->hasVertexCode()) {
- int numTransforms = effect->numTransforms();
+ if (useFixedFunctionTexturing && !(*effect)->hasVertexCode()) {
+ int numTransforms = (*effect)->numTransforms();
if (currTextureCoordSet + numTransforms > this->glCaps().maxFixedFunctionTextureCoords()) {
continue;
}
currTextureCoordSet += numTransforms;
}
- useFixedFunctionTexturing = useFixedFunctionTexturing && !effect->hasVertexCode();
+ useFixedFunctionTexturing = useFixedFunctionTexturing && !(*effect)->hasVertexCode();
for (int i = 0; i < numAttribs; ++i) {
attribIndices[i] = currAttribIndex++;
diff --git a/tests/GpuColorFilterTest.cpp b/tests/GpuColorFilterTest.cpp
index cdb5ef3..9ba9431 100644
--- a/tests/GpuColorFilterTest.cpp
+++ b/tests/GpuColorFilterTest.cpp
@@ -101,7 +101,7 @@
SkAutoTUnref<GrEffectRef> grEffect(cf->asNewEffect(grContext));
GrColor color = test.inputColor;
uint32_t components = test.inputComponents;
- grEffect->getConstantColorComponents(&color, &components);
+ grEffect->get()->getConstantColorComponents(&color, &components);
REPORTER_ASSERT(reporter, filterColor(color, components) == test.outputColor);
REPORTER_ASSERT(reporter, test.outputComponents == components);