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

Unified Diff: src/gpu/GrPath.cpp

Issue 400713003: Add a GrPathRange class (Closed) Base URL: https://skia.googlesource.com/skia.git@clupload-ispath
Patch Set: Fix more windows trivial warningswq Created 6 years, 5 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
Index: src/gpu/GrPath.cpp
diff --git a/src/gpu/GrPath.cpp b/src/gpu/GrPath.cpp
index adb3fe6333a7020f8cc98e89351151da556bbb89..5426e498f0cdd5b841d5d497b2f83bd6bdb01835 100644
--- a/src/gpu/GrPath.cpp
+++ b/src/gpu/GrPath.cpp
@@ -7,25 +7,54 @@
#include "GrPath.h"
+template<int NumBits> static uint64_t get_top_n_float_bits(float f) {
+ char* floatData = reinterpret_cast<char*>(&f);
+ uint32_t floatBits = *reinterpret_cast<uint32_t*>(floatData);
+ return floatBits >> (32 - NumBits);
+}
+
GrResourceKey GrPath::ComputeKey(const SkPath& path, const SkStrokeRec& stroke) {
static const GrResourceKey::ResourceType gPathResourceType = GrResourceKey::GenerateResourceType();
static const GrCacheID::Domain gPathDomain = GrCacheID::GenerateDomain();
GrCacheID::Key key;
- uint32_t* keyData = key.fData32;
+ uint64_t* keyData = key.fData64;
keyData[0] = path.getGenerationID();
+ keyData[1] = ComputeStrokeKey(stroke);
+
+ return GrResourceKey(GrCacheID(gPathDomain, key), gPathResourceType, 0);
+}
+
+uint64_t GrPath::ComputeStrokeKey(const SkStrokeRec& stroke) {
+ enum {
+ kStyleBits = 2,
+ kJoinBits = 2,
+ kCapBits = 2,
+ kWidthBits = 29,
+ kMiterBits = 29,
- SK_COMPILE_ASSERT(SkPaint::kJoinCount <= 3, cap_shift_will_be_wrong);
- keyData[1] = stroke.needToApply();
- if (0 != keyData[1]) {
- keyData[1] |= stroke.getJoin() << 1;
- keyData[1] |= stroke.getCap() << 3;
- keyData[2] = static_cast<uint32_t>(stroke.getMiter());
- keyData[3] = static_cast<uint32_t>(stroke.getWidth());
- } else {
- keyData[2] = 0;
- keyData[3] = 0;
+ kJoinShift = kStyleBits,
+ kCapShift = kJoinShift + kJoinBits,
+ kWidthShift = kCapShift + kCapBits,
+ kMiterShift = kWidthShift + kWidthBits,
+
+ kBitCount = kMiterShift + kMiterBits
+ };
+
+ 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), miter_shift_will_be_wrong);
+ SK_COMPILE_ASSERT(kBitCount == 64, wrong_stroke_key_size);
+
+ if (!stroke.needToApply()) {
+ return SkStrokeRec::kFill_Style;
}
- return GrResourceKey(GrCacheID(gPathDomain, key), gPathResourceType, 0);
+ uint64_t key = stroke.getStyle();
+ key |= stroke.getJoin() << kJoinShift;
+ key |= stroke.getCap() << kCapShift;
+ key |= get_top_n_float_bits<kWidthBits>(stroke.getWidth()) << kWidthShift;
+ key |= get_top_n_float_bits<kMiterBits>(stroke.getMiter()) << kMiterShift;
+
+ return key;
}
« src/gpu/GrDrawTarget.h ('K') | « src/gpu/GrPath.h ('k') | src/gpu/GrPathRange.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698