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

Unified Diff: src/gpu/GrDrawState.cpp

Issue 794843002: Revert of Remove GP from drawstate, revision of invariant output for GP (Closed) Base URL: https://skia.googlesource.com/skia.git@color-to-gp
Patch Set: Created 6 years 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
« no previous file with comments | « src/gpu/GrDrawState.h ('k') | src/gpu/GrDrawTarget.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrDrawState.cpp
diff --git a/src/gpu/GrDrawState.cpp b/src/gpu/GrDrawState.cpp
index 72ec7a32b555ee45a57348f6a167d6165f6e3c2b..465c10c99ac61a25947978e46ed122362937e9b3 100644
--- a/src/gpu/GrDrawState.cpp
+++ b/src/gpu/GrDrawState.cpp
@@ -14,7 +14,7 @@
#include "GrXferProcessor.h"
#include "effects/GrPorterDuffXferProcessor.h"
-bool GrDrawState::isEqual(const GrDrawState& that, bool explicitLocalCoords) const {
+bool GrDrawState::isEqual(const GrDrawState& that) const {
if (this->getRenderTarget() != that.getRenderTarget() ||
this->fColorStages.count() != that.fColorStages.count() ||
this->fCoverageStages.count() != that.fCoverageStages.count() ||
@@ -25,6 +25,17 @@
return false;
}
+ bool explicitLocalCoords = this->hasLocalCoordAttribute();
+ if (this->hasGeometryProcessor()) {
+ if (!that.hasGeometryProcessor()) {
+ return false;
+ } else if (!this->getGeometryProcessor()->isEqual(*that.getGeometryProcessor())) {
+ return false;
+ }
+ } else if (that.hasGeometryProcessor()) {
+ return false;
+ }
+
if (!this->getXPFactory()->isEqual(*that.getXPFactory())) {
return false;
}
@@ -66,6 +77,7 @@
fFlagBits = that.fFlagBits;
fStencilSettings = that.fStencilSettings;
fDrawFace = that.fDrawFace;
+ fGeometryProcessor.reset(SkSafeRef(that.fGeometryProcessor.get()));
fXPFactory.reset(SkRef(that.getXPFactory()));
fColorStages = that.fColorStages;
fCoverageStages = that.fCoverageStages;
@@ -84,9 +96,10 @@
}
void GrDrawState::onReset(const SkMatrix* initialViewMatrix) {
- SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages());
+ SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages());
fRenderTarget.reset(NULL);
+ fGeometryProcessor.reset(NULL);
fXPFactory.reset(GrPorterDuffXPFactory::Create(SkXfermode::kSrc_Mode));
fColorStages.reset();
fCoverageStages.reset();
@@ -107,10 +120,6 @@
fColorCache = GrColor_ILLEGAL;
fCoverageCache = GrColor_ILLEGAL;
-
- fColorPrimProc = NULL;
- fCoveragePrimProc = NULL;
-
}
bool GrDrawState::setIdentityViewMatrix() {
@@ -132,8 +141,9 @@
}
void GrDrawState::setFromPaint(const GrPaint& paint, const SkMatrix& vm, GrRenderTarget* rt) {
- SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numFragmentStages());
-
+ SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages());
+
+ fGeometryProcessor.reset(NULL);
fColorStages.reset();
fCoverageStages.reset();
@@ -187,7 +197,7 @@
this->isCoverageDrawing(), this->isColorWriteDisabled());
}
-bool GrDrawState::hasSolidCoverage(const GrPrimitiveProcessor* pp) const {
+bool GrDrawState::hasSolidCoverage(GrColor coverage) const {
// If we're drawing coverage directly then coverage is effectively treated as color.
if (this->isCoverageDrawing()) {
return true;
@@ -197,15 +207,15 @@
return false;
}
- this->calcCoverageInvariantOutput(pp);
+ this->calcCoverageInvariantOutput(coverage);
return fCoverageProcInfo.isSolidWhite();
}
//////////////////////////////////////////////////////////////////////////////s
-bool GrDrawState::willEffectReadDstColor(const GrPrimitiveProcessor* pp) const {
- this->calcColorInvariantOutput(pp);
- this->calcCoverageInvariantOutput(pp);
+bool GrDrawState::willEffectReadDstColor(GrColor color, GrColor coverage) const {
+ this->calcColorInvariantOutput(color);
+ this->calcCoverageInvariantOutput(coverage);
// TODO: Remove need to create the XP here.
// Also once all custom blends are turned into XPs we can remove the need
// to check other stages since only xp's will be able to read dst
@@ -225,6 +235,15 @@
void GrDrawState::AutoRestoreEffects::set(GrDrawState* ds) {
if (fDrawState) {
+ // See the big comment on the class definition about GPs.
+ if (SK_InvalidUniqueID == fOriginalGPID) {
+ fDrawState->fGeometryProcessor.reset(NULL);
+ } else {
+ SkASSERT(fDrawState->getGeometryProcessor()->getUniqueID() ==
+ fOriginalGPID);
+ fOriginalGPID = SK_InvalidUniqueID;
+ }
+
int m = fDrawState->numColorStages() - fColorEffectCnt;
SkASSERT(m >= 0);
fDrawState->fColorStages.pop_back_n(m);
@@ -240,6 +259,10 @@
}
fDrawState = ds;
if (NULL != ds) {
+ SkASSERT(SK_InvalidUniqueID == fOriginalGPID);
+ if (NULL != ds->getGeometryProcessor()) {
+ fOriginalGPID = ds->getGeometryProcessor()->getUniqueID();
+ }
fColorEffectCnt = ds->numColorStages();
fCoverageEffectCnt = ds->numCoverageStages();
SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;)
@@ -349,35 +372,38 @@
////////////////////////////////////////////////////////////////////////////////
-bool GrDrawState::willBlendWithDst(const GrPrimitiveProcessor* pp) const {
- this->calcColorInvariantOutput(pp);
- this->calcCoverageInvariantOutput(pp);
+bool GrDrawState::srcAlphaWillBeOne(GrColor color, GrColor coverage) const {
+ this->calcColorInvariantOutput(color);
+ if (this->isCoverageDrawing()) {
+ this->calcCoverageInvariantOutput(coverage);
+ return (fColorProcInfo.isOpaque() && fCoverageProcInfo.isOpaque());
+ }
+ return fColorProcInfo.isOpaque();
+}
+
+bool GrDrawState::willBlendWithDst(GrColor color, GrColor coverage) const {
+ this->calcColorInvariantOutput(color);
+ this->calcCoverageInvariantOutput(coverage);
return fXPFactory->willBlendWithDst(fColorProcInfo, fCoverageProcInfo,
this->isCoverageDrawing(), this->isColorWriteDisabled());
}
-void GrDrawState::calcColorInvariantOutput(const GrPrimitiveProcessor* pp) const {
- if (!fColorProcInfoValid || fColorPrimProc != pp) {
- fColorProcInfo.calcColorWithPrimProc(pp, fColorStages.begin(), this->numColorStages());
- fColorProcInfoValid = true;
- fColorPrimProc = pp;
- }
-}
-
-void GrDrawState::calcCoverageInvariantOutput(const GrPrimitiveProcessor* pp) const {
- if (!fCoverageProcInfoValid || fCoveragePrimProc != pp) {
- fCoverageProcInfo.calcCoverageWithPrimProc(pp, fCoverageStages.begin(),
- this->numCoverageStages());
- fCoverageProcInfoValid = true;
- fCoveragePrimProc = pp;
- }
-}
-
void GrDrawState::calcColorInvariantOutput(GrColor color) const {
if (!fColorProcInfoValid || color != fColorCache) {
- GrColorComponentFlags flags = kRGBA_GrColorComponentFlags;
- fColorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColorStages(), color,
- flags, false);
+ GrColorComponentFlags flags;
+ if (this->hasColorVertexAttribute()) {
+ if (fHints & kVertexColorsAreOpaque_Hint) {
+ flags = kA_GrColorComponentFlag;
+ color = 0xFF << GrColor_SHIFT_A;
+ } else {
+ flags = static_cast<GrColorComponentFlags>(0);
+ color = 0;
+ }
+ } else {
+ flags = kRGBA_GrColorComponentFlags;
+ }
+ fColorProcInfo.calcWithInitialValues(fColorStages.begin(), this->numColorStages(),
+ color, flags, false);
fColorProcInfoValid = true;
fColorCache = color;
}
@@ -385,10 +411,16 @@
void GrDrawState::calcCoverageInvariantOutput(GrColor coverage) const {
if (!fCoverageProcInfoValid || coverage != fCoverageCache) {
- GrColorComponentFlags flags = kRGBA_GrColorComponentFlags;
- fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(),
- this->numCoverageStages(), coverage, flags,
- true);
+ GrColorComponentFlags flags;
+ // Check if per-vertex or constant color may have partial alpha
+ if (this->hasCoverageVertexAttribute()) {
+ flags = static_cast<GrColorComponentFlags>(0);
+ coverage = 0;
+ } else {
+ flags = kRGBA_GrColorComponentFlags;
+ }
+ fCoverageProcInfo.calcWithInitialValues(fCoverageStages.begin(), this->numCoverageStages(),
+ coverage, flags, true, fGeometryProcessor.get());
fCoverageProcInfoValid = true;
fCoverageCache = coverage;
}
« no previous file with comments | « src/gpu/GrDrawState.h ('k') | src/gpu/GrDrawTarget.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698