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