| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 | 8 |
| 9 #ifndef GrGLProgram_DEFINED | 9 #ifndef GrGLProgram_DEFINED |
| 10 #define GrGLProgram_DEFINED | 10 #define GrGLProgram_DEFINED |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 * Gets the GL program ID for this program. | 53 * Gets the GL program ID for this program. |
| 54 */ | 54 */ |
| 55 GrGLuint programID() const { return fProgramID; } | 55 GrGLuint programID() const { return fProgramID; } |
| 56 | 56 |
| 57 /* | 57 /* |
| 58 * The base class always has a vertex shader, only the NVPR variants may omi
t a vertex shader | 58 * The base class always has a vertex shader, only the NVPR variants may omi
t a vertex shader |
| 59 */ | 59 */ |
| 60 virtual bool hasVertexShader() const { return true; } | 60 virtual bool hasVertexShader() const { return true; } |
| 61 | 61 |
| 62 /** | 62 /** |
| 63 * The GrDrawState's view matrix along with the aspects of the render target
determine the | 63 * We use the RT's size and origin to adjust from Skia device space to OpenG
L normalized device |
| 64 * matrix sent to GL. The size of the render target affects the GL matrix be
cause we must | 64 * space and to make device space positions have the correct origin for proc
essors that require |
| 65 * convert from Skia device coords to GL's normalized coords. Also the origi
n of the render | 65 * them. |
| 66 * target may require us to perform a mirror-flip. | |
| 67 */ | 66 */ |
| 68 struct MatrixState { | 67 struct RenderTargetState { |
| 69 SkMatrix fViewMatrix; | |
| 70 SkISize fRenderTargetSize; | 68 SkISize fRenderTargetSize; |
| 71 GrSurfaceOrigin fRenderTargetOrigin; | 69 GrSurfaceOrigin fRenderTargetOrigin; |
| 72 | 70 |
| 73 MatrixState() { this->invalidate(); } | 71 RenderTargetState() { this->invalidate(); } |
| 74 void invalidate() { | 72 void invalidate() { |
| 75 fViewMatrix = SkMatrix::InvalidMatrix(); | |
| 76 fRenderTargetSize.fWidth = -1; | 73 fRenderTargetSize.fWidth = -1; |
| 77 fRenderTargetSize.fHeight = -1; | 74 fRenderTargetSize.fHeight = -1; |
| 78 fRenderTargetOrigin = (GrSurfaceOrigin) -1; | 75 fRenderTargetOrigin = (GrSurfaceOrigin) -1; |
| 79 } | 76 } |
| 80 | 77 |
| 81 /** | 78 /** |
| 82 * Gets a matrix that goes from local coords to Skia's device coordinate
s. | |
| 83 */ | |
| 84 template<int Size> void getGLMatrix(GrGLfloat* destMatrix) { | |
| 85 GrGLGetMatrix<Size>(destMatrix, fViewMatrix); | |
| 86 } | |
| 87 | |
| 88 /** | |
| 89 * Gets a matrix that goes from local coordinates to GL normalized devic
e coords. | |
| 90 */ | |
| 91 template<int Size> void getRTAdjustedGLMatrix(GrGLfloat* destMatrix) { | |
| 92 SkMatrix combined; | |
| 93 if (kBottomLeft_GrSurfaceOrigin == fRenderTargetOrigin) { | |
| 94 combined.setAll(SkIntToScalar(2) / fRenderTargetSize.fWidth, 0,
-SK_Scalar1, | |
| 95 0, -SkIntToScalar(2) / fRenderTargetSize.fHeight
, SK_Scalar1, | |
| 96 0, 0, 1); | |
| 97 } else { | |
| 98 combined.setAll(SkIntToScalar(2) / fRenderTargetSize.fWidth, 0,
-SK_Scalar1, | |
| 99 0, SkIntToScalar(2) / fRenderTargetSize.fHeight,
-SK_Scalar1, | |
| 100 0, 0, 1); | |
| 101 } | |
| 102 combined.preConcat(fViewMatrix); | |
| 103 GrGLGetMatrix<Size>(destMatrix, combined); | |
| 104 } | |
| 105 | |
| 106 /** | |
| 107 * Gets a vec4 that adjusts the position from Skia device coords to GL's
normalized device | 79 * Gets a vec4 that adjusts the position from Skia device coords to GL's
normalized device |
| 108 * coords. Assuming the transformed position, pos, is a homogeneous vec3
, the vec, v, is | 80 * coords. Assuming the transformed position, pos, is a homogeneous vec3
, the vec, v, is |
| 109 * applied as such: | 81 * applied as such: |
| 110 * pos.x = dot(v.xy, pos.xz) | 82 * pos.x = dot(v.xy, pos.xz) |
| 111 * pos.y = dot(v.zq, pos.yz) | 83 * pos.y = dot(v.zq, pos.yz) |
| 112 */ | 84 */ |
| 113 void getRTAdjustmentVec(GrGLfloat* destVec) { | 85 void getRTAdjustmentVec(GrGLfloat* destVec) { |
| 114 destVec[0] = 2.f / fRenderTargetSize.fWidth; | 86 destVec[0] = 2.f / fRenderTargetSize.fWidth; |
| 115 destVec[1] = -1.f; | 87 destVec[1] = -1.f; |
| 116 if (kBottomLeft_GrSurfaceOrigin == fRenderTargetOrigin) { | 88 if (kBottomLeft_GrSurfaceOrigin == fRenderTargetOrigin) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 GrGLInstalledFragProc*); | 127 GrGLInstalledFragProc*); |
| 156 void bindTextures(const GrGLInstalledProc*, const GrProcessor&); | 128 void bindTextures(const GrGLInstalledProc*, const GrProcessor&); |
| 157 | 129 |
| 158 /* | 130 /* |
| 159 * Legacy NVPR needs a hook here to flush path tex gen settings. | 131 * Legacy NVPR needs a hook here to flush path tex gen settings. |
| 160 * TODO when legacy nvpr is removed, remove this call. | 132 * TODO when legacy nvpr is removed, remove this call. |
| 161 */ | 133 */ |
| 162 virtual void didSetData(GrGpu::DrawType); | 134 virtual void didSetData(GrGpu::DrawType); |
| 163 | 135 |
| 164 // Helper for setData() that sets the view matrix and loads the render targe
t height uniform | 136 // Helper for setData() that sets the view matrix and loads the render targe
t height uniform |
| 165 void setMatrixAndRenderTargetHeight(const GrOptDrawState&); | 137 void setRenderTargetState(const GrOptDrawState&); |
| 166 virtual void onSetMatrixAndRenderTargetHeight(const GrOptDrawState&); | 138 virtual void onSetRenderTargetState(const GrOptDrawState&); |
| 167 | 139 |
| 168 // these reflect the current values of uniforms (GL uniform values travel wi
th program) | 140 // these reflect the current values of uniforms (GL uniform values travel wi
th program) |
| 169 MatrixState fMatrixState; | 141 RenderTargetState fRenderTargetState; |
| 170 GrColor fColor; | 142 GrColor fColor; |
| 171 uint8_t fCoverage; | 143 uint8_t fCoverage; |
| 172 int fDstCopyTexUnit; | 144 int fDstCopyTexUnit; |
| 173 BuiltinUniformHandles fBuiltinUniformHandles; | 145 BuiltinUniformHandles fBuiltinUniformHandles; |
| 174 GrGLuint fProgramID; | 146 GrGLuint fProgramID; |
| 175 | 147 |
| 176 // the installed effects | 148 // the installed effects |
| 177 SkAutoTDelete<GrGLInstalledGeoProc> fGeometryProcessor; | 149 SkAutoTDelete<GrGLInstalledGeoProc> fGeometryProcessor; |
| 178 SkAutoTDelete<GrGLInstalledXferProc> fXferProcessor; | 150 SkAutoTDelete<GrGLInstalledXferProc> fXferProcessor; |
| 179 SkAutoTUnref<GrGLInstalledFragProcs> fFragmentProcessors; | 151 SkAutoTUnref<GrGLInstalledFragProcs> fFragmentProcessors; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 197 class GrGLNvprProgramBase : public GrGLProgram { | 169 class GrGLNvprProgramBase : public GrGLProgram { |
| 198 protected: | 170 protected: |
| 199 GrGLNvprProgramBase(GrGLGpu*, | 171 GrGLNvprProgramBase(GrGLGpu*, |
| 200 const GrProgramDesc&, | 172 const GrProgramDesc&, |
| 201 const BuiltinUniformHandles&, | 173 const BuiltinUniformHandles&, |
| 202 GrGLuint programID, | 174 GrGLuint programID, |
| 203 const UniformInfoArray&, | 175 const UniformInfoArray&, |
| 204 GrGLInstalledGeoProc*, | 176 GrGLInstalledGeoProc*, |
| 205 GrGLInstalledXferProc* xferProcessor, | 177 GrGLInstalledXferProc* xferProcessor, |
| 206 GrGLInstalledFragProcs* fragmentProcessors); | 178 GrGLInstalledFragProcs* fragmentProcessors); |
| 207 virtual void onSetMatrixAndRenderTargetHeight(const GrOptDrawState&); | 179 virtual void onSetRenderTargetState(const GrOptDrawState&); |
| 208 | 180 |
| 209 typedef GrGLProgram INHERITED; | 181 typedef GrGLProgram INHERITED; |
| 210 }; | 182 }; |
| 211 | 183 |
| 212 class GrGLNvprProgram : public GrGLNvprProgramBase { | 184 class GrGLNvprProgram : public GrGLNvprProgramBase { |
| 213 public: | 185 public: |
| 214 virtual bool hasVertexShader() const SK_OVERRIDE { return true; } | 186 virtual bool hasVertexShader() const SK_OVERRIDE { return true; } |
| 215 | 187 |
| 216 private: | 188 private: |
| 217 typedef GrGLNvprProgramBuilder::SeparableVaryingInfo SeparableVaryingInfo; | 189 typedef GrGLNvprProgramBuilder::SeparableVaryingInfo SeparableVaryingInfo; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 GrGLInstalledFragProc*) SK_OVERRIDE; | 235 GrGLInstalledFragProc*) SK_OVERRIDE; |
| 264 | 236 |
| 265 int fTexCoordSetCnt; | 237 int fTexCoordSetCnt; |
| 266 | 238 |
| 267 friend class GrGLLegacyNvprProgramBuilder; | 239 friend class GrGLLegacyNvprProgramBuilder; |
| 268 | 240 |
| 269 typedef GrGLNvprProgramBase INHERITED; | 241 typedef GrGLNvprProgramBase INHERITED; |
| 270 }; | 242 }; |
| 271 | 243 |
| 272 #endif | 244 #endif |
| OLD | NEW |