diff options
author | tomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-06-25 17:27:28 +0000 |
---|---|---|
committer | tomhudson@google.com <tomhudson@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-06-25 17:27:28 +0000 |
commit | f13f58804659175925042a291304d483a4fd9278 (patch) | |
tree | c3c31ab0c9a984f3f0ded3197209ef0fc679a330 /src/gpu | |
parent | f41f4d22576c95f0e3ddfc87be40fcf4ee34b408 (diff) |
Add GrPaint::*StageEnabled() and GrDrawState::stageEnabled() functions.
These wrap the question of "is this stage of the shader enabled?" so that
we can change the semantics - previously iff there was a texture, now
if there is a texture OR a GrCustomStage, soon (post-cl 6306097) iff there
is a GrCustomStage, which at that point will hold whatever texture is
necessary.
http://codereview.appspot.com/6306104/
git-svn-id: http://skia.googlecode.com/svn/trunk@4325 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrContext.cpp | 10 | ||||
-rw-r--r-- | src/gpu/GrDefaultTextContext.cpp | 4 | ||||
-rw-r--r-- | src/gpu/GrDrawState.h | 8 | ||||
-rw-r--r-- | src/gpu/GrDrawTarget.cpp | 4 | ||||
-rw-r--r-- | src/gpu/GrDrawTarget.h | 8 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 4 |
6 files changed, 19 insertions, 19 deletions
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index a49bf99924..e157a8a28a 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -893,7 +893,7 @@ void GrContext::drawRectToRect(const GrPaint& paint, SK_TRACE_EVENT0("GrContext::drawRectToRect"); // srcRect refers to paint's first texture - if (NULL == paint.getTexture(0)) { + if (!paint.isTextureStageEnabled(0)) { drawRect(paint, dstRect, -1, dstMatrix); return; } @@ -1590,9 +1590,9 @@ void GrContext::setPaint(const GrPaint& paint) { for (int i = 0; i < GrPaint::kMaxTextures; ++i) { int s = i + GrPaint::kFirstTextureStage; - fDrawState->setTexture(s, paint.getTexture(i)); ASSERT_OWNED_RESOURCE(paint.getTexture(i)); - if (paint.getTexture(i)) { + if (paint.isTextureStageEnabled(i)) { + fDrawState->setTexture(s, paint.getTexture(i)); *fDrawState->sampler(s) = paint.getTextureSampler(i); } } @@ -1601,9 +1601,9 @@ void GrContext::setPaint(const GrPaint& paint) { for (int i = 0; i < GrPaint::kMaxMasks; ++i) { int s = i + GrPaint::kFirstMaskStage; - fDrawState->setTexture(s, paint.getMask(i)); ASSERT_OWNED_RESOURCE(paint.getMask(i)); - if (paint.getMask(i)) { + if (paint.isMaskStageEnabled(i)) { + fDrawState->setTexture(s, paint.getMask(i)); *fDrawState->sampler(s) = paint.getMaskSampler(i); } } diff --git a/src/gpu/GrDefaultTextContext.cpp b/src/gpu/GrDefaultTextContext.cpp index 9530f0789f..07a01621a4 100644 --- a/src/gpu/GrDefaultTextContext.cpp +++ b/src/gpu/GrDefaultTextContext.cpp @@ -115,7 +115,7 @@ void GrDefaultTextContext::init(GrContext* context, bool invVMComputed = false; GrMatrix invVM; for (int t = 0; t < GrPaint::kMaxTextures; ++t) { - if (NULL != fGrPaint.getTexture(t)) { + if (fGrPaint.isTextureStageEnabled(t)) { if (invVMComputed || fOrigViewMatrix.invert(&invVM)) { invVMComputed = true; fGrPaint.textureSampler(t)->preConcatMatrix(invVM); @@ -123,7 +123,7 @@ void GrDefaultTextContext::init(GrContext* context, } } for (int m = 0; m < GrPaint::kMaxMasks; ++m) { - if (NULL != fGrPaint.getMask(m)) { + if (fGrPaint.isMaskStageEnabled(m)) { if (invVMComputed || fOrigViewMatrix.invert(&invVM)) { invVMComputed = true; fGrPaint.maskSampler(m)->preConcatMatrix(invVM); diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h index a56baec799..61925cdad7 100644 --- a/src/gpu/GrDrawState.h +++ b/src/gpu/GrDrawState.h @@ -760,6 +760,12 @@ public: /////////////////////////////////////////////////////////////////////////// + bool isStageEnabled(int s) const { + GrAssert((unsigned)s < kNumStages); + return (NULL != fTextures[s]) || + (NULL != fSamplerStates[s].getCustomStage()); + } + // Most stages are usually not used, so conditionals here // reduce the expected number of bytes touched by 50%. bool operator ==(const GrDrawState& s) const { @@ -772,7 +778,7 @@ public: } for (int i = 0; i < kNumStages; i++) { - if (fTextures[i] && + if (this->isStageEnabled(i) && this->fSamplerStates[i] != s.fSamplerStates[i]) { return false; } diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp index a0517160ff..39ea5bfe39 100644 --- a/src/gpu/GrDrawTarget.cpp +++ b/src/gpu/GrDrawTarget.cpp @@ -862,7 +862,7 @@ bool GrDrawTarget::srcAlphaWillBeOne(GrVertexLayout layout) const { } // Check if a color stage could create a partial alpha for (int s = 0; s < drawState.getFirstCoverageStage(); ++s) { - if (StageWillBeUsed(s, this->getDrawState())) { + if (this->isStageEnabled(s)) { GrAssert(NULL != drawState.getTexture(s)); GrPixelConfig config = drawState.getTexture(s)->config(); if (!GrPixelConfigIsOpaque(config)) { @@ -951,7 +951,7 @@ GrDrawTarget::getBlendOpts(bool forceCoverage, for (int s = drawState.getFirstCoverageStage(); !hasCoverage && s < GrDrawState::kNumStages; ++s) { - if (StageWillBeUsed(s, this->getDrawState())) { + if (this->isStageEnabled(s)) { hasCoverage = true; } } diff --git a/src/gpu/GrDrawTarget.h b/src/gpu/GrDrawTarget.h index 73de1c5ee2..f619469f34 100644 --- a/src/gpu/GrDrawTarget.h +++ b/src/gpu/GrDrawTarget.h @@ -952,15 +952,9 @@ protected: return 0; } } - // given (a vertex layout and) a draw state, will a stage be used? - static bool StageWillBeUsed(int stage, - const GrDrawState& state) { - return NULL != state.getTexture(stage); - } bool isStageEnabled(int stage) const { - return StageWillBeUsed(stage, - this->getDrawState()); + return this->getDrawState().isStageEnabled(stage); } StageMask enabledStages() const { diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 8c34c547fa..d3ca0b5005 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -883,7 +883,7 @@ bool drawWithGPUMaskFilter(GrContext* context, const SkPath& path, static const int MASK_IDX = GrPaint::kMaxMasks - 1; // we assume the last mask index is available for use - GrAssert(NULL == grp->getMask(MASK_IDX)); + GrAssert(!grp->isMaskStageEnabled(MASK_IDX)); grp->setMask(MASK_IDX, blurTexture); grp->maskSampler(MASK_IDX)->reset(); @@ -949,7 +949,7 @@ bool drawWithMaskFilter(GrContext* context, const SkPath& path, static const int MASK_IDX = GrPaint::kMaxMasks - 1; // we assume the last mask index is available for use - GrAssert(NULL == grp->getMask(MASK_IDX)); + GrAssert(!grp->isMaskStageEnabled(MASK_IDX)); grp->setMask(MASK_IDX, texture); grp->maskSampler(MASK_IDX)->reset(); |