diff options
author | kkinnunen <kkinnunen@nvidia.com> | 2015-05-18 23:02:07 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-05-18 23:02:07 -0700 |
commit | 50b58e6fbcc50785ceffacb2c51b22c6e67a7ab7 (patch) | |
tree | 90e4c1dbf12534523f1f7e8a1cece158bd58cb45 /src/gpu/GrStrokeInfo.cpp | |
parent | 54b8511189bb5da6bfd248fa63f5c4156e9e2bd6 (diff) |
Improve caching of dashed paths in GrStencilAndCoverPathRenderer
Improve caching of dashed paths in GrStencilAndCoverPathRenderer.
Look up the (NVPR specific) GrGLPath based on GrStrokeInfo and
the original path.
Use unique keys for all GrPaths.
Dash the path with Skia dash stroker and use that path geometry for
NVPR path.
NVPR internal dashing stroke is not used, because the dashing
implementation of NVPR does not match Skia implementation.
Review URL: https://codereview.chromium.org/1116123003
Diffstat (limited to 'src/gpu/GrStrokeInfo.cpp')
-rw-r--r-- | src/gpu/GrStrokeInfo.cpp | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/src/gpu/GrStrokeInfo.cpp b/src/gpu/GrStrokeInfo.cpp index eb3008bb37..0ad4179add 100644 --- a/src/gpu/GrStrokeInfo.cpp +++ b/src/gpu/GrStrokeInfo.cpp @@ -6,7 +6,7 @@ */ #include "GrStrokeInfo.h" - +#include "GrResourceKey.h" #include "SkDashPathPriv.h" bool GrStrokeInfo::applyDashToPath(SkPath* dst, GrStrokeInfo* dstStrokeInfo, @@ -24,3 +24,55 @@ bool GrStrokeInfo::applyDashToPath(SkPath* dst, GrStrokeInfo* dstStrokeInfo, } return false; } + +void GrStrokeInfo::asUniqueKeyFragment(uint32_t* data) const { + const int kSkScalarData32Cnt = sizeof(SkScalar) / sizeof(uint32_t); + enum { + kStyleBits = 2, + kJoinBits = 2, + kCapBits = 32 - kStyleBits - kJoinBits, + + kJoinShift = kStyleBits, + kCapShift = kJoinShift + kJoinBits, + }; + + SK_COMPILE_ASSERT(SkStrokeRec::kStyleCount <= (1 << kStyleBits), style_shift_will_be_wrong); + SK_COMPILE_ASSERT(SkPaint::kJoinCount <= (1 << kJoinBits), cap_shift_will_be_wrong); + SK_COMPILE_ASSERT(SkPaint::kCapCount <= (1 << kCapBits), cap_does_not_fit); + uint32_t styleKey = this->getStyle(); + if (this->needToApply()) { + styleKey |= this->getJoin() << kJoinShift; + styleKey |= this->getCap() << kCapShift; + } + int i = 0; + data[i++] = styleKey; + + // Memcpy the scalar fields. Does not "reinterpret_cast<SkScalar&>(data[i]) = ..." due to + // scalars having more strict alignment requirements than what data can guarantee. The + // compiler should optimize memcpys to assignments. + SkScalar scalar; + scalar = this->getMiter(); + memcpy(&data[i], &scalar, sizeof(scalar)); + i += kSkScalarData32Cnt; + + scalar = this->getWidth(); + memcpy(&data[i], &scalar, sizeof(scalar)); + i += kSkScalarData32Cnt; + + if (this->isDashed()) { + SkScalar phase = this->getDashPhase(); + memcpy(&data[i], &phase, sizeof(phase)); + i += kSkScalarData32Cnt; + + int32_t count = this->getDashCount() & static_cast<int32_t>(~1); + SkASSERT(count == this->getDashCount()); + const SkScalar* intervals = this->getDashIntervals(); + int intervalByteCnt = count * sizeof(SkScalar); + memcpy(&data[i], intervals, intervalByteCnt); + // Enable the line below if fields are added after dashing. + SkDEBUGCODE(i += kSkScalarData32Cnt * count); + } + + SkASSERT(this->computeUniqueKeyFragmentData32Cnt() == i); +} + |