aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
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
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')
-rw-r--r--src/gpu/GrContext.cpp17
-rw-r--r--src/gpu/GrDrawState.h9
-rw-r--r--src/gpu/GrEffect.cpp23
-rw-r--r--src/gpu/GrSWMaskHelper.cpp2
-rw-r--r--src/gpu/SkGpuDevice.cpp34
-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
13 files changed, 162 insertions, 114 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 9d80ebc548..a8ce05510a 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -200,9 +200,10 @@ void convolve_gaussian(GrDrawTarget* target,
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 @@ GrTexture* GrContext::gaussianBlur(GrTexture* srcTexture,
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 @@ GrTexture* GrContext::gaussianBlur(GrTexture* srcTexture,
// 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 1208b776ed..993076bcb3 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -195,13 +195,9 @@ public:
/**
* 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 @@ public:
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 534489fd4e..6db44f4c52 100644
--- a/src/gpu/GrEffect.cpp
+++ b/src/gpu/GrEffect.cpp
@@ -58,7 +58,28 @@ private:
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 @@ void GrEffect::addTextureAccess(const GrTextureAccess* access) {
fTextureAccesses.push_back(access);
}
-void * GrEffect::operator new(size_t size) {
+void* GrEffect::operator new(size_t size) {
return GrEffect_Globals::GetTLS()->allocate(size);
}
diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp
index 32a945b8b1..0a4fe6a8dd 100644
--- a/src/gpu/GrSWMaskHelper.cpp
+++ b/src/gpu/GrSWMaskHelper.cpp
@@ -198,7 +198,7 @@ void GrSWMaskHelper::DrawToTargetWithPathMask(GrTexture* texture,
};
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 a2c388e45e..f205569fa0 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -443,7 +443,7 @@ bool SkGpuDevice::bindDeviceAsTexture(GrPaint* paint) {
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 @@ inline bool skPaint2GrPaintNoShader(SkGpuDevice* dev,
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 @@ inline bool skPaint2GrPaintShader(SkGpuDevice* dev,
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 @@ bool drawWithGPUMaskFilter(GrContext* context, const SkPath& devPath, const SkSt
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 @@ bool drawWithGPUMaskFilter(GrContext* context, const SkPath& devPath, const SkSt
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 @@ bool drawWithMaskFilter(GrContext* context, const SkPath& devPath,
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 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
}
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 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
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 @@ void apply_effect(GrContext* context,
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 @@ static GrTexture* filter_texture(SkDevice* device, GrContext* 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
@@ -1415,16 +1417,16 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap,
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 @@ void SkGpuDevice::drawDevice(const SkDraw& draw, SkDevice* device,
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 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();