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.
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 | #ifndef GrGLUniformManager_DEFINED |
michael@0 | 9 | #define GrGLUniformManager_DEFINED |
michael@0 | 10 | |
michael@0 | 11 | #include "gl/GrGLShaderVar.h" |
michael@0 | 12 | #include "gl/GrGLSL.h" |
michael@0 | 13 | #include "GrAllocator.h" |
michael@0 | 14 | |
michael@0 | 15 | #include "SkTArray.h" |
michael@0 | 16 | |
michael@0 | 17 | class GrGpuGL; |
michael@0 | 18 | class SkMatrix; |
michael@0 | 19 | |
michael@0 | 20 | /** Manages a program's uniforms. |
michael@0 | 21 | */ |
michael@0 | 22 | class GrGLUniformManager { |
michael@0 | 23 | public: |
michael@0 | 24 | // Opaque handle to a uniform |
michael@0 | 25 | class UniformHandle { |
michael@0 | 26 | public: |
michael@0 | 27 | static UniformHandle CreateFromUniformIndex(int i); |
michael@0 | 28 | |
michael@0 | 29 | bool isValid() const { return 0 != fValue; } |
michael@0 | 30 | |
michael@0 | 31 | bool operator==(const UniformHandle& other) const { return other.fValue == fValue; } |
michael@0 | 32 | |
michael@0 | 33 | UniformHandle() |
michael@0 | 34 | : fValue(0) { |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | private: |
michael@0 | 38 | UniformHandle(int value) |
michael@0 | 39 | : fValue(~value) { |
michael@0 | 40 | SkASSERT(isValid()); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | int toUniformIndex() const { SkASSERT(isValid()); return ~fValue; } |
michael@0 | 44 | |
michael@0 | 45 | int fValue; |
michael@0 | 46 | friend class GrGLUniformManager; // For accessing toUniformIndex(). |
michael@0 | 47 | }; |
michael@0 | 48 | |
michael@0 | 49 | GrGLUniformManager(GrGpuGL* gpu); |
michael@0 | 50 | |
michael@0 | 51 | UniformHandle appendUniform(GrSLType type, int arrayCount = GrGLShaderVar::kNonArray); |
michael@0 | 52 | |
michael@0 | 53 | /** Functions for uploading uniform values. The varities ending in v can be used to upload to an |
michael@0 | 54 | * array of uniforms. arrayCount must be <= the array count of the uniform. |
michael@0 | 55 | */ |
michael@0 | 56 | void setSampler(UniformHandle, GrGLint texUnit) const; |
michael@0 | 57 | void set1f(UniformHandle, GrGLfloat v0) const; |
michael@0 | 58 | void set1fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; |
michael@0 | 59 | void set2f(UniformHandle, GrGLfloat, GrGLfloat) const; |
michael@0 | 60 | void set2fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; |
michael@0 | 61 | void set3f(UniformHandle, GrGLfloat, GrGLfloat, GrGLfloat) const; |
michael@0 | 62 | void set3fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; |
michael@0 | 63 | void set4f(UniformHandle, GrGLfloat, GrGLfloat, GrGLfloat, GrGLfloat) const; |
michael@0 | 64 | void set4fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; |
michael@0 | 65 | // matrices are column-major, the first three upload a single matrix, the latter three upload |
michael@0 | 66 | // arrayCount matrices into a uniform array. |
michael@0 | 67 | void setMatrix3f(UniformHandle, const GrGLfloat matrix[]) const; |
michael@0 | 68 | void setMatrix4f(UniformHandle, const GrGLfloat matrix[]) const; |
michael@0 | 69 | void setMatrix3fv(UniformHandle, int arrayCount, const GrGLfloat matrices[]) const; |
michael@0 | 70 | void setMatrix4fv(UniformHandle, int arrayCount, const GrGLfloat matrices[]) const; |
michael@0 | 71 | |
michael@0 | 72 | // convenience method for uploading a SkMatrix to a 3x3 matrix uniform |
michael@0 | 73 | void setSkMatrix(UniformHandle, const SkMatrix&) const; |
michael@0 | 74 | |
michael@0 | 75 | struct BuilderUniform { |
michael@0 | 76 | GrGLShaderVar fVariable; |
michael@0 | 77 | uint32_t fVisibility; |
michael@0 | 78 | }; |
michael@0 | 79 | // This uses an allocator rather than array so that the GrGLShaderVars don't move in memory |
michael@0 | 80 | // after they are inserted. Users of GrGLShaderBuilder get refs to the vars and ptrs to their |
michael@0 | 81 | // name strings. Otherwise, we'd have to hand out copies. |
michael@0 | 82 | typedef GrTAllocator<BuilderUniform> BuilderUniformArray; |
michael@0 | 83 | |
michael@0 | 84 | /** |
michael@0 | 85 | * Called by the GrGLShaderBuilder to know if the manager is using |
michael@0 | 86 | * BindUniformLocation. In that case getUniformLocations must be called |
michael@0 | 87 | * before the program is linked. |
michael@0 | 88 | */ |
michael@0 | 89 | bool isUsingBindUniform() const { return fUsingBindUniform; } |
michael@0 | 90 | |
michael@0 | 91 | /** |
michael@0 | 92 | * Called by the GrGLShaderBuilder to get GL locations for all uniforms. |
michael@0 | 93 | */ |
michael@0 | 94 | void getUniformLocations(GrGLuint programID, const BuilderUniformArray& uniforms); |
michael@0 | 95 | |
michael@0 | 96 | /** |
michael@0 | 97 | * Called by the GrGLShaderBuilder to access the array by the handle (index). |
michael@0 | 98 | */ |
michael@0 | 99 | const BuilderUniform& getBuilderUniform(const BuilderUniformArray&, GrGLUniformManager::UniformHandle) const; |
michael@0 | 100 | |
michael@0 | 101 | private: |
michael@0 | 102 | enum { |
michael@0 | 103 | kUnusedUniform = -1, |
michael@0 | 104 | }; |
michael@0 | 105 | |
michael@0 | 106 | struct Uniform { |
michael@0 | 107 | GrGLint fVSLocation; |
michael@0 | 108 | GrGLint fFSLocation; |
michael@0 | 109 | GrSLType fType; |
michael@0 | 110 | int fArrayCount; |
michael@0 | 111 | }; |
michael@0 | 112 | |
michael@0 | 113 | bool fUsingBindUniform; |
michael@0 | 114 | SkTArray<Uniform, true> fUniforms; |
michael@0 | 115 | GrGpuGL* fGpu; |
michael@0 | 116 | }; |
michael@0 | 117 | |
michael@0 | 118 | #endif |