From 9b1517edc7eb3e116902a3b3da447a73aaa56585 Mon Sep 17 00:00:00 2001 From: "bsalomon@google.com" Date: Mon, 5 Mar 2012 17:58:34 +0000 Subject: [PATCH] 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 --- include/gpu/GrPaint.h | 1 - src/gpu/GrAAConvexPathRenderer.cpp | 15 ++++++++++----- src/gpu/GrContext.cpp | 2 +- src/gpu/GrDrawState.h | 13 ++++++++++++- 4 files changed, 23 insertions(+), 8 deletions(-) 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 @@ public: 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 @@ namespace { 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 @@ struct Segment { 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 @@ void GrContext::setPaint(const GrPaint& paint, GrDrawTarget* target) { } 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 @@ struct GrDrawState { return false; } } + if (kColorMatrix_StateBit & s.fFlagBits) { + if (memcmp(fColorMatrix, + s.fColorMatrix, + sizeof(fColorMatrix))) { + return false; + } + } return true; } @@ -765,6 +772,9 @@ struct GrDrawState { sizeof(GrSamplerState)); } } + if (kColorMatrix_StateBit & s.fFlagBits) { + memcpy(this->fColorMatrix, s.fColorMatrix, sizeof(fColorMatrix)); + } return *this; } @@ -779,7 +789,6 @@ private: DrawFace fDrawFace; VertexEdgeType fVertexEdgeType; GrStencilSettings fStencilSettings; - float fColorMatrix[20]; // 5 x 4 matrix GrRenderTarget* fRenderTarget; // @} @@ -803,6 +812,8 @@ private: // 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. -- 2.7.4