gfx/skia/trunk/src/gpu/gl/GrGLProgram.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 2011 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
michael@0 9 #ifndef GrGLProgram_DEFINED
michael@0 10 #define GrGLProgram_DEFINED
michael@0 11
michael@0 12 #include "GrDrawState.h"
michael@0 13 #include "GrGLContext.h"
michael@0 14 #include "GrGLProgramDesc.h"
michael@0 15 #include "GrGLShaderBuilder.h"
michael@0 16 #include "GrGLSL.h"
michael@0 17 #include "GrGLTexture.h"
michael@0 18 #include "GrGLUniformManager.h"
michael@0 19
michael@0 20 #include "SkString.h"
michael@0 21 #include "SkXfermode.h"
michael@0 22
michael@0 23 class GrBinHashKeyBuilder;
michael@0 24 class GrGLEffect;
michael@0 25 class GrGLProgramEffects;
michael@0 26 class GrGLShaderBuilder;
michael@0 27
michael@0 28 /**
michael@0 29 * This class manages a GPU program and records per-program information.
michael@0 30 * We can specify the attribute locations so that they are constant
michael@0 31 * across our shaders. But the driver determines the uniform locations
michael@0 32 * at link time. We don't need to remember the sampler uniform location
michael@0 33 * because we will bind a texture slot to it and never change it
michael@0 34 * Uniforms are program-local so we can't rely on fHWState to hold the
michael@0 35 * previous uniform state after a program change.
michael@0 36 */
michael@0 37 class GrGLProgram : public SkRefCnt {
michael@0 38 public:
michael@0 39 SK_DECLARE_INST_COUNT(GrGLProgram)
michael@0 40
michael@0 41 static GrGLProgram* Create(GrGpuGL* gpu,
michael@0 42 const GrGLProgramDesc& desc,
michael@0 43 const GrEffectStage* colorStages[],
michael@0 44 const GrEffectStage* coverageStages[]);
michael@0 45
michael@0 46 virtual ~GrGLProgram();
michael@0 47
michael@0 48 /**
michael@0 49 * Call to abandon GL objects owned by this program.
michael@0 50 */
michael@0 51 void abandon();
michael@0 52
michael@0 53 /**
michael@0 54 * The shader may modify the blend coefficients. Params are in/out.
michael@0 55 */
michael@0 56 void overrideBlend(GrBlendCoeff* srcCoeff, GrBlendCoeff* dstCoeff) const;
michael@0 57
michael@0 58 const GrGLProgramDesc& getDesc() { return fDesc; }
michael@0 59
michael@0 60 /**
michael@0 61 * Gets the GL program ID for this program.
michael@0 62 */
michael@0 63 GrGLuint programID() const { return fProgramID; }
michael@0 64
michael@0 65 bool hasVertexShader() const { return fHasVertexShader; }
michael@0 66
michael@0 67 /**
michael@0 68 * Some GL state that is relevant to programs is not stored per-program. In particular color
michael@0 69 * and coverage attributes can be global state. This struct is read and updated by
michael@0 70 * GrGLProgram::setColor and GrGLProgram::setCoverage to allow us to avoid setting this state
michael@0 71 * redundantly.
michael@0 72 */
michael@0 73 struct SharedGLState {
michael@0 74 GrColor fConstAttribColor;
michael@0 75 int fConstAttribColorIndex;
michael@0 76 GrColor fConstAttribCoverage;
michael@0 77 int fConstAttribCoverageIndex;
michael@0 78
michael@0 79 SharedGLState() { this->invalidate(); }
michael@0 80 void invalidate() {
michael@0 81 fConstAttribColor = GrColor_ILLEGAL;
michael@0 82 fConstAttribColorIndex = -1;
michael@0 83 fConstAttribCoverage = GrColor_ILLEGAL;
michael@0 84 fConstAttribCoverageIndex = -1;
michael@0 85 }
michael@0 86 };
michael@0 87
michael@0 88 /**
michael@0 89 * The GrDrawState's view matrix along with the aspects of the render target determine the
michael@0 90 * matrix sent to GL. The size of the render target affects the GL matrix because we must
michael@0 91 * convert from Skia device coords to GL's normalized coords. Also the origin of the render
michael@0 92 * target may require us to perform a mirror-flip.
michael@0 93 */
michael@0 94 struct MatrixState {
michael@0 95 SkMatrix fViewMatrix;
michael@0 96 SkISize fRenderTargetSize;
michael@0 97 GrSurfaceOrigin fRenderTargetOrigin;
michael@0 98
michael@0 99 MatrixState() { this->invalidate(); }
michael@0 100 void invalidate() {
michael@0 101 fViewMatrix = SkMatrix::InvalidMatrix();
michael@0 102 fRenderTargetSize.fWidth = -1;
michael@0 103 fRenderTargetSize.fHeight = -1;
michael@0 104 fRenderTargetOrigin = (GrSurfaceOrigin) -1;
michael@0 105 }
michael@0 106 template<int Size> void getGLMatrix(GrGLfloat* destMatrix) {
michael@0 107 SkMatrix combined;
michael@0 108 if (kBottomLeft_GrSurfaceOrigin == fRenderTargetOrigin) {
michael@0 109 combined.setAll(SkIntToScalar(2) / fRenderTargetSize.fWidth, 0, -SK_Scalar1,
michael@0 110 0, -SkIntToScalar(2) / fRenderTargetSize.fHeight, SK_Scalar1,
michael@0 111 0, 0, SkMatrix::I()[8]);
michael@0 112 } else {
michael@0 113 combined.setAll(SkIntToScalar(2) / fRenderTargetSize.fWidth, 0, -SK_Scalar1,
michael@0 114 0, SkIntToScalar(2) / fRenderTargetSize.fHeight, -SK_Scalar1,
michael@0 115 0, 0, SkMatrix::I()[8]);
michael@0 116 }
michael@0 117 combined.setConcat(combined, fViewMatrix);
michael@0 118 GrGLGetMatrix<Size>(destMatrix, combined);
michael@0 119 }
michael@0 120 };
michael@0 121
michael@0 122 /**
michael@0 123 * This function uploads uniforms and calls each GrGLEffect's setData. It is called before a
michael@0 124 * draw occurs using the program after the program has already been bound. It also uses the
michael@0 125 * GrGpuGL object to bind the textures required by the GrGLEffects. The color and coverage
michael@0 126 * stages come from GrGLProgramDesc::Build().
michael@0 127 */
michael@0 128 void setData(GrDrawState::BlendOptFlags,
michael@0 129 const GrEffectStage* colorStages[],
michael@0 130 const GrEffectStage* coverageStages[],
michael@0 131 const GrDeviceCoordTexture* dstCopy, // can be NULL
michael@0 132 SharedGLState*);
michael@0 133
michael@0 134 private:
michael@0 135 typedef GrGLUniformManager::UniformHandle UniformHandle;
michael@0 136
michael@0 137 // handles for uniforms (aside from per-effect samplers)
michael@0 138 struct UniformHandles {
michael@0 139 UniformHandle fViewMatrixUni;
michael@0 140 UniformHandle fColorUni;
michael@0 141 UniformHandle fCoverageUni;
michael@0 142
michael@0 143 // We use the render target height to provide a y-down frag coord when specifying
michael@0 144 // origin_upper_left is not supported.
michael@0 145 UniformHandle fRTHeightUni;
michael@0 146
michael@0 147 // Uniforms for computing texture coords to do the dst-copy lookup
michael@0 148 UniformHandle fDstCopyTopLeftUni;
michael@0 149 UniformHandle fDstCopyScaleUni;
michael@0 150 UniformHandle fDstCopySamplerUni;
michael@0 151 };
michael@0 152
michael@0 153 GrGLProgram(GrGpuGL* gpu,
michael@0 154 const GrGLProgramDesc& desc,
michael@0 155 const GrEffectStage* colorStages[],
michael@0 156 const GrEffectStage* coverageStages[]);
michael@0 157
michael@0 158 bool succeeded() const { return 0 != fProgramID; }
michael@0 159
michael@0 160 /**
michael@0 161 * This is the heavy initialization routine for building a GLProgram. colorStages and
michael@0 162 * coverageStages correspond to the output of GrGLProgramDesc::Build().
michael@0 163 */
michael@0 164 bool genProgram(GrGLShaderBuilder* builder,
michael@0 165 const GrEffectStage* colorStages[],
michael@0 166 const GrEffectStage* coverageStages[]);
michael@0 167
michael@0 168 // Sets the texture units for samplers
michael@0 169 void initSamplerUniforms();
michael@0 170
michael@0 171 // Helper for setData(). Makes GL calls to specify the initial color when there is not
michael@0 172 // per-vertex colors.
michael@0 173 void setColor(const GrDrawState&, GrColor color, SharedGLState*);
michael@0 174
michael@0 175 // Helper for setData(). Makes GL calls to specify the initial coverage when there is not
michael@0 176 // per-vertex coverages.
michael@0 177 void setCoverage(const GrDrawState&, GrColor coverage, SharedGLState*);
michael@0 178
michael@0 179 // Helper for setData() that sets the view matrix and loads the render target height uniform
michael@0 180 void setMatrixAndRenderTargetHeight(const GrDrawState&);
michael@0 181
michael@0 182 // GL program ID
michael@0 183 GrGLuint fProgramID;
michael@0 184
michael@0 185 // these reflect the current values of uniforms (GL uniform values travel with program)
michael@0 186 MatrixState fMatrixState;
michael@0 187 GrColor fColor;
michael@0 188 GrColor fCoverage;
michael@0 189 int fDstCopyTexUnit;
michael@0 190
michael@0 191 SkAutoTDelete<GrGLProgramEffects> fColorEffects;
michael@0 192 SkAutoTDelete<GrGLProgramEffects> fCoverageEffects;
michael@0 193
michael@0 194 GrGLProgramDesc fDesc;
michael@0 195 GrGpuGL* fGpu;
michael@0 196
michael@0 197 GrGLUniformManager fUniformManager;
michael@0 198 UniformHandles fUniformHandles;
michael@0 199
michael@0 200 bool fHasVertexShader;
michael@0 201 int fNumTexCoordSets;
michael@0 202
michael@0 203 typedef SkRefCnt INHERITED;
michael@0 204 };
michael@0 205
michael@0 206 #endif

mercurial