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 GrResourceKey GrPath::ComputeKey(const SkPath& path, const SkStrokeRec& stroke)
{ | 16 void GrPath::ComputeKey(const SkPath& path, const SkStrokeRec& stroke, GrContent
Key* key) { |
17 static const GrCacheID::Domain gPathDomain = GrCacheID::GenerateDomain(); | 17 static const GrContentKey::Domain kDomain = GrContentKey::GenerateDomain(); |
18 | 18 GrContentKey::Builder builder(key, kDomain, 3); |
19 GrCacheID::Key key; | 19 *reinterpret_cast<uint64_t*>(&builder[0]) = ComputeStrokeKey(stroke); |
20 uint64_t* keyData = key.fData64; | 20 builder[2] = path.getGenerationID(); |
21 keyData[0] = path.getGenerationID(); | |
22 keyData[1] = ComputeStrokeKey(stroke); | |
23 | |
24 return GrResourceKey(GrCacheID(gPathDomain, key), 0); | |
25 } | 21 } |
26 | 22 |
27 uint64_t GrPath::ComputeStrokeKey(const SkStrokeRec& stroke) { | 23 uint64_t GrPath::ComputeStrokeKey(const SkStrokeRec& stroke) { |
28 enum { | 24 enum { |
29 kStyleBits = 2, | 25 kStyleBits = 2, |
30 kJoinBits = 2, | 26 kJoinBits = 2, |
31 kCapBits = 2, | 27 kCapBits = 2, |
32 kWidthBits = 29, | 28 kWidthBits = 29, |
33 kMiterBits = 29, | 29 kMiterBits = 29, |
34 | 30 |
(...skipping 15 matching lines...) Expand all Loading... |
50 } | 46 } |
51 | 47 |
52 uint64_t key = stroke.getStyle(); | 48 uint64_t key = stroke.getStyle(); |
53 key |= stroke.getJoin() << kJoinShift; | 49 key |= stroke.getJoin() << kJoinShift; |
54 key |= stroke.getCap() << kCapShift; | 50 key |= stroke.getCap() << kCapShift; |
55 key |= get_top_n_float_bits<kWidthBits>(stroke.getWidth()) << kWidthShift; | 51 key |= get_top_n_float_bits<kWidthBits>(stroke.getWidth()) << kWidthShift; |
56 key |= get_top_n_float_bits<kMiterBits>(stroke.getMiter()) << kMiterShift; | 52 key |= get_top_n_float_bits<kMiterBits>(stroke.getMiter()) << kMiterShift; |
57 | 53 |
58 return key; | 54 return key; |
59 } | 55 } |
OLD | NEW |