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
This commit is contained in:
parent
e90c900ed7
commit
8f72733994
@ -8,6 +8,124 @@
|
|||||||
#include "GrDrawState.h"
|
#include "GrDrawState.h"
|
||||||
#include "GrPaint.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() {
|
bool GrDrawState::setIdentityViewMatrix() {
|
||||||
if (fColorStages.count() || fCoverageStages.count()) {
|
if (fColorStages.count() || fCoverageStages.count()) {
|
||||||
SkMatrix invVM;
|
SkMatrix invVM;
|
||||||
@ -411,6 +529,40 @@ bool GrDrawState::canIgnoreColorAttribute() const {
|
|||||||
GrDrawState::kEmitCoverage_BlendOptFlag));
|
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;)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -49,19 +49,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Copies another draw state with a preconcat to the view matrix.
|
* Copies another draw state with a preconcat to the view matrix.
|
||||||
**/
|
**/
|
||||||
GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix) {
|
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~GrDrawState() { SkASSERT(0 == fBlockEffectRemovalCnt); }
|
virtual ~GrDrawState() { SkASSERT(0 == fBlockEffectRemovalCnt); }
|
||||||
|
|
||||||
@ -151,17 +139,9 @@ public:
|
|||||||
*/
|
*/
|
||||||
class AutoVertexAttribRestore {
|
class AutoVertexAttribRestore {
|
||||||
public:
|
public:
|
||||||
AutoVertexAttribRestore(GrDrawState* drawState) {
|
AutoVertexAttribRestore(GrDrawState* drawState);
|
||||||
SkASSERT(NULL != drawState);
|
|
||||||
fDrawState = drawState;
|
|
||||||
fVAPtr = drawState->fVAPtr;
|
|
||||||
fVACount = drawState->fVACount;
|
|
||||||
fDrawState->setDefaultVertexAttribs();
|
|
||||||
}
|
|
||||||
|
|
||||||
~AutoVertexAttribRestore(){
|
~AutoVertexAttribRestore() { fDrawState->setVertexAttribs(fVAPtr, fVACount); }
|
||||||
fDrawState->setVertexAttribs(fVAPtr, fVACount);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
GrDrawState* fDrawState;
|
GrDrawState* fDrawState;
|
||||||
@ -169,64 +149,6 @@ public:
|
|||||||
int fVACount;
|
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); }
|
~AutoRestoreEffects() { this->set(NULL); }
|
||||||
|
|
||||||
void set(GrDrawState* ds) {
|
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;)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isSet() const { return NULL != fDrawState; }
|
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
|
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
|
if draws can be batched. The return value indicates whether combining is possible and, if
|
||||||
so, which of the two inputs should be used. */
|
so, which of the two inputs should be used. */
|
||||||
static CombinedState CombineIfPossible(const GrDrawState& a, const GrDrawState& b) {
|
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() ||
|
GrDrawState& operator= (const GrDrawState& that);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void onReset(const SkMatrix* initialViewMatrix) {
|
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
BlendOptFlags calcBlendOpts(bool forceCoverage = false,
|
BlendOptFlags calcBlendOpts(bool forceCoverage = false,
|
||||||
GrBlendCoeff* srcCoeff = NULL,
|
GrBlendCoeff* srcCoeff = NULL,
|
||||||
|
Loading…
Reference in New Issue
Block a user