minor improvement, remove some conditionals in GrAAConvexPathRenderer
Review URL: http://codereview.appspot.com/5728060
git-svn-id: http://skia.googlecode.com/svn/trunk@3316 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/include/gpu/GrPaint.h b/include/gpu/GrPaint.h
index 9f220e0..827b890 100644
--- a/include/gpu/GrPaint.h
+++ b/include/gpu/GrPaint.h
@@ -172,7 +172,6 @@
void resetColorFilter() {
fColorFilterXfermode = SkXfermode::kDst_Mode;
fColorFilterColor = GrColorPackRGBA(0xff, 0xff, 0xff, 0xff);
- memset(fColorMatrix, 0, sizeof(fColorMatrix));
fColorMatrixEnabled = false;
}
diff --git a/src/gpu/GrAAConvexPathRenderer.cpp b/src/gpu/GrAAConvexPathRenderer.cpp
index 60749d8..657dfc1 100644
--- a/src/gpu/GrAAConvexPathRenderer.cpp
+++ b/src/gpu/GrAAConvexPathRenderer.cpp
@@ -22,9 +22,11 @@
struct Segment {
enum {
- kLine,
- kQuad
+ // These enum values are assumed in member functions below.
+ kLine = 0,
+ kQuad = 1,
} fType;
+
// line uses one pt, quad uses 2 pts
GrPoint fPts[2];
// normal to edge ending at each pt
@@ -34,13 +36,16 @@
GrVec fMid;
int countPoints() {
- return (kLine == fType) ? 1 : 2;
+ GR_STATIC_ASSERT(0 == kLine && 1 == kQuad);
+ return fType + 1;
}
const SkPoint& endPt() const {
- return (kLine == fType) ? fPts[0] : fPts[1];
+ GR_STATIC_ASSERT(0 == kLine && 1 == kQuad);
+ return fPts[fType];
};
const SkPoint& endNorm() const {
- return (kLine == fType) ? fNorms[0] : fNorms[1];
+ GR_STATIC_ASSERT(0 == kLine && 1 == kQuad);
+ return fNorms[fType];
};
};
diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp
index 2a12399..2c4a131 100644
--- a/src/gpu/GrContext.cpp
+++ b/src/gpu/GrContext.cpp
@@ -1839,12 +1839,12 @@
}
if (paint.fColorMatrixEnabled) {
drawState->enableState(GrDrawState::kColorMatrix_StateBit);
+ drawState->setColorMatrix(paint.fColorMatrix);
} else {
drawState->disableState(GrDrawState::kColorMatrix_StateBit);
}
drawState->setBlendFunc(paint.fSrcBlendCoeff, paint.fDstBlendCoeff);
drawState->setColorFilter(paint.fColorFilterColor, paint.fColorFilterXfermode);
- drawState->setColorMatrix(paint.fColorMatrix);
drawState->setCoverage(paint.fCoverage);
if (paint.getActiveMaskStageMask() && !target->canApplyCoverage()) {
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index 18dd6bf..7350f0f 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -749,6 +749,13 @@
return false;
}
}
+ if (kColorMatrix_StateBit & s.fFlagBits) {
+ if (memcmp(fColorMatrix,
+ s.fColorMatrix,
+ sizeof(fColorMatrix))) {
+ return false;
+ }
+ }
return true;
}
@@ -765,6 +772,9 @@
sizeof(GrSamplerState));
}
}
+ if (kColorMatrix_StateBit & s.fFlagBits) {
+ memcpy(this->fColorMatrix, s.fColorMatrix, sizeof(fColorMatrix));
+ }
return *this;
}
@@ -779,7 +789,6 @@
DrawFace fDrawFace;
VertexEdgeType fVertexEdgeType;
GrStencilSettings fStencilSettings;
- float fColorMatrix[20]; // 5 x 4 matrix
GrRenderTarget* fRenderTarget;
// @}
@@ -803,6 +812,8 @@
// This field must be last; it will not be copied or compared
// if the corresponding fTexture[] is NULL.
GrSamplerState fSamplerStates[kNumStages];
+ // only compared if the color matrix enable flag is set
+ float fColorMatrix[20]; // 5 x 4 matrix
size_t leadingBytes() const {
// Can't use offsetof() with non-POD types, so stuck with pointer math.