| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef GrGLProgramDataManager_DEFINED | 8 #ifndef GrGLProgramDataManager_DEFINED |
| 9 #define GrGLProgramDataManager_DEFINED | 9 #define GrGLProgramDataManager_DEFINED |
| 10 | 10 |
| 11 #include "gl/GrGLShaderVar.h" | 11 #include "gl/GrGLShaderVar.h" |
| 12 #include "GrAllocator.h" | 12 #include "GrAllocator.h" |
| 13 | 13 |
| 14 #include "SkTArray.h" | 14 #include "SkTArray.h" |
| 15 | 15 |
| 16 class GrGLGpu; | 16 class GrGLGpu; |
| 17 class SkMatrix; | 17 class SkMatrix; |
| 18 class GrGLProgram; | 18 class GrGLProgram; |
| 19 class GrGLProgramBuilder; | 19 class GrGLProgramBuilder; |
| 20 | 20 |
| 21 /** Manages the resources used by a shader program. | 21 /** Manages the resources used by a shader program. |
| 22 * The resources are objects the program uses to communicate with the | 22 * The resources are objects the program uses to communicate with the |
| 23 * application code. | 23 * application code. |
| 24 */ | 24 */ |
| 25 class GrGLProgramDataManager : SkNoncopyable { | 25 class GrGLProgramDataManager : SkNoncopyable { |
| 26 public: | 26 public: |
| 27 // Opaque handle to a uniform | 27 // Opaque handle to a resource |
| 28 class ShaderResourceHandle { | 28 class ShaderResourceHandle { |
| 29 public: | 29 public: |
| 30 bool isValid() const { return -1 != fValue; } | |
| 31 ShaderResourceHandle() | |
| 32 : fValue(-1) { | |
| 33 } | |
| 34 protected: | |
| 35 ShaderResourceHandle(int value) | 30 ShaderResourceHandle(int value) |
| 36 : fValue(value) { | 31 : fValue(value) { |
| 37 SkASSERT(isValid()); | 32 SkASSERT(this->isValid()); |
| 38 } | 33 } |
| 34 |
| 35 ShaderResourceHandle() |
| 36 : fValue(kInvalid_ShaderResourceHandle) { |
| 37 } |
| 38 |
| 39 bool operator==(const ShaderResourceHandle& other) const { return other.
fValue == fValue; } |
| 40 bool isValid() const { return kInvalid_ShaderResourceHandle != fValue; } |
| 41 int toIndex() const { SkASSERT(this->isValid()); return fValue; } |
| 42 |
| 43 private: |
| 44 static const int kInvalid_ShaderResourceHandle = -1; |
| 39 int fValue; | 45 int fValue; |
| 40 }; | 46 }; |
| 41 | 47 |
| 42 class UniformHandle : public ShaderResourceHandle { | 48 typedef ShaderResourceHandle UniformHandle; |
| 43 public: | |
| 44 /** Creates a reference to an unifrom of a GrGLShaderBuilder. | |
| 45 * The ref can be used to set the uniform with corresponding the GrGLPro
gramDataManager.*/ | |
| 46 static UniformHandle CreateFromUniformIndex(int i); | |
| 47 UniformHandle() { } | |
| 48 bool operator==(const UniformHandle& other) const { return other.fValue
== fValue; } | |
| 49 private: | |
| 50 UniformHandle(int value) : ShaderResourceHandle(value) { } | |
| 51 int toProgramDataIndex() const { SkASSERT(isValid()); return fValue; } | |
| 52 int toShaderBuilderIndex() const { return toProgramDataIndex(); } | |
| 53 | |
| 54 friend class GrGLProgramDataManager; // For accessing toProgramDataIndex
(). | |
| 55 friend class GrGLProgramBuilder; // For accessing toShaderBuilderIndex()
. | |
| 56 friend class GrGLGeometryProcessor; | |
| 57 }; | |
| 58 | 49 |
| 59 struct UniformInfo { | 50 struct UniformInfo { |
| 60 GrGLShaderVar fVariable; | 51 GrGLShaderVar fVariable; |
| 61 uint32_t fVisibility; | 52 uint32_t fVisibility; |
| 62 GrGLint fLocation; | 53 GrGLint fLocation; |
| 63 }; | 54 }; |
| 64 | 55 |
| 65 // This uses an allocator rather than array so that the GrGLShaderVars don't
move in memory | 56 // This uses an allocator rather than array so that the GrGLShaderVars don't
move in memory |
| 66 // after they are inserted. Users of GrGLShaderBuilder get refs to the vars
and ptrs to their | 57 // after they are inserted. Users of GrGLShaderBuilder get refs to the vars
and ptrs to their |
| 67 // name strings. Otherwise, we'd have to hand out copies. | 58 // name strings. Otherwise, we'd have to hand out copies. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 98 |
| 108 SkDEBUGCODE(void printUnused(const Uniform&) const;) | 99 SkDEBUGCODE(void printUnused(const Uniform&) const;) |
| 109 | 100 |
| 110 SkTArray<Uniform, true> fUniforms; | 101 SkTArray<Uniform, true> fUniforms; |
| 111 GrGLGpu* fGpu; | 102 GrGLGpu* fGpu; |
| 112 | 103 |
| 113 typedef SkNoncopyable INHERITED; | 104 typedef SkNoncopyable INHERITED; |
| 114 }; | 105 }; |
| 115 | 106 |
| 116 #endif | 107 #endif |
| OLD | NEW |