| 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 |
| 11 #include "GrColor.h" | 11 #include "GrColor.h" |
| 12 #include "GrTypesPriv.h" | 12 #include "GrTypesPriv.h" |
| 13 #include "SkChecksum.h" | 13 #include "SkOpts.h" |
| 14 #include "SkTArray.h" |
| 14 | 15 |
| 15 /** This class describes a program to generate. It also serves as a program cach
e key. Very little | 16 /** This class describes a program to generate. It also serves as a program cach
e key. Very little |
| 16 of this is GL-specific. The GL-specific parts could be factored out into a s
ubclass. */ | 17 of this is GL-specific. The GL-specific parts could be factored out into a s
ubclass. */ |
| 17 class GrProgramDesc { | 18 class GrProgramDesc { |
| 18 public: | 19 public: |
| 19 // Creates an uninitialized key that must be populated by GrGpu::buildProgra
mDesc() | 20 // Creates an uninitialized key that must be populated by GrGpu::buildProgra
mDesc() |
| 20 GrProgramDesc() {} | 21 GrProgramDesc() {} |
| 21 | 22 |
| 22 // Returns this as a uint32_t array to be used as a key in the program cache
. | 23 // Returns this as a uint32_t array to be used as a key in the program cache
. |
| 23 const uint32_t* asKey() const { | 24 const uint32_t* asKey() const { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 return reinterpret_cast<const T*>(reinterpret_cast<intptr_t>(fKey.begin(
)) + OFFSET); | 106 return reinterpret_cast<const T*>(reinterpret_cast<intptr_t>(fKey.begin(
)) + OFFSET); |
| 106 } | 107 } |
| 107 | 108 |
| 108 void finalize() { | 109 void finalize() { |
| 109 int keyLength = fKey.count(); | 110 int keyLength = fKey.count(); |
| 110 SkASSERT(0 == (keyLength % 4)); | 111 SkASSERT(0 == (keyLength % 4)); |
| 111 *(this->atOffset<uint32_t, GrProgramDesc::kLengthOffset>()) = SkToU32(ke
yLength); | 112 *(this->atOffset<uint32_t, GrProgramDesc::kLengthOffset>()) = SkToU32(ke
yLength); |
| 112 | 113 |
| 113 uint32_t* checksum = this->atOffset<uint32_t, GrProgramDesc::kChecksumOf
fset>(); | 114 uint32_t* checksum = this->atOffset<uint32_t, GrProgramDesc::kChecksumOf
fset>(); |
| 114 *checksum = 0; // We'll hash through these bytes, so make sure they're
initialized. | 115 *checksum = 0; // We'll hash through these bytes, so make sure they're
initialized. |
| 115 *checksum = SkChecksum::Murmur3(fKey.begin(), keyLength); | 116 *checksum = SkOpts::hash(fKey.begin(), keyLength); |
| 116 } | 117 } |
| 117 | 118 |
| 118 // The key, stored in fKey, is composed of four parts: | 119 // The key, stored in fKey, is composed of four parts: |
| 119 // 1. uint32_t for total key length. | 120 // 1. uint32_t for total key length. |
| 120 // 2. uint32_t for a checksum. | 121 // 2. uint32_t for a checksum. |
| 121 // 3. Header struct defined above. Also room for extensions to the header | 122 // 3. Header struct defined above. Also room for extensions to the header |
| 122 // 4. A Backend specific payload. Room is preallocated for this | 123 // 4. A Backend specific payload. Room is preallocated for this |
| 123 enum KeyOffsets { | 124 enum KeyOffsets { |
| 124 // Part 1. | 125 // Part 1. |
| 125 kLengthOffset = 0, | 126 kLengthOffset = 0, |
| (...skipping 12 matching lines...) Expand all Loading... |
| 138 }; | 139 }; |
| 139 | 140 |
| 140 SkSTArray<kPreAllocSize, uint8_t, true>& key() { return fKey; } | 141 SkSTArray<kPreAllocSize, uint8_t, true>& key() { return fKey; } |
| 141 const SkSTArray<kPreAllocSize, uint8_t, true>& key() const { return fKey; } | 142 const SkSTArray<kPreAllocSize, uint8_t, true>& key() const { return fKey; } |
| 142 | 143 |
| 143 private: | 144 private: |
| 144 SkSTArray<kPreAllocSize, uint8_t, true> fKey; | 145 SkSTArray<kPreAllocSize, uint8_t, true> fKey; |
| 145 }; | 146 }; |
| 146 | 147 |
| 147 #endif | 148 #endif |
| OLD | NEW |