diff options
Diffstat (limited to 'chromium/third_party/skia/src/gpu/gl/GrGLProgram.h')
-rw-r--r-- | chromium/third_party/skia/src/gpu/gl/GrGLProgram.h | 100 |
1 files changed, 48 insertions, 52 deletions
diff --git a/chromium/third_party/skia/src/gpu/gl/GrGLProgram.h b/chromium/third_party/skia/src/gpu/gl/GrGLProgram.h index 8e2ae74aab9..73a32395a29 100644 --- a/chromium/third_party/skia/src/gpu/gl/GrGLProgram.h +++ b/chromium/third_party/skia/src/gpu/gl/GrGLProgram.h @@ -60,9 +60,9 @@ public: /** * Gets the GL program ID for this program. */ - GrGLuint programID() const { return fProgramID; } + GrGLuint programID() const { return fBuilderOutput.fProgramID; } - bool hasVertexShader() const { return fHasVertexShader; } + bool hasVertexShader() const { return fBuilderOutput.fHasVertexShader; } /** * Some GL state that is relevant to programs is not stored per-program. In particular color @@ -103,20 +103,50 @@ public: fRenderTargetSize.fHeight = -1; fRenderTargetOrigin = (GrSurfaceOrigin) -1; } + + /** + * Gets a matrix that goes from local coords to Skia's device coordinates. + */ template<int Size> void getGLMatrix(GrGLfloat* destMatrix) { + GrGLGetMatrix<Size>(destMatrix, fViewMatrix); + } + + /** + * Gets a matrix that goes from local coordinates to GL normalized device coords. + */ + template<int Size> void getRTAdjustedGLMatrix(GrGLfloat* destMatrix) { SkMatrix combined; if (kBottomLeft_GrSurfaceOrigin == fRenderTargetOrigin) { combined.setAll(SkIntToScalar(2) / fRenderTargetSize.fWidth, 0, -SK_Scalar1, 0, -SkIntToScalar(2) / fRenderTargetSize.fHeight, SK_Scalar1, - 0, 0, SkMatrix::I()[8]); + 0, 0, 1); } else { combined.setAll(SkIntToScalar(2) / fRenderTargetSize.fWidth, 0, -SK_Scalar1, 0, SkIntToScalar(2) / fRenderTargetSize.fHeight, -SK_Scalar1, - 0, 0, SkMatrix::I()[8]); + 0, 0, 1); } - combined.setConcat(combined, fViewMatrix); + combined.preConcat(fViewMatrix); GrGLGetMatrix<Size>(destMatrix, combined); } + + /** + * Gets a vec4 that adjusts the position from Skia device coords to GL's normalized device + * coords. Assuming the transformed position, pos, is a homogeneous vec3, the vec, v, is + * applied as such: + * pos.x = dot(v.xy, pos.xz) + * pos.y = dot(v.zq, pos.yz) + */ + void getRTAdjustmentVec(GrGLfloat* destVec) { + destVec[0] = 2.f / fRenderTargetSize.fWidth; + destVec[1] = -1.f; + if (kBottomLeft_GrSurfaceOrigin == fRenderTargetOrigin) { + destVec[2] = -2.f / fRenderTargetSize.fHeight; + destVec[3] = 1.f; + } else { + destVec[2] = 2.f / fRenderTargetSize.fHeight; + destVec[3] = -1.f; + } + } }; /** @@ -134,38 +164,12 @@ public: private: typedef GrGLUniformManager::UniformHandle UniformHandle; - // handles for uniforms (aside from per-effect samplers) - struct UniformHandles { - UniformHandle fViewMatrixUni; - UniformHandle fColorUni; - UniformHandle fCoverageUni; - - // We use the render target height to provide a y-down frag coord when specifying - // origin_upper_left is not supported. - UniformHandle fRTHeightUni; + GrGLProgram(GrGpuGL*, + const GrGLProgramDesc&, + GrGLUniformManager*, + const GrGLShaderBuilder::GenProgramOutput&); - // Uniforms for computing texture coords to do the dst-copy lookup - UniformHandle fDstCopyTopLeftUni; - UniformHandle fDstCopyScaleUni; - UniformHandle fDstCopySamplerUni; - }; - - GrGLProgram(GrGpuGL* gpu, - const GrGLProgramDesc& desc, - const GrEffectStage* colorStages[], - const GrEffectStage* coverageStages[]); - - bool succeeded() const { return 0 != fProgramID; } - - /** - * This is the heavy initialization routine for building a GLProgram. colorStages and - * coverageStages correspond to the output of GrGLProgramDesc::Build(). - */ - bool genProgram(GrGLShaderBuilder* builder, - const GrEffectStage* colorStages[], - const GrEffectStage* coverageStages[]); - - // Sets the texture units for samplers + // Sets the texture units for samplers. void initSamplerUniforms(); // Helper for setData(). Makes GL calls to specify the initial color when there is not @@ -179,26 +183,18 @@ private: // Helper for setData() that sets the view matrix and loads the render target height uniform void setMatrixAndRenderTargetHeight(const GrDrawState&); - // GL program ID - GrGLuint fProgramID; - // these reflect the current values of uniforms (GL uniform values travel with program) - MatrixState fMatrixState; - GrColor fColor; - GrColor fCoverage; - int fDstCopyTexUnit; - - SkAutoTDelete<GrGLProgramEffects> fColorEffects; - SkAutoTDelete<GrGLProgramEffects> fCoverageEffects; + MatrixState fMatrixState; + GrColor fColor; + GrColor fCoverage; + int fDstCopyTexUnit; - GrGLProgramDesc fDesc; - GrGpuGL* fGpu; + GrGLShaderBuilder::GenProgramOutput fBuilderOutput; - GrGLUniformManager fUniformManager; - UniformHandles fUniformHandles; + GrGLProgramDesc fDesc; + GrGpuGL* fGpu; - bool fHasVertexShader; - int fNumTexCoordSets; + SkAutoTUnref<GrGLUniformManager> fUniformManager; typedef SkRefCnt INHERITED; }; |