| 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 "SkOpts.h" | 13 #include "SkOpts.h" |
| 14 #include "SkTArray.h" | 14 #include "SkTArray.h" |
| 15 | 15 |
| 16 /** This class describes a program to generate. It also serves as a program cach
e key. Very little | 16 class GrGLSLCaps; |
| 17 of this is GL-specific. The GL-specific parts could be factored out into a s
ubclass. */ | 17 class GrPipeline; |
| 18 class GrPrimitiveProcessor; |
| 19 |
| 20 /** This class describes a program to generate. It also serves as a program cach
e key */ |
| 18 class GrProgramDesc { | 21 class GrProgramDesc { |
| 19 public: | 22 public: |
| 20 // Creates an uninitialized key that must be populated by GrGpu::buildProgra
mDesc() | 23 // Creates an uninitialized key that must be populated by GrGpu::buildProgra
mDesc() |
| 21 GrProgramDesc() {} | 24 GrProgramDesc() {} |
| 22 | 25 |
| 26 /** |
| 27 * Builds a program descriptor. Before the descriptor can be used, the client
must call finalize |
| 28 * on the returned GrProgramDesc. |
| 29 * |
| 30 * @param GrPrimitiveProcessor The geometry |
| 31 * @param GrPipeline The optimized drawstate. The descriptor will represent
a program |
| 32 * which this optstate can use to draw with. The opts
tate contains |
| 33 * general draw information, as well as the specific c
olor, geometry, |
| 34 * and coverage stages which will be used to generate
the GL Program for |
| 35 * this optstate. |
| 36 * @param GrGLSLCaps Capabilities of the GLSL backend. |
| 37 * @param GrProgramDesc The built and finalized descriptor |
| 38 **/ |
| 39 static bool Build(GrProgramDesc*, |
| 40 const GrPrimitiveProcessor&, |
| 41 const GrPipeline&, |
| 42 const GrGLSLCaps&); |
| 43 |
| 23 // Returns this as a uint32_t array to be used as a key in the program cache
. | 44 // Returns this as a uint32_t array to be used as a key in the program cache
. |
| 24 const uint32_t* asKey() const { | 45 const uint32_t* asKey() const { |
| 25 return reinterpret_cast<const uint32_t*>(fKey.begin()); | 46 return reinterpret_cast<const uint32_t*>(fKey.begin()); |
| 26 } | 47 } |
| 27 | 48 |
| 28 // Gets the number of bytes in asKey(). It will be a 4-byte aligned value. W
hen comparing two | 49 // Gets the number of bytes in asKey(). It will be a 4-byte aligned value. W
hen comparing two |
| 29 // keys the size of either key can be used with memcmp() since the lengths t
hemselves begin the | 50 // keys the size of either key can be used with memcmp() since the lengths t
hemselves begin the |
| 30 // keys and thus the memcmp will exit early if the keys are of different len
gths. | 51 // keys and thus the memcmp will exit early if the keys are of different len
gths. |
| 31 uint32_t keyLength() const { return *this->atOffset<uint32_t, kLengthOffset>
(); } | 52 uint32_t keyLength() const { return *this->atOffset<uint32_t, kLengthOffset>
(); } |
| 32 | 53 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 111 |
| 91 int numCoverageEffects() const { | 112 int numCoverageEffects() const { |
| 92 return this->header().fCoverageEffectCnt; | 113 return this->header().fCoverageEffectCnt; |
| 93 } | 114 } |
| 94 | 115 |
| 95 int numTotalEffects() const { return this->numColorEffects() + this->numCove
rageEffects(); } | 116 int numTotalEffects() const { return this->numColorEffects() + this->numCove
rageEffects(); } |
| 96 | 117 |
| 97 // This should really only be used internally, base classes should return th
eir own headers | 118 // This should really only be used internally, base classes should return th
eir own headers |
| 98 const KeyHeader& header() const { return *this->atOffset<KeyHeader, kHeaderO
ffset>(); } | 119 const KeyHeader& header() const { return *this->atOffset<KeyHeader, kHeaderO
ffset>(); } |
| 99 | 120 |
| 100 protected: | |
| 101 template<typename T, size_t OFFSET> T* atOffset() { | |
| 102 return reinterpret_cast<T*>(reinterpret_cast<intptr_t>(fKey.begin()) + O
FFSET); | |
| 103 } | |
| 104 | |
| 105 template<typename T, size_t OFFSET> const T* atOffset() const { | |
| 106 return reinterpret_cast<const T*>(reinterpret_cast<intptr_t>(fKey.begin(
)) + OFFSET); | |
| 107 } | |
| 108 | |
| 109 void finalize() { | 121 void finalize() { |
| 110 int keyLength = fKey.count(); | 122 int keyLength = fKey.count(); |
| 111 SkASSERT(0 == (keyLength % 4)); | 123 SkASSERT(0 == (keyLength % 4)); |
| 112 *(this->atOffset<uint32_t, GrProgramDesc::kLengthOffset>()) = SkToU32(ke
yLength); | 124 *(this->atOffset<uint32_t, GrProgramDesc::kLengthOffset>()) = SkToU32(ke
yLength); |
| 113 | 125 |
| 114 uint32_t* checksum = this->atOffset<uint32_t, GrProgramDesc::kChecksumOf
fset>(); | 126 uint32_t* checksum = this->atOffset<uint32_t, GrProgramDesc::kChecksumOf
fset>(); |
| 115 *checksum = 0; // We'll hash through these bytes, so make sure they're
initialized. | 127 *checksum = 0; // We'll hash through these bytes, so make sure they're
initialized. |
| 116 *checksum = SkOpts::hash(fKey.begin(), keyLength); | 128 *checksum = SkOpts::hash(fKey.begin(), keyLength); |
| 117 } | 129 } |
| 118 | 130 |
| 131 protected: |
| 132 template<typename T, size_t OFFSET> T* atOffset() { |
| 133 return reinterpret_cast<T*>(reinterpret_cast<intptr_t>(fKey.begin()) + O
FFSET); |
| 134 } |
| 135 |
| 136 template<typename T, size_t OFFSET> const T* atOffset() const { |
| 137 return reinterpret_cast<const T*>(reinterpret_cast<intptr_t>(fKey.begin(
)) + OFFSET); |
| 138 } |
| 139 |
| 119 // The key, stored in fKey, is composed of four parts: | 140 // The key, stored in fKey, is composed of four parts: |
| 120 // 1. uint32_t for total key length. | 141 // 1. uint32_t for total key length. |
| 121 // 2. uint32_t for a checksum. | 142 // 2. uint32_t for a checksum. |
| 122 // 3. Header struct defined above. Also room for extensions to the header | 143 // 3. Header struct defined above. |
| 123 // 4. A Backend specific payload. Room is preallocated for this | 144 // 4. A Backend specific payload which includes the per-processor keys. |
| 124 enum KeyOffsets { | 145 enum KeyOffsets { |
| 125 // Part 1. | 146 // Part 1. |
| 126 kLengthOffset = 0, | 147 kLengthOffset = 0, |
| 127 // Part 2. | 148 // Part 2. |
| 128 kChecksumOffset = kLengthOffset + sizeof(uint32_t), | 149 kChecksumOffset = kLengthOffset + sizeof(uint32_t), |
| 129 // Part 3. | 150 // Part 3. |
| 130 kHeaderOffset = kChecksumOffset + sizeof(uint32_t), | 151 kHeaderOffset = kChecksumOffset + sizeof(uint32_t), |
| 131 kHeaderSize = SkAlign4(2 * sizeof(KeyHeader)), | 152 kHeaderSize = SkAlign4(sizeof(KeyHeader)), |
| 153 // Part 4. |
| 154 // This is the offset into the backenend specific part of the key, which
includes |
| 155 // per-processor keys. |
| 156 kProcessorKeysOffset = kHeaderOffset + kHeaderSize, |
| 132 }; | 157 }; |
| 133 | 158 |
| 134 enum { | 159 enum { |
| 135 kMaxPreallocProcessors = 8, | 160 kMaxPreallocProcessors = 8, |
| 136 kIntsPerProcessor = 4, // This is an overestimate of the average
effect key size. | 161 kIntsPerProcessor = 4, // This is an overestimate of the average
effect key size. |
| 137 kPreAllocSize = kHeaderOffset + kHeaderSize + | 162 kPreAllocSize = kHeaderOffset + kHeaderSize + |
| 138 kMaxPreallocProcessors * sizeof(uint32_t) * kIntsPerProc
essor, | 163 kMaxPreallocProcessors * sizeof(uint32_t) * kIntsPerProc
essor, |
| 139 }; | 164 }; |
| 140 | 165 |
| 141 SkSTArray<kPreAllocSize, uint8_t, true>& key() { return fKey; } | 166 SkSTArray<kPreAllocSize, uint8_t, true>& key() { return fKey; } |
| 142 const SkSTArray<kPreAllocSize, uint8_t, true>& key() const { return fKey; } | 167 const SkSTArray<kPreAllocSize, uint8_t, true>& key() const { return fKey; } |
| 143 | 168 |
| 144 private: | 169 private: |
| 145 SkSTArray<kPreAllocSize, uint8_t, true> fKey; | 170 SkSTArray<kPreAllocSize, uint8_t, true> fKey; |
| 146 }; | 171 }; |
| 147 | 172 |
| 148 #endif | 173 #endif |
| OLD | NEW |