Cleanup of r2830.
git-svn-id: http://skia.googlecode.com/svn/trunk@2841 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index 7a84262..aa5cf20 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -10,9 +10,10 @@
#include "GrDrawTarget.h"
#include "GrGpuVertex.h"
+#include "GrIndexBuffer.h"
+#include "GrRenderTarget.h"
#include "GrTexture.h"
#include "GrVertexBuffer.h"
-#include "GrIndexBuffer.h"
namespace {
@@ -455,119 +456,6 @@
return fClip;
}
-void GrDrawTarget::setTexture(int stage, GrTexture* tex) {
- GrAssert(stage >= 0 && stage < GrDrawState::kNumStages);
- fCurrDrawState.fTextures[stage] = tex;
-}
-
-const GrTexture* GrDrawTarget::getTexture(int stage) const {
- GrAssert(stage >= 0 && stage < GrDrawState::kNumStages);
- return fCurrDrawState.fTextures[stage];
-}
-
-GrTexture* GrDrawTarget::getTexture(int stage) {
- GrAssert(stage >= 0 && stage < GrDrawState::kNumStages);
- return fCurrDrawState.fTextures[stage];
-}
-
-void GrDrawTarget::setRenderTarget(GrRenderTarget* target) {
- fCurrDrawState.fRenderTarget = target;
-}
-
-const GrRenderTarget* GrDrawTarget::getRenderTarget() const {
- return fCurrDrawState.fRenderTarget;
-}
-
-GrRenderTarget* GrDrawTarget::getRenderTarget() {
- return fCurrDrawState.fRenderTarget;
-}
-
-void GrDrawTarget::setViewMatrix(const GrMatrix& m) {
- fCurrDrawState.fViewMatrix = m;
-}
-
-void GrDrawTarget::preConcatViewMatrix(const GrMatrix& matrix) {
- fCurrDrawState.fViewMatrix.preConcat(matrix);
-}
-
-void GrDrawTarget::postConcatViewMatrix(const GrMatrix& matrix) {
- fCurrDrawState.fViewMatrix.postConcat(matrix);
-}
-
-const GrMatrix& GrDrawTarget::getViewMatrix() const {
- return fCurrDrawState.fViewMatrix;
-}
-
-bool GrDrawTarget::getViewInverse(GrMatrix* matrix) const {
- // Mike: Can we cache this somewhere?
- // Brian: Sure, do we use it often?
-
- GrMatrix inverse;
- if (fCurrDrawState.fViewMatrix.invert(&inverse)) {
- if (matrix) {
- *matrix = inverse;
- }
- return true;
- }
- return false;
-}
-
-void GrDrawTarget::setSamplerState(int stage, const GrSamplerState& state) {
- GrAssert(stage >= 0 && stage < GrDrawState::kNumStages);
- fCurrDrawState.fSamplerStates[stage] = state;
-}
-
-void GrDrawTarget::enableState(uint32_t bits) {
- fCurrDrawState.fFlagBits |= bits;
-}
-
-void GrDrawTarget::disableState(uint32_t bits) {
- fCurrDrawState.fFlagBits &= ~(bits);
-}
-
-void GrDrawTarget::setBlendFunc(GrBlendCoeff srcCoeff,
- GrBlendCoeff dstCoeff) {
- fCurrDrawState.fSrcBlend = srcCoeff;
- fCurrDrawState.fDstBlend = dstCoeff;
-#if GR_DEBUG
- switch (dstCoeff) {
- case kDC_BlendCoeff:
- case kIDC_BlendCoeff:
- case kDA_BlendCoeff:
- case kIDA_BlendCoeff:
- GrPrintf("Unexpected dst blend coeff. Won't work correctly with"
- "coverage stages.\n");
- break;
- default:
- break;
- }
- switch (srcCoeff) {
- case kSC_BlendCoeff:
- case kISC_BlendCoeff:
- case kSA_BlendCoeff:
- case kISA_BlendCoeff:
- GrPrintf("Unexpected src blend coeff. Won't work correctly with"
- "coverage stages.\n");
- break;
- default:
- break;
- }
-#endif
-}
-
-void GrDrawTarget::setColor(GrColor c) {
- fCurrDrawState.fColor = c;
-}
-
-void GrDrawTarget::setColorFilter(GrColor c, SkXfermode::Mode mode) {
- fCurrDrawState.fColorFilterColor = c;
- fCurrDrawState.fColorFilterXfermode = mode;
-}
-
-void GrDrawTarget::setAlpha(uint8_t a) {
- this->setColor((a << 24) | (a << 16) | (a << 8) | a);
-}
-
void GrDrawTarget::saveCurrentDrawState(SavedDrawState* state) const {
state->fState = fCurrDrawState;
}
@@ -800,12 +688,13 @@
}
}
#endif
- if (NULL == this->getRenderTarget()) {
+ const GrDrawState& drawState = this->getDrawState();
+ if (NULL == drawState.getRenderTarget()) {
return false;
}
- if (GrPixelConfigIsUnpremultiplied(this->getRenderTarget()->config())) {
- if (kOne_BlendCoeff != fCurrDrawState.fSrcBlend ||
- kZero_BlendCoeff != fCurrDrawState.fDstBlend) {
+ if (GrPixelConfigIsUnpremultiplied(drawState.getRenderTarget()->config())) {
+ if (kOne_BlendCoeff != drawState.getSrcBlendCoeff() ||
+ kZero_BlendCoeff != drawState.getDstBlendCoeff()) {
return false;
}
}
@@ -817,8 +706,9 @@
// a custom bilerp in the shader. Until Skia itself supports unpremul
// configs there is no pressure to implement this.
if (this->isStageEnabled(s) &&
- GrPixelConfigIsUnpremultiplied(fCurrDrawState.fTextures[s]->config()) &&
- GrSamplerState::kNearest_Filter != fCurrDrawState.fSamplerStates[s].getFilter()) {
+ GrPixelConfigIsUnpremultiplied(drawState.getTexture(s)->config()) &&
+ GrSamplerState::kNearest_Filter !=
+ drawState.getSampler(s).getFilter()) {
return false;
}
}
@@ -861,31 +751,33 @@
* for Cd we find that only 1, ISA, and ISC produce the correct depth
* coeffecient in terms of S' and D.
*/
- return kOne_BlendCoeff == fCurrDrawState.fDstBlend||
- kISA_BlendCoeff == fCurrDrawState.fDstBlend ||
- kISC_BlendCoeff == fCurrDrawState.fDstBlend;
+ GrBlendCoeff dstCoeff = this->getDrawState().getDstBlendCoeff();
+ return kOne_BlendCoeff == dstCoeff ||
+ kISA_BlendCoeff == dstCoeff ||
+ kISC_BlendCoeff == dstCoeff;
}
bool GrDrawTarget::srcAlphaWillBeOne() const {
const GrVertexLayout& layout = this->getGeomSrc().fVertexLayout;
+ const GrDrawState& drawState = this->getDrawState();
// Check if per-vertex or constant color may have partial alpha
if ((layout & kColor_VertexLayoutBit) ||
- 0xff != GrColorUnpackA(fCurrDrawState.fColor)) {
+ 0xff != GrColorUnpackA(drawState.getColor())) {
return false;
}
// Check if color filter could introduce an alpha
// (TODO: Consider being more aggressive with regards to detecting 0xff
// final alpha from color filter).
- if (SkXfermode::kDst_Mode != fCurrDrawState.fColorFilterXfermode) {
+ if (SkXfermode::kDst_Mode != drawState.getColorFilterMode()) {
return false;
}
// Check if a color stage could create a partial alpha
- for (int s = 0; s < fCurrDrawState.fFirstCoverageStage; ++s) {
+ for (int s = 0; s < drawState.getFirstCoverageStage(); ++s) {
if (StageWillBeUsed(s, layout, fCurrDrawState)) {
- GrAssert(NULL != fCurrDrawState.fTextures[s]);
- GrPixelConfig config = fCurrDrawState.fTextures[s]->config();
+ GrAssert(NULL != drawState.getTexture(s));
+ GrPixelConfig config = drawState.getTexture(s)->config();
if (!GrPixelConfigIsOpaque(config)) {
return false;
}
@@ -900,17 +792,18 @@
GrBlendCoeff* dstCoeff) const {
const GrVertexLayout& layout = this->getGeomSrc().fVertexLayout;
+ const GrDrawState& drawState = this->getDrawState();
GrBlendCoeff bogusSrcCoeff, bogusDstCoeff;
if (NULL == srcCoeff) {
srcCoeff = &bogusSrcCoeff;
}
- *srcCoeff = fCurrDrawState.fSrcBlend;
+ *srcCoeff = drawState.getSrcBlendCoeff();
if (NULL == dstCoeff) {
dstCoeff = &bogusDstCoeff;
}
- *dstCoeff = fCurrDrawState.fDstBlend;
+ *dstCoeff = drawState.getDstBlendCoeff();
// We don't ever expect source coeffecients to reference the source
GrAssert(kSA_BlendCoeff != *srcCoeff &&
@@ -923,7 +816,7 @@
kDC_BlendCoeff != *dstCoeff &&
kIDC_BlendCoeff != *dstCoeff);
- if (SkToBool(kNoColorWrites_StateBit & fCurrDrawState.fFlagBits)) {
+ if (drawState.isColorWriteDisabled()) {
*srcCoeff = kZero_BlendCoeff;
*dstCoeff = kOne_BlendCoeff;
}
@@ -939,7 +832,7 @@
// stenciling is enabled. Having color writes disabled is effectively
// (0,1).
if ((kZero_BlendCoeff == *srcCoeff && dstCoeffIsOne)) {
- if (fCurrDrawState.fStencilSettings.doesWrite()) {
+ if (drawState.getStencil().doesWrite()) {
if (fCaps.fShaderSupport) {
return kDisableBlend_BlendOptFlag |
kEmitTransBlack_BlendOptFlag;
@@ -953,10 +846,10 @@
// check for coverage due to edge aa or coverage texture stage
bool hasCoverage = forceCoverage ||
- fCurrDrawState.fEdgeAANumEdges > 0 ||
+ drawState.getNumAAEdges() > 0 ||
(layout & kCoverage_VertexLayoutBit) ||
(layout & kEdge_VertexLayoutBit);
- for (int s = fCurrDrawState.fFirstCoverageStage;
+ for (int s = drawState.getFirstCoverageStage();
!hasCoverage && s < GrDrawState::kNumStages;
++s) {
if (StageWillBeUsed(s, layout, fCurrDrawState)) {
@@ -1023,7 +916,7 @@
// but not in a premul-alpha way. So we only use them when our alpha
// is 0xff and tweaking the color for partial coverage is OK
if (!fCaps.fHWAALineSupport ||
- !(kHWAntialias_StateBit & fCurrDrawState.fFlagBits)) {
+ !this->getDrawState().isHWAntialiasState()) {
return false;
}
BlendOptFlags opts = this->getBlendOpts();
@@ -1043,15 +936,6 @@
this->getBlendOpts());
}
-///////////////////////////////////////////////////////////////////////////////
-
-void GrDrawTarget::setEdgeAAData(const GrDrawState::Edge* edges, int numEdges) {
- GrAssert(numEdges <= GrDrawState::kMaxEdges);
- memcpy(fCurrDrawState.fEdgeAAEdges, edges,
- numEdges * sizeof(GrDrawState::Edge));
- fCurrDrawState.fEdgeAANumEdges = numEdges;
-}
-
////////////////////////////////////////////////////////////////////////////////
@@ -1174,32 +1058,34 @@
GrDrawTarget* target,
GrDrawState::StageMask stageMask) {
GrAssert(NULL != target);
+ GrDrawState* drawState = target->drawState();
fDrawTarget = target;
- fViewMatrix = target->getViewMatrix();
+ fViewMatrix = drawState->getViewMatrix();
fStageMask = stageMask;
if (fStageMask) {
GrMatrix invVM;
if (fViewMatrix.invert(&invVM)) {
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
if (fStageMask & (1 << s)) {
- fSamplerMatrices[s] = target->getSamplerMatrix(s);
+ fSamplerMatrices[s] = drawState->getSampler(s).getMatrix();
}
}
- target->preConcatSamplerMatrices(fStageMask, invVM);
+ drawState->preConcatSamplerMatrices(fStageMask, invVM);
} else {
// sad trombone sound
fStageMask = 0;
}
}
- target->setViewMatrix(GrMatrix::I());
+ drawState->setViewMatrix(GrMatrix::I());
}
GrDrawTarget::AutoDeviceCoordDraw::~AutoDeviceCoordDraw() {
- fDrawTarget->setViewMatrix(fViewMatrix);
+ GrDrawState* drawState = fDrawTarget->drawState();
+ drawState->setViewMatrix(fViewMatrix);
for (int s = 0; s < GrDrawState::kNumStages; ++s) {
if (fStageMask & (1 << s)) {
- fDrawTarget->setSamplerMatrix(s, fSamplerMatrices[s]);
+ drawState->sampler(s)->setMatrix(fSamplerMatrices[s]);
}
}
}