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

Unified Diff: src/gpu/GrStrokeInfo.cpp

Issue 1116123003: Improve caching of dashed paths in GrStencilAndCoverPathRenderer (Closed) Base URL: https://skia.googlesource.com/skia.git@dashing-nvpr-01
Patch Set: Created 5 years, 7 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 | « src/gpu/GrStrokeInfo.h ('k') | src/gpu/gl/GrGLPath.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrStrokeInfo.cpp
diff --git a/src/gpu/GrStrokeInfo.cpp b/src/gpu/GrStrokeInfo.cpp
index eb3008bb37dc67f0027ab8cf03e3a692022b3d46..0ad4179add90af5f36cfad4d8fca1be913f05967 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);
+}
+
« no previous file with comments | « src/gpu/GrStrokeInfo.h ('k') | src/gpu/gl/GrGLPath.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698