gfx/skia/trunk/src/gpu/gl/GrGLProgramEffects.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 GrGLProgramEffects_DEFINED
michael@0 9 #define GrGLProgramEffects_DEFINED
michael@0 10
michael@0 11 #include "GrBackendEffectFactory.h"
michael@0 12 #include "GrTexture.h"
michael@0 13 #include "GrTextureAccess.h"
michael@0 14 #include "GrGLUniformManager.h"
michael@0 15
michael@0 16 class GrEffectStage;
michael@0 17 class GrGLVertexProgramEffectsBuilder;
michael@0 18 class GrGLShaderBuilder;
michael@0 19 class GrGLFullShaderBuilder;
michael@0 20 class GrGLFragmentOnlyShaderBuilder;
michael@0 21
michael@0 22 /**
michael@0 23 * This class encapsulates an array of GrGLEffects and their supporting data (coord transforms
michael@0 24 * and textures). It is built with GrGLProgramEffectsBuilder, then used to manage the necessary GL
michael@0 25 * state and shader uniforms.
michael@0 26 */
michael@0 27 class GrGLProgramEffects {
michael@0 28 public:
michael@0 29 typedef GrBackendEffectFactory::EffectKey EffectKey;
michael@0 30 typedef GrGLUniformManager::UniformHandle UniformHandle;
michael@0 31
michael@0 32 /**
michael@0 33 * These methods generate different portions of an effect's final key.
michael@0 34 */
michael@0 35 static EffectKey GenAttribKey(const GrDrawEffect&);
michael@0 36 static EffectKey GenTransformKey(const GrDrawEffect&);
michael@0 37 static EffectKey GenTextureKey(const GrDrawEffect&, const GrGLCaps&);
michael@0 38
michael@0 39 virtual ~GrGLProgramEffects();
michael@0 40
michael@0 41 /**
michael@0 42 * Assigns a texture unit to each sampler. It starts on *texUnitIdx and writes the next
michael@0 43 * available unit to *texUnitIdx when it returns.
michael@0 44 */
michael@0 45 void initSamplers(const GrGLUniformManager&, int* texUnitIdx);
michael@0 46
michael@0 47 /**
michael@0 48 * Calls setData() on each effect, and sets their transformation matrices and texture bindings.
michael@0 49 */
michael@0 50 virtual void setData(GrGpuGL*,
michael@0 51 const GrGLUniformManager&,
michael@0 52 const GrEffectStage* effectStages[]) = 0;
michael@0 53
michael@0 54 /**
michael@0 55 * Passed to GrGLEffects so they can add transformed coordinates to their shader code.
michael@0 56 */
michael@0 57 class TransformedCoords {
michael@0 58 public:
michael@0 59 TransformedCoords(const SkString& name, GrSLType type)
michael@0 60 : fName(name), fType(type) {
michael@0 61 }
michael@0 62
michael@0 63 const char* c_str() const { return fName.c_str(); }
michael@0 64 GrSLType type() const { return fType; }
michael@0 65 const SkString& getName() const { return fName; }
michael@0 66
michael@0 67 private:
michael@0 68 SkString fName;
michael@0 69 GrSLType fType;
michael@0 70 };
michael@0 71
michael@0 72 typedef SkTArray<TransformedCoords> TransformedCoordsArray;
michael@0 73
michael@0 74 /**
michael@0 75 * Passed to GrGLEffects so they can add texture reads to their shader code.
michael@0 76 */
michael@0 77 class TextureSampler {
michael@0 78 public:
michael@0 79 TextureSampler(UniformHandle uniform, const GrTextureAccess& access)
michael@0 80 : fSamplerUniform(uniform)
michael@0 81 , fConfigComponentMask(GrPixelConfigComponentMask(access.getTexture()->config())) {
michael@0 82 SkASSERT(0 != fConfigComponentMask);
michael@0 83 memcpy(fSwizzle, access.getSwizzle(), 5);
michael@0 84 }
michael@0 85
michael@0 86 UniformHandle samplerUniform() const { return fSamplerUniform; }
michael@0 87 // bitfield of GrColorComponentFlags present in the texture's config.
michael@0 88 uint32_t configComponentMask() const { return fConfigComponentMask; }
michael@0 89 const char* swizzle() const { return fSwizzle; }
michael@0 90
michael@0 91 private:
michael@0 92 UniformHandle fSamplerUniform;
michael@0 93 uint32_t fConfigComponentMask;
michael@0 94 char fSwizzle[5];
michael@0 95 };
michael@0 96
michael@0 97 typedef SkTArray<TextureSampler> TextureSamplerArray;
michael@0 98
michael@0 99 protected:
michael@0 100 GrGLProgramEffects(int reserveCount)
michael@0 101 : fGLEffects(reserveCount)
michael@0 102 , fSamplers(reserveCount) {
michael@0 103 }
michael@0 104
michael@0 105 /**
michael@0 106 * Helper for emitEffect() in a subclasses. Emits uniforms for an effect's texture accesses and
michael@0 107 * appends the necessary data to the TextureSamplerArray* object so effects can add texture
michael@0 108 * lookups to their code. This method is only meant to be called during the construction phase.
michael@0 109 */
michael@0 110 void emitSamplers(GrGLShaderBuilder*, const GrEffectRef&, TextureSamplerArray*);
michael@0 111
michael@0 112 /**
michael@0 113 * Helper for setData(). Binds all the textures for an effect.
michael@0 114 */
michael@0 115 void bindTextures(GrGpuGL*, const GrEffectRef&, int effectIdx);
michael@0 116
michael@0 117 struct Sampler {
michael@0 118 SkDEBUGCODE(Sampler() : fTextureUnit(-1) {})
michael@0 119 UniformHandle fUniform;
michael@0 120 int fTextureUnit;
michael@0 121 };
michael@0 122
michael@0 123 SkTArray<GrGLEffect*> fGLEffects;
michael@0 124 SkTArray<SkSTArray<4, Sampler, true> > fSamplers;
michael@0 125 };
michael@0 126
michael@0 127 /**
michael@0 128 * This is an abstract base class for constructing different types of GrGLProgramEffects objects.
michael@0 129 */
michael@0 130 class GrGLProgramEffectsBuilder {
michael@0 131 public:
michael@0 132 virtual ~GrGLProgramEffectsBuilder() { }
michael@0 133
michael@0 134 /**
michael@0 135 * Emits the effect's shader code, and stores the necessary uniforms internally.
michael@0 136 */
michael@0 137 virtual void emitEffect(const GrEffectStage&,
michael@0 138 GrGLProgramEffects::EffectKey,
michael@0 139 const char* outColor,
michael@0 140 const char* inColor,
michael@0 141 int stageIndex) = 0;
michael@0 142 };
michael@0 143
michael@0 144 ////////////////////////////////////////////////////////////////////////////////
michael@0 145
michael@0 146 /**
michael@0 147 * This is a GrGLProgramEffects implementation that does coord transforms with the vertex shader.
michael@0 148 */
michael@0 149 class GrGLVertexProgramEffects : public GrGLProgramEffects {
michael@0 150 public:
michael@0 151 virtual void setData(GrGpuGL*,
michael@0 152 const GrGLUniformManager&,
michael@0 153 const GrEffectStage* effectStages[]) SK_OVERRIDE;
michael@0 154
michael@0 155 private:
michael@0 156 friend class GrGLVertexProgramEffectsBuilder;
michael@0 157
michael@0 158 GrGLVertexProgramEffects(int reserveCount, bool explicitLocalCoords)
michael@0 159 : INHERITED(reserveCount)
michael@0 160 , fTransforms(reserveCount)
michael@0 161 , fHasExplicitLocalCoords(explicitLocalCoords) {
michael@0 162 }
michael@0 163
michael@0 164 /**
michael@0 165 * Helper for GrGLProgramEffectsBuilder::emitEfffect(). This method is meant to only be called
michael@0 166 * during the construction phase.
michael@0 167 */
michael@0 168 void emitEffect(GrGLFullShaderBuilder*,
michael@0 169 const GrEffectStage&,
michael@0 170 GrGLProgramEffects::EffectKey,
michael@0 171 const char* outColor,
michael@0 172 const char* inColor,
michael@0 173 int stageIndex);
michael@0 174
michael@0 175 /**
michael@0 176 * Helper for emitEffect(). Emits any attributes an effect may have.
michael@0 177 */
michael@0 178 void emitAttributes(GrGLFullShaderBuilder*, const GrEffectStage&);
michael@0 179
michael@0 180 /**
michael@0 181 * Helper for emitEffect(). Emits code to implement an effect's coord transforms in the VS.
michael@0 182 * Varyings are added as an outputs of the VS and inputs to the FS. The varyings may be either a
michael@0 183 * vec2f or vec3f depending upon whether perspective interpolation is required or not. The names
michael@0 184 * of the varyings in the VS and FS as well their types are appended to the
michael@0 185 * TransformedCoordsArray* object, which is in turn passed to the effect's emitCode() function.
michael@0 186 */
michael@0 187 void emitTransforms(GrGLFullShaderBuilder*,
michael@0 188 const GrEffectRef&,
michael@0 189 EffectKey,
michael@0 190 TransformedCoordsArray*);
michael@0 191
michael@0 192 /**
michael@0 193 * Helper for setData(). Sets all the transform matrices for an effect.
michael@0 194 */
michael@0 195 void setTransformData(const GrGLUniformManager&, const GrDrawEffect&, int effectIdx);
michael@0 196
michael@0 197 struct Transform {
michael@0 198 Transform() { fCurrentValue = SkMatrix::InvalidMatrix(); }
michael@0 199 UniformHandle fHandle;
michael@0 200 GrSLType fType;
michael@0 201 SkMatrix fCurrentValue;
michael@0 202 };
michael@0 203
michael@0 204 SkTArray<SkSTArray<2, Transform, true> > fTransforms;
michael@0 205 bool fHasExplicitLocalCoords;
michael@0 206
michael@0 207 typedef GrGLProgramEffects INHERITED;
michael@0 208 };
michael@0 209
michael@0 210 /**
michael@0 211 * This class is used to construct a GrGLVertexProgramEffects* object.
michael@0 212 */
michael@0 213 class GrGLVertexProgramEffectsBuilder : public GrGLProgramEffectsBuilder {
michael@0 214 public:
michael@0 215 GrGLVertexProgramEffectsBuilder(GrGLFullShaderBuilder*, int reserveCount);
michael@0 216 virtual ~GrGLVertexProgramEffectsBuilder() { }
michael@0 217
michael@0 218 virtual void emitEffect(const GrEffectStage&,
michael@0 219 GrGLProgramEffects::EffectKey,
michael@0 220 const char* outColor,
michael@0 221 const char* inColor,
michael@0 222 int stageIndex) SK_OVERRIDE;
michael@0 223
michael@0 224 /**
michael@0 225 * Finalizes the building process and returns the effect array. After this call, the builder
michael@0 226 * becomes invalid.
michael@0 227 */
michael@0 228 GrGLProgramEffects* finish() { return fProgramEffects.detach(); }
michael@0 229
michael@0 230 private:
michael@0 231 GrGLFullShaderBuilder* fBuilder;
michael@0 232 SkAutoTDelete<GrGLVertexProgramEffects> fProgramEffects;
michael@0 233
michael@0 234 typedef GrGLProgramEffectsBuilder INHERITED;
michael@0 235 };
michael@0 236
michael@0 237 ////////////////////////////////////////////////////////////////////////////////
michael@0 238
michael@0 239 /**
michael@0 240 * This is a GrGLProgramEffects implementation that does coord transforms with the the built-in GL
michael@0 241 * TexGen functionality.
michael@0 242 */
michael@0 243 class GrGLTexGenProgramEffects : public GrGLProgramEffects {
michael@0 244 public:
michael@0 245 virtual void setData(GrGpuGL*,
michael@0 246 const GrGLUniformManager&,
michael@0 247 const GrEffectStage* effectStages[]) SK_OVERRIDE;
michael@0 248
michael@0 249 private:
michael@0 250 friend class GrGLTexGenProgramEffectsBuilder;
michael@0 251
michael@0 252 GrGLTexGenProgramEffects(int reserveCount)
michael@0 253 : INHERITED(reserveCount)
michael@0 254 , fTransforms(reserveCount) {
michael@0 255 }
michael@0 256
michael@0 257 /**
michael@0 258 * Helper for GrGLProgramEffectsBuilder::emitEfffect(). This method is meant to only be called
michael@0 259 * during the construction phase.
michael@0 260 */
michael@0 261 void emitEffect(GrGLFragmentOnlyShaderBuilder*,
michael@0 262 const GrEffectStage&,
michael@0 263 GrGLProgramEffects::EffectKey,
michael@0 264 const char* outColor,
michael@0 265 const char* inColor,
michael@0 266 int stageIndex);
michael@0 267
michael@0 268 /**
michael@0 269 * Helper for emitEffect(). Allocates texture units from the builder for each transform in an
michael@0 270 * effect. The transforms all use adjacent texture units. They either use two or three of the
michael@0 271 * coordinates at a given texture unit, depending on if they need perspective interpolation.
michael@0 272 * The expressions to access the transformed coords (i.e. 'vec2(gl_TexCoord[0])') as well as the
michael@0 273 * types are appended to the TransformedCoordsArray* object, which is in turn passed to the
michael@0 274 * effect's emitCode() function.
michael@0 275 */
michael@0 276 void setupTexGen(GrGLFragmentOnlyShaderBuilder*,
michael@0 277 const GrEffectRef&,
michael@0 278 EffectKey,
michael@0 279 TransformedCoordsArray*);
michael@0 280
michael@0 281 /**
michael@0 282 * Helper for setData(). Sets the TexGen state for each transform in an effect.
michael@0 283 */
michael@0 284 void setTexGenState(GrGpuGL*, const GrDrawEffect&, int effectIdx);
michael@0 285
michael@0 286 struct Transforms {
michael@0 287 Transforms(EffectKey transformKey, int texCoordIndex)
michael@0 288 : fTransformKey(transformKey), fTexCoordIndex(texCoordIndex) {}
michael@0 289 EffectKey fTransformKey;
michael@0 290 int fTexCoordIndex;
michael@0 291 };
michael@0 292
michael@0 293 SkTArray<Transforms> fTransforms;
michael@0 294
michael@0 295 typedef GrGLProgramEffects INHERITED;
michael@0 296 };
michael@0 297
michael@0 298 /**
michael@0 299 * This class is used to construct a GrGLTexGenProgramEffects* object.
michael@0 300 */
michael@0 301 class GrGLTexGenProgramEffectsBuilder : public GrGLProgramEffectsBuilder {
michael@0 302 public:
michael@0 303 GrGLTexGenProgramEffectsBuilder(GrGLFragmentOnlyShaderBuilder*, int reserveCount);
michael@0 304 virtual ~GrGLTexGenProgramEffectsBuilder() { }
michael@0 305
michael@0 306 virtual void emitEffect(const GrEffectStage&,
michael@0 307 GrGLProgramEffects::EffectKey,
michael@0 308 const char* outColor,
michael@0 309 const char* inColor,
michael@0 310 int stageIndex) SK_OVERRIDE;
michael@0 311
michael@0 312 /**
michael@0 313 * Finalizes the building process and returns the effect array. After this call, the builder
michael@0 314 * becomes invalid.
michael@0 315 */
michael@0 316 GrGLProgramEffects* finish() { return fProgramEffects.detach(); }
michael@0 317
michael@0 318 private:
michael@0 319 GrGLFragmentOnlyShaderBuilder* fBuilder;
michael@0 320 SkAutoTDelete<GrGLTexGenProgramEffects> fProgramEffects;
michael@0 321
michael@0 322 typedef GrGLProgramEffectsBuilder INHERITED;
michael@0 323 };
michael@0 324
michael@0 325 #endif

mercurial