Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Unified Diff: src/gpu/GrDrawState.cpp

Issue 508663002: Create an optimized draw state but not hooked in yet to gpu pipeline (Closed) Base URL: https://skia.googlesource.com/skia.git@drawBase
Patch Set: Review changes Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/gpu/GrDrawState.cpp
diff --git a/src/gpu/GrDrawState.cpp b/src/gpu/GrDrawState.cpp
index a6b3d68238cdc18a20f527c9f7a3dccd5b05b8c9..0c966a824d282914047c09278cf9a7d51e3c6a07 100644
--- a/src/gpu/GrDrawState.cpp
+++ b/src/gpu/GrDrawState.cpp
@@ -6,8 +6,22 @@
*/
#include "GrDrawState.h"
-#include "GrPaint.h"
+
#include "GrDrawTargetCaps.h"
+#include "GrOptDrawState.h"
+#include "GrPaint.h"
+
+//////////////////////////////////////////////////////////////////////////////s
+
+GrOptDrawState* GrDrawState::createOptState() const {
+ if (NULL == fCachedOptState) {
+ fCachedOptState = SkNEW_ARGS(GrOptDrawState, (*this));
+ } else {
+ SkASSERT(GrOptDrawState(*this) == *fCachedOptState);
+ }
+ fCachedOptState->ref();
+ return fCachedOptState;
+}
//////////////////////////////////////////////////////////////////////////////s
@@ -50,7 +64,8 @@ GrDrawState::CombinedState GrDrawState::CombineIfPossible(
//////////////////////////////////////////////////////////////////////////////s
-GrDrawState::GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix) {
+GrDrawState::GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatrix)
+ : fCachedOptState(NULL) {
SkDEBUGCODE(fBlockEffectRemovalCnt = 0;)
*this = state;
if (!preConcatMatrix.isIdentity()) {
@@ -60,7 +75,7 @@ GrDrawState::GrDrawState(const GrDrawState& state, const SkMatrix& preConcatMatr
for (int i = 0; i < this->numCoverageStages(); ++i) {
fCoverageStages[i].localCoordChange(preConcatMatrix);
}
- this->invalidateBlendOptFlags();
+ this->invalidateOptState();
}
}
@@ -87,6 +102,8 @@ GrDrawState& GrDrawState::operator=(const GrDrawState& that) {
fHints = that.fHints;
+ SkRefCnt_SafeAssign(fCachedOptState, that.fCachedOptState);
+
memcpy(fFixedFunctionVertexAttribIndices,
that.fFixedFunctionVertexAttribIndices,
sizeof(fFixedFunctionVertexAttribIndices));
@@ -118,7 +135,7 @@ void GrDrawState::onReset(const SkMatrix* initialViewMatrix) {
fHints = 0;
- this->invalidateBlendOptFlags();
+ this->invalidateOptState();
}
bool GrDrawState::setIdentityViewMatrix() {
@@ -173,7 +190,7 @@ void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRende
this->setBlendFunc(paint.getSrcBlendCoeff(), paint.getDstBlendCoeff());
this->setCoverage(paint.getCoverage());
- this->invalidateBlendOptFlags();
+ this->invalidateOptState();
}
////////////////////////////////////////////////////////////////////////////////
@@ -231,7 +248,7 @@ void GrDrawState::setVertexAttribs(const GrVertexAttrib* attribs, int count) {
overlapCheck |= (mask << offsetShift);
#endif
}
- this->invalidateBlendOptFlags();
+ this->invalidateOptState();
// Positions must be specified.
SkASSERT(-1 != fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding]);
}
@@ -251,7 +268,7 @@ void GrDrawState::setDefaultVertexAttribs() {
0xff,
sizeof(fFixedFunctionVertexAttribIndices));
fFixedFunctionVertexAttribIndices[kPosition_GrVertexAttribBinding] = 0;
- this->invalidateBlendOptFlags();
+ this->invalidateOptState();
}
////////////////////////////////////////////////////////////////////////////////
@@ -273,8 +290,7 @@ bool GrDrawState::couldApplyCoverage(const GrDrawTargetCaps& caps) const {
//////////////////////////////////////////////////////////////////////////////
-GrDrawState::AutoVertexAttribRestore::AutoVertexAttribRestore(
- GrDrawState* drawState) {
+GrDrawState::AutoVertexAttribRestore::AutoVertexAttribRestore(GrDrawState* drawState) {
SkASSERT(NULL != drawState);
fDrawState = drawState;
fVAPtr = drawState->fVAPtr;
@@ -294,7 +310,7 @@ void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) {
SkASSERT(n >= 0);
fDrawState->fCoverageStages.pop_back_n(n);
if (m + n > 0) {
- fDrawState->invalidateBlendOptFlags();
+ fDrawState->invalidateOptState();
}
SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;)
}
@@ -435,6 +451,7 @@ void GrDrawState::AutoViewMatrixRestore::restore() {
for (int s = 0; s < numCoverageStages; ++s, ++i) {
fDrawState->fCoverageStages[s].restoreCoordChange(fSavedCoordChanges[i]);
}
+ fDrawState->invalidateOptState();
fDrawState = NULL;
}
}
@@ -454,6 +471,7 @@ void GrDrawState::AutoViewMatrixRestore::set(GrDrawState* drawState,
this->doEffectCoordChanges(preconcatMatrix);
SkDEBUGCODE(++fDrawState->fBlockEffectRemovalCnt;)
+ drawState->invalidateOptState();
}
bool GrDrawState::AutoViewMatrixRestore::setIdentity(GrDrawState* drawState) {
@@ -467,6 +485,7 @@ bool GrDrawState::AutoViewMatrixRestore::setIdentity(GrDrawState* drawState) {
return true;
}
+ drawState->invalidateOptState();
fViewMatrix = drawState->getViewMatrix();
if (0 == drawState->numTotalStages()) {
drawState->fViewMatrix.reset();
« no previous file with comments | « src/gpu/GrDrawState.h ('k') | src/gpu/GrOptDrawState.h » ('j') | src/gpu/GrOptDrawState.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698