// 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;
};
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();
SkMatrix sampleM;
sampleM.setIDiv(srcMask->width(), srcMask->height());
- drawState->stage(0)->setEffect(
+ drawState->setEffect(0,
GrTextureDomainEffect::Create(srcMask,
sampleM,
GrTextureDomainEffect::MakeTexelDomain(srcMask, srcBound),
direction,
radius,
sigma));
- drawState->stage(0)->setEffect(conv);
+ drawState->setEffect(0, conv);
target->drawSimpleRect(rect, NULL);
}
ast.set(this, desc, match);
GrTexture* texture = ast.texture();
if (texture) {
- GrEffectStage stage;
// compute a matrix to perform the draw
SkMatrix textureMatrix;
if (flipY) {
}
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));
// 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();
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);
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,
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));
}
}
-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;
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;
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;
}
}
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);
}
}
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);
}
}
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]);
}
}
}
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);
}
}
}
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]);
}
}
}
inverted = true;
}
fRestoreMask |= (1 << s);
- GrEffectStage* stage = drawState->stage(s);
+ GrEffectStage* stage = drawState->fStages + s;
stage->saveCoordChange(&fSavedCoordChanges[s]);
stage->preConcatCoordChange(invVM);
}
/// @}
///////////////////////////////////////////////////////////////////////////
- /// @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,
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() {
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.
GrDrawState* fDrawState;
};
- /// @}
-
- ///////////////////////////////////////////////////////////////////////////
- /// @name Stages
- ////
-
/**
* Returns the current stage by index.
*/
return fStages[stageIdx];
}
- /**
- * 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.
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());
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);
}
}
-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);
}
}
};
// 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;
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);
}