aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/effects
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-01-16 15:16:18 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-01-16 15:16:18 +0000
commit0ac6af49975c54c2debf41e9200af416ecd2d973 (patch)
tree79ee2038a2b5c994f688f30f9770310555dcc6bf /src/gpu/effects
parent6f54724c11ab739fa0d6deff1d4b564596fe3970 (diff)
Wrap GrEffects in GrEffectPtr.
This is the first step towards automatic recycling of scratch resouces in the cache via ref-cnts. R=robertphillips@google.com Review URL: https://codereview.appspot.com/7092061 git-svn-id: http://skia.googlecode.com/svn/trunk@7222 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu/effects')
-rw-r--r--src/gpu/effects/GrConfigConversionEffect.cpp57
-rw-r--r--src/gpu/effects/GrConfigConversionEffect.h1
-rw-r--r--src/gpu/effects/GrConvolutionEffect.cpp8
-rw-r--r--src/gpu/effects/GrConvolutionEffect.h31
-rw-r--r--src/gpu/effects/GrSingleTextureEffect.cpp26
-rw-r--r--src/gpu/effects/GrSingleTextureEffect.h30
-rw-r--r--src/gpu/effects/GrTextureDomainEffect.cpp28
-rw-r--r--src/gpu/effects/GrTextureDomainEffect.h10
8 files changed, 109 insertions, 82 deletions
diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp
index d42896d210..a547c1a2da 100644
--- a/src/gpu/effects/GrConfigConversionEffect.cpp
+++ b/src/gpu/effects/GrConfigConversionEffect.cpp
@@ -124,9 +124,9 @@ bool GrConfigConversionEffect::isEqual(const GrEffect& s) const {
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) {
@@ -134,10 +134,12 @@ GrEffect* GrConfigConversionEffect::TestCreate(SkRandom* random,
} 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);
}
///////////////////////////////////////////////////////////////////////////////
@@ -204,21 +206,22 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context
// 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);
@@ -260,7 +263,7 @@ bool GrConfigConversionEffect::InstallEffect(GrTexture* texture,
// 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() &&
@@ -269,9 +272,11 @@ bool GrConfigConversionEffect::InstallEffect(GrTexture* texture,
// 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;
}
}
diff --git a/src/gpu/effects/GrConfigConversionEffect.h b/src/gpu/effects/GrConfigConversionEffect.h
index 48c776ccf4..b8dd7d0ed4 100644
--- a/src/gpu/effects/GrConfigConversionEffect.h
+++ b/src/gpu/effects/GrConfigConversionEffect.h
@@ -10,6 +10,7 @@
#include "GrSingleTextureEffect.h"
+class GrEffectStage;
class GrGLConfigConversionEffect;
/**
diff --git a/src/gpu/effects/GrConvolutionEffect.cpp b/src/gpu/effects/GrConvolutionEffect.cpp
index 047dc4165e..1f4c094814 100644
--- a/src/gpu/effects/GrConvolutionEffect.cpp
+++ b/src/gpu/effects/GrConvolutionEffect.cpp
@@ -180,9 +180,9 @@ bool GrConvolutionEffect::isEqual(const GrEffect& sBase) const {
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;
@@ -192,6 +192,6 @@ GrEffect* GrConvolutionEffect::TestCreate(SkRandom* random,
kernel[i] = random->nextSScalar1();
}
- return SkNEW_ARGS(GrConvolutionEffect, (textures[texIdx], dir, radius, kernel));
+ return GrConvolutionEffect::Create(textures[texIdx], dir, radius,kernel);
}
diff --git a/src/gpu/effects/GrConvolutionEffect.h b/src/gpu/effects/GrConvolutionEffect.h
index 3638c0cf6a..ff661b2adb 100644
--- a/src/gpu/effects/GrConvolutionEffect.h
+++ b/src/gpu/effects/GrConvolutionEffect.h
@@ -22,13 +22,26 @@ class GrConvolutionEffect : public Gr1DKernelEffect {
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; }
@@ -56,6 +69,14 @@ protected:
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;
diff --git a/src/gpu/effects/GrSingleTextureEffect.cpp b/src/gpu/effects/GrSingleTextureEffect.cpp
index 2cf83472d7..18e35e4349 100644
--- a/src/gpu/effects/GrSingleTextureEffect.cpp
+++ b/src/gpu/effects/GrSingleTextureEffect.cpp
@@ -57,24 +57,6 @@ private:
///////////////////////////////////////////////////////////////////////////////
-GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture)
- : fTextureAccess(texture) {
- fMatrix.reset();
- this->addTextureAccess(&fTextureAccess);
-}
-
-GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, bool bilerp)
- : fTextureAccess(texture, bilerp) {
- fMatrix.reset();
- this->addTextureAccess(&fTextureAccess);
-}
-
-GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, const GrTextureParams& params)
- : fTextureAccess(texture, params) {
- fMatrix.reset();
- this->addTextureAccess(&fTextureAccess);
-}
-
GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture, const SkMatrix& m)
: fTextureAccess(texture)
, fMatrix(m) {
@@ -117,11 +99,11 @@ const GrBackendEffectFactory& GrSingleTextureEffect::getFactory() const {
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);
}
diff --git a/src/gpu/effects/GrSingleTextureEffect.h b/src/gpu/effects/GrSingleTextureEffect.h
index b732913c38..fad2c21239 100644
--- a/src/gpu/effects/GrSingleTextureEffect.h
+++ b/src/gpu/effects/GrSingleTextureEffect.h
@@ -19,17 +19,23 @@ class GrTexture;
* 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();
@@ -50,7 +56,13 @@ public:
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;
diff --git a/src/gpu/effects/GrTextureDomainEffect.cpp b/src/gpu/effects/GrTextureDomainEffect.cpp
index 6884682829..74727a05c5 100644
--- a/src/gpu/effects/GrTextureDomainEffect.cpp
+++ b/src/gpu/effects/GrTextureDomainEffect.cpp
@@ -121,14 +121,14 @@ GrGLEffect::EffectKey GrGLTextureDomainEffect::GenKey(const GrEffectStage& stage
///////////////////////////////////////////////////////////////////////////////
-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.
@@ -142,8 +142,14 @@ GrEffect* GrTextureDomainEffect::Create(GrTexture* 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);
+
}
}
@@ -174,9 +180,9 @@ bool GrTextureDomainEffect::isEqual(const GrEffect& sBase) const {
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;
diff --git a/src/gpu/effects/GrTextureDomainEffect.h b/src/gpu/effects/GrTextureDomainEffect.h
index c1ce6d11a6..a5c2d70198 100644
--- a/src/gpu/effects/GrTextureDomainEffect.h
+++ b/src/gpu/effects/GrTextureDomainEffect.h
@@ -34,11 +34,11 @@ public:
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();