aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/gpu/GrContext.h19
-rw-r--r--src/gpu/GrClipMaskManager.cpp8
-rw-r--r--src/gpu/GrContext.cpp78
-rw-r--r--src/gpu/GrDrawState.cpp18
-rw-r--r--src/gpu/GrDrawState.h29
-rw-r--r--src/gpu/GrSWMaskHelper.cpp1
-rw-r--r--src/gpu/GrTextContext.cpp2
-rw-r--r--src/gpu/effects/GrConfigConversionEffect.cpp21
-rw-r--r--src/gpu/effects/GrConfigConversionEffect.h9
-rw-r--r--tests/GLProgramsTest.cpp10
10 files changed, 85 insertions, 110 deletions
diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h
index 556893895a..98683a475c 100644
--- a/include/gpu/GrContext.h
+++ b/include/gpu/GrContext.h
@@ -910,14 +910,17 @@ private:
// for use with textures released from an GrAutoScratchTexture.
void addExistingTextureToCache(GrTexture* texture);
- bool installPMToUPMEffect(GrTexture* texture,
- bool swapRAndB,
- const SkMatrix& matrix,
- GrEffectStage* stage);
- bool installUPMToPMEffect(GrTexture* texture,
- bool swapRAndB,
- const SkMatrix& matrix,
- GrEffectStage* stage);
+ /**
+ * These functions create premul <-> unpremul effects if it is possible to generate a pair
+ * of effects that make a readToUPM->writeToPM->readToUPM cycle invariant. Otherwise, they
+ * return NULL.
+ */
+ const GrEffectRef* createPMToUPMEffect(GrTexture* texture,
+ bool swapRAndB,
+ const SkMatrix& matrix);
+ const GrEffectRef* createUPMToPMEffect(GrTexture* texture,
+ bool swapRAndB,
+ const SkMatrix& matrix);
typedef GrRefCnt INHERITED;
};
diff --git a/src/gpu/GrClipMaskManager.cpp b/src/gpu/GrClipMaskManager.cpp
index f3f773d536..bc7b79188b 100644
--- a/src/gpu/GrClipMaskManager.cpp
+++ b/src/gpu/GrClipMaskManager.cpp
@@ -45,12 +45,10 @@ void setup_drawstate_aaclip(GrGpu* gpu,
SkIntToScalar(-devBound.fTop));
mat.preConcat(drawState->getViewMatrix());
- drawState->stage(kMaskStage)->reset();
-
SkIRect domainTexels = SkIRect::MakeWH(devBound.width(), devBound.height());
// This could be a long-lived effect that is cached with the alpha-mask.
- drawState->stage(kMaskStage)->setEffect(
- GrTextureDomainEffect::Create(result,
+ drawState->setEffect(kMaskStage,
+ GrTextureDomainEffect::Create(result,
mat,
GrTextureDomainEffect::MakeTexelDomain(result, domainTexels),
GrTextureDomainEffect::kDecal_WrapMode))->unref();
@@ -352,7 +350,7 @@ void GrClipMaskManager::mergeMask(GrTexture* dstMask,
SkMatrix sampleM;
sampleM.setIDiv(srcMask->width(), srcMask->height());
- drawState->stage(0)->setEffect(
+ drawState->setEffect(0,
GrTextureDomainEffect::Create(srcMask,
sampleM,
GrTextureDomainEffect::MakeTexelDomain(srcMask, srcBound),
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 46415834b3..b2df67c799 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -204,7 +204,7 @@ void convolve_gaussian(GrDrawTarget* target,
direction,
radius,
sigma));
- drawState->stage(0)->setEffect(conv);
+ drawState->setEffect(0, conv);
target->drawSimpleRect(rect, NULL);
}
@@ -1375,7 +1375,6 @@ bool GrContext::readRenderTargetPixels(GrRenderTarget* target,
ast.set(this, desc, match);
GrTexture* texture = ast.texture();
if (texture) {
- GrEffectStage stage;
// compute a matrix to perform the draw
SkMatrix textureMatrix;
if (flipY) {
@@ -1387,30 +1386,30 @@ bool GrContext::readRenderTargetPixels(GrRenderTarget* target,
}
textureMatrix.postIDiv(src->width(), src->height());
- bool effectInstalled = false;
+ SkAutoTUnref<const GrEffectRef> effect;
if (unpremul) {
- if (this->installPMToUPMEffect(src, swapRAndB, textureMatrix, &stage)) {
- effectInstalled = true;
+ effect.reset(this->createPMToUPMEffect(src, swapRAndB, textureMatrix));
+ if (NULL != effect) {
unpremul = false; // we no longer need to do this on CPU after the readback.
}
}
// If we failed to create a PM->UPM effect and have no other conversions to perform then
// there is no longer any point to using the scratch.
- if (effectInstalled || flipY || swapRAndB) {
- if (!effectInstalled) {
- SkAssertResult(GrConfigConversionEffect::InstallEffect(
- src,
- swapRAndB,
- GrConfigConversionEffect::kNone_PMConversion,
- textureMatrix,
- &stage));
+ if (NULL != effect || flipY || swapRAndB) {
+ if (!effect) {
+ effect.reset(GrConfigConversionEffect::Create(
+ src,
+ swapRAndB,
+ GrConfigConversionEffect::kNone_PMConversion,
+ textureMatrix));
}
swapRAndB = false; // we will handle the swap in the draw.
flipY = false; // we already incorporated the y flip in the matrix
GrDrawTarget::AutoStateRestore asr(fGpu, GrDrawTarget::kReset_ASRInit);
GrDrawState* drawState = fGpu->drawState();
- *drawState->stage(0) = stage;
+ GrAssert(effect);
+ *drawState->setEffect(0, effect);
drawState->setRenderTarget(texture->asRenderTarget());
GrRect rect = GrRect::MakeWH(SkIntToScalar(width), SkIntToScalar(height));
@@ -1503,7 +1502,7 @@ void GrContext::copyTexture(GrTexture* src, GrRenderTarget* dst, const SkIPoint*
// Writes pending to the source texture are not tracked, so a flush
// is required to ensure that the copy captures the most recent contents
- // of the source texture. See similar behaviour in
+ // of the source texture. See similar behavior in
// GrContext::resolveRenderTarget.
this->flush();
@@ -1584,23 +1583,19 @@ void GrContext::writeRenderTargetPixels(GrRenderTarget* target,
return;
}
- GrEffectStage stage;
+ SkAutoTUnref<const GrEffectRef> effect;
SkMatrix textureMatrix;
textureMatrix.setIDiv(texture->width(), texture->height());
// allocate a tmp buffer and sw convert the pixels to premul
SkAutoSTMalloc<128 * 128, uint32_t> tmpPixels(0);
- bool effectInstalled = false;
if (kUnpremul_PixelOpsFlag & flags) {
if (kRGBA_8888_GrPixelConfig != config && kBGRA_8888_GrPixelConfig != config) {
return;
}
- effectInstalled = this->installUPMToPMEffect(texture,
- swapRAndB,
- textureMatrix,
- &stage);
- if (!effectInstalled) {
+ effect.reset(this->createUPMToPMEffect(texture, swapRAndB, textureMatrix));
+ if (NULL == effect) {
SkCanvas::Config8888 srcConfig8888, dstConfig8888;
GR_DEBUGCODE(bool success = )
grconfig_to_config8888(config, true, &srcConfig8888);
@@ -1617,13 +1612,11 @@ void GrContext::writeRenderTargetPixels(GrRenderTarget* target,
rowBytes = 4 * width;
}
}
- if (!effectInstalled) {
- SkAssertResult(GrConfigConversionEffect::InstallEffect(
- texture,
- swapRAndB,
- GrConfigConversionEffect::kNone_PMConversion,
- textureMatrix,
- &stage));
+ if (NULL == effect) {
+ effect.reset(GrConfigConversionEffect::Create(texture,
+ swapRAndB,
+ GrConfigConversionEffect::kNone_PMConversion,
+ textureMatrix));
}
this->writeTexturePixels(texture,
@@ -1633,7 +1626,8 @@ void GrContext::writeRenderTargetPixels(GrRenderTarget* target,
GrDrawTarget::AutoStateRestore asr(fGpu, GrDrawTarget::kReset_ASRInit);
GrDrawState* drawState = fGpu->drawState();
- *drawState->stage(0) = stage;
+ GrAssert(effect);
+ *drawState->setEffect(0, effect);
SkMatrix matrix;
matrix.setTranslate(SkIntToScalar(left), SkIntToScalar(top));
@@ -1822,10 +1816,9 @@ void test_pm_conversions(GrContext* ctx, int* pmToUPMValue, int* upmToPMValue) {
}
}
-bool GrContext::installPMToUPMEffect(GrTexture* texture,
- bool swapRAndB,
- const SkMatrix& matrix,
- GrEffectStage* stage) {
+const GrEffectRef* GrContext::createPMToUPMEffect(GrTexture* texture,
+ bool swapRAndB,
+ const SkMatrix& matrix) {
if (!fDidTestPMConversions) {
test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion);
fDidTestPMConversions = true;
@@ -1833,17 +1826,15 @@ bool GrContext::installPMToUPMEffect(GrTexture* texture,
GrConfigConversionEffect::PMConversion pmToUPM =
static_cast<GrConfigConversionEffect::PMConversion>(fPMToUPMConversion);
if (GrConfigConversionEffect::kNone_PMConversion != pmToUPM) {
- GrConfigConversionEffect::InstallEffect(texture, swapRAndB, pmToUPM, matrix, stage);
- return true;
+ return GrConfigConversionEffect::Create(texture, swapRAndB, pmToUPM, matrix);
} else {
- return false;
+ return NULL;
}
}
-bool GrContext::installUPMToPMEffect(GrTexture* texture,
- bool swapRAndB,
- const SkMatrix& matrix,
- GrEffectStage* stage) {
+const GrEffectRef* GrContext::createUPMToPMEffect(GrTexture* texture,
+ bool swapRAndB,
+ const SkMatrix& matrix) {
if (!fDidTestPMConversions) {
test_pm_conversions(this, &fPMToUPMConversion, &fUPMToPMConversion);
fDidTestPMConversions = true;
@@ -1851,10 +1842,9 @@ bool GrContext::installUPMToPMEffect(GrTexture* texture,
GrConfigConversionEffect::PMConversion upmToPM =
static_cast<GrConfigConversionEffect::PMConversion>(fUPMToPMConversion);
if (GrConfigConversionEffect::kNone_PMConversion != upmToPM) {
- GrConfigConversionEffect::InstallEffect(texture, swapRAndB, upmToPM, matrix, stage);
- return true;
+ return GrConfigConversionEffect::Create(texture, swapRAndB, upmToPM, matrix);
} else {
- return false;
+ return NULL;
}
}
diff --git a/src/gpu/GrDrawState.cpp b/src/gpu/GrDrawState.cpp
index bdb12302a1..2d5c7aa68f 100644
--- a/src/gpu/GrDrawState.cpp
+++ b/src/gpu/GrDrawState.cpp
@@ -13,7 +13,9 @@ void GrDrawState::setFromPaint(const GrPaint& paint) {
for (int i = 0; i < GrPaint::kMaxColorStages; ++i) {
int s = i + GrPaint::kFirstColorStage;
if (paint.isColorStageEnabled(i)) {
- *this->stage(s) = paint.getColorStage(i);
+ fStages[s] = paint.getColorStage(i);
+ } else {
+ fStages[s].setEffect(NULL);
}
}
@@ -22,7 +24,9 @@ void GrDrawState::setFromPaint(const GrPaint& paint) {
for (int i = 0; i < GrPaint::kMaxCoverageStages; ++i) {
int s = i + GrPaint::kFirstCoverageStage;
if (paint.isCoverageStageEnabled(i)) {
- *this->stage(s) = paint.getCoverageStage(i);
+ fStages[s] = paint.getCoverageStage(i);
+ } else {
+ fStages[s].setEffect(NULL);
}
}
@@ -48,7 +52,7 @@ void GrDrawState::AutoViewMatrixRestore::restore() {
fDrawState->setViewMatrix(fViewMatrix);
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
if (fRestoreMask & (1 << s)) {
- fDrawState->stage(s)->restoreCoordChange(fSavedCoordChanges[s]);
+ fDrawState->fStages[s].restoreCoordChange(fSavedCoordChanges[s]);
}
}
}
@@ -71,8 +75,8 @@ void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState,
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
if (!(explicitCoordStageMask & (1 << s)) && drawState->isStageEnabled(s)) {
fRestoreMask |= (1 << s);
- fDrawState->stage(s)->saveCoordChange(&fSavedCoordChanges[s]);
- drawState->stage(s)->preConcatCoordChange(preconcatMatrix);
+ fDrawState->fStages[s].saveCoordChange(&fSavedCoordChanges[s]);
+ drawState->fStages[s].preConcatCoordChange(preconcatMatrix);
}
}
}
@@ -84,7 +88,7 @@ void GrDrawState::AutoDeviceCoordDraw::restore() {
fDrawState->setViewMatrix(fViewMatrix);
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
if (fRestoreMask & (1 << s)) {
- fDrawState->stage(s)->restoreCoordChange(fSavedCoordChanges[s]);
+ fDrawState->fStages[s].restoreCoordChange(fSavedCoordChanges[s]);
}
}
}
@@ -117,7 +121,7 @@ bool GrDrawState::AutoDeviceCoordDraw::set(GrDrawState* drawState,
inverted = true;
}
fRestoreMask |= (1 << s);
- GrEffectStage* stage = drawState->stage(s);
+ GrEffectStage* stage = drawState->fStages + s;
stage->saveCoordChange(&fSavedCoordChanges[s]);
stage->preConcatCoordChange(invVM);
}
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index ba9eb217d6..326df0bf95 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -185,16 +185,21 @@ public:
/// @}
///////////////////////////////////////////////////////////////////////////
- /// @name Textures
+ /// @name Effect Stages
////
+ const GrEffectRef* setEffect(int stageIdx, const GrEffectRef* effect) {
+ fStages[stageIdx].setEffect(effect);
+ return effect;
+ }
+
/**
* Creates a GrSimpleTextureEffect.
*/
void createTextureEffect(int stageIdx, GrTexture* texture, const SkMatrix& matrix) {
GrAssert(!this->getStage(stageIdx).getEffect());
GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix);
- this->stage(stageIdx)->setEffect(effect)->unref();
+ this->setEffect(stageIdx, effect)->unref();
}
void createTextureEffect(int stageIdx,
GrTexture* texture,
@@ -202,7 +207,7 @@ public:
const GrTextureParams& params) {
GrAssert(!this->getStage(stageIdx).getEffect());
GrEffectRef* effect = GrSimpleTextureEffect::Create(texture, matrix, params);
- this->stage(stageIdx)->setEffect(effect)->unref();
+ this->setEffect(stageIdx, effect)->unref();
}
bool stagesDisabled() {
@@ -214,9 +219,7 @@ public:
return true;
}
- void disableStage(int stageIdx) {
- fStages[stageIdx].setEffect(NULL);
- }
+ void disableStage(int stageIdx) { this->setEffect(stageIdx, NULL); }
/**
* Release all the GrEffects referred to by this draw state.
@@ -239,12 +242,6 @@ public:
GrDrawState* fDrawState;
};
- /// @}
-
- ///////////////////////////////////////////////////////////////////////////
- /// @name Stages
- ////
-
/**
* Returns the current stage by index.
*/
@@ -254,14 +251,6 @@ public:
}
/**
- * Writable pointer to a stage.
- */
- GrEffectStage* stage(int stageIdx) {
- GrAssert((unsigned)stageIdx < kNumStages);
- return fStages + stageIdx;
- }
-
- /**
* Called when the source coord system is changing. preConcat gives the transformation from the
* old coord system to the new coord system.
*/
diff --git a/src/gpu/GrSWMaskHelper.cpp b/src/gpu/GrSWMaskHelper.cpp
index 6d27d873b3..50fcc2be19 100644
--- a/src/gpu/GrSWMaskHelper.cpp
+++ b/src/gpu/GrSWMaskHelper.cpp
@@ -197,7 +197,6 @@ void GrSWMaskHelper::DrawToTargetWithPathMask(GrTexture* texture,
kPathMaskStage = GrPaint::kTotalStages,
};
GrAssert(!drawState->isStageEnabled(kPathMaskStage));
- drawState->stage(kPathMaskStage)->reset();
drawState->createTextureEffect(kPathMaskStage, texture, SkMatrix::I());
SkScalar w = SkIntToScalar(rect.width());
SkScalar h = SkIntToScalar(rect.height());
diff --git a/src/gpu/GrTextContext.cpp b/src/gpu/GrTextContext.cpp
index 9daa31572f..beb3f91f6b 100644
--- a/src/gpu/GrTextContext.cpp
+++ b/src/gpu/GrTextContext.cpp
@@ -30,8 +30,6 @@ void GrTextContext::flushGlyphs() {
GrDrawState* drawState = fDrawTarget->drawState();
if (fCurrVertex > 0) {
// setup our sampler state for our text texture/atlas
- drawState->stage(kGlyphMaskStage)->reset();
-
GrAssert(GrIsALIGN4(fCurrVertex));
GrAssert(fCurrTexture);
GrTextureParams params(SkShader::kRepeat_TileMode, false);
diff --git a/src/gpu/effects/GrConfigConversionEffect.cpp b/src/gpu/effects/GrConfigConversionEffect.cpp
index 4c4d0792c0..92df82d940 100644
--- a/src/gpu/effects/GrConfigConversionEffect.cpp
+++ b/src/gpu/effects/GrConfigConversionEffect.cpp
@@ -261,29 +261,26 @@ void GrConfigConversionEffect::TestForPreservingPMConversions(GrContext* context
}
}
-bool GrConfigConversionEffect::InstallEffect(GrTexture* texture,
- bool swapRedAndBlue,
- PMConversion pmConversion,
- const SkMatrix& matrix,
- GrEffectStage* stage) {
+const GrEffectRef* GrConfigConversionEffect::Create(GrTexture* texture,
+ bool swapRedAndBlue,
+ PMConversion pmConversion,
+ const SkMatrix& matrix) {
if (!swapRedAndBlue && kNone_PMConversion == pmConversion) {
- // If we returned a GrConfigConversionEffect that was equivalent to a GrSingleTextureEffect
+ // If we returned a GrConfigConversionEffect that was equivalent to a GrSimpleTextureEffect
// 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(GrSimpleTextureEffect::Create(texture, matrix))->unref();
- return true;
+ // conversions were requested we instead return a GrSimpleTextureEffect.
+ return GrSimpleTextureEffect::Create(texture, matrix);
} else {
if (kRGBA_8888_GrPixelConfig != texture->config() &&
kBGRA_8888_GrPixelConfig != texture->config() &&
kNone_PMConversion != pmConversion) {
// The PM conversions assume colors are 0..255
- return false;
+ return NULL;
}
AutoEffectUnref effect(SkNEW_ARGS(GrConfigConversionEffect, (texture,
swapRedAndBlue,
pmConversion,
matrix)));
- stage->setEffect(CreateEffectRef(effect))->unref();
- return true;
+ return CreateEffectRef(effect);
}
}
diff --git a/src/gpu/effects/GrConfigConversionEffect.h b/src/gpu/effects/GrConfigConversionEffect.h
index 3845d32bbd..169c3d7db8 100644
--- a/src/gpu/effects/GrConfigConversionEffect.h
+++ b/src/gpu/effects/GrConfigConversionEffect.h
@@ -35,11 +35,10 @@ public:
};
// Installs an effect in the GrEffectStage to perform a config conversion.
- static bool InstallEffect(GrTexture*,
- bool swapRedAndBlue,
- PMConversion pmConversion,
- const SkMatrix& matrix,
- GrEffectStage* stage);
+ static const GrEffectRef* Create(GrTexture*,
+ bool swapRedAndBlue,
+ PMConversion pmConversion,
+ const SkMatrix& matrix);
static const char* Name() { return "Config Conversion"; }
typedef GrGLConfigConversionEffect GLEffect;
diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp
index e83ddebfa9..f9dd9188e4 100644
--- a/tests/GLProgramsTest.cpp
+++ b/tests/GLProgramsTest.cpp
@@ -169,12 +169,10 @@ void forceLinking();
void forceLinking() {
SkLightingImageFilter::CreateDistantLitDiffuse(SkPoint3(0,0,0), 0, 0, 0);
SkMagnifierImageFilter mag(SkRect::MakeWH(SK_Scalar1, SK_Scalar1), SK_Scalar1);
- GrEffectStage dummyStage;
- GrConfigConversionEffect::InstallEffect(NULL,
- false,
- GrConfigConversionEffect::kNone_PMConversion,
- SkMatrix::I(),
- &dummyStage);
+ GrConfigConversionEffect::Create(NULL,
+ false,
+ GrConfigConversionEffect::kNone_PMConversion,
+ SkMatrix::I());
SkScalar matrix[20];
SkColorMatrixFilter cmf(matrix);
}