gfx/skia/trunk/src/gpu/gl/GrGLProgramDesc.h

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /*
michael@0 2 * Copyright 2013 Google Inc.
michael@0 3 *
michael@0 4 * Use of this source code is governed by a BSD-style license that can be
michael@0 5 * found in the LICENSE file.
michael@0 6 */
michael@0 7
michael@0 8 #ifndef GrGLProgramDesc_DEFINED
michael@0 9 #define GrGLProgramDesc_DEFINED
michael@0 10
michael@0 11 #include "GrGLEffect.h"
michael@0 12 #include "GrDrawState.h"
michael@0 13 #include "GrGLShaderBuilder.h"
michael@0 14
michael@0 15 class GrGpuGL;
michael@0 16
michael@0 17 #ifdef SK_DEBUG
michael@0 18 // Optionally compile the experimental GS code. Set to SK_DEBUG so that debug build bots will
michael@0 19 // execute the code.
michael@0 20 #define GR_GL_EXPERIMENTAL_GS 1
michael@0 21 #else
michael@0 22 #define GR_GL_EXPERIMENTAL_GS 0
michael@0 23 #endif
michael@0 24
michael@0 25
michael@0 26 /** This class describes a program to generate. It also serves as a program cache key. Very little
michael@0 27 of this is GL-specific. There is the generation of GrGLEffect::EffectKeys and the dst-read part
michael@0 28 of the key set by GrGLShaderBuilder. If the interfaces that set those portions were abstracted
michael@0 29 to be API-neutral then so could this class. */
michael@0 30 class GrGLProgramDesc {
michael@0 31 public:
michael@0 32 GrGLProgramDesc() : fInitialized(false) {}
michael@0 33 GrGLProgramDesc(const GrGLProgramDesc& desc) { *this = desc; }
michael@0 34
michael@0 35 // Returns this as a uint32_t array to be used as a key in the program cache.
michael@0 36 const uint32_t* asKey() const {
michael@0 37 SkASSERT(fInitialized);
michael@0 38 return reinterpret_cast<const uint32_t*>(fKey.get());
michael@0 39 }
michael@0 40
michael@0 41 // Gets the number of bytes in asKey(). It will be a 4-byte aligned value. When comparing two
michael@0 42 // keys the size of either key can be used with memcmp() since the lengths themselves begin the
michael@0 43 // keys and thus the memcmp will exit early if the keys are of different lengths.
michael@0 44 uint32_t keyLength() const { return *this->atOffset<uint32_t, kLengthOffset>(); }
michael@0 45
michael@0 46 // Gets the a checksum of the key. Can be used as a hash value for a fast lookup in a cache.
michael@0 47 uint32_t getChecksum() const { return *this->atOffset<uint32_t, kChecksumOffset>(); }
michael@0 48
michael@0 49 // For unit testing.
michael@0 50 void setRandom(SkRandom*,
michael@0 51 const GrGpuGL* gpu,
michael@0 52 const GrRenderTarget* dummyDstRenderTarget,
michael@0 53 const GrTexture* dummyDstCopyTexture,
michael@0 54 const GrEffectStage* stages[],
michael@0 55 int numColorStages,
michael@0 56 int numCoverageStages,
michael@0 57 int currAttribIndex);
michael@0 58
michael@0 59 /**
michael@0 60 * Builds a program descriptor from a GrDrawState. Whether the primitive type is points, the
michael@0 61 * output of GrDrawState::getBlendOpts, and the caps of the GrGpuGL are also inputs. It also
michael@0 62 * outputs the color and coverage stages referenced by the generated descriptor. This may
michael@0 63 * not contain all stages from the draw state and coverage stages from the drawState may
michael@0 64 * be treated as color stages in the output.
michael@0 65 */
michael@0 66 static void Build(const GrDrawState&,
michael@0 67 bool isPoints,
michael@0 68 GrDrawState::BlendOptFlags,
michael@0 69 GrBlendCoeff srcCoeff,
michael@0 70 GrBlendCoeff dstCoeff,
michael@0 71 const GrGpuGL* gpu,
michael@0 72 const GrDeviceCoordTexture* dstCopy,
michael@0 73 SkTArray<const GrEffectStage*, true>* outColorStages,
michael@0 74 SkTArray<const GrEffectStage*, true>* outCoverageStages,
michael@0 75 GrGLProgramDesc* outDesc);
michael@0 76
michael@0 77 int numColorEffects() const {
michael@0 78 SkASSERT(fInitialized);
michael@0 79 return this->getHeader().fColorEffectCnt;
michael@0 80 }
michael@0 81
michael@0 82 int numCoverageEffects() const {
michael@0 83 SkASSERT(fInitialized);
michael@0 84 return this->getHeader().fCoverageEffectCnt;
michael@0 85 }
michael@0 86
michael@0 87 int numTotalEffects() const { return this->numColorEffects() + this->numCoverageEffects(); }
michael@0 88
michael@0 89 GrGLProgramDesc& operator= (const GrGLProgramDesc& other);
michael@0 90
michael@0 91 bool operator== (const GrGLProgramDesc& other) const {
michael@0 92 SkASSERT(fInitialized && other.fInitialized);
michael@0 93 // The length is masked as a hint to the compiler that the address will be 4 byte aligned.
michael@0 94 return 0 == memcmp(this->asKey(), other.asKey(), this->keyLength() & ~0x3);
michael@0 95 }
michael@0 96
michael@0 97 bool operator!= (const GrGLProgramDesc& other) const {
michael@0 98 return !(*this == other);
michael@0 99 }
michael@0 100
michael@0 101 static bool Less(const GrGLProgramDesc& a, const GrGLProgramDesc& b) {
michael@0 102 return memcmp(a.asKey(), b.asKey(), a.keyLength() & ~0x3) < 0;
michael@0 103 }
michael@0 104
michael@0 105 private:
michael@0 106 // Specifies where the initial color comes from before the stages are applied.
michael@0 107 enum ColorInput {
michael@0 108 kSolidWhite_ColorInput,
michael@0 109 kTransBlack_ColorInput,
michael@0 110 kAttribute_ColorInput,
michael@0 111 kUniform_ColorInput,
michael@0 112
michael@0 113 kColorInputCnt
michael@0 114 };
michael@0 115
michael@0 116 enum CoverageOutput {
michael@0 117 // modulate color and coverage, write result as the color output.
michael@0 118 kModulate_CoverageOutput,
michael@0 119 // Writes color*coverage as the primary color output and also writes coverage as the
michael@0 120 // secondary output. Only set if dual source blending is supported.
michael@0 121 kSecondaryCoverage_CoverageOutput,
michael@0 122 // Writes color*coverage as the primary color output and also writes coverage * (1 - colorA)
michael@0 123 // as the secondary output. Only set if dual source blending is supported.
michael@0 124 kSecondaryCoverageISA_CoverageOutput,
michael@0 125 // Writes color*coverage as the primary color output and also writes coverage *
michael@0 126 // (1 - colorRGB) as the secondary output. Only set if dual source blending is supported.
michael@0 127 kSecondaryCoverageISC_CoverageOutput,
michael@0 128 // Combines the coverage, dst, and color as coverage * color + (1 - coverage) * dst. This
michael@0 129 // can only be set if fDstReadKey is non-zero.
michael@0 130 kCombineWithDst_CoverageOutput,
michael@0 131
michael@0 132 kCoverageOutputCnt
michael@0 133 };
michael@0 134
michael@0 135 static bool CoverageOutputUsesSecondaryOutput(CoverageOutput co) {
michael@0 136 switch (co) {
michael@0 137 case kSecondaryCoverage_CoverageOutput: // fallthru
michael@0 138 case kSecondaryCoverageISA_CoverageOutput:
michael@0 139 case kSecondaryCoverageISC_CoverageOutput:
michael@0 140 return true;
michael@0 141 default:
michael@0 142 return false;
michael@0 143 }
michael@0 144 }
michael@0 145
michael@0 146 struct KeyHeader {
michael@0 147 GrGLShaderBuilder::DstReadKey fDstReadKey; // set by GrGLShaderBuilder if there
michael@0 148 // are effects that must read the dst.
michael@0 149 // Otherwise, 0.
michael@0 150 GrGLShaderBuilder::FragPosKey fFragPosKey; // set by GrGLShaderBuilder if there are
michael@0 151 // effects that read the fragment position.
michael@0 152 // Otherwise, 0.
michael@0 153
michael@0 154 ColorInput fColorInput : 8;
michael@0 155 ColorInput fCoverageInput : 8;
michael@0 156 CoverageOutput fCoverageOutput : 8;
michael@0 157
michael@0 158 SkBool8 fHasVertexCode;
michael@0 159 SkBool8 fEmitsPointSize;
michael@0 160
michael@0 161 // To enable experimental geometry shader code (not for use in
michael@0 162 // production)
michael@0 163 #if GR_GL_EXPERIMENTAL_GS
michael@0 164 SkBool8 fExperimentalGS;
michael@0 165 #endif
michael@0 166
michael@0 167 int8_t fPositionAttributeIndex;
michael@0 168 int8_t fLocalCoordAttributeIndex;
michael@0 169 int8_t fColorAttributeIndex;
michael@0 170 int8_t fCoverageAttributeIndex;
michael@0 171
michael@0 172 int8_t fColorEffectCnt;
michael@0 173 int8_t fCoverageEffectCnt;
michael@0 174 };
michael@0 175
michael@0 176 // The key is 1 uint32_t for the length, followed another for the checksum, the header, and then
michael@0 177 // the effect keys. Everything is fixed length except the effect key array.
michael@0 178 enum {
michael@0 179 kLengthOffset = 0,
michael@0 180 kChecksumOffset = kLengthOffset + sizeof(uint32_t),
michael@0 181 kHeaderOffset = kChecksumOffset + sizeof(uint32_t),
michael@0 182 kHeaderSize = SkAlign4(sizeof(KeyHeader)),
michael@0 183 kEffectKeyOffset = kHeaderOffset + kHeaderSize,
michael@0 184 };
michael@0 185
michael@0 186 template<typename T, size_t OFFSET> T* atOffset() {
michael@0 187 return reinterpret_cast<T*>(reinterpret_cast<intptr_t>(fKey.get()) + OFFSET);
michael@0 188 }
michael@0 189
michael@0 190 template<typename T, size_t OFFSET> const T* atOffset() const {
michael@0 191 return reinterpret_cast<const T*>(reinterpret_cast<intptr_t>(fKey.get()) + OFFSET);
michael@0 192 }
michael@0 193
michael@0 194 typedef GrGLEffect::EffectKey EffectKey;
michael@0 195
michael@0 196 uint32_t* checksum() { return this->atOffset<uint32_t, kChecksumOffset>(); }
michael@0 197 KeyHeader* header() { return this->atOffset<KeyHeader, kHeaderOffset>(); }
michael@0 198 EffectKey* effectKeys() { return this->atOffset<EffectKey, kEffectKeyOffset>(); }
michael@0 199
michael@0 200 const KeyHeader& getHeader() const { return *this->atOffset<KeyHeader, kHeaderOffset>(); }
michael@0 201 const EffectKey* getEffectKeys() const { return this->atOffset<EffectKey, kEffectKeyOffset>(); }
michael@0 202
michael@0 203 static size_t KeyLength(int effectCnt) {
michael@0 204 GR_STATIC_ASSERT(!(sizeof(EffectKey) & 0x3));
michael@0 205 return kEffectKeyOffset + effectCnt * sizeof(EffectKey);
michael@0 206 }
michael@0 207
michael@0 208 enum {
michael@0 209 kMaxPreallocEffects = 16,
michael@0 210 kPreAllocSize = kEffectKeyOffset + kMaxPreallocEffects * sizeof(EffectKey),
michael@0 211 };
michael@0 212
michael@0 213 SkAutoSMalloc<kPreAllocSize> fKey;
michael@0 214 bool fInitialized;
michael@0 215
michael@0 216 // GrGLProgram and GrGLShaderBuilder read the private fields to generate code. TODO: Move all
michael@0 217 // code generation to GrGLShaderBuilder (and maybe add getters rather than friending).
michael@0 218 friend class GrGLProgram;
michael@0 219 friend class GrGLShaderBuilder;
michael@0 220 friend class GrGLFullShaderBuilder;
michael@0 221 friend class GrGLFragmentOnlyShaderBuilder;
michael@0 222 };
michael@0 223
michael@0 224 #endif

mercurial