OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 #ifndef GrProgramDesc_DEFINED | 8 #ifndef GrProgramDesc_DEFINED |
9 #define GrProgramDesc_DEFINED | 9 #define GrProgramDesc_DEFINED |
10 | 10 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 template<typename T, size_t OFFSET> const T* atOffset() const { | 100 template<typename T, size_t OFFSET> const T* atOffset() const { |
101 return reinterpret_cast<const T*>(reinterpret_cast<intptr_t>(fKey.begin(
)) + OFFSET); | 101 return reinterpret_cast<const T*>(reinterpret_cast<intptr_t>(fKey.begin(
)) + OFFSET); |
102 } | 102 } |
103 | 103 |
104 void finalize() { | 104 void finalize() { |
105 int keyLength = fKey.count(); | 105 int keyLength = fKey.count(); |
106 SkASSERT(0 == (keyLength % 4)); | 106 SkASSERT(0 == (keyLength % 4)); |
107 *(this->atOffset<uint32_t, GrProgramDesc::kLengthOffset>()) = SkToU32(ke
yLength); | 107 *(this->atOffset<uint32_t, GrProgramDesc::kLengthOffset>()) = SkToU32(ke
yLength); |
108 | 108 |
109 uint32_t* checksum = this->atOffset<uint32_t, GrProgramDesc::kChecksumOf
fset>(); | 109 uint32_t* checksum = this->atOffset<uint32_t, GrProgramDesc::kChecksumOf
fset>(); |
110 *checksum = 0; | 110 *checksum = 0; // We'll hash through these bytes, so make sure they're
initialized. |
111 *checksum = SkChecksum::Compute(reinterpret_cast<uint32_t*>(fKey.begin()
), keyLength); | 111 *checksum = SkChecksum::Murmur3(fKey.begin(), keyLength); |
112 } | 112 } |
113 | 113 |
114 // The key, stored in fKey, is composed of four parts: | 114 // The key, stored in fKey, is composed of four parts: |
115 // 1. uint32_t for total key length. | 115 // 1. uint32_t for total key length. |
116 // 2. uint32_t for a checksum. | 116 // 2. uint32_t for a checksum. |
117 // 3. Header struct defined above. Also room for extensions to the header | 117 // 3. Header struct defined above. Also room for extensions to the header |
118 // 4. A Backend specific payload. Room is preallocated for this | 118 // 4. A Backend specific payload. Room is preallocated for this |
119 enum KeyOffsets { | 119 enum KeyOffsets { |
120 // Part 1. | 120 // Part 1. |
121 kLengthOffset = 0, | 121 kLengthOffset = 0, |
(...skipping 12 matching lines...) Expand all Loading... |
134 }; | 134 }; |
135 | 135 |
136 SkSTArray<kPreAllocSize, uint8_t, true>& key() { return fKey; } | 136 SkSTArray<kPreAllocSize, uint8_t, true>& key() { return fKey; } |
137 const SkSTArray<kPreAllocSize, uint8_t, true>& key() const { return fKey; } | 137 const SkSTArray<kPreAllocSize, uint8_t, true>& key() const { return fKey; } |
138 | 138 |
139 private: | 139 private: |
140 SkSTArray<kPreAllocSize, uint8_t, true> fKey; | 140 SkSTArray<kPreAllocSize, uint8_t, true> fKey; |
141 }; | 141 }; |
142 | 142 |
143 #endif | 143 #endif |
OLD | NEW |