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

Unified Diff: include/gpu/GrEffectStage.h

Issue 18295008: Remove possiblity of NULL effect in GrEffectStage (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: wrap line Created 7 years, 5 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 | « no previous file | src/gpu/GrDrawState.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/gpu/GrEffectStage.h
diff --git a/include/gpu/GrEffectStage.h b/include/gpu/GrEffectStage.h
index 3f10bdcf1e22a1d1363df54b34fc8f03f01f34ac..08fb159260750682af680bf85aed11cef2dd3d58 100644
--- a/include/gpu/GrEffectStage.h
+++ b/include/gpu/GrEffectStage.h
@@ -20,14 +20,8 @@
class GrEffectStage {
public:
- GrEffectStage() {
- fCoordChangeMatrixSet = false;
- fVertexAttribIndices[0] = -1;
- fVertexAttribIndices[1] = -1;
- }
jvanverth1 2013/07/15 13:20:02 You may want to make the default constructor priva
bsalomon 2013/07/15 13:24:53 Since we have other constructors, there is no auto
-
explicit GrEffectStage(const GrEffectRef* effectRef, int attrIndex0 = -1, int attrIndex1 = -1)
- : fEffectRef(SkSafeRef(effectRef)) {
+ : fEffectRef(SkRef(effectRef)) {
fCoordChangeMatrixSet = false;
fVertexAttribIndices[0] = attrIndex0;
fVertexAttribIndices[1] = attrIndex1;
@@ -37,23 +31,25 @@ public:
*this = other;
}
+ class DeferredStage;
+ // This constructor balances DeferredStage::saveFrom().
+ explicit GrEffectStage(const DeferredStage& deferredStage) {
+ deferredStage.restoreTo(this);
+ }
+
GrEffectStage& operator= (const GrEffectStage& other) {
fCoordChangeMatrixSet = other.fCoordChangeMatrixSet;
if (other.fCoordChangeMatrixSet) {
fCoordChangeMatrix = other.fCoordChangeMatrix;
}
- fEffectRef.reset(SkSafeRef(other.fEffectRef.get()));
+ fEffectRef.reset(SkRef(other.fEffectRef.get()));
memcpy(fVertexAttribIndices, other.fVertexAttribIndices, sizeof(fVertexAttribIndices));
return *this;
}
bool operator== (const GrEffectStage& other) const {
- // first handle cases where one or the other has no effect
- if (NULL == fEffectRef.get()) {
- return NULL == other.fEffectRef.get();
- } else if (NULL == other.fEffectRef.get()) {
- return false;
- }
+ GrAssert(NULL != fEffectRef.get());
+ GrAssert(NULL != other.fEffectRef.get());
if (!(*this->getEffect())->isEqual(*other.getEffect())) {
return false;
@@ -108,7 +104,7 @@ public:
savedCoordChange->fCoordChangeMatrix = fCoordChangeMatrix;
}
GrAssert(NULL == savedCoordChange->fEffectRef.get());
- GR_DEBUGCODE(GrSafeRef(fEffectRef.get());)
+ GR_DEBUGCODE(SkRef(fEffectRef.get());)
GR_DEBUGCODE(savedCoordChange->fEffectRef.reset(fEffectRef.get());)
}
@@ -142,43 +138,32 @@ public:
void saveFrom(const GrEffectStage& stage) {
GrAssert(!fInitialized);
- if (NULL != stage.fEffectRef.get()) {
- stage.fEffectRef->get()->incDeferredRefCounts();
- fEffect = stage.fEffectRef->get();
- fCoordChangeMatrixSet = stage.fCoordChangeMatrixSet;
- if (fCoordChangeMatrixSet) {
- fCoordChangeMatrix = stage.fCoordChangeMatrix;
- }
- fVertexAttribIndices[0] = stage.fVertexAttribIndices[0];
- fVertexAttribIndices[1] = stage.fVertexAttribIndices[1];
+ GrAssert(NULL != stage.fEffectRef.get());
+ stage.fEffectRef->get()->incDeferredRefCounts();
+ fEffect = stage.fEffectRef->get();
+ fCoordChangeMatrixSet = stage.fCoordChangeMatrixSet;
+ if (fCoordChangeMatrixSet) {
+ fCoordChangeMatrix = stage.fCoordChangeMatrix;
}
+ fVertexAttribIndices[0] = stage.fVertexAttribIndices[0];
+ fVertexAttribIndices[1] = stage.fVertexAttribIndices[1];
SkDEBUGCODE(fInitialized = true;)
}
- void restoreTo(GrEffectStage* stage) {
+ void restoreTo(GrEffectStage* stage) const {
GrAssert(fInitialized);
- if (NULL != fEffect) {
- stage->fEffectRef.reset(GrEffect::CreateEffectRef(fEffect));
- stage->fCoordChangeMatrixSet = fCoordChangeMatrixSet;
- if (fCoordChangeMatrixSet) {
- stage->fCoordChangeMatrix = fCoordChangeMatrix;
- }
- stage->fVertexAttribIndices[0] = fVertexAttribIndices[0];
- stage->fVertexAttribIndices[1] = fVertexAttribIndices[1];
- } else {
- stage->fEffectRef.reset(NULL);
+ stage->fEffectRef.reset(GrEffect::CreateEffectRef(fEffect));
+ stage->fCoordChangeMatrixSet = fCoordChangeMatrixSet;
+ if (fCoordChangeMatrixSet) {
+ stage->fCoordChangeMatrix = fCoordChangeMatrix;
}
+ stage->fVertexAttribIndices[0] = fVertexAttribIndices[0];
+ stage->fVertexAttribIndices[1] = fVertexAttribIndices[1];
}
bool isEqual(const GrEffectStage& stage, bool ignoreCoordChange) const {
- if (NULL == stage.fEffectRef.get()) {
- return NULL == fEffect;
- } else if (NULL == fEffect) {
- return false;
- }
-
- if (fVertexAttribIndices[0] != stage.fVertexAttribIndices[0]
- || fVertexAttribIndices[1] != stage.fVertexAttribIndices[1]) {
+ if (fVertexAttribIndices[0] != stage.fVertexAttribIndices[0] ||
+ fVertexAttribIndices[1] != stage.fVertexAttribIndices[1]) {
return false;
}
@@ -223,18 +208,6 @@ public:
}
}
- void reset() { fEffectRef.reset(NULL); }
-
- const GrEffectRef* setEffect(const GrEffectRef* effect, int attr0 = -1, int attr1 = -1) {
- fEffectRef.reset(SkSafeRef(effect));
- fCoordChangeMatrixSet = false;
-
- fVertexAttribIndices[0] = attr0;
- fVertexAttribIndices[1] = attr1;
-
- return effect;
- }
-
const GrEffectRef* getEffect() const { return fEffectRef.get(); }
const int* getVertexAttribIndices() const { return fVertexAttribIndices; }
« no previous file with comments | « no previous file | src/gpu/GrDrawState.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698