aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar bsalomon <bsalomon@google.com>2014-08-05 07:50:06 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-08-05 07:50:08 -0700
commit8f7273399466c95c0c86b099de438d6ef1a15c88 (patch)
treee2b8e0ecc85e860d2abe7b745d5e5ffff37876da /src
parente90c900ed7b2be3d0f9c7134d7fcd5f820b0464c (diff)
Move functions from GrDrawState.h to GrDrawState.cpp and delete unused functions.
R=egdaniel@google.com Author: bsalomon@google.com Review URL: https://codereview.chromium.org/427713005
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrDrawState.cpp152
-rw-r--r--src/gpu/GrDrawState.h205
2 files changed, 160 insertions, 197 deletions
diff --git a/src/gpu/GrDrawState.cpp b/src/gpu/GrDrawState.cpp
index 1b40642251..3189a0a079 100644
--- a/src/gpu/GrDrawState.cpp
+++ b/src/gpu/GrDrawState.cpp
@@ -8,6 +8,124 @@
#include "GrDrawState.h"
#include "GrPaint.h"
+//////////////////////////////////////////////////////////////////////////////s
+
+GrDrawState::CombinedState GrDrawState::CombineIfPossible(
+ const GrDrawState& a, const GrDrawState& b) {
+
+ bool usingVertexColors = a.hasColorVertexAttribute();
+ if (!usingVertexColors && a.fColor != b.fColor) {
+ return kIncompatible_CombinedState;
+ }
+
+ if (a.fRenderTarget.get() != b.fRenderTarget.get() ||
+ a.fColorStages.count() != b.fColorStages.count() ||
+ a.fCoverageStages.count() != b.fCoverageStages.count() ||
+ !a.fViewMatrix.cheapEqualTo(b.fViewMatrix) ||
+ a.fSrcBlend != b.fSrcBlend ||
+ a.fDstBlend != b.fDstBlend ||
+ a.fBlendConstant != b.fBlendConstant ||
+ a.fFlagBits != b.fFlagBits ||
+ a.fVACount != b.fVACount ||
+ memcmp(a.fVAPtr, b.fVAPtr, a.fVACount * sizeof(GrVertexAttrib)) ||
+ a.fStencilSettings != b.fStencilSettings ||
+ a.fDrawFace != b.fDrawFace) {
+ return kIncompatible_CombinedState;
+ }
+
+ bool usingVertexCoverage = a.hasCoverageVertexAttribute();
+ if (!usingVertexCoverage && a.fCoverage != b.fCoverage) {
+ return kIncompatible_CombinedState;
+ }
+
+ bool explicitLocalCoords = a.hasLocalCoordAttribute();
+ for (int i = 0; i < a.fColorStages.count(); i++) {
+ if (!GrEffectStage::AreCompatible(a.fColorStages[i], b.fColorStages[i],
+ explicitLocalCoords)) {
+ return kIncompatible_CombinedState;
+ }
+ }
+ for (int i = 0; i < a.fCoverageStages.count(); i++) {
+ if (!GrEffectStage::AreCompatible(a.fCoverageStages[i], b.fCoverageStages[i],
+ explicitLocalCoords)) {
+ return kIncompatible_CombinedState;
+ }
+ }
+ SkASSERT(0 == memcmp(a.fFixedFunctionVertexAttribIndices,
+ b.fFixedFunctionVertexAttribIndices,
+ sizeof(a.fFixedFunctionVertexAttribIndices)));
+ return kAOrB_CombinedState;
+}
+
+
+//////////////////////////////////////////////////////////////////////////////s
+
+GrDrawState::GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix) {
+ SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
+ *this = state;
+ if (!preConcatMatrix.isIdentity()) {
+ for (int i = 0; i < fColorStages.count(); ++i) {
+ fColorStages[i].localCoordChange(preConcatMatrix);
+ }
+ for (int i = 0; i < fCoverageStages.count(); ++i) {
+ fCoverageStages[i].localCoordChange(preConcatMatrix);
+ }
+ this->invalidateBlendOptFlags();
+ }
+}
+
+GrDrawState& GrDrawState::operator=(const GrDrawState& that) {
+ SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages());
+ this->setRenderTarget(that.fRenderTarget.get());
+ fColor = that.fColor;
+ fViewMatrix = that.fViewMatrix;
+ fSrcBlend = that.fSrcBlend;
+ fDstBlend = that.fDstBlend;
+ fBlendConstant = that.fBlendConstant;
+ fFlagBits = that.fFlagBits;
+ fVACount = that.fVACount;
+ fVAPtr = that.fVAPtr;
+ fStencilSettings = that.fStencilSettings;
+ fCoverage = that.fCoverage;
+ fDrawFace = that.fDrawFace;
+ fColorStages = that.fColorStages;
+ fCoverageStages = that.fCoverageStages;
+ fOptSrcBlend = that.fOptSrcBlend;
+ fOptDstBlend = that.fOptDstBlend;
+ fBlendOptFlags = that.fBlendOptFlags;
+
+ memcpy(fFixedFunctionVertexAttribIndices,
+ that.fFixedFunctionVertexAttribIndices,
+ sizeof(fFixedFunctionVertexAttribIndices));
+ return *this;
+}
+
+void GrDrawState::onReset(const SkMatrix* initialViewMatrix) {
+ SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages());
+ fColorStages.reset();
+ fCoverageStages.reset();
+
+ fRenderTarget.reset(NULL);
+
+ this->setDefaultVertexAttribs();
+
+ fColor = 0xffffffff;
+ if (NULL == initialViewMatrix) {
+ fViewMatrix.reset();
+ } else {
+ fViewMatrix = *initialViewMatrix;
+ }
+ fSrcBlend = kOne_GrBlendCoeff;
+ fDstBlend = kZero_GrBlendCoeff;
+ fBlendConstant = 0x0;
+ fFlagBits = 0x0;
+ fStencilSettings.setDisabled();
+ fCoverage = 0xffffffff;
+ fDrawFace = kBoth_DrawFace;
+
+ this->invalidateBlendOptFlags();
+}
+
bool GrDrawState::setIdentityViewMatrix() {
if (fColorStages.count() || fCoverageStages.count()) {
SkMatrix invVM;
@@ -411,6 +529,40 @@ bool GrDrawState::canIgnoreColorAttribute() const {
GrDrawState::kEmitCoverage_BlendOptFlag));
}
+//////////////////////////////////////////////////////////////////////////////
+
+GrDrawState::AutoVertexAttribRestore::AutoVertexAttribRestore(
+ GrDrawState* drawState) {
+ SkASSERT(NULL != drawState);
+ fDrawState = drawState;
+ fVAPtr = drawState->fVAPtr;
+ fVACount = drawState->fVACount;
+ fDrawState->setDefaultVertexAttribs();
+}
+
+//////////////////////////////////////////////////////////////////////////////s
+
+void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) {
+ if (NULL != fDrawState) {
+ int m = fDrawState->fColorStages.count() - fColorEffectCnt;
+ SkASSERT(m >= 0);
+ fDrawState->fColorStages.pop_back_n(m);
+
+ int n = fDrawState->fCoverageStages.count() - fCoverageEffectCnt;
+ SkASSERT(n >= 0);
+ fDrawState->fCoverageStages.pop_back_n(n);
+ if (m + n > 0) {
+ fDrawState->invalidateBlendOptFlags();
+ }
+ SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;)
+ }
+ fDrawState = ds;
+ if (NULL != ds) {
+ fColorEffectCnt = ds->fColorStages.count();
+ fCoverageEffectCnt = ds->fCoverageStages.count();
+ SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;)
+ }
+}
////////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index 90bdc64507..6ed04eded9 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -49,19 +49,7 @@ public:
/**
* Copies another draw state with a preconcat to the view matrix.
**/
- GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix) {
- SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
- *this = state;
- if (!preConcatMatrix.isIdentity()) {
- for (int i = 0; i < fColorStages.count(); ++i) {
- fColorStages[i].localCoordChange(preConcatMatrix);
- }
- for (int i = 0; i < fCoverageStages.count(); ++i) {
- fCoverageStages[i].localCoordChange(preConcatMatrix);
- }
- this->invalidateBlendOptFlags();
- }
- }
+ GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix);
virtual ~GrDrawState() { SkASSERT(0 == fBlockEffectRemovalCnt); }
@@ -151,17 +139,9 @@ public:
*/
class AutoVertexAttribRestore {
public:
- AutoVertexAttribRestore(GrDrawState* drawState) {
- SkASSERT(NULL != drawState);
- fDrawState = drawState;
- fVAPtr = drawState->fVAPtr;
- fVACount = drawState->fVACount;
- fDrawState->setDefaultVertexAttribs();
- }
-
- ~AutoVertexAttribRestore(){
- fDrawState->setVertexAttribs(fVAPtr, fVACount);
- }
+ AutoVertexAttribRestore(GrDrawState* drawState);
+
+ ~AutoVertexAttribRestore() { fDrawState->setVertexAttribs(fVAPtr, fVACount); }
private:
GrDrawState* fDrawState;
@@ -169,64 +149,6 @@ public:
int fVACount;
};
- /**
- * Accessing positions, local coords, or colors, of a vertex within an array is a hassle
- * involving casts and simple math. These helpers exist to keep GrDrawTarget clients' code a bit
- * nicer looking.
- */
-
- /**
- * Gets a pointer to a GrPoint of a vertex's position or texture
- * coordinate.
- * @param vertices the vertex array
- * @param vertexIndex the index of the vertex in the array
- * @param vertexSize the size of each vertex in the array
- * @param offset the offset in bytes of the vertex component.
- * Defaults to zero (corresponding to vertex position)
- * @return pointer to the vertex component as a GrPoint
- */
- static SkPoint* GetVertexPoint(void* vertices,
- int vertexIndex,
- int vertexSize,
- int offset = 0) {
- intptr_t start = GrTCast<intptr_t>(vertices);
- return GrTCast<SkPoint*>(start + offset +
- vertexIndex * vertexSize);
- }
- static const SkPoint* GetVertexPoint(const void* vertices,
- int vertexIndex,
- int vertexSize,
- int offset = 0) {
- intptr_t start = GrTCast<intptr_t>(vertices);
- return GrTCast<const SkPoint*>(start + offset +
- vertexIndex * vertexSize);
- }
-
- /**
- * Gets a pointer to a GrColor inside a vertex within a vertex array.
- * @param vertices the vetex array
- * @param vertexIndex the index of the vertex in the array
- * @param vertexSize the size of each vertex in the array
- * @param offset the offset in bytes of the vertex color
- * @return pointer to the vertex component as a GrColor
- */
- static GrColor* GetVertexColor(void* vertices,
- int vertexIndex,
- int vertexSize,
- int offset) {
- intptr_t start = GrTCast<intptr_t>(vertices);
- return GrTCast<GrColor*>(start + offset +
- vertexIndex * vertexSize);
- }
- static const GrColor* GetVertexColor(const void* vertices,
- int vertexIndex,
- int vertexSize,
- int offset) {
- const intptr_t start = GrTCast<intptr_t>(vertices);
- return GrTCast<const GrColor*>(start + offset +
- vertexIndex * vertexSize);
- }
-
/// @}
/**
@@ -364,27 +286,7 @@ public:
~AutoRestoreEffects() { this->set(NULL); }
- void set(GrDrawState* ds) {
- if (NULL != fDrawState) {
- int m = fDrawState->fColorStages.count() - fColorEffectCnt;
- SkASSERT(m >= 0);
- fDrawState->fColorStages.pop_back_n(m);
-
- int n = fDrawState->fCoverageStages.count() - fCoverageEffectCnt;
- SkASSERT(n >= 0);
- fDrawState->fCoverageStages.pop_back_n(n);
- if (m + n > 0) {
- fDrawState->invalidateBlendOptFlags();
- }
- SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;)
- }
- fDrawState = ds;
- if (NULL != ds) {
- fColorEffectCnt = ds->fColorStages.count();
- fCoverageEffectCnt = ds->fCoverageStages.count();
- SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;)
- }
- }
+ void set(GrDrawState* ds);
bool isSet() const { return NULL != fDrawState; }
@@ -860,104 +762,13 @@ public:
a single GrDrawState. This is used to avoid storing redundant GrDrawStates and to determine
if draws can be batched. The return value indicates whether combining is possible and, if
so, which of the two inputs should be used. */
- static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawState& b) {
- bool usingVertexColors = a.hasColorVertexAttribute();
- if (!usingVertexColors && a.fColor != b.fColor) {
- return kIncompatible_CombinedState;
- }
-
- if (a.fRenderTarget.get() != b.fRenderTarget.get() ||
- a.fColorStages.count() != b.fColorStages.count() ||
- a.fCoverageStages.count() != b.fCoverageStages.count() ||
- !a.fViewMatrix.cheapEqualTo(b.fViewMatrix) ||
- a.fSrcBlend != b.fSrcBlend ||
- a.fDstBlend != b.fDstBlend ||
- a.fBlendConstant != b.fBlendConstant ||
- a.fFlagBits != b.fFlagBits ||
- a.fVACount != b.fVACount ||
- memcmp(a.fVAPtr, b.fVAPtr, a.fVACount * sizeof(GrVertexAttrib)) ||
- a.fStencilSettings != b.fStencilSettings ||
- a.fDrawFace != b.fDrawFace) {
- return kIncompatible_CombinedState;
- }
+ static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawState& b);
- bool usingVertexCoverage = a.hasCoverageVertexAttribute();
- if (!usingVertexCoverage && a.fCoverage != b.fCoverage) {
- return kIncompatible_CombinedState;
- }
-
- bool explicitLocalCoords = a.hasLocalCoordAttribute();
- for (int i = 0; i < a.fColorStages.count(); i++) {
- if (!GrEffectStage::AreCompatible(a.fColorStages[i], b.fColorStages[i],
- explicitLocalCoords)) {
- return kIncompatible_CombinedState;
- }
- }
- for (int i = 0; i < a.fCoverageStages.count(); i++) {
- if (!GrEffectStage::AreCompatible(a.fCoverageStages[i], b.fCoverageStages[i],
- explicitLocalCoords)) {
- return kIncompatible_CombinedState;
- }
- }
- SkASSERT(0 == memcmp(a.fFixedFunctionVertexAttribIndices,
- b.fFixedFunctionVertexAttribIndices,
- sizeof(a.fFixedFunctionVertexAttribIndices)));
- return kAOrB_CombinedState;
- }
-
- GrDrawState& operator= (const GrDrawState& that) {
- SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages());
- this->setRenderTarget(that.fRenderTarget.get());
- fColor = that.fColor;
- fViewMatrix = that.fViewMatrix;
- fSrcBlend = that.fSrcBlend;
- fDstBlend = that.fDstBlend;
- fBlendConstant = that.fBlendConstant;
- fFlagBits = that.fFlagBits;
- fVACount = that.fVACount;
- fVAPtr = that.fVAPtr;
- fStencilSettings = that.fStencilSettings;
- fCoverage = that.fCoverage;
- fDrawFace = that.fDrawFace;
- fColorStages = that.fColorStages;
- fCoverageStages = that.fCoverageStages;
- fOptSrcBlend = that.fOptSrcBlend;
- fOptDstBlend = that.fOptDstBlend;
- fBlendOptFlags = that.fBlendOptFlags;
-
- memcpy(fFixedFunctionVertexAttribIndices,
- that.fFixedFunctionVertexAttribIndices,
- sizeof(fFixedFunctionVertexAttribIndices));
- return *this;
- }
+ GrDrawState& operator= (const GrDrawState& that);
private:
- void onReset(const SkMatrix* initialViewMatrix) {
- SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages());
- fColorStages.reset();
- fCoverageStages.reset();
-
- fRenderTarget.reset(NULL);
-
- this->setDefaultVertexAttribs();
-
- fColor = 0xffffffff;
- if (NULL == initialViewMatrix) {
- fViewMatrix.reset();
- } else {
- fViewMatrix = *initialViewMatrix;
- }
- fSrcBlend = kOne_GrBlendCoeff;
- fDstBlend = kZero_GrBlendCoeff;
- fBlendConstant = 0x0;
- fFlagBits = 0x0;
- fStencilSettings.setDisabled();
- fCoverage = 0xffffffff;
- fDrawFace = kBoth_DrawFace;
-
- this->invalidateBlendOptFlags();
- }
+ void onReset(const SkMatrix* initialViewMatrix);
BlendOptFlags calcBlendOpts(bool forceCoverage = false,
GrBlendCoeff* srcCoeff = NULL,