gfx/skia/trunk/src/gpu/gl/GrGLUniformManager.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.

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

mercurial