Make it explicit that some validate methods are debug only
https://codereview.chromium.org/25716003/
git-svn-id: http://skia.googlecode.com/svn/trunk@11575 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/core/SkPathRef.h b/include/core/SkPathRef.h
index 2c5086a..97643d6 100644
--- a/include/core/SkPathRef.h
+++ b/include/core/SkPathRef.h
@@ -64,7 +64,7 @@
* return value is a pointer to where the points for the verb should be written.
*/
SkPoint* growForVerb(int /*SkPath::Verb*/ verb) {
- fPathRef->validate();
+ SkDEBUGCODE(fPathRef->validate();)
return fPathRef->growForVerb(verb);
}
@@ -78,14 +78,14 @@
void grow(int newVerbs, int newPts, uint8_t** verbs, SkPoint** pts) {
SkASSERT(NULL != verbs);
SkASSERT(NULL != pts);
- fPathRef->validate();
+ SkDEBUGCODE(fPathRef->validate();)
int oldVerbCnt = fPathRef->fVerbCnt;
int oldPointCnt = fPathRef->fPointCnt;
SkASSERT(verbs && pts);
fPathRef->grow(newVerbs, newPts);
*verbs = fPathRef->fVerbs - oldVerbCnt;
*pts = fPathRef->fPoints + oldPointCnt;
- fPathRef->validate();
+ SkDEBUGCODE(fPathRef->validate();)
}
/**
@@ -171,7 +171,7 @@
static void Rewind(SkAutoTUnref<SkPathRef>* pathRef);
virtual ~SkPathRef() {
- this->validate();
+ SkDEBUGCODE(this->validate();)
sk_free(fPoints);
SkDEBUGCODE(fPoints = NULL;)
@@ -183,13 +183,13 @@
SkDEBUGCODE(fEditorsAttached = 0x7777777;)
}
- int countPoints() const { this->validate(); return fPointCnt; }
- int countVerbs() const { this->validate(); return fVerbCnt; }
+ int countPoints() const { SkDEBUGCODE(this->validate();) return fPointCnt; }
+ int countVerbs() const { SkDEBUGCODE(this->validate();) return fVerbCnt; }
/**
* Returns a pointer one beyond the first logical verb (last verb in memory order).
*/
- const uint8_t* verbs() const { this->validate(); return fVerbs; }
+ const uint8_t* verbs() const { SkDEBUGCODE(this->validate();) return fVerbs; }
/**
* Returns a const pointer to the first verb in memory (which is the last logical verb).
@@ -199,15 +199,15 @@
/**
* Returns a const pointer to the first point.
*/
- const SkPoint* points() const { this->validate(); return fPoints; }
+ const SkPoint* points() const { SkDEBUGCODE(this->validate();) return fPoints; }
/**
* Shortcut for this->points() + this->countPoints()
*/
const SkPoint* pointsEnd() const { return this->points() + this->countPoints(); }
- const SkScalar* conicWeights() const { this->validate(); return fConicWeights.begin(); }
- const SkScalar* conicWeightsEnd() const { this->validate(); return fConicWeights.end(); }
+ const SkScalar* conicWeights() const { SkDEBUGCODE(this->validate();) return fConicWeights.begin(); }
+ const SkScalar* conicWeightsEnd() const { SkDEBUGCODE(this->validate();) return fConicWeights.end(); }
/**
* Convenience methods for getting to a verb or point by index.
@@ -247,7 +247,7 @@
fFreeSpace = 0;
fGenerationID = kEmptyGenID;
SkDEBUGCODE(fEditorsAttached = 0;)
- this->validate();
+ SkDEBUGCODE(this->validate();)
}
void copy(const SkPathRef& ref, int additionalReserveVerbs, int additionalReservePoints);
@@ -274,10 +274,10 @@
/** Makes additional room but does not change the counts or change the genID */
void incReserve(int additionalVerbs, int additionalPoints) {
- this->validate();
+ SkDEBUGCODE(this->validate();)
size_t space = additionalVerbs * sizeof(uint8_t) + additionalPoints * sizeof (SkPoint);
this->makeSpace(space);
- this->validate();
+ SkDEBUGCODE(this->validate();)
}
/** Resets the path ref with verbCount verbs and pointCount points, all uninitialized. Also
@@ -290,14 +290,14 @@
* are uninitialized.
*/
void grow(int newVerbs, int newPoints) {
- this->validate();
+ SkDEBUGCODE(this->validate();)
size_t space = newVerbs * sizeof(uint8_t) + newPoints * sizeof (SkPoint);
this->makeSpace(space);
fVerbCnt += newVerbs;
fPointCnt += newPoints;
fFreeSpace -= space;
fBoundsIsDirty = true; // this also invalidates fIsFinite
- this->validate();
+ SkDEBUGCODE(this->validate();)
}
/**
@@ -317,7 +317,7 @@
* Private, non-const-ptr version of the public function verbsMemBegin().
*/
uint8_t* verbsMemWritable() {
- this->validate();
+ SkDEBUGCODE(this->validate();)
return fVerbs - fVerbCnt;
}
@@ -336,7 +336,7 @@
*/
int32_t genID() const;
- void validate() const;
+ SkDEBUGCODE(void validate() const;)
enum {
kMinSize = 256,
diff --git a/include/core/SkRefCnt.h b/include/core/SkRefCnt.h
index 35f7349..d6120d6 100644
--- a/include/core/SkRefCnt.h
+++ b/include/core/SkRefCnt.h
@@ -79,9 +79,11 @@
}
}
+#ifdef SK_DEBUG
void validate() const {
SkASSERT(fRefCnt > 0);
}
+#endif
/**
* Alias for unref(), for compatibility with WTF::RefPtr.
diff --git a/include/core/SkWeakRefCnt.h b/include/core/SkWeakRefCnt.h
index e6871fe..0102cbb 100644
--- a/include/core/SkWeakRefCnt.h
+++ b/include/core/SkWeakRefCnt.h
@@ -73,10 +73,12 @@
*/
int32_t getWeakCnt() const { return fWeakCnt; }
+#ifdef SK_DEBUG
void validate() const {
- SkRefCnt::validate();
+ this->INHERITED::validate();
SkASSERT(fWeakCnt > 0);
}
+#endif
/** Creates a strong reference from a weak reference, if possible. The
caller must already be an owner. If try_ref() returns true the owner
diff --git a/include/gpu/GrTexture.h b/include/gpu/GrTexture.h
index 4fe1894..e56f6f4 100644
--- a/include/gpu/GrTexture.h
+++ b/include/gpu/GrTexture.h
@@ -126,9 +126,8 @@
this->validateDesc();
}
-#else
- void validate() const {}
#endif
+
static GrResourceKey ComputeKey(const GrGpu* gpu,
const GrTextureParams* params,
const GrTextureDesc& desc,
diff --git a/src/core/SkPathRef.cpp b/src/core/SkPathRef.cpp
index dd18793..08cc4cb 100644
--- a/src/core/SkPathRef.cpp
+++ b/src/core/SkPathRef.cpp
@@ -29,7 +29,7 @@
}
SkPoint* SkPathRef::Editor::growForConic(SkScalar w) {
- fPathRef->validate();
+ SkDEBUGCODE(fPathRef->validate();)
SkPoint* pts = fPathRef->growForVerb(SkPath::kConic_Verb);
*fPathRef->fConicWeights.append() = w;
return pts;
@@ -39,12 +39,12 @@
void SkPathRef::CreateTransformedCopy(SkAutoTUnref<SkPathRef>* dst,
const SkPathRef& src,
const SkMatrix& matrix) {
- src.validate();
+ SkDEBUGCODE(src.validate();)
if (matrix.isIdentity()) {
if (*dst != &src) {
src.ref();
dst->reset(const_cast<SkPathRef*>(&src));
- (*dst)->validate();
+ SkDEBUGCODE((*dst)->validate();)
}
return;
}
@@ -87,7 +87,7 @@
(*dst)->fBoundsIsDirty = true;
}
- (*dst)->validate();
+ SkDEBUGCODE((*dst)->validate();)
}
SkPathRef* SkPathRef::CreateFromBuffer(SkRBuffer* buffer
@@ -127,14 +127,14 @@
void SkPathRef::Rewind(SkAutoTUnref<SkPathRef>* pathRef) {
if ((*pathRef)->unique()) {
- (*pathRef)->validate();
+ SkDEBUGCODE((*pathRef)->validate();)
(*pathRef)->fBoundsIsDirty = true; // this also invalidates fIsFinite
(*pathRef)->fVerbCnt = 0;
(*pathRef)->fPointCnt = 0;
(*pathRef)->fFreeSpace = (*pathRef)->currSize();
(*pathRef)->fGenerationID = 0;
(*pathRef)->fConicWeights.rewind();
- (*pathRef)->validate();
+ SkDEBUGCODE((*pathRef)->validate();)
} else {
int oldVCnt = (*pathRef)->countVerbs();
int oldPCnt = (*pathRef)->countPoints();
@@ -144,8 +144,8 @@
}
bool SkPathRef::operator== (const SkPathRef& ref) const {
- this->validate();
- ref.validate();
+ SkDEBUGCODE(this->validate();)
+ SkDEBUGCODE(ref.validate();)
bool genIDMatch = fGenerationID && fGenerationID == ref.fGenerationID;
#ifdef SK_RELEASE
if (genIDMatch) {
@@ -184,7 +184,7 @@
}
void SkPathRef::writeToBuffer(SkWBuffer* buffer) {
- this->validate();
+ SkDEBUGCODE(this->validate();)
SkDEBUGCODE(size_t beforePos = buffer->pos();)
// Call getBounds() to ensure (as a side-effect) that fBounds
@@ -219,7 +219,7 @@
void SkPathRef::copy(const SkPathRef& ref,
int additionalReserveVerbs,
int additionalReservePoints) {
- this->validate();
+ SkDEBUGCODE(this->validate();)
this->resetToSize(ref.fVerbCnt, ref.fPointCnt, ref.fConicWeights.count(),
additionalReserveVerbs, additionalReservePoints);
memcpy(this->verbsMemWritable(), ref.verbsMemBegin(), ref.fVerbCnt * sizeof(uint8_t));
@@ -233,12 +233,12 @@
fBounds = ref.fBounds;
fIsFinite = ref.fIsFinite;
}
- this->validate();
+ SkDEBUGCODE(this->validate();)
}
void SkPathRef::resetToSize(int verbCount, int pointCount, int conicCount,
int reserveVerbs, int reservePoints) {
- this->validate();
+ SkDEBUGCODE(this->validate();)
fBoundsIsDirty = true; // this also invalidates fIsFinite
fGenerationID = 0;
@@ -265,11 +265,11 @@
fFreeSpace = this->currSize() - minSize;
}
fConicWeights.setCount(conicCount);
- this->validate();
+ SkDEBUGCODE(this->validate();)
}
SkPoint* SkPathRef::growForVerb(int /* SkPath::Verb*/ verb) {
- this->validate();
+ SkDEBUGCODE(this->validate();)
int pCnt;
switch (verb) {
case SkPath::kMove_Verb:
@@ -304,12 +304,12 @@
fPointCnt += pCnt;
fFreeSpace -= space;
fBoundsIsDirty = true; // this also invalidates fIsFinite
- this->validate();
+ SkDEBUGCODE(this->validate();)
return ret;
}
void SkPathRef::makeSpace(size_t size) {
- this->validate();
+ SkDEBUGCODE(this->validate();)
ptrdiff_t growSize = size - fFreeSpace;
if (growSize <= 0) {
return;
@@ -336,7 +336,7 @@
memmove(newVerbsDst, oldVerbsSrc, oldVerbSize);
fVerbs = reinterpret_cast<uint8_t*>(reinterpret_cast<intptr_t>(fPoints) + newSize);
fFreeSpace += growSize;
- this->validate();
+ SkDEBUGCODE(this->validate();)
}
int32_t SkPathRef::genID() const {
@@ -356,7 +356,9 @@
return fGenerationID;
}
+#ifdef SK_DEBUG
void SkPathRef::validate() const {
+ this->INHERITED::validate();
SkASSERT(static_cast<ptrdiff_t>(fFreeSpace) >= 0);
SkASSERT(reinterpret_cast<intptr_t>(fVerbs) - reinterpret_cast<intptr_t>(fPoints) >= 0);
SkASSERT((NULL == fPoints) == (NULL == fVerbs));
@@ -381,3 +383,4 @@
}
#endif
}
+#endif
diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp
index 80822a1..96a5560 100644
--- a/tests/SurfaceTest.cpp
+++ b/tests/SurfaceTest.cpp
@@ -209,22 +209,22 @@
SkSurface* surface = createSurface(surfaceType, context);
SkAutoTUnref<SkSurface> aur_surface(surface);
surface->notifyContentWillChange(mode);
- surface->validate();
+ SkDEBUGCODE(surface->validate();)
}
{
SkSurface* surface = createSurface(surfaceType, context);
SkAutoTUnref<SkSurface> aur_surface(surface);
SkImage* image1 = surface->newImageSnapshot();
SkAutoTUnref<SkImage> aur_image1(image1);
- image1->validate();
- surface->validate();
+ SkDEBUGCODE(image1->validate();)
+ SkDEBUGCODE(surface->validate();)
surface->notifyContentWillChange(mode);
- image1->validate();
- surface->validate();
+ SkDEBUGCODE(image1->validate();)
+ SkDEBUGCODE(surface->validate();)
SkImage* image2 = surface->newImageSnapshot();
SkAutoTUnref<SkImage> aur_image2(image2);
- image2->validate();
- surface->validate();
+ SkDEBUGCODE(image2->validate();)
+ SkDEBUGCODE(surface->validate();)
REPORTER_ASSERT(reporter, image1 != image2);
}