gfx/skia/trunk/src/gpu/gl/GrGLUniformManager.cpp

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 2012 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 #include "gl/GrGLShaderBuilder.h"
michael@0 9 #include "gl/GrGLProgram.h"
michael@0 10 #include "gl/GrGLUniformHandle.h"
michael@0 11 #include "gl/GrGpuGL.h"
michael@0 12 #include "SkMatrix.h"
michael@0 13
michael@0 14 #define ASSERT_ARRAY_UPLOAD_IN_BOUNDS(UNI, COUNT) \
michael@0 15 SkASSERT(arrayCount <= uni.fArrayCount || \
michael@0 16 (1 == arrayCount && GrGLShaderVar::kNonArray == uni.fArrayCount))
michael@0 17
michael@0 18 GrGLUniformManager::GrGLUniformManager(GrGpuGL* gpu) : fGpu(gpu) {
michael@0 19 // skbug.com/2056
michael@0 20 fUsingBindUniform = fGpu->glInterface()->fFunctions.fBindUniformLocation != NULL;
michael@0 21 }
michael@0 22
michael@0 23 GrGLUniformManager::UniformHandle GrGLUniformManager::appendUniform(GrSLType type, int arrayCount) {
michael@0 24 int idx = fUniforms.count();
michael@0 25 Uniform& uni = fUniforms.push_back();
michael@0 26 SkASSERT(GrGLShaderVar::kNonArray == arrayCount || arrayCount > 0);
michael@0 27 uni.fArrayCount = arrayCount;
michael@0 28 uni.fType = type;
michael@0 29 uni.fVSLocation = kUnusedUniform;
michael@0 30 uni.fFSLocation = kUnusedUniform;
michael@0 31 return GrGLUniformManager::UniformHandle::CreateFromUniformIndex(idx);
michael@0 32 }
michael@0 33
michael@0 34 void GrGLUniformManager::setSampler(UniformHandle u, GrGLint texUnit) const {
michael@0 35 const Uniform& uni = fUniforms[u.toUniformIndex()];
michael@0 36 SkASSERT(uni.fType == kSampler2D_GrSLType);
michael@0 37 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
michael@0 38 // FIXME: We still insert a single sampler uniform for every stage. If the shader does not
michael@0 39 // reference the sampler then the compiler may have optimized it out. Uncomment this assert
michael@0 40 // once stages insert their own samplers.
michael@0 41 // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
michael@0 42 if (kUnusedUniform != uni.fFSLocation) {
michael@0 43 GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fFSLocation, texUnit));
michael@0 44 }
michael@0 45 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
michael@0 46 GR_GL_CALL(fGpu->glInterface(), Uniform1i(uni.fVSLocation, texUnit));
michael@0 47 }
michael@0 48 }
michael@0 49
michael@0 50 void GrGLUniformManager::set1f(UniformHandle u, GrGLfloat v0) const {
michael@0 51 const Uniform& uni = fUniforms[u.toUniformIndex()];
michael@0 52 SkASSERT(uni.fType == kFloat_GrSLType);
michael@0 53 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
michael@0 54 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
michael@0 55 if (kUnusedUniform != uni.fFSLocation) {
michael@0 56 GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fFSLocation, v0));
michael@0 57 }
michael@0 58 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
michael@0 59 GR_GL_CALL(fGpu->glInterface(), Uniform1f(uni.fVSLocation, v0));
michael@0 60 }
michael@0 61 }
michael@0 62
michael@0 63 void GrGLUniformManager::set1fv(UniformHandle u,
michael@0 64 int arrayCount,
michael@0 65 const GrGLfloat v[]) const {
michael@0 66 const Uniform& uni = fUniforms[u.toUniformIndex()];
michael@0 67 SkASSERT(uni.fType == kFloat_GrSLType);
michael@0 68 SkASSERT(arrayCount > 0);
michael@0 69 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
michael@0 70 // This assert fires in some instances of the two-pt gradient for its VSParams.
michael@0 71 // Once the uniform manager is responsible for inserting the duplicate uniform
michael@0 72 // arrays in VS and FS driver bug workaround, this can be enabled.
michael@0 73 //SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
michael@0 74 if (kUnusedUniform != uni.fFSLocation) {
michael@0 75 GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fFSLocation, arrayCount, v));
michael@0 76 }
michael@0 77 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
michael@0 78 GR_GL_CALL(fGpu->glInterface(), Uniform1fv(uni.fVSLocation, arrayCount, v));
michael@0 79 }
michael@0 80 }
michael@0 81
michael@0 82 void GrGLUniformManager::set2f(UniformHandle u, GrGLfloat v0, GrGLfloat v1) const {
michael@0 83 const Uniform& uni = fUniforms[u.toUniformIndex()];
michael@0 84 SkASSERT(uni.fType == kVec2f_GrSLType);
michael@0 85 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
michael@0 86 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
michael@0 87 if (kUnusedUniform != uni.fFSLocation) {
michael@0 88 GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fFSLocation, v0, v1));
michael@0 89 }
michael@0 90 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
michael@0 91 GR_GL_CALL(fGpu->glInterface(), Uniform2f(uni.fVSLocation, v0, v1));
michael@0 92 }
michael@0 93 }
michael@0 94
michael@0 95 void GrGLUniformManager::set2fv(UniformHandle u,
michael@0 96 int arrayCount,
michael@0 97 const GrGLfloat v[]) const {
michael@0 98 const Uniform& uni = fUniforms[u.toUniformIndex()];
michael@0 99 SkASSERT(uni.fType == kVec2f_GrSLType);
michael@0 100 SkASSERT(arrayCount > 0);
michael@0 101 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
michael@0 102 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
michael@0 103 if (kUnusedUniform != uni.fFSLocation) {
michael@0 104 GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fFSLocation, arrayCount, v));
michael@0 105 }
michael@0 106 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
michael@0 107 GR_GL_CALL(fGpu->glInterface(), Uniform2fv(uni.fVSLocation, arrayCount, v));
michael@0 108 }
michael@0 109 }
michael@0 110
michael@0 111 void GrGLUniformManager::set3f(UniformHandle u, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2) const {
michael@0 112 const Uniform& uni = fUniforms[u.toUniformIndex()];
michael@0 113 SkASSERT(uni.fType == kVec3f_GrSLType);
michael@0 114 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
michael@0 115 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
michael@0 116 if (kUnusedUniform != uni.fFSLocation) {
michael@0 117 GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fFSLocation, v0, v1, v2));
michael@0 118 }
michael@0 119 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
michael@0 120 GR_GL_CALL(fGpu->glInterface(), Uniform3f(uni.fVSLocation, v0, v1, v2));
michael@0 121 }
michael@0 122 }
michael@0 123
michael@0 124 void GrGLUniformManager::set3fv(UniformHandle u,
michael@0 125 int arrayCount,
michael@0 126 const GrGLfloat v[]) const {
michael@0 127 const Uniform& uni = fUniforms[u.toUniformIndex()];
michael@0 128 SkASSERT(uni.fType == kVec3f_GrSLType);
michael@0 129 SkASSERT(arrayCount > 0);
michael@0 130 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
michael@0 131 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
michael@0 132 if (kUnusedUniform != uni.fFSLocation) {
michael@0 133 GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fFSLocation, arrayCount, v));
michael@0 134 }
michael@0 135 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
michael@0 136 GR_GL_CALL(fGpu->glInterface(), Uniform3fv(uni.fVSLocation, arrayCount, v));
michael@0 137 }
michael@0 138 }
michael@0 139
michael@0 140 void GrGLUniformManager::set4f(UniformHandle u,
michael@0 141 GrGLfloat v0,
michael@0 142 GrGLfloat v1,
michael@0 143 GrGLfloat v2,
michael@0 144 GrGLfloat v3) const {
michael@0 145 const Uniform& uni = fUniforms[u.toUniformIndex()];
michael@0 146 SkASSERT(uni.fType == kVec4f_GrSLType);
michael@0 147 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
michael@0 148 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
michael@0 149 if (kUnusedUniform != uni.fFSLocation) {
michael@0 150 GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fFSLocation, v0, v1, v2, v3));
michael@0 151 }
michael@0 152 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
michael@0 153 GR_GL_CALL(fGpu->glInterface(), Uniform4f(uni.fVSLocation, v0, v1, v2, v3));
michael@0 154 }
michael@0 155 }
michael@0 156
michael@0 157 void GrGLUniformManager::set4fv(UniformHandle u,
michael@0 158 int arrayCount,
michael@0 159 const GrGLfloat v[]) const {
michael@0 160 const Uniform& uni = fUniforms[u.toUniformIndex()];
michael@0 161 SkASSERT(uni.fType == kVec4f_GrSLType);
michael@0 162 SkASSERT(arrayCount > 0);
michael@0 163 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
michael@0 164 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
michael@0 165 if (kUnusedUniform != uni.fFSLocation) {
michael@0 166 GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fFSLocation, arrayCount, v));
michael@0 167 }
michael@0 168 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
michael@0 169 GR_GL_CALL(fGpu->glInterface(), Uniform4fv(uni.fVSLocation, arrayCount, v));
michael@0 170 }
michael@0 171 }
michael@0 172
michael@0 173 void GrGLUniformManager::setMatrix3f(UniformHandle u, const GrGLfloat matrix[]) const {
michael@0 174 const Uniform& uni = fUniforms[u.toUniformIndex()];
michael@0 175 SkASSERT(uni.fType == kMat33f_GrSLType);
michael@0 176 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
michael@0 177 // TODO: Re-enable this assert once texture matrices aren't forced on all effects
michael@0 178 // SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
michael@0 179 if (kUnusedUniform != uni.fFSLocation) {
michael@0 180 GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fFSLocation, 1, false, matrix));
michael@0 181 }
michael@0 182 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
michael@0 183 GR_GL_CALL(fGpu->glInterface(), UniformMatrix3fv(uni.fVSLocation, 1, false, matrix));
michael@0 184 }
michael@0 185 }
michael@0 186
michael@0 187 void GrGLUniformManager::setMatrix4f(UniformHandle u, const GrGLfloat matrix[]) const {
michael@0 188 const Uniform& uni = fUniforms[u.toUniformIndex()];
michael@0 189 SkASSERT(uni.fType == kMat44f_GrSLType);
michael@0 190 SkASSERT(GrGLShaderVar::kNonArray == uni.fArrayCount);
michael@0 191 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
michael@0 192 if (kUnusedUniform != uni.fFSLocation) {
michael@0 193 GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fFSLocation, 1, false, matrix));
michael@0 194 }
michael@0 195 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
michael@0 196 GR_GL_CALL(fGpu->glInterface(), UniformMatrix4fv(uni.fVSLocation, 1, false, matrix));
michael@0 197 }
michael@0 198 }
michael@0 199
michael@0 200 void GrGLUniformManager::setMatrix3fv(UniformHandle u,
michael@0 201 int arrayCount,
michael@0 202 const GrGLfloat matrices[]) const {
michael@0 203 const Uniform& uni = fUniforms[u.toUniformIndex()];
michael@0 204 SkASSERT(uni.fType == kMat33f_GrSLType);
michael@0 205 SkASSERT(arrayCount > 0);
michael@0 206 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
michael@0 207 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
michael@0 208 if (kUnusedUniform != uni.fFSLocation) {
michael@0 209 GR_GL_CALL(fGpu->glInterface(),
michael@0 210 UniformMatrix3fv(uni.fFSLocation, arrayCount, false, matrices));
michael@0 211 }
michael@0 212 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
michael@0 213 GR_GL_CALL(fGpu->glInterface(),
michael@0 214 UniformMatrix3fv(uni.fVSLocation, arrayCount, false, matrices));
michael@0 215 }
michael@0 216 }
michael@0 217
michael@0 218 void GrGLUniformManager::setMatrix4fv(UniformHandle u,
michael@0 219 int arrayCount,
michael@0 220 const GrGLfloat matrices[]) const {
michael@0 221 const Uniform& uni = fUniforms[u.toUniformIndex()];
michael@0 222 SkASSERT(uni.fType == kMat44f_GrSLType);
michael@0 223 SkASSERT(arrayCount > 0);
michael@0 224 ASSERT_ARRAY_UPLOAD_IN_BOUNDS(uni, arrayCount);
michael@0 225 SkASSERT(kUnusedUniform != uni.fFSLocation || kUnusedUniform != uni.fVSLocation);
michael@0 226 if (kUnusedUniform != uni.fFSLocation) {
michael@0 227 GR_GL_CALL(fGpu->glInterface(),
michael@0 228 UniformMatrix4fv(uni.fFSLocation, arrayCount, false, matrices));
michael@0 229 }
michael@0 230 if (kUnusedUniform != uni.fVSLocation && uni.fVSLocation != uni.fFSLocation) {
michael@0 231 GR_GL_CALL(fGpu->glInterface(),
michael@0 232 UniformMatrix4fv(uni.fVSLocation, arrayCount, false, matrices));
michael@0 233 }
michael@0 234 }
michael@0 235
michael@0 236 void GrGLUniformManager::setSkMatrix(UniformHandle u, const SkMatrix& matrix) const {
michael@0 237 GrGLfloat mt[] = {
michael@0 238 matrix.get(SkMatrix::kMScaleX),
michael@0 239 matrix.get(SkMatrix::kMSkewY),
michael@0 240 matrix.get(SkMatrix::kMPersp0),
michael@0 241 matrix.get(SkMatrix::kMSkewX),
michael@0 242 matrix.get(SkMatrix::kMScaleY),
michael@0 243 matrix.get(SkMatrix::kMPersp1),
michael@0 244 matrix.get(SkMatrix::kMTransX),
michael@0 245 matrix.get(SkMatrix::kMTransY),
michael@0 246 matrix.get(SkMatrix::kMPersp2),
michael@0 247 };
michael@0 248 this->setMatrix3f(u, mt);
michael@0 249 }
michael@0 250
michael@0 251
michael@0 252 void GrGLUniformManager::getUniformLocations(GrGLuint programID, const BuilderUniformArray& uniforms) {
michael@0 253 SkASSERT(uniforms.count() == fUniforms.count());
michael@0 254 int count = fUniforms.count();
michael@0 255 for (int i = 0; i < count; ++i) {
michael@0 256 SkASSERT(uniforms[i].fVariable.getType() == fUniforms[i].fType);
michael@0 257 SkASSERT(uniforms[i].fVariable.getArrayCount() == fUniforms[i].fArrayCount);
michael@0 258 GrGLint location;
michael@0 259 // TODO: Move the Xoom uniform array in both FS and VS bug workaround here.
michael@0 260 if (fUsingBindUniform) {
michael@0 261 location = i;
michael@0 262 GR_GL_CALL(fGpu->glInterface(),
michael@0 263 BindUniformLocation(programID, location, uniforms[i].fVariable.c_str()));
michael@0 264 } else {
michael@0 265 GR_GL_CALL_RET(fGpu->glInterface(), location,
michael@0 266 GetUniformLocation(programID, uniforms[i].fVariable.c_str()));
michael@0 267 }
michael@0 268 if (GrGLShaderBuilder::kVertex_Visibility & uniforms[i].fVisibility) {
michael@0 269 fUniforms[i].fVSLocation = location;
michael@0 270 }
michael@0 271 if (GrGLShaderBuilder::kFragment_Visibility & uniforms[i].fVisibility) {
michael@0 272 fUniforms[i].fFSLocation = location;
michael@0 273 }
michael@0 274 }
michael@0 275 }
michael@0 276
michael@0 277 const GrGLUniformManager::BuilderUniform&
michael@0 278 GrGLUniformManager::getBuilderUniform(const BuilderUniformArray& array, UniformHandle handle) const {
michael@0 279 return array[handle.toUniformIndex()];
michael@0 280 }

mercurial