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
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 9d80ebc..a8ce055 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -200,9 +200,10 @@
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);
}
@@ -1859,8 +1860,9 @@
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;
@@ -1917,8 +1919,9 @@
// 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);
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index 1208b77..993076b 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -195,13 +195,9 @@
/**
* 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,
@@ -209,11 +205,10 @@
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()) {
diff --git a/src/gpu/GrEffect.cpp b/src/gpu/GrEffect.cpp
index 534489f..6db44f4 100644
--- a/src/gpu/GrEffect.cpp
+++ b/src/gpu/GrEffect.cpp
@@ -58,7 +58,28 @@
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 {
@@ -81,7 +102,7 @@
fTextureAccesses.push_back(access);
}
-void * GrEffect::operator new(size_t size) {
+void* GrEffect::operator new(size_t size) {
return GrEffect_Globals::GetTLS()->allocate(size);
}
diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp
index 32a945b..0a4fe6a 100644
--- a/src/gpu/GrSWMaskHelper.cpp
+++ b/src/gpu/GrSWMaskHelper.cpp
@@ -198,7 +198,7 @@
};
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(),
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index a2c388e..f205569 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -443,7 +443,7 @@
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;
@@ -512,7 +512,7 @@
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 {
@@ -544,7 +544,7 @@
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;
@@ -796,7 +796,8 @@
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);
@@ -827,7 +828,8 @@
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;
}
@@ -883,7 +885,7 @@
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),
@@ -1313,7 +1315,7 @@
}
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;
@@ -1338,7 +1340,7 @@
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);
@@ -1350,7 +1352,7 @@
GrTexture* srcTexture,
GrTexture* dstTexture,
const GrRect& rect,
- GrEffect* effect) {
+ GrEffectRef* effect) {
SkASSERT(srcTexture && srcTexture->getContext() == context);
GrContext::AutoMatrix am;
am.setIdentity(context);
@@ -1375,7 +1377,7 @@
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
@@ -1415,16 +1417,16 @@
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();
}
@@ -1497,8 +1499,8 @@
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();
}
diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp
index d42896d..a547c1a 100644
--- a/src/gpu/effects/GrConfigConversionEffect.cpp
+++ b/src/gpu/effects/GrConfigConversionEffect.cpp
@@ -124,9 +124,9 @@
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 @@
} 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 @@
// 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 @@
// 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 @@
// 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 48c776c..b8dd7d0 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 047dc41..1f4c094 100644
--- a/src/gpu/effects/GrConvolutionEffect.cpp
+++ b/src/gpu/effects/GrConvolutionEffect.cpp
@@ -180,9 +180,9 @@
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 @@
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 3638c0c..ff661b2 100644
--- a/src/gpu/effects/GrConvolutionEffect.h
+++ b/src/gpu/effects/GrConvolutionEffect.h
@@ -22,13 +22,26 @@
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 @@
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 2cf8347..18e35e4 100644
--- a/src/gpu/effects/GrSingleTextureEffect.cpp
+++ b/src/gpu/effects/GrSingleTextureEffect.cpp
@@ -57,24 +57,6 @@
///////////////////////////////////////////////////////////////////////////////
-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 @@
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 b732913..fad2c21 100644
--- a/src/gpu/effects/GrSingleTextureEffect.h
+++ b/src/gpu/effects/GrSingleTextureEffect.h
@@ -19,17 +19,23 @@
* 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 @@
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 6884682..74727a0 100644
--- a/src/gpu/effects/GrTextureDomainEffect.cpp
+++ b/src/gpu/effects/GrTextureDomainEffect.cpp
@@ -121,14 +121,14 @@
///////////////////////////////////////////////////////////////////////////////
-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 @@
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 @@
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 c1ce6d1..a5c2d70 100644
--- a/src/gpu/effects/GrTextureDomainEffect.h
+++ b/src/gpu/effects/GrTextureDomainEffect.h
@@ -34,11 +34,11 @@
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();