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

Unified Diff: src/gpu/GrDrawState.h

Issue 25023003: Implement color filter as GrGLEffect (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 7 years, 2 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
« no previous file with comments | « src/gpu/GrContext.cpp ('k') | src/gpu/GrDrawState.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrDrawState.h
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index 6440790c10b1d611e651ea786f97a4b0a008d79e..cb899b5eb3bf254b6f163996d76dd93061a98e7b 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -266,18 +266,6 @@ public:
}
/**
- * Add a color filter that can be represented by a color and a mode. Applied
- * after color-computing effect stages.
- */
- void setColorFilter(GrColor c, SkXfermode::Mode mode) {
- fCommon.fColorFilterColor = c;
- fCommon.fColorFilterMode = mode;
- }
-
- GrColor getColorFilterColor() const { return fCommon.fColorFilterColor; }
- SkXfermode::Mode getColorFilterMode() const { return fCommon.fColorFilterMode; }
-
- /**
* Constructor sets the color to be 'color' which is undone by the destructor.
*/
class AutoColorRestore : public ::SkNoncopyable {
@@ -360,13 +348,13 @@ public:
const GrEffectRef* addColorEffect(const GrEffectRef* effect, int attr0 = -1, int attr1 = -1) {
SkASSERT(NULL != effect);
- SkNEW_APPEND_TO_TARRAY(&fColorStages, GrEffectStage, (effect, attr0, attr1));
+ fColorStages.appendStage(effect, attr0, attr1);
return effect;
}
const GrEffectRef* addCoverageEffect(const GrEffectRef* effect, int attr0 = -1, int attr1 = -1) {
SkASSERT(NULL != effect);
- SkNEW_APPEND_TO_TARRAY(&fCoverageStages, GrEffectStage, (effect, attr0, attr1));
+ fCoverageStages.appendStage(effect, attr0, attr1);
return effect;
}
@@ -403,9 +391,20 @@ public:
*/
class AutoRestoreEffects : public ::SkNoncopyable {
public:
- AutoRestoreEffects() : fDrawState(NULL), fColorEffectCnt(0), fCoverageEffectCnt(0) {}
+ AutoRestoreEffects()
+ : fDrawState(NULL),
+ fFirstEffectiveColorEffect(0),
+ fColorEffectCnt(0),
+ fFirstEffectiveCoverageEffect(0),
+ fCoverageEffectCnt(0) {
+ }
- AutoRestoreEffects(GrDrawState* ds) : fDrawState(NULL), fColorEffectCnt(0), fCoverageEffectCnt(0) {
+ AutoRestoreEffects(GrDrawState* ds)
+ : fDrawState(NULL),
+ fFirstEffectiveColorEffect(0),
+ fColorEffectCnt(0),
+ fFirstEffectiveCoverageEffect(0),
+ fCoverageEffectCnt(0) {
this->set(ds);
}
@@ -415,15 +414,17 @@ public:
if (NULL != fDrawState) {
int n = fDrawState->fColorStages.count() - fColorEffectCnt;
SkASSERT(n >= 0);
- fDrawState->fColorStages.pop_back_n(n);
+ fDrawState->fColorStages.removeLastStages(n, fFirstEffectiveColorEffect);
n = fDrawState->fCoverageStages.count() - fCoverageEffectCnt;
SkASSERT(n >= 0);
- fDrawState->fCoverageStages.pop_back_n(n);
+ fDrawState->fCoverageStages.removeLastStages(n, fFirstEffectiveCoverageEffect);
SkDEBUGCODE(--fDrawState->fBlockEffectRemovalCnt;)
}
fDrawState = ds;
if (NULL != ds) {
+ fFirstEffectiveColorEffect = ds->fColorStages.getFirstEffectiveStageIndex();
fColorEffectCnt = ds->fColorStages.count();
+ fFirstEffectiveCoverageEffect = ds->fCoverageStages.getFirstEffectiveStageIndex();
fCoverageEffectCnt = ds->fCoverageStages.count();
SkDEBUGCODE(++ds->fBlockEffectRemovalCnt;)
}
@@ -431,16 +432,20 @@ public:
private:
GrDrawState* fDrawState;
+ int fFirstEffectiveColorEffect;
int fColorEffectCnt;
+ int fFirstEffectiveCoverageEffect;
int fCoverageEffectCnt;
};
- int numColorStages() const { return fColorStages.count(); }
- int numCoverageStages() const { return fCoverageStages.count(); }
- int numTotalStages() const { return this->numColorStages() + this->numCoverageStages(); }
+ int totalStageCount() const { return fColorStages.count() + fCoverageStages.count(); }
+
+ int effectiveColorStageCount() const { return fColorStages.effectiveStageCount(); }
+ int effectiveCoverageStageCount() const { return fCoverageStages.effectiveStageCount(); }
+ int totalEffectiveStageCount() const { return this->effectiveColorStageCount() + this->effectiveCoverageStageCount(); }
- const GrEffectStage& getColorStage(int stageIdx) const { return fColorStages[stageIdx]; }
- const GrEffectStage& getCoverageStage(int stageIdx) const { return fCoverageStages[stageIdx]; }
+ const GrEffectStage& getEffectiveColorStage(int stageIdx) const { return fColorStages.getEffectiveStage(stageIdx); }
+ const GrEffectStage& getEffectiveCoverageStage(int stageIdx) const { return fCoverageStages.getEffectiveStage(stageIdx); }
/**
* Checks whether any of the effects will read the dst pixel color.
@@ -884,18 +889,19 @@ public:
bool operator !=(const GrDrawState& s) const { return !(*this == s); }
GrDrawState& operator= (const GrDrawState& s) {
- SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages());
+ SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->totalStageCount());
this->setRenderTarget(s.fRenderTarget.get());
fCommon = s.fCommon;
fColorStages = s.fColorStages;
fCoverageStages = s.fCoverageStages;
+
return *this;
}
private:
void onReset(const SkMatrix* initialViewMatrix) {
- SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->numTotalStages());
+ SkASSERT(0 == fBlockEffectRemovalCnt || 0 == this->totalStageCount());
fColorStages.reset();
fCoverageStages.reset();
@@ -915,8 +921,6 @@ private:
fCommon.fFlagBits = 0x0;
fCommon.fStencilSettings.setDisabled();
fCommon.fCoverage = 0xffffffff;
- fCommon.fColorFilterMode = SkXfermode::kDst_Mode;
- fCommon.fColorFilterColor = 0x0;
fCommon.fDrawFace = kBoth_DrawFace;
}
@@ -933,8 +937,6 @@ private:
int fVACount;
GrStencilSettings fStencilSettings;
GrColor fCoverage;
- SkXfermode::Mode fColorFilterMode;
- GrColor fColorFilterColor;
DrawFace fDrawFace;
// This is simply a different representation of info in fVertexAttribs and thus does
@@ -952,8 +954,6 @@ private:
!memcmp(fVAPtr, other.fVAPtr, fVACount * sizeof(GrVertexAttrib)) &&
fStencilSettings == other.fStencilSettings &&
fCoverage == other.fCoverage &&
- fColorFilterMode == other.fColorFilterMode &&
- fColorFilterColor == other.fColorFilterColor &&
fDrawFace == other.fDrawFace;
SkASSERT(!result || 0 == memcmp(fFixedFunctionVertexAttribIndices,
other.fFixedFunctionVertexAttribIndices,
@@ -1012,13 +1012,12 @@ public:
// reinflate color/cov stage arrays.
drawState->fColorStages.reset();
for (int i = 0; i < fColorStageCnt; ++i) {
- SkNEW_APPEND_TO_TARRAY(&drawState->fColorStages, GrEffectStage, (fStages[i]));
+ drawState->fColorStages.appendStage(fStages[i]);
}
int coverageStageCnt = fStages.count() - fColorStageCnt;
drawState->fCoverageStages.reset();
for (int i = 0; i < coverageStageCnt; ++i) {
- SkNEW_APPEND_TO_TARRAY(&drawState->fCoverageStages,
- GrEffectStage, (fStages[i + fColorStageCnt]));
+ drawState->fCoverageStages.appendStage(fStages[i + fColorStageCnt]);
}
}
@@ -1061,7 +1060,59 @@ private:
SkAutoTUnref<GrRenderTarget> fRenderTarget;
CommonState fCommon;
- typedef SkSTArray<4, GrEffectStage> EffectStageArray;
+ class EffectStageArray {
bsalomon 2013/10/07 14:05:00 It seems like we'd be adding a fair amount of comp
Kimmo Kinnunen 2013/10/10 08:12:29 Done.
+ public:
+ EffectStageArray()
+ : fFirstEffectiveStage(0) {
+ }
+
+ int getFirstEffectiveStageIndex() const { return fFirstEffectiveStage; }
+
+ const GrEffectStage& getEffectiveStage(int i) const { return fArray[i + fFirstEffectiveStage]; }
+
+ int effectiveStageCount() const { return fArray.count() - fFirstEffectiveStage; }
+
+ void appendStage(const GrEffectRef* effect, int attr0, int attr1) {
+ GrEffectStage* newStage = SkNEW_APPEND_TO_TARRAY(&fArray, GrEffectStage, (effect, attr0, attr1));
+ if (!(*newStage->getEffect())->willUseInputColor()) {
+ fFirstEffectiveStage = fArray.count() - 1;
+ }
+ }
+
+ void appendStage(const GrEffectStage::DeferredStage& effect) {
+ GrEffectStage* newStage = SkNEW_APPEND_TO_TARRAY(&fArray, GrEffectStage, (effect));
+ if (!(*newStage->getEffect())->willUseInputColor()) {
+ fFirstEffectiveStage = fArray.count() - 1;
+ }
+ }
+
+ void appendStage(const GrEffectStage& effect) {
+ GrEffectStage& newStage = fArray.push_back(effect);
+ if (!(*newStage.getEffect())->willUseInputColor()) {
+ fFirstEffectiveStage = fArray.count() - 1;
+ }
+ }
+
+ void removeLastStages(int n, int newFirstEffectiveStage) {
+ fArray.pop_back_n(n);
+ fFirstEffectiveStage = newFirstEffectiveStage;
+ }
+
+ const GrEffectStage& operator[](int i) const { return fArray[i]; }
+ GrEffectStage& operator[](int i) { return fArray[i]; }
+
+ void reset() {
+ fArray.reset();
+ fFirstEffectiveStage = 0;
+ }
+
+ int count() const { return fArray.count(); }
+
+ private:
+ SkSTArray<4, GrEffectStage> fArray;
+ int fFirstEffectiveStage;
+ };
+
EffectStageArray fColorStages;
EffectStageArray fCoverageStages;
« no previous file with comments | « src/gpu/GrContext.cpp ('k') | src/gpu/GrDrawState.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698