From 018fb62d12d1febf121fe265da5b6117b86a6541 Mon Sep 17 00:00:00 2001 From: egdaniel Date: Wed, 28 Oct 2015 07:26:40 -0700 Subject: [PATCH] Create GLSL base class for ProgramDataManager BUG=skia: Review URL: https://codereview.chromium.org/1428543003 --- gm/dcshader.cpp | 3 +- gyp/gpu.gypi | 1 + src/core/SkLightingShader.cpp | 11 +-- src/effects/GrCircleBlurFragmentProcessor.cpp | 7 +- src/effects/SkAlphaThresholdFilter.cpp | 9 ++- src/effects/SkArithmeticMode_gpu.cpp | 10 +-- src/effects/SkBlurMaskFilter.cpp | 19 ++--- src/effects/SkColorCubeFilter.cpp | 11 +-- src/effects/SkColorMatrixFilter.cpp | 13 ++-- src/effects/SkDisplacementMapEffect.cpp | 9 ++- src/effects/SkLightingImageFilter.cpp | 43 +++++----- src/effects/SkMagnifierImageFilter.cpp | 9 ++- src/effects/SkMorphologyImageFilter.cpp | 9 ++- src/effects/SkPerlinNoiseShader.cpp | 16 ++-- src/effects/SkTableColorFilter.cpp | 5 +- src/effects/gradients/SkGradientShader.cpp | 13 ++-- src/effects/gradients/SkGradientShaderPriv.h | 11 +-- .../SkTwoPointConicalGradient_gpu.cpp | 33 ++++---- src/gpu/GrDefaultGeoProcFactory.cpp | 9 ++- src/gpu/GrFragmentProcessor.cpp | 9 ++- src/gpu/GrOvalRenderer.cpp | 21 ++--- src/gpu/GrPathProcessor.cpp | 7 +- src/gpu/batches/GrAAConvexPathRenderer.cpp | 8 +- src/gpu/effects/GrBezierEffect.cpp | 23 +++--- src/gpu/effects/GrBicubicEffect.cpp | 9 ++- src/gpu/effects/GrBitmapTextGeoProc.cpp | 7 +- src/gpu/effects/GrConstColorProcessor.cpp | 9 ++- src/gpu/effects/GrConvexPolyEffect.cpp | 15 ++-- src/gpu/effects/GrConvolutionEffect.cpp | 9 ++- src/gpu/effects/GrCoverageSetOpXP.cpp | 2 +- src/gpu/effects/GrCustomXfermode.cpp | 3 +- src/gpu/effects/GrDashingEffect.cpp | 17 ++-- src/gpu/effects/GrDisableColorXP.cpp | 3 +- src/gpu/effects/GrDistanceFieldGeoProc.cpp | 19 ++--- src/gpu/effects/GrMatrixConvolutionEffect.cpp | 9 ++- src/gpu/effects/GrOvalEffect.cpp | 23 +++--- src/gpu/effects/GrPorterDuffXferProcessor.cpp | 7 +- src/gpu/effects/GrRRectEffect.cpp | 21 ++--- src/gpu/effects/GrTextureDomain.cpp | 15 ++-- src/gpu/effects/GrTextureDomain.h | 11 +-- src/gpu/effects/GrYUVtoRGBEffect.cpp | 19 ++--- src/gpu/gl/GrGLFragmentProcessor.cpp | 2 +- src/gpu/gl/GrGLFragmentProcessor.h | 10 +-- src/gpu/gl/GrGLGeometryProcessor.h | 6 +- src/gpu/gl/GrGLGpuProgramCache.cpp | 3 +- src/gpu/gl/GrGLPathRendering.cpp | 4 +- src/gpu/gl/GrGLPathRendering.h | 2 +- src/gpu/gl/GrGLPrimitiveProcessor.h | 13 ++-- src/gpu/gl/GrGLProcessor.h | 5 +- src/gpu/gl/GrGLProgram.cpp | 2 +- src/gpu/gl/GrGLProgram.h | 5 +- src/gpu/gl/GrGLProgramDataManager.cpp | 34 ++++---- src/gpu/gl/GrGLProgramDataManager.h | 61 +++++---------- src/gpu/gl/GrGLUtil.cpp | 6 +- src/gpu/gl/GrGLUtil.h | 2 +- src/gpu/gl/GrGLXferProcessor.cpp | 7 +- src/gpu/gl/GrGLXferProcessor.h | 11 +-- src/gpu/gl/builders/GrGLProgramBuilder.cpp | 5 +- src/gpu/gl/builders/GrGLProgramBuilder.h | 4 +- src/gpu/glsl/GrGLSLProgramDataManager.h | 78 +++++++++++++++++++ 60 files changed, 440 insertions(+), 327 deletions(-) create mode 100644 src/gpu/glsl/GrGLSLProgramDataManager.h diff --git a/gm/dcshader.cpp b/gm/dcshader.cpp index 967ff6bf95..e161f4da58 100644 --- a/gm/dcshader.cpp +++ b/gm/dcshader.cpp @@ -13,6 +13,7 @@ #include "effects/GrXfermodeFragmentProcessor.h" #include "gl/GrGLProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" #include "Resources.h" #include "SkReadBuffer.h" #include "SkShader.h" @@ -76,7 +77,7 @@ public: "%s = color * %s;", args.fOutputColor, GrGLSLExpr4(args.fInputColor).c_str()); } - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override {} + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override {} }; return new DCGLFP; } diff --git a/gyp/gpu.gypi b/gyp/gpu.gypi index d1c835009b..43841d3de2 100644 --- a/gyp/gpu.gypi +++ b/gyp/gpu.gypi @@ -368,6 +368,7 @@ '<(skia_src_path)/gpu/glsl/GrGLSL_impl.h', '<(skia_src_path)/gpu/glsl/GrGLSLCaps.cpp', '<(skia_src_path)/gpu/glsl/GrGLSLCaps.h', + '<(skia_src_path)/gpu/glsl/GrGLSLProgramDataManager.h', '<(skia_src_path)/gpu/glsl/GrGLSLShaderVar.h', # Sk files diff --git a/src/core/SkLightingShader.cpp b/src/core/SkLightingShader.cpp index 16441aa84b..4c8ed3bb1d 100644 --- a/src/core/SkLightingShader.cpp +++ b/src/core/SkLightingShader.cpp @@ -132,6 +132,7 @@ private: #include "GrTextureAccess.h" #include "gl/GrGLProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" #include "SkGr.h" #include "SkGrPriv.h" @@ -237,7 +238,7 @@ public: } protected: - void onSetData(const GrGLProgramDataManager& pdman, const GrProcessor& proc) override { + void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override { const LightingFP& lightingFP = proc.cast(); const SkVector3& lightDir = lightingFP.lightDir(); @@ -267,16 +268,16 @@ public: private: SkVector3 fLightDir; - GrGLProgramDataManager::UniformHandle fLightDirUni; + GrGLSLProgramDataManager::UniformHandle fLightDirUni; SkColor3f fLightColor; - GrGLProgramDataManager::UniformHandle fLightColorUni; + GrGLSLProgramDataManager::UniformHandle fLightColorUni; SkColor3f fAmbientColor; - GrGLProgramDataManager::UniformHandle fAmbientColorUni; + GrGLSLProgramDataManager::UniformHandle fAmbientColorUni; SkVector fInvNormRotation; - GrGLProgramDataManager::UniformHandle fXformUni; + GrGLSLProgramDataManager::UniformHandle fXformUni; }; void onGetGLProcessorKey(const GrGLSLCaps& caps, GrProcessorKeyBuilder* b) const override { diff --git a/src/effects/GrCircleBlurFragmentProcessor.cpp b/src/effects/GrCircleBlurFragmentProcessor.cpp index bec15042e4..e5887329ae 100644 --- a/src/effects/GrCircleBlurFragmentProcessor.cpp +++ b/src/effects/GrCircleBlurFragmentProcessor.cpp @@ -15,6 +15,7 @@ #include "gl/GrGLFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" class GrGLCircleBlurFragmentProcessor : public GrGLFragmentProcessor { public: @@ -22,10 +23,10 @@ public: void emitCode(EmitArgs&) override; protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; private: - GrGLProgramDataManager::UniformHandle fDataUniform; + GrGLSLProgramDataManager::UniformHandle fDataUniform; typedef GrGLFragmentProcessor INHERITED; }; @@ -63,7 +64,7 @@ void GrGLCircleBlurFragmentProcessor::emitCode(EmitArgs& args) { fsBuilder->codeAppendf("%s = src * intensity;\n", args.fOutputColor ); } -void GrGLCircleBlurFragmentProcessor::onSetData(const GrGLProgramDataManager& pdman, +void GrGLCircleBlurFragmentProcessor::onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) { const GrCircleBlurFragmentProcessor& cbfp = proc.cast(); const SkRect& circle = cbfp.circle(); diff --git a/src/effects/SkAlphaThresholdFilter.cpp b/src/effects/SkAlphaThresholdFilter.cpp index e7a4c4ffd4..495c62f3a4 100644 --- a/src/effects/SkAlphaThresholdFilter.cpp +++ b/src/effects/SkAlphaThresholdFilter.cpp @@ -59,6 +59,7 @@ SkImageFilter* SkAlphaThresholdFilter::Create(const SkRegion& region, #include "gl/GrGLFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" class AlphaThresholdEffect : public GrFragmentProcessor { @@ -126,12 +127,12 @@ public: virtual void emitCode(EmitArgs&) override; protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; private: - GrGLProgramDataManager::UniformHandle fInnerThresholdVar; - GrGLProgramDataManager::UniformHandle fOuterThresholdVar; + GrGLSLProgramDataManager::UniformHandle fInnerThresholdVar; + GrGLSLProgramDataManager::UniformHandle fOuterThresholdVar; typedef GrGLFragmentProcessor INHERITED; }; @@ -182,7 +183,7 @@ void GrGLAlphaThresholdEffect::emitCode(EmitArgs& args) { (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr4("color")).c_str()); } -void GrGLAlphaThresholdEffect::onSetData(const GrGLProgramDataManager& pdman, +void GrGLAlphaThresholdEffect::onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) { const AlphaThresholdEffect& alpha_threshold = proc.cast(); pdman.set1f(fInnerThresholdVar, alpha_threshold.innerThreshold()); diff --git a/src/effects/SkArithmeticMode_gpu.cpp b/src/effects/SkArithmeticMode_gpu.cpp index e72ead8db8..dd015ca975 100644 --- a/src/effects/SkArithmeticMode_gpu.cpp +++ b/src/effects/SkArithmeticMode_gpu.cpp @@ -15,8 +15,8 @@ #include "GrTexture.h" #include "gl/GrGLCaps.h" #include "gl/GrGLFragmentProcessor.h" -#include "gl/GrGLProgramDataManager.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" static const bool gUseUnpremul = false; @@ -80,14 +80,14 @@ public: } protected: - void onSetData(const GrGLProgramDataManager& pdman, const GrProcessor& proc) override { + void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) override { const GrArithmeticFP& arith = proc.cast(); pdman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4()); fEnforcePMColor = arith.enforcePMColor(); } private: - GrGLProgramDataManager::UniformHandle fKUni; + GrGLSLProgramDataManager::UniformHandle fKUni; bool fEnforcePMColor; typedef GrGLFragmentProcessor INHERITED; @@ -218,14 +218,14 @@ private: add_arithmetic_code(fsBuilder, srcColor, dstColor, outColor, kUni, fEnforcePMColor); } - void onSetData(const GrGLProgramDataManager& pdman, + void onSetData(const GrGLSLProgramDataManager& pdman, const GrXferProcessor& processor) override { const ArithmeticXP& arith = processor.cast(); pdman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4()); fEnforcePMColor = arith.enforcePMColor(); }; - GrGLProgramDataManager::UniformHandle fKUni; + GrGLSLProgramDataManager::UniformHandle fKUni; bool fEnforcePMColor; typedef GrGLXferProcessor INHERITED; diff --git a/src/effects/SkBlurMaskFilter.cpp b/src/effects/SkBlurMaskFilter.cpp index 3d32d8d259..8c47e0349c 100644 --- a/src/effects/SkBlurMaskFilter.cpp +++ b/src/effects/SkBlurMaskFilter.cpp @@ -29,6 +29,7 @@ #include "effects/GrSimpleTextureEffect.h" #include "gl/GrGLFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" #endif SkScalar SkBlurMaskFilter::ConvertRadiusToSigma(SkScalar radius) { @@ -682,10 +683,10 @@ public: static void GenKey(GrSLPrecision precision, GrProcessorKeyBuilder* b); protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; private: - typedef GrGLProgramDataManager::UniformHandle UniformHandle; + typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; UniformHandle fProxyRectUniform; UniformHandle fProfileSizeUniform; @@ -763,7 +764,7 @@ void GrGLRectBlurEffect::emitCode(EmitArgs& args) { fsBuilder->codeAppendf("%s = src * final;", args.fOutputColor); } -void GrGLRectBlurEffect::onSetData(const GrGLProgramDataManager& pdman, +void GrGLRectBlurEffect::onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) { const GrRectBlurEffect& rbe = proc.cast(); SkRect rect = rbe.getRect(); @@ -1047,12 +1048,12 @@ public: virtual void emitCode(EmitArgs&) override; protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; private: - GrGLProgramDataManager::UniformHandle fProxyRectUniform; - GrGLProgramDataManager::UniformHandle fCornerRadiusUniform; - GrGLProgramDataManager::UniformHandle fBlurRadiusUniform; + GrGLSLProgramDataManager::UniformHandle fProxyRectUniform; + GrGLSLProgramDataManager::UniformHandle fCornerRadiusUniform; + GrGLSLProgramDataManager::UniformHandle fBlurRadiusUniform; typedef GrGLFragmentProcessor INHERITED; }; @@ -1110,8 +1111,8 @@ void GrGLRRectBlurEffect::emitCode(EmitArgs& args) { fsBuilder->codeAppend(";"); } -void GrGLRRectBlurEffect::onSetData(const GrGLProgramDataManager& pdman, - const GrProcessor& proc) { +void GrGLRRectBlurEffect::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& proc) { const GrRRectBlurEffect& brre = proc.cast(); SkRRect rrect = brre.getRRect(); diff --git a/src/effects/SkColorCubeFilter.cpp b/src/effects/SkColorCubeFilter.cpp index 7cb41f312a..3010287ef7 100644 --- a/src/effects/SkColorCubeFilter.cpp +++ b/src/effects/SkColorCubeFilter.cpp @@ -20,6 +20,7 @@ #include "SkGr.h" #include "gl/GrGLFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" #endif /////////////////////////////////////////////////////////////////////////////// @@ -183,11 +184,11 @@ public: static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder*); protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; private: - GrGLProgramDataManager::UniformHandle fColorCubeSizeUni; - GrGLProgramDataManager::UniformHandle fColorCubeInvSizeUni; + GrGLSLProgramDataManager::UniformHandle fColorCubeSizeUni; + GrGLSLProgramDataManager::UniformHandle fColorCubeInvSizeUni; typedef GrGLFragmentProcessor INHERITED; }; @@ -291,8 +292,8 @@ void GrColorCubeEffect::GLProcessor::emitCode(EmitArgs& args) { cubeIdx, nonZeroAlpha, args.fInputColor); } -void GrColorCubeEffect::GLProcessor::onSetData(const GrGLProgramDataManager& pdman, - const GrProcessor& proc) { +void GrColorCubeEffect::GLProcessor::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& proc) { const GrColorCubeEffect& colorCube = proc.cast(); SkScalar size = SkIntToScalar(colorCube.colorCubeSize()); pdman.set1f(fColorCubeSizeUni, SkScalarToFloat(size)); diff --git a/src/effects/SkColorMatrixFilter.cpp b/src/effects/SkColorMatrixFilter.cpp index 68150963c6..ef8fb116d6 100644 --- a/src/effects/SkColorMatrixFilter.cpp +++ b/src/effects/SkColorMatrixFilter.cpp @@ -387,6 +387,7 @@ SkColorFilter* SkColorMatrixFilter::newComposed(const SkColorFilter* innerFilter #include "GrInvariantOutput.h" #include "gl/GrGLFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" class ColorMatrixEffect : public GrFragmentProcessor { public: @@ -433,19 +434,19 @@ public: } protected: - virtual void onSetData(const GrGLProgramDataManager& uniManager, - const GrProcessor& proc) override { + virtual void onSetData(const GrGLSLProgramDataManager& uniManager, + const GrProcessor& proc) override { const ColorMatrixEffect& cme = proc.cast(); const float* m = cme.fMatrix.fMat; // The GL matrix is transposed from SkColorMatrix. - GrGLfloat mt[] = { + float mt[] = { m[0], m[5], m[10], m[15], m[1], m[6], m[11], m[16], m[2], m[7], m[12], m[17], m[3], m[8], m[13], m[18], }; static const float kScale = 1.0f / 255.0f; - GrGLfloat vec[] = { + float vec[] = { m[4] * kScale, m[9] * kScale, m[14] * kScale, m[19] * kScale, }; uniManager.setMatrix4fv(fMatrixHandle, 1, mt); @@ -453,8 +454,8 @@ public: } private: - GrGLProgramDataManager::UniformHandle fMatrixHandle; - GrGLProgramDataManager::UniformHandle fVectorHandle; + GrGLSLProgramDataManager::UniformHandle fMatrixHandle; + GrGLSLProgramDataManager::UniformHandle fVectorHandle; typedef GrGLFragmentProcessor INHERITED; }; diff --git a/src/effects/SkDisplacementMapEffect.cpp b/src/effects/SkDisplacementMapEffect.cpp index b3397476ab..776083c079 100644 --- a/src/effects/SkDisplacementMapEffect.cpp +++ b/src/effects/SkDisplacementMapEffect.cpp @@ -19,6 +19,7 @@ #include "effects/GrTextureDomain.h" #include "gl/GrGLFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" #endif namespace { @@ -314,12 +315,12 @@ public: const GrTextureDomain::GLDomain& glDomain() const { return fGLDomain; } protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; private: SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector; SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector; - GrGLProgramDataManager::UniformHandle fScaleUni; + GrGLSLProgramDataManager::UniformHandle fScaleUni; GrTextureDomain::GLDomain fGLDomain; typedef GrGLFragmentProcessor INHERITED; @@ -610,8 +611,8 @@ void GrGLDisplacementMapEffect::emitCode(EmitArgs& args) { fsBuilder->codeAppend(";\n"); } -void GrGLDisplacementMapEffect::onSetData(const GrGLProgramDataManager& pdman, - const GrProcessor& proc) { +void GrGLDisplacementMapEffect::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& proc) { const GrDisplacementMapEffect& displacementMap = proc.cast(); GrTexture* colorTex = displacementMap.texture(1); SkScalar scaleX = displacementMap.scale().fX / colorTex->width(); diff --git a/src/effects/SkLightingImageFilter.cpp b/src/effects/SkLightingImageFilter.cpp index 615d269ce6..ecb4111158 100644 --- a/src/effects/SkLightingImageFilter.cpp +++ b/src/effects/SkLightingImageFilter.cpp @@ -23,12 +23,13 @@ #include "effects/GrSingleTextureEffect.h" #include "gl/GrGLFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" class GrGLDiffuseLightingEffect; class GrGLSpecularLightingEffect; // For brevity -typedef GrGLProgramDataManager::UniformHandle UniformHandle; +typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; #endif namespace { @@ -39,13 +40,13 @@ const SkScalar gOneHalf = 0.5f; const SkScalar gOneQuarter = 0.25f; #if SK_SUPPORT_GPU -void setUniformPoint3(const GrGLProgramDataManager& pdman, UniformHandle uni, +void setUniformPoint3(const GrGLSLProgramDataManager& pdman, UniformHandle uni, const SkPoint3& point) { - GR_STATIC_ASSERT(sizeof(SkPoint3) == 3 * sizeof(GrGLfloat)); + GR_STATIC_ASSERT(sizeof(SkPoint3) == 3 * sizeof(float)); pdman.set3fv(uni, 1, &point.fX); } -void setUniformNormal3(const GrGLProgramDataManager& pdman, UniformHandle uni, +void setUniformNormal3(const GrGLSLProgramDataManager& pdman, UniformHandle uni, const SkPoint3& point) { setUniformPoint3(pdman, uni, point); } @@ -611,7 +612,7 @@ public: // This is called from GrGLLightingEffect's setData(). Subclasses of GrGLLight must call // INHERITED::setData(). - virtual void setData(const GrGLProgramDataManager&, const SkImageFilterLight* light) const; + virtual void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* light) const; protected: /** @@ -631,7 +632,7 @@ private: class GrGLDistantLight : public GrGLLight { public: virtual ~GrGLDistantLight() {} - void setData(const GrGLProgramDataManager&, const SkImageFilterLight* light) const override; + void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* light) const override; void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override; private: @@ -644,7 +645,7 @@ private: class GrGLPointLight : public GrGLLight { public: virtual ~GrGLPointLight() {} - void setData(const GrGLProgramDataManager&, const SkImageFilterLight* light) const override; + void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* light) const override; void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override; private: @@ -657,7 +658,7 @@ private: class GrGLSpotLight : public GrGLLight { public: virtual ~GrGLSpotLight() {} - void setData(const GrGLProgramDataManager&, const SkImageFilterLight* light) const override; + void setData(const GrGLSLProgramDataManager&, const SkImageFilterLight* light) const override; void emitSurfaceToLight(GrGLFPBuilder*, const char* z) override; void emitLightColor(GrGLFPBuilder*, const char *surfaceToLight) override; @@ -1519,7 +1520,7 @@ protected: /** * Subclasses of GrGLLightingEffect must call INHERITED::onSetData(); */ - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; virtual void emitLightFunc(GrGLFPBuilder*, SkString* funcName) = 0; @@ -1540,7 +1541,7 @@ public: void emitLightFunc(GrGLFPBuilder*, SkString* funcName) override; protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; private: typedef GrGLLightingEffect INHERITED; @@ -1556,7 +1557,7 @@ public: void emitLightFunc(GrGLFPBuilder*, SkString* funcName) override; protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; private: typedef GrGLLightingEffect INHERITED; @@ -1742,8 +1743,8 @@ void GrGLLightingEffect::GenKey(const GrProcessor& proc, b->add32(lighting.boundaryMode() << 2 | lighting.light()->type()); } -void GrGLLightingEffect::onSetData(const GrGLProgramDataManager& pdman, - const GrProcessor& proc) { +void GrGLLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& proc) { const GrLightingEffect& lighting = proc.cast(); GrTexture* texture = lighting.texture(0); float ySign = texture->origin() == kTopLeft_GrSurfaceOrigin ? -1.0f : 1.0f; @@ -1784,8 +1785,8 @@ void GrGLDiffuseLightingEffect::emitLightFunc(GrGLFPBuilder* builder, SkString* funcName); } -void GrGLDiffuseLightingEffect::onSetData(const GrGLProgramDataManager& pdman, - const GrProcessor& proc) { +void GrGLDiffuseLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& proc) { INHERITED::onSetData(pdman, proc); const GrDiffuseLightingEffect& diffuse = proc.cast(); pdman.set1f(fKDUni, diffuse.kd()); @@ -1874,8 +1875,8 @@ void GrGLSpecularLightingEffect::emitLightFunc(GrGLFPBuilder* builder, SkString* funcName); } -void GrGLSpecularLightingEffect::onSetData(const GrGLProgramDataManager& pdman, - const GrProcessor& effect) { +void GrGLSpecularLightingEffect::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& effect) { INHERITED::onSetData(pdman, effect); const GrSpecularLightingEffect& spec = effect.cast(); pdman.set1f(fKSUni, spec.ks()); @@ -1893,7 +1894,7 @@ void GrGLLight::emitLightColor(GrGLFPBuilder* builder, const char *surfaceToLigh builder->getFragmentShaderBuilder()->codeAppend(builder->getUniformCStr(this->lightColorUni())); } -void GrGLLight::setData(const GrGLProgramDataManager& pdman, +void GrGLLight::setData(const GrGLSLProgramDataManager& pdman, const SkImageFilterLight* light) const { setUniformPoint3(pdman, fColorUni, light->color().makeScale(SkScalarInvert(SkIntToScalar(255)))); @@ -1901,7 +1902,7 @@ void GrGLLight::setData(const GrGLProgramDataManager& pdman, /////////////////////////////////////////////////////////////////////////////// -void GrGLDistantLight::setData(const GrGLProgramDataManager& pdman, +void GrGLDistantLight::setData(const GrGLSLProgramDataManager& pdman, const SkImageFilterLight* light) const { INHERITED::setData(pdman, light); SkASSERT(light->type() == SkImageFilterLight::kDistant_LightType); @@ -1919,7 +1920,7 @@ void GrGLDistantLight::emitSurfaceToLight(GrGLFPBuilder* builder, const char* z) /////////////////////////////////////////////////////////////////////////////// -void GrGLPointLight::setData(const GrGLProgramDataManager& pdman, +void GrGLPointLight::setData(const GrGLSLProgramDataManager& pdman, const SkImageFilterLight* light) const { INHERITED::setData(pdman, light); SkASSERT(light->type() == SkImageFilterLight::kPoint_LightType); @@ -1939,7 +1940,7 @@ void GrGLPointLight::emitSurfaceToLight(GrGLFPBuilder* builder, const char* z) { /////////////////////////////////////////////////////////////////////////////// -void GrGLSpotLight::setData(const GrGLProgramDataManager& pdman, +void GrGLSpotLight::setData(const GrGLSLProgramDataManager& pdman, const SkImageFilterLight* light) const { INHERITED::setData(pdman, light); SkASSERT(light->type() == SkImageFilterLight::kSpot_LightType); diff --git a/src/effects/SkMagnifierImageFilter.cpp b/src/effects/SkMagnifierImageFilter.cpp index 903f34ca14..c7d3d5ae2d 100644 --- a/src/effects/SkMagnifierImageFilter.cpp +++ b/src/effects/SkMagnifierImageFilter.cpp @@ -20,6 +20,7 @@ #include "gl/GrGLFragmentProcessor.h" #include "gl/GrGLTexture.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" class GrMagnifierEffect : public GrSingleTextureEffect { @@ -95,7 +96,7 @@ private: }; // For brevity -typedef GrGLProgramDataManager::UniformHandle UniformHandle; +typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; class GrGLMagnifierEffect : public GrGLFragmentProcessor { public: @@ -104,7 +105,7 @@ public: virtual void emitCode(EmitArgs&) override; protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; private: UniformHandle fOffsetVar; @@ -171,8 +172,8 @@ void GrGLMagnifierEffect::emitCode(EmitArgs& args) { fsBuilder->codeAppend(modulate.c_str()); } -void GrGLMagnifierEffect::onSetData(const GrGLProgramDataManager& pdman, - const GrProcessor& effect) { +void GrGLMagnifierEffect::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& effect) { const GrMagnifierEffect& zoom = effect.cast(); pdman.set2f(fOffsetVar, zoom.x_offset(), zoom.y_offset()); pdman.set2f(fInvZoomVar, zoom.x_inv_zoom(), zoom.y_inv_zoom()); diff --git a/src/effects/SkMorphologyImageFilter.cpp b/src/effects/SkMorphologyImageFilter.cpp index 546e6f5d93..5b9141fd2a 100644 --- a/src/effects/SkMorphologyImageFilter.cpp +++ b/src/effects/SkMorphologyImageFilter.cpp @@ -21,6 +21,7 @@ #include "effects/Gr1DKernelEffect.h" #include "gl/GrGLFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" #endif SkMorphologyImageFilter::SkMorphologyImageFilter(int radiusX, @@ -262,7 +263,7 @@ public: static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder* b); protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; private: int width() const { return GrMorphologyEffect::WidthFromRadius(fRadius); } @@ -271,8 +272,8 @@ private: Gr1DKernelEffect::Direction fDirection; bool fUseRange; GrMorphologyEffect::MorphologyType fType; - GrGLProgramDataManager::UniformHandle fPixelSizeUni; - GrGLProgramDataManager::UniformHandle fRangeUni; + GrGLSLProgramDataManager::UniformHandle fPixelSizeUni; + GrGLSLProgramDataManager::UniformHandle fRangeUni; typedef GrGLFragmentProcessor INHERITED; }; @@ -363,7 +364,7 @@ void GrGLMorphologyEffect::GenKey(const GrProcessor& proc, b->add32(key); } -void GrGLMorphologyEffect::onSetData(const GrGLProgramDataManager& pdman, +void GrGLMorphologyEffect::onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& proc) { const GrMorphologyEffect& m = proc.cast(); GrTexture& texture = *m.texture(0); diff --git a/src/effects/SkPerlinNoiseShader.cpp b/src/effects/SkPerlinNoiseShader.cpp index 0a3341a9b1..0c455693c3 100644 --- a/src/effects/SkPerlinNoiseShader.cpp +++ b/src/effects/SkPerlinNoiseShader.cpp @@ -22,6 +22,7 @@ #include "effects/GrConstColorProcessor.h" #include "gl/GrGLFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" #endif static const int kBlockSize = 256; @@ -492,15 +493,15 @@ public: static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder* b); protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; private: - GrGLProgramDataManager::UniformHandle fStitchDataUni; - SkPerlinNoiseShader::Type fType; - bool fStitchTiles; - int fNumOctaves; - GrGLProgramDataManager::UniformHandle fBaseFrequencyUni; + GrGLSLProgramDataManager::UniformHandle fStitchDataUni; + SkPerlinNoiseShader::Type fType; + bool fStitchTiles; + int fNumOctaves; + GrGLSLProgramDataManager::UniformHandle fBaseFrequencyUni; private: typedef GrGLFragmentProcessor INHERITED; @@ -894,7 +895,8 @@ void GrGLPerlinNoise::GenKey(const GrProcessor& processor, const GrGLSLCaps&, b->add32(key); } -void GrGLPerlinNoise::onSetData(const GrGLProgramDataManager& pdman, const GrProcessor& processor) { +void GrGLPerlinNoise::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& processor) { INHERITED::onSetData(pdman, processor); const GrPerlinNoiseEffect& turbulence = processor.cast(); diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp index 8f1a4d7e65..0f95a81596 100644 --- a/src/effects/SkTableColorFilter.cpp +++ b/src/effects/SkTableColorFilter.cpp @@ -337,6 +337,7 @@ SkColorFilter* SkTable_ColorFilter::newComposed(const SkColorFilter* innerFilter #include "effects/GrTextureStripAtlas.h" #include "gl/GrGLFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" class ColorTableEffect : public GrFragmentProcessor { public: @@ -382,7 +383,7 @@ public: static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder* b) {} protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; private: UniformHandle fRGBAYValuesUni; @@ -392,7 +393,7 @@ private: GLColorTableEffect::GLColorTableEffect(const GrProcessor&) { } -void GLColorTableEffect::onSetData(const GrGLProgramDataManager& pdm, const GrProcessor& proc) { +void GLColorTableEffect::onSetData(const GrGLSLProgramDataManager& pdm, const GrProcessor& proc) { // The textures are organized in a strip where the rows are ordered a, r, g, b. float rgbaYValues[4]; const ColorTableEffect& cte = proc.cast(); diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp index 2fe23827f4..e3a3759fa9 100644 --- a/src/effects/gradients/SkGradientShader.cpp +++ b/src/effects/gradients/SkGradientShader.cpp @@ -910,6 +910,7 @@ SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END #include "GrInvariantOutput.h" #include "gl/GrGLContext.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" #include "SkGr.h" GrGLGradientEffect::GrGLGradientEffect() @@ -946,8 +947,8 @@ void GrGLGradientEffect::emitUniforms(GrGLFPBuilder* builder, const GrGradientEf } } -static inline void set_color_uni(const GrGLProgramDataManager& pdman, - const GrGLProgramDataManager::UniformHandle uni, +static inline void set_color_uni(const GrGLSLProgramDataManager& pdman, + const GrGLSLProgramDataManager::UniformHandle uni, const SkColor* color) { pdman.set4f(uni, SkColorGetR(*color) / 255.f, @@ -956,8 +957,8 @@ static inline void set_color_uni(const GrGLProgramDataManager& pdman, SkColorGetA(*color) / 255.f); } -static inline void set_mul_color_uni(const GrGLProgramDataManager& pdman, - const GrGLProgramDataManager::UniformHandle uni, +static inline void set_mul_color_uni(const GrGLSLProgramDataManager& pdman, + const GrGLSLProgramDataManager::UniformHandle uni, const SkColor* color){ float a = SkColorGetA(*color) / 255.f; float aDiv255 = a / 255.f; @@ -968,8 +969,8 @@ static inline void set_mul_color_uni(const GrGLProgramDataManager& pdman, a); } -void GrGLGradientEffect::onSetData(const GrGLProgramDataManager& pdman, - const GrProcessor& processor) { +void GrGLGradientEffect::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& processor) { const GrGradientEffect& e = processor.cast(); diff --git a/src/effects/gradients/SkGradientShaderPriv.h b/src/effects/gradients/SkGradientShaderPriv.h index 01c53e86e2..2286c22fd5 100644 --- a/src/effects/gradients/SkGradientShaderPriv.h +++ b/src/effects/gradients/SkGradientShaderPriv.h @@ -297,6 +297,7 @@ static inline int next_dither_toggle16(int toggle) { #include "GrCoordTransform.h" #include "GrFragmentProcessor.h" #include "gl/GrGLFragmentProcessor.h" +#include "glsl/GrGLSLProgramDataManager.h" class GrInvariantOutput; @@ -401,7 +402,7 @@ public: virtual ~GrGLGradientEffect(); protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; protected: /** @@ -444,10 +445,10 @@ private: GR_STATIC_ASSERT(kBaseKeyBitCnt <= 32); SkScalar fCachedYCoord; - GrGLProgramDataManager::UniformHandle fFSYUni; - GrGLProgramDataManager::UniformHandle fColorStartUni; - GrGLProgramDataManager::UniformHandle fColorMidUni; - GrGLProgramDataManager::UniformHandle fColorEndUni; + GrGLSLProgramDataManager::UniformHandle fFSYUni; + GrGLSLProgramDataManager::UniformHandle fColorStartUni; + GrGLSLProgramDataManager::UniformHandle fColorMidUni; + GrGLSLProgramDataManager::UniformHandle fColorEndUni; typedef GrGLFragmentProcessor INHERITED; }; diff --git a/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp b/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp index 4976575f52..b5716b1de0 100644 --- a/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp +++ b/src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp @@ -13,8 +13,9 @@ #if SK_SUPPORT_GPU #include "GrPaint.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" // For brevity -typedef GrGLProgramDataManager::UniformHandle UniformHandle; +typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; static const SkScalar kErrorTol = 0.00001f; static const SkScalar kEdgeErrorTol = 5.f * kErrorTol; @@ -147,7 +148,7 @@ public: static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKeyBuilder* b); protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; UniformHandle fParamUni; @@ -273,8 +274,8 @@ void GLEdge2PtConicalEffect::emitCode(EmitArgs& args) { fsBuilder->codeAppend("\t}\n"); } -void GLEdge2PtConicalEffect::onSetData(const GrGLProgramDataManager& pdman, - const GrProcessor& processor) { +void GLEdge2PtConicalEffect::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& processor) { INHERITED::onSetData(pdman, processor); const Edge2PtConicalEffect& data = processor.cast(); SkScalar radius0 = data.radius(); @@ -423,7 +424,7 @@ public: static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKeyBuilder* b); protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; UniformHandle fParamUni; @@ -540,8 +541,8 @@ void GLFocalOutside2PtConicalEffect::emitCode(EmitArgs& args) { fsBuilder->codeAppend("\t}\n"); } -void GLFocalOutside2PtConicalEffect::onSetData(const GrGLProgramDataManager& pdman, - const GrProcessor& processor) { +void GLFocalOutside2PtConicalEffect::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& processor) { INHERITED::onSetData(pdman, processor); const FocalOutside2PtConicalEffect& data = processor.cast(); SkASSERT(data.isFlipped() == fIsFlipped); @@ -629,7 +630,7 @@ public: static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKeyBuilder* b); protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; UniformHandle fFocalUni; @@ -723,8 +724,8 @@ void GLFocalInside2PtConicalEffect::emitCode(EmitArgs& args) { args.fSamplers); } -void GLFocalInside2PtConicalEffect::onSetData(const GrGLProgramDataManager& pdman, - const GrProcessor& processor) { +void GLFocalInside2PtConicalEffect::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& processor) { INHERITED::onSetData(pdman, processor); const FocalInside2PtConicalEffect& data = processor.cast(); SkScalar focal = data.focal(); @@ -866,7 +867,7 @@ public: static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKeyBuilder* b); protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; UniformHandle fCenterUni; UniformHandle fParamUni; @@ -983,8 +984,8 @@ void GLCircleInside2PtConicalEffect::emitCode(EmitArgs& args) { args.fSamplers); } -void GLCircleInside2PtConicalEffect::onSetData(const GrGLProgramDataManager& pdman, - const GrProcessor& processor) { +void GLCircleInside2PtConicalEffect::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& processor) { INHERITED::onSetData(pdman, processor); const CircleInside2PtConicalEffect& data = processor.cast(); SkScalar centerX = data.centerX(); @@ -1088,7 +1089,7 @@ public: static void GenKey(const GrProcessor&, const GrGLSLCaps& caps, GrProcessorKeyBuilder* b); protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; UniformHandle fCenterUni; UniformHandle fParamUni; @@ -1229,8 +1230,8 @@ void GLCircleOutside2PtConicalEffect::emitCode(EmitArgs& args) { fsBuilder->codeAppend("\t}\n"); } -void GLCircleOutside2PtConicalEffect::onSetData(const GrGLProgramDataManager& pdman, - const GrProcessor& processor) { +void GLCircleOutside2PtConicalEffect::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& processor) { INHERITED::onSetData(pdman, processor); const CircleOutside2PtConicalEffect& data = processor.cast(); SkASSERT(data.isFlipped() == fIsFlipped); diff --git a/src/gpu/GrDefaultGeoProcFactory.cpp b/src/gpu/GrDefaultGeoProcFactory.cpp index 2f7d14ac7e..23530acaed 100644 --- a/src/gpu/GrDefaultGeoProcFactory.cpp +++ b/src/gpu/GrDefaultGeoProcFactory.cpp @@ -131,18 +131,19 @@ public: b->add32(key); } - void setData(const GrGLProgramDataManager& pdman, const GrPrimitiveProcessor& gp) override { + void setData(const GrGLSLProgramDataManager& pdman, + const GrPrimitiveProcessor& gp) override { const DefaultGeoProc& dgp = gp.cast(); if (!dgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dgp.viewMatrix())) { fViewMatrix = dgp.viewMatrix(); - GrGLfloat viewMatrix[3 * 3]; + float viewMatrix[3 * 3]; GrGLGetMatrix<3>(viewMatrix, fViewMatrix); pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); } if (dgp.color() != fColor && !dgp.hasVertexColor()) { - GrGLfloat c[4]; + float c[4]; GrColorToRGBAFloat(dgp.color(), c); pdman.set4fv(fColorUniform, 1, c); fColor = dgp.color(); @@ -156,7 +157,7 @@ public: } void setTransformData(const GrPrimitiveProcessor& primProc, - const GrGLProgramDataManager& pdman, + const GrGLSLProgramDataManager& pdman, int index, const SkTArray& transforms) override { this->setTransformDataHelper(primProc, pdman, index, transforms); diff --git a/src/gpu/GrFragmentProcessor.cpp b/src/gpu/GrFragmentProcessor.cpp index d1a3fa161e..ec5aaac3ee 100644 --- a/src/gpu/GrFragmentProcessor.cpp +++ b/src/gpu/GrFragmentProcessor.cpp @@ -10,6 +10,7 @@ #include "GrCoordTransform.h" #include "gl/GrGLFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" #include "effects/GrConstColorProcessor.h" #include "effects/GrXfermodeFragmentProcessor.h" @@ -231,12 +232,12 @@ const GrFragmentProcessor* GrFragmentProcessor::OverrideInput(const GrFragmentPr } private: - void onSetData(const GrGLProgramDataManager& pdman, + void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor& fp) override { GrColor color = fp.cast().fColor; if (!fHaveSetColor || color != fPreviousColor) { - static const GrGLfloat scale = 1.f / 255.f; - GrGLfloat floatColor[4] = { + static const float scale = 1.f / 255.f; + float floatColor[4] = { GrColorUnpackR(color) * scale, GrColorUnpackG(color) * scale, GrColorUnpackB(color) * scale, @@ -248,7 +249,7 @@ const GrFragmentProcessor* GrFragmentProcessor::OverrideInput(const GrFragmentPr } } - GrGLProgramDataManager::UniformHandle fColorUni; + GrGLSLProgramDataManager::UniformHandle fColorUni; bool fHaveSetColor; GrColor fPreviousColor; }; diff --git a/src/gpu/GrOvalRenderer.cpp b/src/gpu/GrOvalRenderer.cpp index 258e3f4638..a647e62af0 100644 --- a/src/gpu/GrOvalRenderer.cpp +++ b/src/gpu/GrOvalRenderer.cpp @@ -25,6 +25,7 @@ #include "gl/GrGLProcessor.h" #include "gl/GrGLGeometryProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" // TODO(joshualitt) - Break this file up during GrBatch post implementation cleanup @@ -139,10 +140,11 @@ public: b->add32(key); } - void setData(const GrGLProgramDataManager& pdman, const GrPrimitiveProcessor& gp) override { + void setData(const GrGLSLProgramDataManager& pdman, + const GrPrimitiveProcessor& gp) override { const CircleEdgeEffect& ce = gp.cast(); if (ce.color() != fColor) { - GrGLfloat c[4]; + float c[4]; GrColorToRGBAFloat(ce.color(), c); pdman.set4fv(fColorUniform, 1, c); fColor = ce.color(); @@ -150,7 +152,7 @@ public: } void setTransformData(const GrPrimitiveProcessor& primProc, - const GrGLProgramDataManager& pdman, + const GrGLSLProgramDataManager& pdman, int index, const SkTArray& transforms) override { this->setTransformDataHelper(primProc, pdman, index, transforms); @@ -307,10 +309,10 @@ public: b->add32(key); } - void setData(const GrGLProgramDataManager& pdman, const GrPrimitiveProcessor& gp) override { + void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor& gp) override { const EllipseEdgeEffect& ee = gp.cast(); if (ee.color() != fColor) { - GrGLfloat c[4]; + float c[4]; GrColorToRGBAFloat(ee.color(), c); pdman.set4fv(fColorUniform, 1, c); fColor = ee.color(); @@ -318,7 +320,7 @@ public: } void setTransformData(const GrPrimitiveProcessor& primProc, - const GrGLProgramDataManager& pdman, + const GrGLSLProgramDataManager& pdman, int index, const SkTArray& transforms) override { this->setTransformDataHelper(primProc, pdman, index, transforms); @@ -497,18 +499,19 @@ public: b->add32(key); } - void setData(const GrGLProgramDataManager& pdman, const GrPrimitiveProcessor& gp) override { + void setData(const GrGLSLProgramDataManager& pdman, + const GrPrimitiveProcessor& gp) override { const DIEllipseEdgeEffect& dee = gp.cast(); if (!dee.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dee.viewMatrix())) { fViewMatrix = dee.viewMatrix(); - GrGLfloat viewMatrix[3 * 3]; + float viewMatrix[3 * 3]; GrGLGetMatrix<3>(viewMatrix, fViewMatrix); pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); } if (dee.color() != fColor) { - GrGLfloat c[4]; + float c[4]; GrColorToRGBAFloat(dee.color(), c); pdman.set4fv(fColorUniform, 1, c); fColor = dee.color(); diff --git a/src/gpu/GrPathProcessor.cpp b/src/gpu/GrPathProcessor.cpp index aa5095448f..e4050a9e92 100644 --- a/src/gpu/GrPathProcessor.cpp +++ b/src/gpu/GrPathProcessor.cpp @@ -71,10 +71,11 @@ public: } } - void setData(const GrGLProgramDataManager& pd, const GrPrimitiveProcessor& primProc) override { + void setData(const GrGLSLProgramDataManager& pd, + const GrPrimitiveProcessor& primProc) override { const GrPathProcessor& pathProc = primProc.cast(); if (pathProc.opts().readsColor() && pathProc.color() != fColor) { - GrGLfloat c[4]; + float c[4]; GrColorToRGBAFloat(pathProc.color(), c); pd.set4fv(fColorUniform, 1, c); fColor = pathProc.color(); @@ -82,7 +83,7 @@ public: } void setTransformData(const GrPrimitiveProcessor& primProc, - const GrGLProgramDataManager& pdman, + const GrGLSLProgramDataManager& pdman, int index, const SkTArray& coordTransforms) override { const GrPathProcessor& pathProc = primProc.cast(); diff --git a/src/gpu/batches/GrAAConvexPathRenderer.cpp b/src/gpu/batches/GrAAConvexPathRenderer.cpp index 543885e54f..cb015f80ff 100644 --- a/src/gpu/batches/GrAAConvexPathRenderer.cpp +++ b/src/gpu/batches/GrAAConvexPathRenderer.cpp @@ -28,6 +28,7 @@ #include "gl/GrGLProcessor.h" #include "gl/GrGLGeometryProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" GrAAConvexPathRenderer::GrAAConvexPathRenderer() { } @@ -605,10 +606,11 @@ public: b->add32(key); } - void setData(const GrGLProgramDataManager& pdman, const GrPrimitiveProcessor& gp) override { + void setData(const GrGLSLProgramDataManager& pdman, + const GrPrimitiveProcessor& gp) override { const QuadEdgeEffect& qe = gp.cast(); if (qe.color() != fColor) { - GrGLfloat c[4]; + float c[4]; GrColorToRGBAFloat(qe.color(), c); pdman.set4fv(fColorUniform, 1, c); fColor = qe.color(); @@ -616,7 +618,7 @@ public: } void setTransformData(const GrPrimitiveProcessor& primProc, - const GrGLProgramDataManager& pdman, + const GrGLSLProgramDataManager& pdman, int index, const SkTArray& transforms) override { this->setTransformDataHelper(primProc, pdman, index, transforms); diff --git a/src/gpu/effects/GrBezierEffect.cpp b/src/gpu/effects/GrBezierEffect.cpp index 25362e6441..41fe7fc6b1 100644 --- a/src/gpu/effects/GrBezierEffect.cpp +++ b/src/gpu/effects/GrBezierEffect.cpp @@ -11,6 +11,7 @@ #include "gl/GrGLGeometryProcessor.h" #include "gl/GrGLUtil.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" class GrGLConicEffect : public GrGLGeometryProcessor { public: @@ -22,19 +23,19 @@ public: const GrGLSLCaps&, GrProcessorKeyBuilder*); - void setData(const GrGLProgramDataManager& pdman, + void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor& primProc) override { const GrConicEffect& ce = primProc.cast(); if (!ce.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(ce.viewMatrix())) { fViewMatrix = ce.viewMatrix(); - GrGLfloat viewMatrix[3 * 3]; + float viewMatrix[3 * 3]; GrGLGetMatrix<3>(viewMatrix, fViewMatrix); pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); } if (ce.color() != fColor) { - GrGLfloat c[4]; + float c[4]; GrColorToRGBAFloat(ce.color(), c); pdman.set4fv(fColorUniform, 1, c); fColor = ce.color(); @@ -47,7 +48,7 @@ public: } void setTransformData(const GrPrimitiveProcessor& primProc, - const GrGLProgramDataManager& pdman, + const GrGLSLProgramDataManager& pdman, int index, const SkTArray& transforms) override { this->setTransformDataHelper(primProc, pdman, index, transforms); @@ -238,19 +239,19 @@ public: const GrGLSLCaps&, GrProcessorKeyBuilder*); - void setData(const GrGLProgramDataManager& pdman, + void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor& primProc) override { const GrQuadEffect& qe = primProc.cast(); if (!qe.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(qe.viewMatrix())) { fViewMatrix = qe.viewMatrix(); - GrGLfloat viewMatrix[3 * 3]; + float viewMatrix[3 * 3]; GrGLGetMatrix<3>(viewMatrix, fViewMatrix); pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); } if (qe.color() != fColor) { - GrGLfloat c[4]; + float c[4]; GrColorToRGBAFloat(qe.color(), c); pdman.set4fv(fColorUniform, 1, c); fColor = qe.color(); @@ -263,7 +264,7 @@ public: } void setTransformData(const GrPrimitiveProcessor& primProc, - const GrGLProgramDataManager& pdman, + const GrGLSLProgramDataManager& pdman, int index, const SkTArray& transforms) override { this->setTransformDataHelper(primProc, pdman, index, transforms); @@ -440,19 +441,19 @@ public: const GrGLSLCaps&, GrProcessorKeyBuilder*); - void setData(const GrGLProgramDataManager& pdman, + void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor& primProc) override { const GrCubicEffect& ce = primProc.cast(); if (!ce.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(ce.viewMatrix())) { fViewMatrix = ce.viewMatrix(); - GrGLfloat viewMatrix[3 * 3]; + float viewMatrix[3 * 3]; GrGLGetMatrix<3>(viewMatrix, fViewMatrix); pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); } if (ce.color() != fColor) { - GrGLfloat c[4]; + float c[4]; GrColorToRGBAFloat(ce.color(), c); pdman.set4fv(fColorUniform, 1, c); fColor = ce.color(); diff --git a/src/gpu/effects/GrBicubicEffect.cpp b/src/gpu/effects/GrBicubicEffect.cpp index 3bed4bea3f..a6ed1909d7 100644 --- a/src/gpu/effects/GrBicubicEffect.cpp +++ b/src/gpu/effects/GrBicubicEffect.cpp @@ -8,6 +8,7 @@ #include "GrBicubicEffect.h" #include "GrInvariantOutput.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" #define DS(x) SkDoubleToScalar(x) @@ -32,10 +33,10 @@ public: } protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; private: - typedef GrGLProgramDataManager::UniformHandle UniformHandle; + typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; UniformHandle fCoefficientsUni; UniformHandle fImageIncrementUni; @@ -105,8 +106,8 @@ void GrGLBicubicEffect::emitCode(EmitArgs& args) { GrGLSLExpr4(args.fInputColor)).c_str()); } -void GrGLBicubicEffect::onSetData(const GrGLProgramDataManager& pdman, - const GrProcessor& processor) { +void GrGLBicubicEffect::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& processor) { const GrBicubicEffect& bicubicEffect = processor.cast(); const GrTexture& texture = *processor.texture(0); float imageIncrement[2]; diff --git a/src/gpu/effects/GrBitmapTextGeoProc.cpp b/src/gpu/effects/GrBitmapTextGeoProc.cpp index c866ae6ca5..371ef010fc 100644 --- a/src/gpu/effects/GrBitmapTextGeoProc.cpp +++ b/src/gpu/effects/GrBitmapTextGeoProc.cpp @@ -12,6 +12,7 @@ #include "gl/GrGLTexture.h" #include "gl/GrGLGeometryProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" class GrGLBitmapTextGeoProc : public GrGLGeometryProcessor { public: @@ -78,10 +79,10 @@ public: } } - void setData(const GrGLProgramDataManager& pdman, const GrPrimitiveProcessor& gp) override { + void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor& gp) override { const GrBitmapTextGeoProc& btgp = gp.cast(); if (btgp.color() != fColor && !btgp.hasVertexColor()) { - GrGLfloat c[4]; + float c[4]; GrColorToRGBAFloat(btgp.color(), c); pdman.set4fv(fColorUniform, 1, c); fColor = btgp.color(); @@ -89,7 +90,7 @@ public: } void setTransformData(const GrPrimitiveProcessor& primProc, - const GrGLProgramDataManager& pdman, + const GrGLSLProgramDataManager& pdman, int index, const SkTArray& transforms) override { this->setTransformDataHelper(primProc, pdman, index, transforms); diff --git a/src/gpu/effects/GrConstColorProcessor.cpp b/src/gpu/effects/GrConstColorProcessor.cpp index 627139fa41..a290b84971 100644 --- a/src/gpu/effects/GrConstColorProcessor.cpp +++ b/src/gpu/effects/GrConstColorProcessor.cpp @@ -8,6 +8,7 @@ #include "effects/GrConstColorProcessor.h" #include "gl/GrGLFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" class GLConstColorProcessor : public GrGLFragmentProcessor { public: @@ -39,14 +40,14 @@ public: } protected: - void onSetData(const GrGLProgramDataManager& pdm, const GrProcessor& processor) override { + void onSetData(const GrGLSLProgramDataManager& pdm, const GrProcessor& processor) override { GrColor color = processor.cast().color(); // We use the "illegal" color value as an uninit sentinel. However, ut isn't inherently // illegal to use this processor with unpremul colors. So we correctly handle the case // when the "illegal" color is used but we will always upload it. if (GrColor_ILLEGAL == color || fPrevColor != color) { - static const GrGLfloat scale = 1.f / 255.f; - GrGLfloat floatColor[4] = { + static const float scale = 1.f / 255.f; + float floatColor[4] = { GrColorUnpackR(color) * scale, GrColorUnpackG(color) * scale, GrColorUnpackB(color) * scale, @@ -58,7 +59,7 @@ protected: } private: - GrGLProgramDataManager::UniformHandle fColorUniform; + GrGLSLProgramDataManager::UniformHandle fColorUniform; GrColor fPrevColor; typedef GrGLFragmentProcessor INHERITED; diff --git a/src/gpu/effects/GrConvexPolyEffect.cpp b/src/gpu/effects/GrConvexPolyEffect.cpp index 3596ab548f..d22a3472a5 100644 --- a/src/gpu/effects/GrConvexPolyEffect.cpp +++ b/src/gpu/effects/GrConvexPolyEffect.cpp @@ -11,6 +11,7 @@ #include "gl/GrGLContext.h" #include "gl/GrGLFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" ////////////////////////////////////////////////////////////////////////////// class AARectEffect : public GrFragmentProcessor { @@ -87,10 +88,10 @@ public: static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder*); protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; private: - GrGLProgramDataManager::UniformHandle fRectUniform; + GrGLSLProgramDataManager::UniformHandle fRectUniform; SkRect fPrevRect; typedef GrGLFragmentProcessor INHERITED; }; @@ -138,7 +139,8 @@ void GLAARectEffect::emitCode(EmitArgs& args) { (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha")).c_str()); } -void GLAARectEffect::onSetData(const GrGLProgramDataManager& pdman, const GrProcessor& processor) { +void GLAARectEffect::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& processor) { const AARectEffect& aare = processor.cast(); const SkRect& rect = aare.getRect(); if (rect != fPrevRect) { @@ -173,10 +175,10 @@ public: static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder*); protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; private: - GrGLProgramDataManager::UniformHandle fEdgeUniform; + GrGLSLProgramDataManager::UniformHandle fEdgeUniform; SkScalar fPrevEdges[3 * GrConvexPolyEffect::kMaxEdges]; typedef GrGLFragmentProcessor INHERITED; }; @@ -222,7 +224,8 @@ void GrGLConvexPolyEffect::emitCode(EmitArgs& args) { (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha")).c_str()); } -void GrGLConvexPolyEffect::onSetData(const GrGLProgramDataManager& pdman, const GrProcessor& effect) { +void GrGLConvexPolyEffect::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& effect) { const GrConvexPolyEffect& cpe = effect.cast(); size_t byteSize = 3 * cpe.getEdgeCount() * sizeof(SkScalar); if (0 != memcmp(fPrevEdges, cpe.getEdges(), byteSize)) { diff --git a/src/gpu/effects/GrConvolutionEffect.cpp b/src/gpu/effects/GrConvolutionEffect.cpp index ef4e791fb2..96d1578f08 100644 --- a/src/gpu/effects/GrConvolutionEffect.cpp +++ b/src/gpu/effects/GrConvolutionEffect.cpp @@ -9,9 +9,10 @@ #include "gl/GrGLFragmentProcessor.h" #include "gl/GrGLTexture.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" // For brevity -typedef GrGLProgramDataManager::UniformHandle UniformHandle; +typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; class GrGLConvolutionEffect : public GrGLFragmentProcessor { public: @@ -22,7 +23,7 @@ public: static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder*); protected: - void onSetData(const GrGLProgramDataManager& pdman, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager& pdman, const GrProcessor&) override; private: int width() const { return Gr1DKernelEffect::WidthFromRadius(fRadius); } @@ -100,8 +101,8 @@ void GrGLConvolutionEffect::emitCode(EmitArgs& args) { fsBuilder->codeAppend(modulate.c_str()); } -void GrGLConvolutionEffect::onSetData(const GrGLProgramDataManager& pdman, - const GrProcessor& processor) { +void GrGLConvolutionEffect::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& processor) { const GrConvolutionEffect& conv = processor.cast(); GrTexture& texture = *conv.texture(0); // the code we generated was for a specific kernel radius diff --git a/src/gpu/effects/GrCoverageSetOpXP.cpp b/src/gpu/effects/GrCoverageSetOpXP.cpp index 89d7565894..b3fe0965c7 100644 --- a/src/gpu/effects/GrCoverageSetOpXP.cpp +++ b/src/gpu/effects/GrCoverageSetOpXP.cpp @@ -81,7 +81,7 @@ private: } } - void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) override {}; + void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) override {}; typedef GrGLXferProcessor INHERITED; }; diff --git a/src/gpu/effects/GrCustomXfermode.cpp b/src/gpu/effects/GrCustomXfermode.cpp index 0d31034013..8ebb80ae6d 100644 --- a/src/gpu/effects/GrCustomXfermode.cpp +++ b/src/gpu/effects/GrCustomXfermode.cpp @@ -22,6 +22,7 @@ #include "gl/GrGLProgramDataManager.h" #include "gl/builders/GrGLProgramBuilder.h" #include "glsl/GrGLSLCaps.h" +#include "glsl/GrGLSLProgramDataManager.h" bool GrCustomXfermode::IsSupportedMode(SkXfermode::Mode mode) { return mode > SkXfermode::kLastCoeffMode && mode <= SkXfermode::kLastMode; @@ -168,7 +169,7 @@ private: GrGLSLBlend::AppendMode(fsBuilder, srcColor, dstColor, outColor, xp.mode()); } - void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) override {} + void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) override {} typedef GrGLXferProcessor INHERITED; }; diff --git a/src/gpu/effects/GrDashingEffect.cpp b/src/gpu/effects/GrDashingEffect.cpp index 106ee49672..4a8c09ea55 100644 --- a/src/gpu/effects/GrDashingEffect.cpp +++ b/src/gpu/effects/GrDashingEffect.cpp @@ -24,6 +24,7 @@ #include "gl/GrGLGeometryProcessor.h" #include "gl/GrGLFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" /////////////////////////////////////////////////////////////////////////////// @@ -821,10 +822,10 @@ public: const GrGLSLCaps&, GrProcessorKeyBuilder*); - void setData(const GrGLProgramDataManager&, const GrPrimitiveProcessor&) override; + void setData(const GrGLSLProgramDataManager&, const GrPrimitiveProcessor&) override; void setTransformData(const GrPrimitiveProcessor& primProc, - const GrGLProgramDataManager& pdman, + const GrGLSLProgramDataManager& pdman, int index, const SkTArray& transforms) override { this->setTransformDataHelper(primProc, pdman, index, transforms); @@ -896,11 +897,11 @@ void GLDashingCircleEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); } -void GLDashingCircleEffect::setData(const GrGLProgramDataManager& pdman, +void GLDashingCircleEffect::setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor& processor) { const DashingCircleEffect& dce = processor.cast(); if (dce.color() != fColor) { - GrGLfloat c[4]; + float c[4]; GrColorToRGBAFloat(dce.color(), c); pdman.set4fv(fColorUniform, 1, c); fColor = dce.color(); @@ -1032,10 +1033,10 @@ public: const GrGLSLCaps&, GrProcessorKeyBuilder*); - void setData(const GrGLProgramDataManager&, const GrPrimitiveProcessor&) override; + void setData(const GrGLSLProgramDataManager&, const GrPrimitiveProcessor&) override; void setTransformData(const GrPrimitiveProcessor& primProc, - const GrGLProgramDataManager& pdman, + const GrGLSLProgramDataManager& pdman, int index, const SkTArray& transforms) override { this->setTransformDataHelper(primProc, pdman, index, transforms); @@ -1120,11 +1121,11 @@ void GLDashingLineEffect::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { fsBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); } -void GLDashingLineEffect::setData(const GrGLProgramDataManager& pdman, +void GLDashingLineEffect::setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor& processor) { const DashingLineEffect& de = processor.cast(); if (de.color() != fColor) { - GrGLfloat c[4]; + float c[4]; GrColorToRGBAFloat(de.color(), c); pdman.set4fv(fColorUniform, 1, c); fColor = de.color(); diff --git a/src/gpu/effects/GrDisableColorXP.cpp b/src/gpu/effects/GrDisableColorXP.cpp index 3e1024b162..0f3382f8fd 100644 --- a/src/gpu/effects/GrDisableColorXP.cpp +++ b/src/gpu/effects/GrDisableColorXP.cpp @@ -10,6 +10,7 @@ #include "gl/GrGLXferProcessor.h" #include "gl/builders/GrGLFragmentShaderBuilder.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" /** * This xfer processor disables color writing. Thus color and coverage and ignored and no blending @@ -66,7 +67,7 @@ private: fsBuilder->codeAppendf("%s = vec4(0);", args.fOutputPrimary); } - void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) override {} + void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) override {} typedef GrGLXferProcessor INHERITED; }; diff --git a/src/gpu/effects/GrDistanceFieldGeoProc.cpp b/src/gpu/effects/GrDistanceFieldGeoProc.cpp index 79004aec46..0cef6be408 100644 --- a/src/gpu/effects/GrDistanceFieldGeoProc.cpp +++ b/src/gpu/effects/GrDistanceFieldGeoProc.cpp @@ -15,6 +15,7 @@ #include "gl/GrGLTexture.h" #include "gl/GrGLGeometryProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" // Assuming a radius of a little less than the diagonal of the fragment #define SK_DistanceFieldAAFactor "0.65" @@ -143,7 +144,7 @@ public: fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); } - void setData(const GrGLProgramDataManager& pdman, const GrPrimitiveProcessor& proc) override { + void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor& proc) override { #ifdef SK_GAMMA_APPLY_TO_A8 const GrDistanceFieldA8TextGeoProc& dfTexEffect = proc.cast(); float distanceAdjust = dfTexEffect.getDistanceAdjust(); @@ -156,13 +157,13 @@ public: if (!dfa8gp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dfa8gp.viewMatrix())) { fViewMatrix = dfa8gp.viewMatrix(); - GrGLfloat viewMatrix[3 * 3]; + float viewMatrix[3 * 3]; GrGLGetMatrix<3>(viewMatrix, fViewMatrix); pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); } if (dfa8gp.color() != fColor && !dfa8gp.hasVertexColor()) { - GrGLfloat c[4]; + float c[4]; GrColorToRGBAFloat(dfa8gp.color(), c); pdman.set4fv(fColorUniform, 1, c); fColor = dfa8gp.color(); @@ -370,7 +371,7 @@ public: fsBuilder->codeAppendf("%s = vec4(val);", args.fOutputCoverage); } - void setData(const GrGLProgramDataManager& pdman, const GrPrimitiveProcessor& proc) override { + void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor& proc) override { SkASSERT(fTextureSizeUni.isValid()); GrTexture* texture = proc.texture(0); @@ -386,13 +387,13 @@ public: if (!dfpgp.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dfpgp.viewMatrix())) { fViewMatrix = dfpgp.viewMatrix(); - GrGLfloat viewMatrix[3 * 3]; + float viewMatrix[3 * 3]; GrGLGetMatrix<3>(viewMatrix, fViewMatrix); pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); } if (dfpgp.color() != fColor) { - GrGLfloat c[4]; + float c[4]; GrColorToRGBAFloat(dfpgp.color(), c); pdman.set4fv(fColorUniform, 1, c); fColor = dfpgp.color(); @@ -639,7 +640,7 @@ public: fsBuilder->codeAppendf("%s = val;", args.fOutputCoverage); } - void setData(const GrGLProgramDataManager& pdman, + void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor& processor) override { SkASSERT(fDistanceAdjustUni.isValid()); @@ -655,13 +656,13 @@ public: if (!dflcd.viewMatrix().isIdentity() && !fViewMatrix.cheapEqualTo(dflcd.viewMatrix())) { fViewMatrix = dflcd.viewMatrix(); - GrGLfloat viewMatrix[3 * 3]; + float viewMatrix[3 * 3]; GrGLGetMatrix<3>(viewMatrix, fViewMatrix); pdman.setMatrix3f(fViewMatrixUniform, viewMatrix); } if (dflcd.color() != fColor) { - GrGLfloat c[4]; + float c[4]; GrColorToRGBAFloat(dflcd.color(), c); pdman.set4fv(fColorUniform, 1, c); fColor = dflcd.color(); diff --git a/src/gpu/effects/GrMatrixConvolutionEffect.cpp b/src/gpu/effects/GrMatrixConvolutionEffect.cpp index 8de8580489..af09db5090 100644 --- a/src/gpu/effects/GrMatrixConvolutionEffect.cpp +++ b/src/gpu/effects/GrMatrixConvolutionEffect.cpp @@ -8,6 +8,7 @@ #include "gl/GrGLFragmentProcessor.h" #include "gl/GrGLTexture.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" class GrGLMatrixConvolutionEffect : public GrGLFragmentProcessor { public: @@ -17,10 +18,10 @@ public: static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder*); protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; private: - typedef GrGLProgramDataManager::UniformHandle UniformHandle; + typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; SkISize fKernelSize; bool fConvolveAlpha; @@ -111,8 +112,8 @@ void GrGLMatrixConvolutionEffect::GenKey(const GrProcessor& processor, b->add32(GrTextureDomain::GLDomain::DomainKey(m.domain())); } -void GrGLMatrixConvolutionEffect::onSetData(const GrGLProgramDataManager& pdman, - const GrProcessor& processor) { +void GrGLMatrixConvolutionEffect::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& processor) { const GrMatrixConvolutionEffect& conv = processor.cast(); GrTexture& texture = *conv.texture(0); // the code we generated was for a specific kernel size diff --git a/src/gpu/effects/GrOvalEffect.cpp b/src/gpu/effects/GrOvalEffect.cpp index 42b71ade9e..1bc6589a3e 100644 --- a/src/gpu/effects/GrOvalEffect.cpp +++ b/src/gpu/effects/GrOvalEffect.cpp @@ -12,6 +12,7 @@ #include "SkRect.h" #include "gl/GrGLFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" ////////////////////////////////////////////////////////////////////////////// @@ -98,12 +99,12 @@ public: static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder*); protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; private: - GrGLProgramDataManager::UniformHandle fCircleUniform; - SkPoint fPrevCenter; - SkScalar fPrevRadius; + GrGLSLProgramDataManager::UniformHandle fCircleUniform; + SkPoint fPrevCenter; + SkScalar fPrevRadius; typedef GrGLFragmentProcessor INHERITED; }; @@ -153,7 +154,8 @@ void GLCircleEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps&, b->add32(ce.getEdgeType()); } -void GLCircleEffect::onSetData(const GrGLProgramDataManager& pdman, const GrProcessor& processor) { +void GLCircleEffect::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& processor) { const CircleEffect& ce = processor.cast(); if (ce.getRadius() != fPrevRadius || ce.getCenter() != fPrevCenter) { SkScalar radius = ce.getRadius(); @@ -269,12 +271,12 @@ public: static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder*); protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; private: - GrGLProgramDataManager::UniformHandle fEllipseUniform; - SkPoint fPrevCenter; - SkVector fPrevRadii; + GrGLSLProgramDataManager::UniformHandle fEllipseUniform; + SkPoint fPrevCenter; + SkVector fPrevRadii; typedef GrGLFragmentProcessor INHERITED; }; @@ -334,7 +336,8 @@ void GLEllipseEffect::GenKey(const GrProcessor& effect, const GrGLSLCaps&, b->add32(ee.getEdgeType()); } -void GLEllipseEffect::onSetData(const GrGLProgramDataManager& pdman, const GrProcessor& effect) { +void GLEllipseEffect::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& effect) { const EllipseEffect& ee = effect.cast(); if (ee.getRadii() != fPrevRadii || ee.getCenter() != fPrevCenter) { SkScalar invRXSqd = 1.f / (ee.getRadii().fX * ee.getRadii().fX); diff --git a/src/gpu/effects/GrPorterDuffXferProcessor.cpp b/src/gpu/effects/GrPorterDuffXferProcessor.cpp index e31ff653f3..a7f390a5dc 100644 --- a/src/gpu/effects/GrPorterDuffXferProcessor.cpp +++ b/src/gpu/effects/GrPorterDuffXferProcessor.cpp @@ -17,6 +17,7 @@ #include "gl/GrGLXferProcessor.h" #include "gl/builders/GrGLFragmentShaderBuilder.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" /** * Wraps the shader outputs and HW blend state that comprise a Porter Duff blend mode with coverage. @@ -450,7 +451,7 @@ private: args.fOutputPrimary, args.fInputColor, args.fInputCoverage); } - void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) override {} + void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) override {} typedef GrGLXferProcessor INHERITED; }; @@ -550,7 +551,7 @@ private: GrGLSLBlend::AppendMode(fsBuilder, srcColor, dstColor, outColor, xp.getXfermode()); } - void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) override {} + void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) override {} typedef GrGLXferProcessor INHERITED; }; @@ -628,7 +629,7 @@ private: args.fInputCoverage); } - void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) override {}; + void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) override {}; typedef GrGLXferProcessor INHERITED; }; diff --git a/src/gpu/effects/GrRRectEffect.cpp b/src/gpu/effects/GrRRectEffect.cpp index b5b95679f5..aeab0e4dbf 100644 --- a/src/gpu/effects/GrRRectEffect.cpp +++ b/src/gpu/effects/GrRRectEffect.cpp @@ -14,6 +14,7 @@ #include "SkRRect.h" #include "gl/GrGLFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" // The effects defined here only handle rrect radii >= kRadiusMin. static const SkScalar kRadiusMin = SK_ScalarHalf; @@ -133,11 +134,11 @@ public: static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder*); protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; private: - GrGLProgramDataManager::UniformHandle fInnerRectUniform; - GrGLProgramDataManager::UniformHandle fRadiusPlusHalfUniform; + GrGLSLProgramDataManager::UniformHandle fInnerRectUniform; + GrGLSLProgramDataManager::UniformHandle fRadiusPlusHalfUniform; SkRRect fPrevRRect; typedef GrGLFragmentProcessor INHERITED; }; @@ -281,8 +282,8 @@ void GLCircularRRectEffect::GenKey(const GrProcessor& processor, const GrGLSLCap b->add32((crre.getCircularCornerFlags() << 3) | crre.getEdgeType()); } -void GLCircularRRectEffect::onSetData(const GrGLProgramDataManager& pdman, - const GrProcessor& processor) { +void GLCircularRRectEffect::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& processor) { const CircularRRectEffect& crre = processor.cast(); const SkRRect& rrect = crre.getRRect(); if (rrect != fPrevRRect) { @@ -479,11 +480,11 @@ public: static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder*); protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; private: - GrGLProgramDataManager::UniformHandle fInnerRectUniform; - GrGLProgramDataManager::UniformHandle fInvRadiiSqdUniform; + GrGLSLProgramDataManager::UniformHandle fInnerRectUniform; + GrGLSLProgramDataManager::UniformHandle fInvRadiiSqdUniform; SkRRect fPrevRRect; typedef GrGLFragmentProcessor INHERITED; }; @@ -572,8 +573,8 @@ void GLEllipticalRRectEffect::GenKey(const GrProcessor& effect, const GrGLSLCaps b->add32(erre.getRRect().getType() | erre.getEdgeType() << 3); } -void GLEllipticalRRectEffect::onSetData(const GrGLProgramDataManager& pdman, - const GrProcessor& effect) { +void GLEllipticalRRectEffect::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& effect) { const EllipticalRRectEffect& erre = effect.cast(); const SkRRect& rrect = erre.getRRect(); if (rrect != fPrevRRect) { diff --git a/src/gpu/effects/GrTextureDomain.cpp b/src/gpu/effects/GrTextureDomain.cpp index 93d3afb8c4..760fd57507 100644 --- a/src/gpu/effects/GrTextureDomain.cpp +++ b/src/gpu/effects/GrTextureDomain.cpp @@ -12,6 +12,7 @@ #include "gl/GrGLContext.h" #include "gl/GrGLFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" GrTextureDomain::GrTextureDomain(const SkRect& domain, Mode mode, int index) : fIndex(index) { @@ -142,12 +143,12 @@ void GrTextureDomain::GLDomain::sampleTexture(GrGLShaderBuilder* builder, } } -void GrTextureDomain::GLDomain::setData(const GrGLProgramDataManager& pdman, +void GrTextureDomain::GLDomain::setData(const GrGLSLProgramDataManager& pdman, const GrTextureDomain& textureDomain, GrSurfaceOrigin textureOrigin) { SkASSERT(textureDomain.mode() == fMode); if (kIgnore_Mode != textureDomain.mode()) { - GrGLfloat values[kPrevDomainCount] = { + float values[kPrevDomainCount] = { SkScalarToFloat(textureDomain.domain().left()), SkScalarToFloat(textureDomain.domain().top()), SkScalarToFloat(textureDomain.domain().right()), @@ -161,9 +162,9 @@ void GrTextureDomain::GLDomain::setData(const GrGLProgramDataManager& pdman, // of elements so that values = (l, t, r, b). SkTSwap(values[1], values[3]); } - if (0 != memcmp(values, fPrevDomain, kPrevDomainCount * sizeof(GrGLfloat))) { + if (0 != memcmp(values, fPrevDomain, kPrevDomainCount * sizeof(float))) { pdman.set4fv(fDomainUni, 1, values); - memcpy(fPrevDomain, values, kPrevDomainCount * sizeof(GrGLfloat)); + memcpy(fPrevDomain, values, kPrevDomainCount * sizeof(float)); } } } @@ -180,7 +181,7 @@ public: static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder*); protected: - void onSetData(const GrGLProgramDataManager&, const GrProcessor&) override; + void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) override; private: GrTextureDomain::GLDomain fGLDomain; @@ -200,8 +201,8 @@ void GrGLTextureDomainEffect::emitCode(EmitArgs& args) { args.fInputColor); } -void GrGLTextureDomainEffect::onSetData(const GrGLProgramDataManager& pdman, - const GrProcessor& processor) { +void GrGLTextureDomainEffect::onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& processor) { const GrTextureDomainEffect& textureDomainEffect = processor.cast(); const GrTextureDomain& domain = textureDomainEffect.textureDomain(); fGLDomain.setData(pdman, domain, processor.texture(0)->origin()); diff --git a/src/gpu/effects/GrTextureDomain.h b/src/gpu/effects/GrTextureDomain.h index 978a68cbf0..0b93ac859f 100644 --- a/src/gpu/effects/GrTextureDomain.h +++ b/src/gpu/effects/GrTextureDomain.h @@ -10,6 +10,7 @@ #include "GrSingleTextureEffect.h" #include "gl/GrGLFragmentProcessor.h" +#include "glsl/GrGLSLProgramDataManager.h" class GrGLProgramBuilder; class GrGLShaderBuilder; @@ -122,7 +123,7 @@ public: * Call this from GrGLProcessor::setData() to upload uniforms necessary for the texture * domain. The rectangle is automatically adjusted to account for the texture's origin. */ - void setData(const GrGLProgramDataManager& pdman, const GrTextureDomain& textureDomain, + void setData(const GrGLSLProgramDataManager& pdman, const GrTextureDomain& textureDomain, GrSurfaceOrigin textureOrigin); enum { @@ -140,10 +141,10 @@ public: private: static const int kPrevDomainCount = 4; - SkDEBUGCODE(Mode fMode;) - GrGLProgramDataManager::UniformHandle fDomainUni; - SkString fDomainName; - GrGLfloat fPrevDomain[kPrevDomainCount]; + SkDEBUGCODE(Mode fMode;) + GrGLSLProgramDataManager::UniformHandle fDomainUni; + SkString fDomainName; + float fPrevDomain[kPrevDomainCount]; }; protected: diff --git a/src/gpu/effects/GrYUVtoRGBEffect.cpp b/src/gpu/effects/GrYUVtoRGBEffect.cpp index a0ee114c34..39a974348b 100644 --- a/src/gpu/effects/GrYUVtoRGBEffect.cpp +++ b/src/gpu/effects/GrYUVtoRGBEffect.cpp @@ -12,6 +12,7 @@ #include "GrProcessor.h" #include "gl/GrGLFragmentProcessor.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" namespace { @@ -52,9 +53,9 @@ public: class GLProcessor : public GrGLFragmentProcessor { public: - static const GrGLfloat kJPEGConversionMatrix[16]; - static const GrGLfloat kRec601ConversionMatrix[16]; - static const GrGLfloat kRec709ConversionMatrix[16]; + static const float kJPEGConversionMatrix[16]; + static const float kRec601ConversionMatrix[16]; + static const float kRec709ConversionMatrix[16]; // this class always generates the same code. static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder*) {} @@ -81,8 +82,8 @@ public: } protected: - virtual void onSetData(const GrGLProgramDataManager& pdman, - const GrProcessor& processor) override { + virtual void onSetData(const GrGLSLProgramDataManager& pdman, + const GrProcessor& processor) override { const YUVtoRGBEffect& yuvEffect = processor.cast(); switch (yuvEffect.getColorSpace()) { case kJPEG_SkYUVColorSpace: @@ -98,7 +99,7 @@ public: } private: - GrGLProgramDataManager::UniformHandle fMatrixUni; + GrGLSLProgramDataManager::UniformHandle fMatrixUni; typedef GrGLFragmentProcessor INHERITED; }; @@ -152,17 +153,17 @@ private: typedef GrFragmentProcessor INHERITED; }; -const GrGLfloat YUVtoRGBEffect::GLProcessor::kJPEGConversionMatrix[16] = { +const float YUVtoRGBEffect::GLProcessor::kJPEGConversionMatrix[16] = { 1.0f, 0.0f, 1.402f, -0.701f, 1.0f, -0.34414f, -0.71414f, 0.529f, 1.0f, 1.772f, 0.0f, -0.886f, 0.0f, 0.0f, 0.0f, 1.0}; -const GrGLfloat YUVtoRGBEffect::GLProcessor::kRec601ConversionMatrix[16] = { +const float YUVtoRGBEffect::GLProcessor::kRec601ConversionMatrix[16] = { 1.164f, 0.0f, 1.596f, -0.87075f, 1.164f, -0.391f, -0.813f, 0.52925f, 1.164f, 2.018f, 0.0f, -1.08175f, 0.0f, 0.0f, 0.0f, 1.0}; -const GrGLfloat YUVtoRGBEffect::GLProcessor::kRec709ConversionMatrix[16] = { +const float YUVtoRGBEffect::GLProcessor::kRec709ConversionMatrix[16] = { 1.164f, 0.0f, 1.793f, -0.96925f, 1.164f, -0.213f, -0.533f, 0.30025f, 1.164f, 2.112f, 0.0f, -1.12875f, diff --git a/src/gpu/gl/GrGLFragmentProcessor.cpp b/src/gpu/gl/GrGLFragmentProcessor.cpp index 225e5bffff..5f30262508 100644 --- a/src/gpu/gl/GrGLFragmentProcessor.cpp +++ b/src/gpu/gl/GrGLFragmentProcessor.cpp @@ -10,7 +10,7 @@ #include "builders/GrGLFragmentShaderBuilder.h" #include "builders/GrGLProgramBuilder.h" -void GrGLFragmentProcessor::setData(const GrGLProgramDataManager& pdman, +void GrGLFragmentProcessor::setData(const GrGLSLProgramDataManager& pdman, const GrFragmentProcessor& processor) { this->onSetData(pdman, processor); SkASSERT(fChildProcessors.count() == processor.numChildProcessors()); diff --git a/src/gpu/gl/GrGLFragmentProcessor.h b/src/gpu/gl/GrGLFragmentProcessor.h index 1e4dd481b3..00bd063d8e 100644 --- a/src/gpu/gl/GrGLFragmentProcessor.h +++ b/src/gpu/gl/GrGLFragmentProcessor.h @@ -8,11 +8,11 @@ #ifndef GrGLFragmentProcessor_DEFINED #define GrGLFragmentProcessor_DEFINED -#include "GrGLProgramDataManager.h" #include "GrGLProcessor.h" -#include "GrTextureAccess.h" +#include "glsl/GrGLSLProgramDataManager.h" class GrGLFPBuilder; +class GrGLSLCaps; class GrGLFragmentProcessor { public: @@ -24,7 +24,7 @@ public: } } - typedef GrGLProgramDataManager::UniformHandle UniformHandle; + typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; typedef GrGLProcessor::TransformedCoordsArray TransformedCoordsArray; typedef GrGLProcessor::TextureSamplerArray TextureSamplerArray; @@ -70,7 +70,7 @@ public: virtual void emitCode(EmitArgs&) = 0; - void setData(const GrGLProgramDataManager& pdman, const GrFragmentProcessor& processor); + void setData(const GrGLSLProgramDataManager& pdman, const GrFragmentProcessor& processor); static void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder*) {} @@ -101,7 +101,7 @@ protected: parameter is guaranteed to be of the same type that created this GrGLFragmentProcessor and to have an identical processor key as the one that created this GrGLFragmentProcessor. */ // TODO update this to pass in GrFragmentProcessor - virtual void onSetData(const GrGLProgramDataManager&, const GrProcessor&) {} + virtual void onSetData(const GrGLSLProgramDataManager&, const GrProcessor&) {} private: void internalEmitChild(int, const char*, const char*, EmitArgs&); diff --git a/src/gpu/gl/GrGLGeometryProcessor.h b/src/gpu/gl/GrGLGeometryProcessor.h index 1c7ab5371b..1b3b8d9277 100644 --- a/src/gpu/gl/GrGLGeometryProcessor.h +++ b/src/gpu/gl/GrGLGeometryProcessor.h @@ -24,7 +24,7 @@ public: // By default we use the identity matrix void setTransformData(const GrPrimitiveProcessor&, - const GrGLProgramDataManager& pdman, + const GrGLSLProgramDataManager& pdman, int index, const SkTArray& transforms) override { this->setTransformDataMatrix(SkMatrix::I(), pdman, index, transforms); @@ -33,7 +33,7 @@ public: // A helper which subclasses can use if needed template void setTransformDataHelper(const GrPrimitiveProcessor& primProc, - const GrGLProgramDataManager& pdman, + const GrGLSLProgramDataManager& pdman, int index, const SkTArray& transforms) { const GeometryProcessor& gp = primProc.cast(); @@ -87,7 +87,7 @@ protected: private: void setTransformDataMatrix(const SkMatrix& localMatrix, - const GrGLProgramDataManager& pdman, + const GrGLSLProgramDataManager& pdman, int index, const SkTArray& transforms) { SkSTArray<2, Transform, true>& procTransforms = fInstalledTransforms[index]; diff --git a/src/gpu/gl/GrGLGpuProgramCache.cpp b/src/gpu/gl/GrGLGpuProgramCache.cpp index d74b54aeba..84794ac1cc 100644 --- a/src/gpu/gl/GrGLGpuProgramCache.cpp +++ b/src/gpu/gl/GrGLGpuProgramCache.cpp @@ -11,6 +11,7 @@ #include "GrProcessor.h" #include "GrGLFragmentProcessor.h" #include "GrGLPathRendering.h" +#include "glsl/GrGLSLProgramDataManager.h" #include "SkRTConf.h" #include "SkTSearch.h" @@ -19,7 +20,7 @@ SK_CONF_DECLARE(bool, c_DisplayCache, "gpu.displayCache", false, "Display program cache usage."); #endif -typedef GrGLProgramDataManager::UniformHandle UniformHandle; +typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; struct GrGLGpu::ProgramCache::Entry { diff --git a/src/gpu/gl/GrGLPathRendering.cpp b/src/gpu/gl/GrGLPathRendering.cpp index a74014b96b..f18a4c671b 100644 --- a/src/gpu/gl/GrGLPathRendering.cpp +++ b/src/gpu/gl/GrGLPathRendering.cpp @@ -186,7 +186,7 @@ void GrGLPathRendering::onDrawPaths(const DrawPathArgs& args, const GrPathRange* void GrGLPathRendering::setProgramPathFragmentInputTransform(GrGLuint program, GrGLint location, GrGLenum genMode, GrGLint components, const SkMatrix& matrix) { - GrGLfloat coefficients[3 * 3]; + float coefficients[3 * 3]; SkASSERT(components >= 1 && components <= 3); coefficients[0] = SkScalarToFloat(matrix[SkMatrix::kMScaleX]); @@ -224,7 +224,7 @@ void GrGLPathRendering::setProjectionMatrix(const SkMatrix& matrix, fHWProjectionMatrixState.fRenderTargetSize = renderTargetSize; fHWProjectionMatrixState.fRenderTargetOrigin = renderTargetOrigin; - GrGLfloat glMatrix[4 * 4]; + float glMatrix[4 * 4]; fHWProjectionMatrixState.getRTAdjustedGLMatrix<4>(glMatrix); GL_CALL(MatrixLoadf(GR_GL_PATH_PROJECTION, glMatrix)); } diff --git a/src/gpu/gl/GrGLPathRendering.h b/src/gpu/gl/GrGLPathRendering.h index 651ddeea5d..d61df2fe40 100644 --- a/src/gpu/gl/GrGLPathRendering.h +++ b/src/gpu/gl/GrGLPathRendering.h @@ -94,7 +94,7 @@ private: /** * Gets a matrix that goes from local coordinates to GL normalized device coords. */ - template void getRTAdjustedGLMatrix(GrGLfloat* destMatrix) { + template void getRTAdjustedGLMatrix(float* destMatrix) { SkMatrix combined; if (kBottomLeft_GrSurfaceOrigin == fRenderTargetOrigin) { combined.setAll(SkIntToScalar(2) / fRenderTargetSize.fWidth, 0, -SK_Scalar1, diff --git a/src/gpu/gl/GrGLPrimitiveProcessor.h b/src/gpu/gl/GrGLPrimitiveProcessor.h index bf1c388698..cff964037d 100644 --- a/src/gpu/gl/GrGLPrimitiveProcessor.h +++ b/src/gpu/gl/GrGLPrimitiveProcessor.h @@ -10,6 +10,7 @@ #include "GrPrimitiveProcessor.h" #include "GrGLProcessor.h" +#include "glsl/GrGLSLProgramDataManager.h" class GrBatchTracker; class GrPrimitiveProcessor; @@ -19,7 +20,7 @@ class GrGLPrimitiveProcessor { public: virtual ~GrGLPrimitiveProcessor() {} - typedef GrGLProgramDataManager::UniformHandle UniformHandle; + typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; typedef GrGLProcessor::TextureSamplerArray TextureSamplerArray; typedef SkSTArray<2, const GrCoordTransform*, true> ProcCoords; @@ -63,12 +64,12 @@ public: GrPrimitiveProcessor parameter is guaranteed to be of the same type that created this GrGLPrimitiveProcessor and to have an identical processor key as the one that created this GrGLPrimitiveProcessor. */ - virtual void setData(const GrGLProgramDataManager&, const GrPrimitiveProcessor&) = 0; + virtual void setData(const GrGLSLProgramDataManager&, const GrPrimitiveProcessor&) = 0; static SkMatrix GetTransformMatrix(const SkMatrix& localMatrix, const GrCoordTransform&); virtual void setTransformData(const GrPrimitiveProcessor&, - const GrGLProgramDataManager& pdman, + const GrGLSLProgramDataManager& pdman, int index, const SkTArray& transforms) = 0; @@ -77,9 +78,9 @@ protected: struct Transform { Transform() : fType(kVoid_GrSLType) { fCurrentValue = SkMatrix::InvalidMatrix(); } - GrGLProgramDataManager::UniformHandle fHandle; - SkMatrix fCurrentValue; - GrSLType fType; + GrGLSLProgramDataManager::UniformHandle fHandle; + SkMatrix fCurrentValue; + GrSLType fType; }; SkSTArray<8, SkSTArray<2, Transform, true> > fInstalledTransforms; diff --git a/src/gpu/gl/GrGLProcessor.h b/src/gpu/gl/GrGLProcessor.h index f99b1c5030..c389ce4bfa 100644 --- a/src/gpu/gl/GrGLProcessor.h +++ b/src/gpu/gl/GrGLProcessor.h @@ -8,9 +8,10 @@ #ifndef GrGLProcessor_DEFINED #define GrGLProcessor_DEFINED -#include "GrGLProgramDataManager.h" #include "GrProcessor.h" +#include "GrShaderVar.h" #include "GrTextureAccess.h" +#include "glsl/GrGLSLProgramDataManager.h" /** @file This file contains specializations for OpenGL of the shader stages declared in @@ -29,7 +30,7 @@ // TODO delete this and make TextureSampler its own thing class GrGLProcessor { public: - typedef GrGLProgramDataManager::UniformHandle UniformHandle; + typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; /** * Passed to GrGLProcessors so they can add transformed coordinates to their shader code. diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp index 08127c819a..552a0fb27f 100644 --- a/src/gpu/gl/GrGLProgram.cpp +++ b/src/gpu/gl/GrGLProgram.cpp @@ -135,7 +135,7 @@ void GrGLProgram::setRenderTargetState(const GrPrimitiveProcessor& primProc, fRenderTargetState.fRenderTargetSize = size; fRenderTargetState.fRenderTargetOrigin = rt->origin(); - GrGLfloat rtAdjustmentVec[4]; + float rtAdjustmentVec[4]; fRenderTargetState.getRTAdjustmentVec(rtAdjustmentVec); fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec); } diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h index 9c5ab73ca4..dc64a70d26 100644 --- a/src/gpu/gl/GrGLProgram.h +++ b/src/gpu/gl/GrGLProgram.h @@ -13,6 +13,7 @@ #include "GrGLProgramDesc.h" #include "GrGLTexture.h" #include "GrGLProgramDataManager.h" +#include "glsl/GrGLSLProgramDataManager.h" #include "SkString.h" #include "SkXfermode.h" @@ -74,7 +75,7 @@ public: * pos.x = dot(v.xy, pos.xz) * pos.y = dot(v.zw, pos.yz) */ - void getRTAdjustmentVec(GrGLfloat* destVec) { + void getRTAdjustmentVec(float* destVec) { destVec[0] = 2.f / fRenderTargetSize.fWidth; destVec[1] = -1.f; if (kBottomLeft_GrSurfaceOrigin == fRenderTargetOrigin) { @@ -97,7 +98,7 @@ public: SkTArray* textureBindings); protected: - typedef GrGLProgramDataManager::UniformHandle UniformHandle; + typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray; typedef GrGLProgramDataManager::SeparableVaryingInfoArray SeparableVaryingInfoArray; diff --git a/src/gpu/gl/GrGLProgramDataManager.cpp b/src/gpu/gl/GrGLProgramDataManager.cpp index 590287e318..7320b2dd8a 100644 --- a/src/gpu/gl/GrGLProgramDataManager.cpp +++ b/src/gpu/gl/GrGLProgramDataManager.cpp @@ -60,7 +60,7 @@ GrGLProgramDataManager::GrGLProgramDataManager(GrGLGpu* gpu, GrGLuint programID, } } -void GrGLProgramDataManager::setSampler(UniformHandle u, GrGLint texUnit) const { +void GrGLProgramDataManager::setSampler(UniformHandle u, int texUnit) const { const Uniform& uni = fUniforms[u.toIndex()]; SkASSERT(uni.fType == kSampler2D_GrSLType); SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); @@ -76,7 +76,7 @@ void GrGLProgramDataManager::setSampler(UniformHandle u, GrGLint texUnit) const } } -void GrGLProgramDataManager::set1f(UniformHandle u, GrGLfloat v0) const { +void GrGLProgramDataManager::set1f(UniformHandle u, float v0) const { const Uniform& uni = fUniforms[u.toIndex()]; SkASSERT(uni.fType == kFloat_GrSLType); SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); @@ -91,7 +91,7 @@ void GrGLProgramDataManager::set1f(UniformHandle u, GrGLfloat v0) const { void GrGLProgramDataManager::set1fv(UniformHandle u, int arrayCount, - const GrGLfloat v[]) const { + const float v[]) const { const Uniform& uni = fUniforms[u.toIndex()]; SkASSERT(uni.fType == kFloat_GrSLType); SkASSERT(arrayCount > 0); @@ -108,7 +108,7 @@ void GrGLProgramDataManager::set1fv(UniformHandle u, } } -void GrGLProgramDataManager::set2f(UniformHandle u, GrGLfloat v0, GrGLfloat v1) const { +void GrGLProgramDataManager::set2f(UniformHandle u, float v0, float v1) const { const Uniform& uni = fUniforms[u.toIndex()]; SkASSERT(uni.fType == kVec2f_GrSLType); SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); @@ -123,7 +123,7 @@ void GrGLProgramDataManager::set2f(UniformHandle u, GrGLfloat v0, GrGLfloat v1) void GrGLProgramDataManager::set2fv(UniformHandle u, int arrayCount, - const GrGLfloat v[]) const { + const float v[]) const { const Uniform& uni = fUniforms[u.toIndex()]; SkASSERT(uni.fType == kVec2f_GrSLType); SkASSERT(arrayCount > 0); @@ -137,7 +137,7 @@ void GrGLProgramDataManager::set2fv(UniformHandle u, } } -void GrGLProgramDataManager::set3f(UniformHandle u, GrGLfloat v0, GrGLfloat v1, GrGLfloat v2) const { +void GrGLProgramDataManager::set3f(UniformHandle u, float v0, float v1, float v2) const { const Uniform& uni = fUniforms[u.toIndex()]; SkASSERT(uni.fType == kVec3f_GrSLType); SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); @@ -152,7 +152,7 @@ void GrGLProgramDataManager::set3f(UniformHandle u, GrGLfloat v0, GrGLfloat v1, void GrGLProgramDataManager::set3fv(UniformHandle u, int arrayCount, - const GrGLfloat v[]) const { + const float v[]) const { const Uniform& uni = fUniforms[u.toIndex()]; SkASSERT(uni.fType == kVec3f_GrSLType); SkASSERT(arrayCount > 0); @@ -167,10 +167,10 @@ void GrGLProgramDataManager::set3fv(UniformHandle u, } void GrGLProgramDataManager::set4f(UniformHandle u, - GrGLfloat v0, - GrGLfloat v1, - GrGLfloat v2, - GrGLfloat v3) const { + float v0, + float v1, + float v2, + float v3) const { const Uniform& uni = fUniforms[u.toIndex()]; SkASSERT(uni.fType == kVec4f_GrSLType); SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); @@ -185,7 +185,7 @@ void GrGLProgramDataManager::set4f(UniformHandle u, void GrGLProgramDataManager::set4fv(UniformHandle u, int arrayCount, - const GrGLfloat v[]) const { + const float v[]) const { const Uniform& uni = fUniforms[u.toIndex()]; SkASSERT(uni.fType == kVec4f_GrSLType); SkASSERT(arrayCount > 0); @@ -199,7 +199,7 @@ void GrGLProgramDataManager::set4fv(UniformHandle u, } } -void GrGLProgramDataManager::setMatrix3f(UniformHandle u, const GrGLfloat matrix[]) const { +void GrGLProgramDataManager::setMatrix3f(UniformHandle u, const float matrix[]) const { const Uniform& uni = fUniforms[u.toIndex()]; SkASSERT(uni.fType == kMat33f_GrSLType); SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); @@ -212,7 +212,7 @@ void GrGLProgramDataManager::setMatrix3f(UniformHandle u, const GrGLfloat matrix } } -void GrGLProgramDataManager::setMatrix4f(UniformHandle u, const GrGLfloat matrix[]) const { +void GrGLProgramDataManager::setMatrix4f(UniformHandle u, const float matrix[]) const { const Uniform& uni = fUniforms[u.toIndex()]; SkASSERT(uni.fType == kMat44f_GrSLType); SkASSERT(GrGLSLShaderVar::kNonArray == uni.fArrayCount); @@ -227,7 +227,7 @@ void GrGLProgramDataManager::setMatrix4f(UniformHandle u, const GrGLfloat matrix void GrGLProgramDataManager::setMatrix3fv(UniformHandle u, int arrayCount, - const GrGLfloat matrices[]) const { + const float matrices[]) const { const Uniform& uni = fUniforms[u.toIndex()]; SkASSERT(uni.fType == kMat33f_GrSLType); SkASSERT(arrayCount > 0); @@ -245,7 +245,7 @@ void GrGLProgramDataManager::setMatrix3fv(UniformHandle u, void GrGLProgramDataManager::setMatrix4fv(UniformHandle u, int arrayCount, - const GrGLfloat matrices[]) const { + const float matrices[]) const { const Uniform& uni = fUniforms[u.toIndex()]; SkASSERT(uni.fType == kMat44f_GrSLType); SkASSERT(arrayCount > 0); @@ -262,7 +262,7 @@ void GrGLProgramDataManager::setMatrix4fv(UniformHandle u, } void GrGLProgramDataManager::setSkMatrix(UniformHandle u, const SkMatrix& matrix) const { - GrGLfloat mt[] = { + float mt[] = { matrix.get(SkMatrix::kMScaleX), matrix.get(SkMatrix::kMSkewY), matrix.get(SkMatrix::kMPersp0), diff --git a/src/gpu/gl/GrGLProgramDataManager.h b/src/gpu/gl/GrGLProgramDataManager.h index 04d519fb16..ea7b19e034 100644 --- a/src/gpu/gl/GrGLProgramDataManager.h +++ b/src/gpu/gl/GrGLProgramDataManager.h @@ -8,6 +8,8 @@ #ifndef GrGLProgramDataManager_DEFINED #define GrGLProgramDataManager_DEFINED +#include "glsl/GrGLSLProgramDataManager.h" + #include "GrAllocator.h" #include "gl/GrGLTypes.h" #include "glsl/GrGLSLShaderVar.h" @@ -23,31 +25,8 @@ class GrGLProgramBuilder; * The resources are objects the program uses to communicate with the * application code. */ -class GrGLProgramDataManager : SkNoncopyable { +class GrGLProgramDataManager : public GrGLSLProgramDataManager { public: - // Opaque handle to a resource - class ShaderResourceHandle { - public: - ShaderResourceHandle(int value) - : fValue(value) { - SkASSERT(this->isValid()); - } - - ShaderResourceHandle() - : fValue(kInvalid_ShaderResourceHandle) { - } - - bool operator==(const ShaderResourceHandle& other) const { return other.fValue == fValue; } - bool isValid() const { return kInvalid_ShaderResourceHandle != fValue; } - int toIndex() const { SkASSERT(this->isValid()); return fValue; } - - private: - static const int kInvalid_ShaderResourceHandle = -1; - int fValue; - }; - - typedef ShaderResourceHandle UniformHandle; - struct UniformInfo { GrGLSLShaderVar fVariable; uint32_t fVisibility; @@ -71,29 +50,29 @@ public: /** Functions for uploading uniform values. The varities ending in v can be used to upload to an * array of uniforms. arrayCount must be <= the array count of the uniform. */ - void setSampler(UniformHandle, GrGLint texUnit) const; - void set1f(UniformHandle, GrGLfloat v0) const; - void set1fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; - void set2f(UniformHandle, GrGLfloat, GrGLfloat) const; - void set2fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; - void set3f(UniformHandle, GrGLfloat, GrGLfloat, GrGLfloat) const; - void set3fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; - void set4f(UniformHandle, GrGLfloat, GrGLfloat, GrGLfloat, GrGLfloat) const; - void set4fv(UniformHandle, int arrayCount, const GrGLfloat v[]) const; + void setSampler(UniformHandle, int texUnit) const; + + void set1f(UniformHandle, float v0) const override; + void set1fv(UniformHandle, int arrayCount, const float v[]) const override; + void set2f(UniformHandle, float, float) const override; + void set2fv(UniformHandle, int arrayCount, const float v[]) const override; + void set3f(UniformHandle, float, float, float) const override; + void set3fv(UniformHandle, int arrayCount, const float v[]) const override; + void set4f(UniformHandle, float, float, float, float) const override; + void set4fv(UniformHandle, int arrayCount, const float v[]) const override; // matrices are column-major, the first three upload a single matrix, the latter three upload // arrayCount matrices into a uniform array. - void setMatrix3f(UniformHandle, const GrGLfloat matrix[]) const; - void setMatrix4f(UniformHandle, const GrGLfloat matrix[]) const; - void setMatrix3fv(UniformHandle, int arrayCount, const GrGLfloat matrices[]) const; - void setMatrix4fv(UniformHandle, int arrayCount, const GrGLfloat matrices[]) const; + void setMatrix3f(UniformHandle, const float matrix[]) const override; + void setMatrix4f(UniformHandle, const float matrix[]) const override; + void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const override; + void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const override; // convenience method for uploading a SkMatrix to a 3x3 matrix uniform - void setSkMatrix(UniformHandle, const SkMatrix&) const; + void setSkMatrix(UniformHandle, const SkMatrix&) const override; // for nvpr only - typedef GrGLProgramDataManager::ShaderResourceHandle SeparableVaryingHandle; void setPathFragmentInputTransform(SeparableVaryingHandle u, int components, - const SkMatrix& matrix) const; + const SkMatrix& matrix) const override; private: enum { @@ -127,7 +106,7 @@ private: GrGLGpu* fGpu; GrGLuint fProgramID; - typedef SkNoncopyable INHERITED; + typedef GrGLSLProgramDataManager INHERITED; }; #endif diff --git a/src/gpu/gl/GrGLUtil.cpp b/src/gpu/gl/GrGLUtil.cpp index 5579701796..7f0713ed6a 100644 --- a/src/gpu/gl/GrGLUtil.cpp +++ b/src/gpu/gl/GrGLUtil.cpp @@ -306,7 +306,8 @@ GrGLRenderer GrGLGetRenderer(const GrGLInterface* gl) { return GrGLGetRendererFromString((const char*) v); } -template<> void GrGLGetMatrix<3>(GrGLfloat* dest, const SkMatrix& src) { +template<> void GrGLGetMatrix<3>(float* dest, const SkMatrix& src) { + GR_STATIC_ASSERT(sizeof(float) == sizeof (GrGLfloat)); // Col 0 dest[0] = SkScalarToFloat(src[SkMatrix::kMScaleX]); dest[1] = SkScalarToFloat(src[SkMatrix::kMSkewY]); @@ -323,7 +324,8 @@ template<> void GrGLGetMatrix<3>(GrGLfloat* dest, const SkMatrix& src) { dest[8] = SkScalarToFloat(src[SkMatrix::kMPersp2]); } -template<> void GrGLGetMatrix<4>(GrGLfloat* dest, const SkMatrix& src) { +template<> void GrGLGetMatrix<4>(float* dest, const SkMatrix& src) { + GR_STATIC_ASSERT(sizeof(float) == sizeof (GrGLfloat)); // Col 0 dest[0] = SkScalarToFloat(src[SkMatrix::kMScaleX]); dest[1] = SkScalarToFloat(src[SkMatrix::kMSkewY]); diff --git a/src/gpu/gl/GrGLUtil.h b/src/gpu/gl/GrGLUtil.h index 35dfe6ae9f..dec784c977 100644 --- a/src/gpu/gl/GrGLUtil.h +++ b/src/gpu/gl/GrGLUtil.h @@ -141,7 +141,7 @@ void GrGLClearErr(const GrGLInterface* gl); /** * Helper for converting SkMatrix to a column-major GL float array */ -template void GrGLGetMatrix(GrGLfloat* dest, const SkMatrix& src); +template void GrGLGetMatrix(float* dest, const SkMatrix& src); //////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/gl/GrGLXferProcessor.cpp b/src/gpu/gl/GrGLXferProcessor.cpp index e62497193f..528d354bfc 100644 --- a/src/gpu/gl/GrGLXferProcessor.cpp +++ b/src/gpu/gl/GrGLXferProcessor.cpp @@ -10,6 +10,7 @@ #include "GrXferProcessor.h" #include "gl/builders/GrGLFragmentShaderBuilder.h" #include "gl/builders/GrGLProgramBuilder.h" +#include "glsl/GrGLSLProgramDataManager.h" void GrGLXferProcessor::emitCode(const EmitArgs& args) { if (!args.fXP.willReadDstColor()) { @@ -77,11 +78,11 @@ void GrGLXferProcessor::emitCode(const EmitArgs& args) { } } -void GrGLXferProcessor::setData(const GrGLProgramDataManager& pdm, const GrXferProcessor& xp) { +void GrGLXferProcessor::setData(const GrGLSLProgramDataManager& pdm, const GrXferProcessor& xp) { if (xp.getDstTexture()) { if (fDstTopLeftUni.isValid()) { - pdm.set2f(fDstTopLeftUni, static_cast(xp.dstTextureOffset().fX), - static_cast(xp.dstTextureOffset().fY)); + pdm.set2f(fDstTopLeftUni, static_cast(xp.dstTextureOffset().fX), + static_cast(xp.dstTextureOffset().fY)); pdm.set2f(fDstScaleUni, 1.f / xp.getDstTexture()->width(), 1.f / xp.getDstTexture()->height()); } else { diff --git a/src/gpu/gl/GrGLXferProcessor.h b/src/gpu/gl/GrGLXferProcessor.h index c9c6cb5c41..bf16cf4d36 100644 --- a/src/gpu/gl/GrGLXferProcessor.h +++ b/src/gpu/gl/GrGLXferProcessor.h @@ -8,7 +8,8 @@ #ifndef GrGLXferProcessor_DEFINED #define GrGLXferProcessor_DEFINED -#include "GrGLFragmentProcessor.h" +#include "GrGLProcessor.h" +#include "glsl/GrGLSLProgramDataManager.h" class GrGLXPBuilder; class GrXferProcessor; @@ -56,7 +57,7 @@ public: to have an identical processor key as the one that created this GrGLXferProcessor. This function calls onSetData on the subclass of GrGLXferProcessor */ - void setData(const GrGLProgramDataManager& pdm, const GrXferProcessor& xp); + void setData(const GrGLSLProgramDataManager& pdm, const GrXferProcessor& xp); private: /** @@ -78,10 +79,10 @@ private: SkFAIL("emitBlendCodeForDstRead not implemented."); } - virtual void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) = 0; + virtual void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) = 0; - GrGLProgramDataManager::UniformHandle fDstTopLeftUni; - GrGLProgramDataManager::UniformHandle fDstScaleUni; + GrGLSLProgramDataManager::UniformHandle fDstTopLeftUni; + GrGLSLProgramDataManager::UniformHandle fDstScaleUni; typedef GrGLProcessor INHERITED; }; diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp index a0ddcf2410..b74a8673cd 100644 --- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp +++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp @@ -19,6 +19,7 @@ #include "gl/GrGLSLPrettyPrint.h" #include "gl/GrGLXferProcessor.h" #include "glsl/GrGLSLCaps.h" +#include "glsl/GrGLSLProgramDataManager.h" #define GL_CALL(X) GR_GL_CALL(this->gpu()->glInterface(), X) #define GL_CALL_RET(R, X) GR_GL_CALL_RET(this->gpu()->glInterface(), R, X) @@ -118,7 +119,7 @@ void GrGLProgramBuilder::nameVariable(SkString* out, char prefix, const char* na } } -GrGLProgramDataManager::UniformHandle GrGLProgramBuilder::addUniformArray( +GrGLSLProgramDataManager::UniformHandle GrGLProgramBuilder::addUniformArray( uint32_t visibility, GrSLType type, GrSLPrecision precision, @@ -152,7 +153,7 @@ GrGLProgramDataManager::UniformHandle GrGLProgramBuilder::addUniformArray( if (outName) { *outName = uni.fVariable.c_str(); } - return GrGLProgramDataManager::UniformHandle(fUniforms.count() - 1); + return GrGLSLProgramDataManager::UniformHandle(fUniforms.count() - 1); } void GrGLProgramBuilder::appendUniformDecls(ShaderVisibility visibility, diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.h b/src/gpu/gl/builders/GrGLProgramBuilder.h index 11c367df8c..7690b39a8b 100644 --- a/src/gpu/gl/builders/GrGLProgramBuilder.h +++ b/src/gpu/gl/builders/GrGLProgramBuilder.h @@ -11,7 +11,7 @@ #include "GrGLFragmentShaderBuilder.h" #include "GrGLGeometryShaderBuilder.h" #include "GrGLVertexShaderBuilder.h" -#include "../GrGLProgramDataManager.h" +#include "glsl/GrGLSLProgramDataManager.h" #include "../GrGLPrimitiveProcessor.h" #include "../GrGLXferProcessor.h" #include "../../GrPipeline.h" @@ -42,7 +42,7 @@ public: virtual ~GrGLUniformBuilder() {} - typedef GrGLProgramDataManager::UniformHandle UniformHandle; + typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; typedef GrGLProgramDataManager::SeparableVaryingHandle SeparableVaryingHandle; /** Add a uniform variable to the current program, that has visibility in one or more shaders. diff --git a/src/gpu/glsl/GrGLSLProgramDataManager.h b/src/gpu/glsl/GrGLSLProgramDataManager.h new file mode 100644 index 0000000000..29513f08b0 --- /dev/null +++ b/src/gpu/glsl/GrGLSLProgramDataManager.h @@ -0,0 +1,78 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrGLSLProgramDataManager_DEFINED +#define GrGLSLProgramDataManager_DEFINED + +#include "SkTypes.h" + +/** Manages the resources used by a shader program. + * The resources are objects the program uses to communicate with the + * application code. + */ +class GrGLSLProgramDataManager : SkNoncopyable { +public: + // Opaque handle to a resource + class ShaderResourceHandle { + public: + ShaderResourceHandle(int value) + : fValue(value) { + SkASSERT(this->isValid()); + } + + ShaderResourceHandle() + : fValue(kInvalid_ShaderResourceHandle) { + } + + bool operator==(const ShaderResourceHandle& other) const { return other.fValue == fValue; } + bool isValid() const { return kInvalid_ShaderResourceHandle != fValue; } + int toIndex() const { SkASSERT(this->isValid()); return fValue; } + + private: + static const int kInvalid_ShaderResourceHandle = -1; + int fValue; + }; + + typedef ShaderResourceHandle UniformHandle; + + virtual ~GrGLSLProgramDataManager() {} + + /** Functions for uploading uniform values. The varities ending in v can be used to upload to an + * array of uniforms. arrayCount must be <= the array count of the uniform. + */ + virtual void set1f(UniformHandle, float v0) const = 0; + virtual void set1fv(UniformHandle, int arrayCount, const float v[]) const = 0; + virtual void set2f(UniformHandle, float, float) const = 0; + virtual void set2fv(UniformHandle, int arrayCount, const float v[]) const = 0; + virtual void set3f(UniformHandle, float, float, float) const = 0; + virtual void set3fv(UniformHandle, int arrayCount, const float v[]) const = 0; + virtual void set4f(UniformHandle, float, float, float, float) const = 0; + virtual void set4fv(UniformHandle, int arrayCount, const float v[]) const = 0; + // matrices are column-major, the first three upload a single matrix, the latter three upload + // arrayCount matrices into a uniform array. + virtual void setMatrix3f(UniformHandle, const float matrix[]) const = 0; + virtual void setMatrix4f(UniformHandle, const float matrix[]) const = 0; + virtual void setMatrix3fv(UniformHandle, int arrayCount, const float matrices[]) const = 0; + virtual void setMatrix4fv(UniformHandle, int arrayCount, const float matrices[]) const = 0; + + // convenience method for uploading a SkMatrix to a 3x3 matrix uniform + virtual void setSkMatrix(UniformHandle, const SkMatrix&) const = 0; + + // for nvpr only + typedef ShaderResourceHandle SeparableVaryingHandle; + virtual void setPathFragmentInputTransform(SeparableVaryingHandle u, int components, + const SkMatrix& matrix) const = 0; + +protected: + GrGLSLProgramDataManager() {} + +private: + + typedef SkNoncopyable INHERITED; +}; + +#endif