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) { |
| 11 char* floatData = reinterpret_cast<char*>(&f); |
| 12 uint32_t floatBits = *reinterpret_cast<uint32_t*>(floatData); |
| 13 return floatBits >> (32 - NumBits); |
| 14 } |
| 15 |
10 GrResourceKey GrPath::ComputeKey(const SkPath& path, const SkStrokeRec& stroke)
{ | 16 GrResourceKey GrPath::ComputeKey(const SkPath& path, const SkStrokeRec& stroke)
{ |
11 static const GrResourceKey::ResourceType gPathResourceType = GrResourceKey::
GenerateResourceType(); | 17 static const GrResourceKey::ResourceType gPathResourceType = GrResourceKey::
GenerateResourceType(); |
12 static const GrCacheID::Domain gPathDomain = GrCacheID::GenerateDomain(); | 18 static const GrCacheID::Domain gPathDomain = GrCacheID::GenerateDomain(); |
13 | 19 |
14 GrCacheID::Key key; | 20 GrCacheID::Key key; |
15 uint32_t* keyData = key.fData32; | 21 uint64_t* keyData = key.fData64; |
16 keyData[0] = path.getGenerationID(); | 22 keyData[0] = path.getGenerationID(); |
17 | 23 keyData[1] = ComputeStrokeKey(stroke); |
18 SK_COMPILE_ASSERT(SkPaint::kJoinCount <= 3, cap_shift_will_be_wrong); | |
19 keyData[1] = stroke.needToApply(); | |
20 if (0 != keyData[1]) { | |
21 keyData[1] |= stroke.getJoin() << 1; | |
22 keyData[1] |= stroke.getCap() << 3; | |
23 keyData[2] = static_cast<uint32_t>(stroke.getMiter()); | |
24 keyData[3] = static_cast<uint32_t>(stroke.getWidth()); | |
25 } else { | |
26 keyData[2] = 0; | |
27 keyData[3] = 0; | |
28 } | |
29 | 24 |
30 return GrResourceKey(GrCacheID(gPathDomain, key), gPathResourceType, 0); | 25 return GrResourceKey(GrCacheID(gPathDomain, key), gPathResourceType, 0); |
31 } | 26 } |
| 27 |
| 28 uint64_t GrPath::ComputeStrokeKey(const SkStrokeRec& stroke) { |
| 29 enum { |
| 30 kStyleBits = 2, |
| 31 kJoinBits = 2, |
| 32 kCapBits = 2, |
| 33 kWidthBits = 29, |
| 34 kMiterBits = 29, |
| 35 |
| 36 kJoinShift = kStyleBits, |
| 37 kCapShift = kJoinShift + kJoinBits, |
| 38 kWidthShift = kCapShift + kCapBits, |
| 39 kMiterShift = kWidthShift + kWidthBits, |
| 40 |
| 41 kBitCount = kMiterShift + kMiterBits |
| 42 }; |
| 43 |
| 44 SK_COMPILE_ASSERT(SkStrokeRec::kStyleCount <= (1 << kStyleBits), style_shift
_will_be_wrong); |
| 45 SK_COMPILE_ASSERT(SkPaint::kJoinCount <= (1 << kJoinBits), cap_shift_will_be
_wrong); |
| 46 SK_COMPILE_ASSERT(SkPaint::kCapCount <= (1 << kCapBits), miter_shift_will_be
_wrong); |
| 47 SK_COMPILE_ASSERT(kBitCount == 64, wrong_stroke_key_size); |
| 48 |
| 49 if (!stroke.needToApply()) { |
| 50 return SkStrokeRec::kFill_Style; |
| 51 } |
| 52 |
| 53 uint64_t key = stroke.getStyle(); |
| 54 key |= stroke.getJoin() << kJoinShift; |
| 55 key |= stroke.getCap() << kCapShift; |
| 56 key |= get_top_n_float_bits<kWidthBits>(stroke.getWidth()) << kWidthShift; |
| 57 key |= get_top_n_float_bits<kMiterBits>(stroke.getMiter()) << kMiterShift; |
| 58 |
| 59 return key; |
| 60 } |
OLD | NEW |