Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrPath.h" | 8 #include "GrPath.h" |
| 9 | 9 |
| 10 template<int NumBits> static uint64_t get_top_n_float_bits(float f) { | 10 template<int NumBits> static uint64_t get_top_n_float_bits(float f) { |
| 11 char* floatData = reinterpret_cast<char*>(&f); | 11 char* floatData = reinterpret_cast<char*>(&f); |
| 12 uint32_t floatBits = *reinterpret_cast<uint32_t*>(floatData); | 12 uint32_t floatBits = *reinterpret_cast<uint32_t*>(floatData); |
| 13 return floatBits >> (32 - NumBits); | 13 return floatBits >> (32 - NumBits); |
| 14 } | 14 } |
| 15 | 15 |
| 16 void GrPath::ComputeKey(const SkPath& path, const SkStrokeRec& stroke, GrUniqueK ey* key) { | 16 void GrPath::ComputeKey(const SkPath& path, const GrStrokeInfo& stroke, GrUnique Key* key) { |
| 17 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); | 17 static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain(); |
| 18 GrUniqueKey::Builder builder(key, kDomain, 3); | 18 GrUniqueKey::Builder builder(key, kDomain, 3); |
| 19 *reinterpret_cast<uint64_t*>(&builder[0]) = ComputeStrokeKey(stroke); | 19 *reinterpret_cast<uint64_t*>(&builder[0]) = ComputeStrokeKey(stroke); |
| 20 builder[2] = path.getGenerationID(); | 20 builder[2] = path.getGenerationID(); |
| 21 } | 21 } |
| 22 | 22 |
| 23 uint64_t GrPath::ComputeStrokeKey(const SkStrokeRec& stroke) { | 23 uint64_t GrPath::ComputeStrokeKey(const GrStrokeInfo& stroke) { |
| 24 enum { | 24 enum { |
| 25 kStyleBits = 2, | 25 kStyleBits = 2, |
| 26 kJoinBits = 2, | 26 kJoinBits = 2, |
| 27 kCapBits = 2, | 27 kCapBits = 2, |
| 28 kWidthBits = 29, | 28 kWidthBits = 29, |
| 29 kMiterBits = 29, | 29 kMiterBits = 29, |
| 30 | 30 |
| 31 kJoinShift = kStyleBits, | 31 kJoinShift = kStyleBits, |
| 32 kCapShift = kJoinShift + kJoinBits, | 32 kCapShift = kJoinShift + kJoinBits, |
| 33 kWidthShift = kCapShift + kCapBits, | 33 kWidthShift = kCapShift + kCapBits, |
| 34 kMiterShift = kWidthShift + kWidthBits, | 34 kMiterShift = kWidthShift + kWidthBits, |
| 35 | 35 |
| 36 kBitCount = kMiterShift + kMiterBits | 36 kBitCount = kMiterShift + kMiterBits |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 SK_COMPILE_ASSERT(SkStrokeRec::kStyleCount <= (1 << kStyleBits), style_shift _will_be_wrong); | 39 SK_COMPILE_ASSERT(SkStrokeRec::kStyleCount <= (1 << kStyleBits), style_shift _will_be_wrong); |
| 40 SK_COMPILE_ASSERT(SkPaint::kJoinCount <= (1 << kJoinBits), cap_shift_will_be _wrong); | 40 SK_COMPILE_ASSERT(SkPaint::kJoinCount <= (1 << kJoinBits), cap_shift_will_be _wrong); |
| 41 SK_COMPILE_ASSERT(SkPaint::kCapCount <= (1 << kCapBits), miter_shift_will_be _wrong); | 41 SK_COMPILE_ASSERT(SkPaint::kCapCount <= (1 << kCapBits), miter_shift_will_be _wrong); |
| 42 SK_COMPILE_ASSERT(kBitCount == 64, wrong_stroke_key_size); | 42 SK_COMPILE_ASSERT(kBitCount == 64, wrong_stroke_key_size); |
| 43 | 43 const SkStrokeRec& strokeRec = stroke.getStrokeRec(); |
| 44 if (!stroke.needToApply()) { | 44 uint64_t key = strokeRec.getStyle(); |
| 45 return SkStrokeRec::kFill_Style; | 45 if (strokeRec.needToApply()) { |
| 46 key |= strokeRec.getJoin() << kJoinShift; | |
| 47 key |= strokeRec.getCap() << kCapShift; | |
| 48 key |= get_top_n_float_bits<kWidthBits>(strokeRec.getWidth()) << kWidthS hift; | |
| 49 key |= get_top_n_float_bits<kMiterBits>(strokeRec.getMiter()) << kMiterS hift; | |
| 46 } | 50 } |
| 47 | 51 if (stroke.isDashed()) { |
| 48 uint64_t key = stroke.getStyle(); | 52 int32_t count = stroke.getDashCount() & static_cast<int32_t>(~1); |
| 49 key |= stroke.getJoin() << kJoinShift; | 53 SkASSERT(count == stroke.getDashCount()); |
| 50 key |= stroke.getCap() << kCapShift; | 54 const SkScalar* intervals = stroke.getDashIntervals(); |
| 51 key |= get_top_n_float_bits<kWidthBits>(stroke.getWidth()) << kWidthShift; | 55 for (int i = 0; i < count; i += 2) { |
| 52 key |= get_top_n_float_bits<kMiterBits>(stroke.getMiter()) << kMiterShift; | 56 key ^= get_top_n_float_bits<32>(intervals[i]); |
|
egdaniel
2015/05/05 19:48:44
So this doesn't seem like it will give a unique ke
Kimmo Kinnunen
2015/05/06 08:30:25
Done.
| |
| 53 | 57 key ^= get_top_n_float_bits<32>(intervals[i + 1]) << 32; |
| 58 } | |
| 59 key ^= get_top_n_float_bits<32>(stroke.getDashPhase()); | |
| 60 key ^= static_cast<uint64_t>(count) << 32; | |
| 61 } | |
| 54 return key; | 62 return key; |
| 55 } | 63 } |
| OLD | NEW |