diff options
author | joshualitt <joshualitt@chromium.org> | 2015-09-11 11:45:01 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-11 11:45:01 -0700 |
commit | d8dd47b5fa52430a1ab5c07335c0c13fcd43a82d (patch) | |
tree | f48c0561aadb86359aca63165f716ae86c6106a3 /src | |
parent | 212aab07d9899e6067feae45cd61ee441cd34d96 (diff) |
remove path specific program building classes
BUG=skia:
Review URL: https://codereview.chromium.org/1336763003
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/gl/GrGLGeometryProcessor.h | 8 | ||||
-rw-r--r-- | src/gpu/gl/GrGLPathProcessor.cpp | 2 | ||||
-rw-r--r-- | src/gpu/gl/GrGLPathProcessor.h | 10 | ||||
-rw-r--r-- | src/gpu/gl/GrGLPathProgram.cpp | 52 | ||||
-rw-r--r-- | src/gpu/gl/GrGLPathProgram.h | 49 | ||||
-rw-r--r-- | src/gpu/gl/GrGLPathProgramDataManager.cpp | 46 | ||||
-rw-r--r-- | src/gpu/gl/GrGLPathProgramDataManager.h | 55 | ||||
-rw-r--r-- | src/gpu/gl/GrGLPrimitiveProcessor.h | 7 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgram.cpp | 40 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgram.h | 24 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgramDataManager.cpp | 39 | ||||
-rw-r--r-- | src/gpu/gl/GrGLProgramDataManager.h | 27 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLPathProgramBuilder.cpp | 63 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLPathProgramBuilder.h | 32 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLProgramBuilder.cpp | 71 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLProgramBuilder.h | 8 |
16 files changed, 153 insertions, 380 deletions
diff --git a/src/gpu/gl/GrGLGeometryProcessor.h b/src/gpu/gl/GrGLGeometryProcessor.h index bfd7e1da7e..1c7ab5371b 100644 --- a/src/gpu/gl/GrGLGeometryProcessor.h +++ b/src/gpu/gl/GrGLGeometryProcessor.h @@ -23,10 +23,10 @@ public: void emitCode(EmitArgs&) override; // By default we use the identity matrix - virtual void setTransformData(const GrPrimitiveProcessor&, - const GrGLProgramDataManager& pdman, - int index, - const SkTArray<const GrCoordTransform*, true>& transforms) { + void setTransformData(const GrPrimitiveProcessor&, + const GrGLProgramDataManager& pdman, + int index, + const SkTArray<const GrCoordTransform*, true>& transforms) override { this->setTransformDataMatrix(SkMatrix::I(), pdman, index, transforms); } diff --git a/src/gpu/gl/GrGLPathProcessor.cpp b/src/gpu/gl/GrGLPathProcessor.cpp index 00283ac50e..d313d0c4e5 100644 --- a/src/gpu/gl/GrGLPathProcessor.cpp +++ b/src/gpu/gl/GrGLPathProcessor.cpp @@ -84,7 +84,7 @@ void GrGLPathProcessor::emitTransforms(GrGLGPBuilder* pb, const TransformsIn& ti void GrGLPathProcessor::setTransformData( const GrPrimitiveProcessor& primProc, - const GrGLPathProgramDataManager& pdman, + const GrGLProgramDataManager& pdman, int index, const SkTArray<const GrCoordTransform*, true>& coordTransforms) { const GrPathProcessor& pathProc = primProc.cast<GrPathProcessor>(); diff --git a/src/gpu/gl/GrGLPathProcessor.h b/src/gpu/gl/GrGLPathProcessor.h index 2cbf13034b..ef968d170c 100644 --- a/src/gpu/gl/GrGLPathProcessor.h +++ b/src/gpu/gl/GrGLPathProcessor.h @@ -13,7 +13,6 @@ class GrPathProcessor; class GrGLPathRendering; class GrGLGpu; -class GrGLPathProgramDataManager; class GrGLPathProcessor : public GrGLPrimitiveProcessor { public: @@ -27,17 +26,12 @@ public: void emitTransforms(GrGLGPBuilder*, const TransformsIn&, TransformsOut*); - void bindSeparableVaryings(GrGLGpu* gpu, GrGLuint programID); - void resolveSeparableVaryings(GrGLGpu* gpu, GrGLuint programId); - void setData(const GrGLProgramDataManager&, const GrPrimitiveProcessor&) override; void setTransformData(const GrPrimitiveProcessor&, - const GrGLPathProgramDataManager&, + const GrGLProgramDataManager&, int index, - const SkTArray<const GrCoordTransform*, true>& transforms); - - virtual void didSetData(GrGLPathRendering*) {} + const SkTArray<const GrCoordTransform*, true>& transforms) override; private: UniformHandle fColorUniform; diff --git a/src/gpu/gl/GrGLPathProgram.cpp b/src/gpu/gl/GrGLPathProgram.cpp deleted file mode 100644 index 5bcadfe4d0..0000000000 --- a/src/gpu/gl/GrGLPathProgram.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2015 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "GrGLPathProgram.h" -#include "GrGLPathProcessor.h" -#include "GrGLGpu.h" -#include "GrPathProcessor.h" - -GrGLPathProgram::GrGLPathProgram(GrGLGpu* gpu, - const GrProgramDesc& desc, - const BuiltinUniformHandles& builtinUniforms, - GrGLuint programID, - const UniformInfoArray& uniforms, - const SeparableVaryingInfoArray& separableVaryings, - GrGLInstalledGeoProc* primProc, - GrGLInstalledXferProc* xferProcessor, - GrGLInstalledFragProcs* fragmentProcessors, - SkTArray<UniformHandle>* passSamplerUniforms) - : INHERITED(gpu, desc, builtinUniforms, programID, uniforms, primProc, - xferProcessor, fragmentProcessors, passSamplerUniforms) - , fPathProgramDataManager(gpu, fProgramID, separableVaryings) { -} -void GrGLPathProgram::didSetData() { - GrGLPathProcessor* pathProc = - static_cast<GrGLPathProcessor*>(fGeometryProcessor.get()->fGLProc.get()); - pathProc->didSetData(fGpu->glPathRendering()); -} - -void GrGLPathProgram::setTransformData(const GrPrimitiveProcessor& primProc, - const GrFragmentProcessor& processor, - int index, - GrGLInstalledFragProc* ip) { - GrGLPathProcessor* pathProc = - static_cast<GrGLPathProcessor*>(fGeometryProcessor.get()->fGLProc.get()); - pathProc->setTransformData(primProc, fPathProgramDataManager, index, - processor.coordTransforms()); -} - -void GrGLPathProgram::onSetRenderTargetState(const GrPrimitiveProcessor& primProc, - const GrPipeline& pipeline) { - SkASSERT(!primProc.willUseGeoShader() && primProc.numAttribs() == 0); - const GrRenderTarget* rt = pipeline.getRenderTarget(); - SkISize size; - size.set(rt->width(), rt->height()); - const GrPathProcessor& pathProc = primProc.cast<GrPathProcessor>(); - fGpu->glPathRendering()->setProjectionMatrix(pathProc.viewMatrix(), - size, rt->origin()); -} diff --git a/src/gpu/gl/GrGLPathProgram.h b/src/gpu/gl/GrGLPathProgram.h deleted file mode 100644 index 74f43e56df..0000000000 --- a/src/gpu/gl/GrGLPathProgram.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * 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 GrGLPathProgram_DEFINED -#define GrGLPathProgram_DEFINED - -#include "gl/GrGLProgram.h" -#include "gl/GrGLPathProgramDataManager.h" - -/* - * The default GrGL programs consist of at the very least a vertex and fragment shader. - * 1.3+ Nvpr ignores the vertex shader, but both require - * specialized methods for setting transform data. NVPR also requires setting the - * projection matrix through a special function call. - */ -class GrGLPathProgram : public GrGLProgram { -protected: - typedef GrGLPathProgramDataManager::SeparableVaryingInfoArray SeparableVaryingInfoArray; - GrGLPathProgram(GrGLGpu*, - const GrProgramDesc&, - const BuiltinUniformHandles&, - GrGLuint programID, - const UniformInfoArray&, - const SeparableVaryingInfoArray&, - GrGLInstalledGeoProc*, - GrGLInstalledXferProc* xferProcessor, - GrGLInstalledFragProcs* fragmentProcessors, - SkTArray<UniformHandle>* passSamplerUniforms); - -private: - void didSetData() override; - virtual void setTransformData(const GrPrimitiveProcessor&, - const GrFragmentProcessor&, - int index, - GrGLInstalledFragProc*) override; - void onSetRenderTargetState(const GrPrimitiveProcessor&, const GrPipeline&) override; - - friend class GrGLPathProgramBuilder; - - GrGLPathProgramDataManager fPathProgramDataManager; - - typedef GrGLProgram INHERITED; -}; - -#endif diff --git a/src/gpu/gl/GrGLPathProgramDataManager.cpp b/src/gpu/gl/GrGLPathProgramDataManager.cpp deleted file mode 100644 index 567c49c88c..0000000000 --- a/src/gpu/gl/GrGLPathProgramDataManager.cpp +++ /dev/null @@ -1,46 +0,0 @@ - /* - * Copyright 2015 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "gl/GrGLPathProgramDataManager.h" -#include "gl/GrGLPathRendering.h" -#include "gl/GrGLGpu.h" -#include "SkMatrix.h" - -GrGLPathProgramDataManager::GrGLPathProgramDataManager( - GrGLGpu* gpu, GrGLuint programID, const SeparableVaryingInfoArray& separableVaryings) - : fGpu(gpu) - , fProgramID(programID) { - int count = separableVaryings.count(); - fSeparableVaryings.push_back_n(count); - for (int i = 0; i < count; i++) { - SeparableVarying& separableVarying = fSeparableVaryings[i]; - const SeparableVaryingInfo& builderSeparableVarying = separableVaryings[i]; - SkASSERT(GrGLShaderVar::kNonArray == builderSeparableVarying.fVariable.getArrayCount() || - builderSeparableVarying.fVariable.getArrayCount() > 0); - SkDEBUGCODE( - separableVarying.fArrayCount = builderSeparableVarying.fVariable.getArrayCount(); - separableVarying.fType = builderSeparableVarying.fVariable.getType(); - ); - separableVarying.fLocation = builderSeparableVarying.fLocation; - } -} - -void GrGLPathProgramDataManager::setPathFragmentInputTransform(SeparableVaryingHandle u, - int components, - const SkMatrix& matrix) const { - const SeparableVarying& fragmentInput = fSeparableVaryings[u.toIndex()]; - - SkASSERT((components == 2 && fragmentInput.fType == kVec2f_GrSLType) || - (components == 3 && fragmentInput.fType == kVec3f_GrSLType)); - - fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID, - fragmentInput.fLocation, - GR_GL_OBJECT_LINEAR, - components, - matrix); -} - diff --git a/src/gpu/gl/GrGLPathProgramDataManager.h b/src/gpu/gl/GrGLPathProgramDataManager.h deleted file mode 100644 index 376dff4b2d..0000000000 --- a/src/gpu/gl/GrGLPathProgramDataManager.h +++ /dev/null @@ -1,55 +0,0 @@ -/* - * 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 GrGLPathProgramDataManager_DEFINED -#define GrGLPathProgramDataManager_DEFINED - -#include "gl/GrGLProgramDataManager.h" - -class GrGLPathProgram; -class GrGLPathProgramBuilder; - -/** Manages the resources used by a shader program for NVPR rendering. - */ -class GrGLPathProgramDataManager : SkNoncopyable { -public: - typedef GrGLProgramDataManager::ShaderResourceHandle SeparableVaryingHandle; - - struct SeparableVaryingInfo { - GrGLShaderVar fVariable; - GrGLint fLocation; - }; - - // This uses an allocator rather than array so that the GrGLShaderVars don't move in memory - // after they are inserted. Users of GrGLShaderBuilder get refs to the vars and ptrs to their - // name strings. Otherwise, we'd have to hand out copies. - typedef GrTAllocator<SeparableVaryingInfo> SeparableVaryingInfoArray; - - GrGLPathProgramDataManager(GrGLGpu*, GrGLuint programID, const SeparableVaryingInfoArray&); - - /** Functions for uploading the varying values. - */ - void setPathFragmentInputTransform(SeparableVaryingHandle u, - int components, - const SkMatrix& matrix) const; -private: - enum { - kUnusedSeparableVarying = -1, - }; - struct SeparableVarying { - GrGLint fLocation; - SkDEBUGCODE( - GrSLType fType; - int fArrayCount; - ); - }; - SkTArray<SeparableVarying, true> fSeparableVaryings; - GrGLGpu* fGpu; - GrGLuint fProgramID; - typedef SkNoncopyable INHERITED; -}; -#endif diff --git a/src/gpu/gl/GrGLPrimitiveProcessor.h b/src/gpu/gl/GrGLPrimitiveProcessor.h index ce413f3338..bf1c388698 100644 --- a/src/gpu/gl/GrGLPrimitiveProcessor.h +++ b/src/gpu/gl/GrGLPrimitiveProcessor.h @@ -10,7 +10,6 @@ #include "GrPrimitiveProcessor.h" #include "GrGLProcessor.h" -#include "GrGLPathProgramDataManager.h" class GrBatchTracker; class GrPrimitiveProcessor; @@ -21,7 +20,6 @@ public: virtual ~GrGLPrimitiveProcessor() {} typedef GrGLProgramDataManager::UniformHandle UniformHandle; - typedef GrGLPathProgramDataManager::SeparableVaryingHandle SeparableVaryingHandle; typedef GrGLProcessor::TextureSamplerArray TextureSamplerArray; typedef SkSTArray<2, const GrCoordTransform*, true> ProcCoords; @@ -69,6 +67,11 @@ public: static SkMatrix GetTransformMatrix(const SkMatrix& localMatrix, const GrCoordTransform&); + virtual void setTransformData(const GrPrimitiveProcessor&, + const GrGLProgramDataManager& pdman, + int index, + const SkTArray<const GrCoordTransform*, true>& transforms) = 0; + protected: void setupUniformColor(GrGLGPBuilder* pb, const char* outputName, UniformHandle* colorUniform); diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp index c89c5089b2..5f6d4edd7d 100644 --- a/src/gpu/gl/GrGLProgram.cpp +++ b/src/gpu/gl/GrGLProgram.cpp @@ -31,6 +31,7 @@ GrGLProgram::GrGLProgram(GrGLGpu* gpu, const BuiltinUniformHandles& builtinUniforms, GrGLuint programID, const UniformInfoArray& uniforms, + const SeparableVaryingInfoArray& separableVaryings, GrGLInstalledGeoProc* geometryProcessor, GrGLInstalledXferProc* xferProcessor, GrGLInstalledFragProcs* fragmentProcessors, @@ -45,7 +46,7 @@ GrGLProgram::GrGLProgram(GrGLGpu* gpu, , fFragmentProcessors(SkRef(fragmentProcessors)) , fDesc(desc) , fGpu(gpu) - , fProgramDataManager(gpu, uniforms) { + , fProgramDataManager(gpu, programID, uniforms, separableVaryings) { fSamplerUniforms.swap(passSamplerUniforms); // Assign texture units to sampler uniforms one time up front. GL_CALL(UseProgram(fProgramID)); @@ -95,9 +96,6 @@ void GrGLProgram::setData(const GrPrimitiveProcessor& primProc, const GrXferProcessor& xp = *pipeline.getXferProcessor(); fXferProcessor->fGLProc->setData(fProgramDataManager, xp); append_texture_bindings(fXferProcessor.get(), xp, textureBindings); - - // Some of GrGLProgram subclasses need to update state here - this->didSetData(); } void GrGLProgram::setFragmentData(const GrPrimitiveProcessor& primProc, @@ -118,8 +116,7 @@ void GrGLProgram::setTransformData(const GrPrimitiveProcessor& primProc, const GrFragmentProcessor& processor, int index, GrGLInstalledFragProc* ip) { - GrGLGeometryProcessor* gp = - static_cast<GrGLGeometryProcessor*>(fGeometryProcessor.get()->fGLProc.get()); + GrGLPrimitiveProcessor* gp = fGeometryProcessor.get()->fGLProc.get(); gp->setTransformData(primProc, fProgramDataManager, index, processor.coordTransforms()); } @@ -133,23 +130,24 @@ void GrGLProgram::setRenderTargetState(const GrPrimitiveProcessor& primProc, SkIntToScalar(pipeline.getRenderTarget()->height())); } - // call subclasses to set the actual view matrix - this->onSetRenderTargetState(primProc, pipeline); -} - -void GrGLProgram::onSetRenderTargetState(const GrPrimitiveProcessor&, - const GrPipeline& pipeline) { + // set RT adjustment const GrRenderTarget* rt = pipeline.getRenderTarget(); SkISize size; size.set(rt->width(), rt->height()); - if (fRenderTargetState.fRenderTargetOrigin != rt->origin() || - fRenderTargetState.fRenderTargetSize != size) { - fRenderTargetState.fRenderTargetSize = size; - fRenderTargetState.fRenderTargetOrigin = rt->origin(); - - GrGLfloat rtAdjustmentVec[4]; - fRenderTargetState.getRTAdjustmentVec(rtAdjustmentVec); - fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec); + if (!primProc.isPathRendering()) { + if (fRenderTargetState.fRenderTargetOrigin != rt->origin() || + fRenderTargetState.fRenderTargetSize != size) { + fRenderTargetState.fRenderTargetSize = size; + fRenderTargetState.fRenderTargetOrigin = rt->origin(); + + GrGLfloat rtAdjustmentVec[4]; + fRenderTargetState.getRTAdjustmentVec(rtAdjustmentVec); + fProgramDataManager.set4fv(fBuiltinUniformHandles.fRTAdjustmentUni, 1, rtAdjustmentVec); + } + } else { + SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport()); + const GrPathProcessor& pathProc = primProc.cast<GrPathProcessor>(); + fGpu->glPathRendering()->setProjectionMatrix(pathProc.viewMatrix(), + size, rt->origin()); } } - diff --git a/src/gpu/gl/GrGLProgram.h b/src/gpu/gl/GrGLProgram.h index 4dfeba345c..7b10c147b4 100644 --- a/src/gpu/gl/GrGLProgram.h +++ b/src/gpu/gl/GrGLProgram.h @@ -9,7 +9,6 @@ #ifndef GrGLProgram_DEFINED #define GrGLProgram_DEFINED -#include "builders/GrGLProgramBuilder.h" #include "GrGLContext.h" #include "GrGLProgramDesc.h" #include "GrGLTexture.h" @@ -18,6 +17,8 @@ #include "SkString.h" #include "SkXfermode.h" +#include "builders/GrGLProgramBuilder.h" + class GrGLProcessor; class GrGLInstalledProcessors; class GrGLProgramBuilder; @@ -34,11 +35,9 @@ class GrPipeline; */ class GrGLProgram : public SkRefCnt { public: - - typedef GrGLProgramBuilder::BuiltinUniformHandles BuiltinUniformHandles; - virtual ~GrGLProgram(); + ~GrGLProgram(); /** * Call to abandon GL objects owned by this program. @@ -100,12 +99,14 @@ public: protected: typedef GrGLProgramDataManager::UniformHandle UniformHandle; typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray; + typedef GrGLProgramDataManager::SeparableVaryingInfoArray SeparableVaryingInfoArray; GrGLProgram(GrGLGpu*, const GrProgramDesc&, const BuiltinUniformHandles&, GrGLuint programID, const UniformInfoArray&, + const SeparableVaryingInfoArray&, GrGLInstalledGeoProc* geometryProcessor, GrGLInstalledXferProc* xferProcessor, GrGLInstalledFragProcs* fragmentProcessors, @@ -114,20 +115,13 @@ protected: // A templated helper to loop over effects, set the transforms(via subclass) and bind textures void setFragmentData(const GrPrimitiveProcessor&, const GrPipeline&, SkTArray<const GrTextureAccess*>* textureBindings); - virtual void setTransformData(const GrPrimitiveProcessor&, - const GrFragmentProcessor&, - int index, - GrGLInstalledFragProc*); - - /* - * Legacy NVPR needs a hook here to flush path tex gen settings. - * TODO when legacy nvpr is removed, remove this call. - */ - virtual void didSetData() {} + void setTransformData(const GrPrimitiveProcessor&, + const GrFragmentProcessor&, + int index, + GrGLInstalledFragProc*); // Helper for setData() that sets the view matrix and loads the render target height uniform void setRenderTargetState(const GrPrimitiveProcessor&, const GrPipeline&); - virtual void onSetRenderTargetState(const GrPrimitiveProcessor&, const GrPipeline&); // these reflect the current values of uniforms (GL uniform values travel with program) RenderTargetState fRenderTargetState; diff --git a/src/gpu/gl/GrGLProgramDataManager.cpp b/src/gpu/gl/GrGLProgramDataManager.cpp index ed497bd192..4d5d711de4 100644 --- a/src/gpu/gl/GrGLProgramDataManager.cpp +++ b/src/gpu/gl/GrGLProgramDataManager.cpp @@ -13,8 +13,11 @@ SkASSERT(arrayCount <= uni.fArrayCount || \ (1 == arrayCount && GrGLShaderVar::kNonArray == uni.fArrayCount)) -GrGLProgramDataManager::GrGLProgramDataManager(GrGLGpu* gpu, const UniformInfoArray& uniforms) - : fGpu(gpu) { +GrGLProgramDataManager::GrGLProgramDataManager(GrGLGpu* gpu, GrGLuint programID, + const UniformInfoArray& uniforms, + const SeparableVaryingInfoArray& separableVaryings) + : fGpu(gpu) + , fProgramID(programID) { int count = uniforms.count(); fUniforms.push_back_n(count); for (int i = 0; i < count; i++) { @@ -39,6 +42,22 @@ GrGLProgramDataManager::GrGLProgramDataManager(GrGLGpu* gpu, const UniformInfoAr uniform.fFSLocation = kUnusedUniform; } } + + // NVPR programs have separable varyings + count = separableVaryings.count(); + fSeparableVaryings.push_back_n(count); + for (int i = 0; i < count; i++) { + SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport()); + SeparableVarying& separableVarying = fSeparableVaryings[i]; + const SeparableVaryingInfo& builderSeparableVarying = separableVaryings[i]; + SkASSERT(GrGLShaderVar::kNonArray == builderSeparableVarying.fVariable.getArrayCount() || + builderSeparableVarying.fVariable.getArrayCount() > 0); + SkDEBUGCODE( + separableVarying.fArrayCount = builderSeparableVarying.fVariable.getArrayCount(); + separableVarying.fType = builderSeparableVarying.fVariable.getType(); + ); + separableVarying.fLocation = builderSeparableVarying.fLocation; + } } void GrGLProgramDataManager::setSampler(UniformHandle u, GrGLint texUnit) const { @@ -257,6 +276,22 @@ void GrGLProgramDataManager::setSkMatrix(UniformHandle u, const SkMatrix& matrix this->setMatrix3f(u, mt); } +void GrGLProgramDataManager::setPathFragmentInputTransform(SeparableVaryingHandle u, + int components, + const SkMatrix& matrix) const { + SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport()); + const SeparableVarying& fragmentInput = fSeparableVaryings[u.toIndex()]; + + SkASSERT((components == 2 && fragmentInput.fType == kVec2f_GrSLType) || + (components == 3 && fragmentInput.fType == kVec3f_GrSLType)); + + fGpu->glPathRendering()->setProgramPathFragmentInputTransform(fProgramID, + fragmentInput.fLocation, + GR_GL_OBJECT_LINEAR, + components, + matrix); +} + #ifdef SK_DEBUG void GrGLProgramDataManager::printUnused(const Uniform& uni) const { if (kUnusedUniform == uni.fFSLocation && kUnusedUniform == uni.fVSLocation) { diff --git a/src/gpu/gl/GrGLProgramDataManager.h b/src/gpu/gl/GrGLProgramDataManager.h index 7931768ddb..916f2a320b 100644 --- a/src/gpu/gl/GrGLProgramDataManager.h +++ b/src/gpu/gl/GrGLProgramDataManager.h @@ -53,12 +53,19 @@ public: GrGLint fLocation; }; + struct SeparableVaryingInfo { + GrGLShaderVar fVariable; + GrGLint fLocation; + }; + // This uses an allocator rather than array so that the GrGLShaderVars don't move in memory // after they are inserted. Users of GrGLShaderBuilder get refs to the vars and ptrs to their // name strings. Otherwise, we'd have to hand out copies. typedef GrTAllocator<UniformInfo> UniformInfoArray; + typedef GrTAllocator<SeparableVaryingInfo> SeparableVaryingInfoArray; - GrGLProgramDataManager(GrGLGpu*, const UniformInfoArray&); + GrGLProgramDataManager(GrGLGpu*, GrGLuint programID, const UniformInfoArray&, + const SeparableVaryingInfoArray&); /** 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. @@ -82,6 +89,11 @@ public: // convenience method for uploading a SkMatrix to a 3x3 matrix uniform void setSkMatrix(UniformHandle, const SkMatrix&) const; + // for nvpr only + typedef GrGLProgramDataManager::ShaderResourceHandle SeparableVaryingHandle; + void setPathFragmentInputTransform(SeparableVaryingHandle u, int components, + const SkMatrix& matrix) const; + private: enum { kUnusedUniform = -1, @@ -96,10 +108,23 @@ private: ); }; + enum { + kUnusedSeparableVarying = -1, + }; + struct SeparableVarying { + GrGLint fLocation; + SkDEBUGCODE( + GrSLType fType; + int fArrayCount; + ); + }; + SkDEBUGCODE(void printUnused(const Uniform&) const;) SkTArray<Uniform, true> fUniforms; + SkTArray<SeparableVarying, true> fSeparableVaryings; GrGLGpu* fGpu; + GrGLuint fProgramID; typedef SkNoncopyable INHERITED; }; diff --git a/src/gpu/gl/builders/GrGLPathProgramBuilder.cpp b/src/gpu/gl/builders/GrGLPathProgramBuilder.cpp deleted file mode 100644 index dd6a2763e9..0000000000 --- a/src/gpu/gl/builders/GrGLPathProgramBuilder.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2015 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "GrGLPathProgramBuilder.h" -#include "gl/GrGLGpu.h" -#include "gl/GrGLPathProgram.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) - -GrGLPathProgramBuilder::GrGLPathProgramBuilder(GrGLGpu* gpu, const DrawArgs& args) - : INHERITED(gpu, args) - , fSeparableVaryingInfos(kVarsPerBlock) { -} - -GrGLProgram* GrGLPathProgramBuilder::createProgram(GrGLuint programID) { - return new GrGLPathProgram(fGpu, this->desc(), fUniformHandles, programID, fUniforms, - fSeparableVaryingInfos, fGeometryProcessor, fXferProcessor, - fFragmentProcessors.get(), &fSamplerUniforms); -} - -GrGLProgramBuilder::SeparableVaryingHandle GrGLPathProgramBuilder::addSeparableVarying( - const char* name, GrGLVertToFrag* v, GrSLPrecision fsPrecision) { - this->addVarying(name, v, fsPrecision); - SeparableVaryingInfo& varyingInfo = fSeparableVaryingInfos.push_back(); - varyingInfo.fVariable = this->getFragmentShaderBuilder()->fInputs.back(); - varyingInfo.fLocation = fSeparableVaryingInfos.count() - 1; - return SeparableVaryingHandle(varyingInfo.fLocation); -} - -void GrGLPathProgramBuilder::bindProgramResourceLocations(GrGLuint programID) { - this->INHERITED::bindProgramResourceLocations(programID); - if (!fGpu->glPathRendering()->shouldBindFragmentInputs()) { - return; - } - int count = fSeparableVaryingInfos.count(); - for (int i = 0; i < count; ++i) { - GL_CALL(BindFragmentInputLocation(programID, - i, - fSeparableVaryingInfos[i].fVariable.c_str())); - fSeparableVaryingInfos[i].fLocation = i; - } -} - -void GrGLPathProgramBuilder::resolveProgramResourceLocations(GrGLuint programID) { - this->INHERITED::resolveProgramResourceLocations(programID); - if (fGpu->glPathRendering()->shouldBindFragmentInputs()) { - return; - } - int count = fSeparableVaryingInfos.count(); - for (int i = 0; i < count; ++i) { - GrGLint location; - GL_CALL_RET(location, - GetProgramResourceLocation(programID, - GR_GL_FRAGMENT_INPUT, - fSeparableVaryingInfos[i].fVariable.c_str())); - fSeparableVaryingInfos[i].fLocation = location; - } -} diff --git a/src/gpu/gl/builders/GrGLPathProgramBuilder.h b/src/gpu/gl/builders/GrGLPathProgramBuilder.h deleted file mode 100644 index d0c77fcdc7..0000000000 --- a/src/gpu/gl/builders/GrGLPathProgramBuilder.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * 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 GrGLPathProgramBuilder_DEFINED -#define GrGLPathProgramBuilder_DEFINED - -#include "GrGLProgramBuilder.h" - -class GrGLPathProgramBuilder : public GrGLProgramBuilder { -public: - GrGLPathProgramBuilder(GrGLGpu* gpu, const DrawArgs& args); - - GrGLProgram* createProgram(GrGLuint programID) override; - - SeparableVaryingHandle addSeparableVarying(const char* name, GrGLVertToFrag* v, - GrSLPrecision fsPrecision) override; - void bindProgramResourceLocations(GrGLuint programID) override; - void resolveProgramResourceLocations(GrGLuint programID) override; - -private: - typedef GrGLPathProgramDataManager::SeparableVaryingInfo SeparableVaryingInfo; - typedef GrGLPathProgramDataManager::SeparableVaryingInfoArray SeparableVaryingInfoArray; - - SeparableVaryingInfoArray fSeparableVaryingInfos; - - typedef GrGLProgramBuilder INHERITED; -}; - -#endif diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp index 8b1843c6cb..166ba0c5a4 100644 --- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp +++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp @@ -9,7 +9,6 @@ #include "GrAutoLocaleSetter.h" #include "GrCoordTransform.h" -#include "GrGLPathProgramBuilder.h" #include "GrGLProgramBuilder.h" #include "GrTexture.h" #include "SkRTConf.h" @@ -32,7 +31,7 @@ GrGLProgram* GrGLProgramBuilder::CreateProgram(const DrawArgs& args, GrGLGpu* gp // create a builder. This will be handed off to effects so they can use it to add // uniforms, varyings, textures, etc - SkAutoTDelete<GrGLProgramBuilder> builder(CreateProgramBuilder(args, gpu)); + SkAutoTDelete<GrGLProgramBuilder> builder(new GrGLProgramBuilder(gpu, args)); GrGLProgramBuilder* pb = builder.get(); @@ -48,18 +47,6 @@ GrGLProgram* GrGLProgramBuilder::CreateProgram(const DrawArgs& args, GrGLGpu* gp return pb->finalize(); } -GrGLProgramBuilder* GrGLProgramBuilder::CreateProgramBuilder(const DrawArgs& args, - GrGLGpu* gpu) { - if (args.fPrimitiveProcessor->isPathRendering()) { - SkASSERT(gpu->glCaps().shaderCaps()->pathRenderingSupport() && - !args.fPrimitiveProcessor->willUseGeoShader() && - args.fPrimitiveProcessor->numAttribs() == 0); - return new GrGLPathProgramBuilder(gpu, args); - } else { - return new GrGLProgramBuilder(gpu, args); - } -} - ///////////////////////////////////////////////////////////////////////////// GrGLProgramBuilder::GrGLProgramBuilder(GrGLGpu* gpu, const DrawArgs& args) @@ -73,7 +60,8 @@ GrGLProgramBuilder::GrGLProgramBuilder(GrGLGpu* gpu, const DrawArgs& args) , fArgs(args) , fGpu(gpu) , fUniforms(kVarsPerBlock) - , fSamplerUniforms(4) { + , fSamplerUniforms(4) + , fSeparableVaryingInfos(kVarsPerBlock) { } void GrGLProgramBuilder::addVarying(const char* name, @@ -100,16 +88,20 @@ void GrGLProgramBuilder::addPassThroughAttribute(const GrPrimitiveProcessor::Att fFS.codeAppendf("%s = %s;", output, v.fsIn()); } -GrGLProgramBuilder::SeparableVaryingHandle GrGLProgramBuilder::addSeparableVarying(const char*, - GrGLVertToFrag*, - GrSLPrecision) { - // This call is not used for non-NVPR backends. However, the polymorphism between - // GrPrimitiveProcessor, GrGLPrimitiveProcessor and GrGLProgramBuilder does not allow for - // a system where GrGLPathProcessor would be able to refer to a primitive-specific builder - // that would understand separable varyings. Thus separable varyings need to be present - // early in the inheritance chain of builders. - SkASSERT(false); - return SeparableVaryingHandle(); +GrGLProgramBuilder::SeparableVaryingHandle GrGLProgramBuilder::addSeparableVarying( + const char* name, + GrGLVertToFrag* v, + GrSLPrecision fsPrecision) { + // This call is not used for non-NVPR backends. + SkASSERT(fGpu->glCaps().shaderCaps()->pathRenderingSupport() && + fArgs.fPrimitiveProcessor->isPathRendering() && + !fArgs.fPrimitiveProcessor->willUseGeoShader() && + fArgs.fPrimitiveProcessor->numAttribs() == 0); + this->addVarying(name, v, fsPrecision); + SeparableVaryingInfo& varyingInfo = fSeparableVaryingInfos.push_back(); + varyingInfo.fVariable = this->getFragmentShaderBuilder()->fInputs.back(); + varyingInfo.fLocation = fSeparableVaryingInfos.count() - 1; + return SeparableVaryingHandle(varyingInfo.fLocation); } void GrGLProgramBuilder::nameVariable(SkString* out, char prefix, const char* name) { @@ -440,6 +432,19 @@ void GrGLProgramBuilder::bindProgramResourceLocations(GrGLuint programID) { } fFS.bindFragmentShaderLocations(programID); + + // handle NVPR separable varyings + if (!fGpu->glCaps().shaderCaps()->pathRenderingSupport() || + !fGpu->glPathRendering()->shouldBindFragmentInputs()) { + return; + } + int count = fSeparableVaryingInfos.count(); + for (int i = 0; i < count; ++i) { + GL_CALL(BindFragmentInputLocation(programID, + i, + fSeparableVaryingInfos[i].fVariable.c_str())); + fSeparableVaryingInfos[i].fLocation = i; + } } bool GrGLProgramBuilder::checkLinkStatus(GrGLuint programID) { @@ -476,6 +481,21 @@ void GrGLProgramBuilder::resolveProgramResourceLocations(GrGLuint programID) { fUniforms[i].fLocation = location; } } + + // handle NVPR separable varyings + if (!fGpu->glCaps().shaderCaps()->pathRenderingSupport() || + !fGpu->glPathRendering()->shouldBindFragmentInputs()) { + return; + } + int count = fSeparableVaryingInfos.count(); + for (int i = 0; i < count; ++i) { + GrGLint location; + GL_CALL_RET(location, + GetProgramResourceLocation(programID, + GR_GL_FRAGMENT_INPUT, + fSeparableVaryingInfos[i].fVariable.c_str())); + fSeparableVaryingInfos[i].fLocation = location; + } } void GrGLProgramBuilder::cleanupProgram(GrGLuint programID, const SkTDArray<GrGLuint>& shaderIDs) { @@ -490,6 +510,7 @@ void GrGLProgramBuilder::cleanupShaders(const SkTDArray<GrGLuint>& shaderIDs) { GrGLProgram* GrGLProgramBuilder::createProgram(GrGLuint programID) { return new GrGLProgram(fGpu, this->desc(), fUniformHandles, programID, fUniforms, + fSeparableVaryingInfos, fGeometryProcessor, fXferProcessor, fFragmentProcessors.get(), &fSamplerUniforms); } diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.h b/src/gpu/gl/builders/GrGLProgramBuilder.h index 589a679681..e3c140a4e4 100644 --- a/src/gpu/gl/builders/GrGLProgramBuilder.h +++ b/src/gpu/gl/builders/GrGLProgramBuilder.h @@ -12,7 +12,6 @@ #include "GrGLGeometryShaderBuilder.h" #include "GrGLVertexShaderBuilder.h" #include "../GrGLProgramDataManager.h" -#include "../GrGLPathProgramDataManager.h" #include "../GrGLPrimitiveProcessor.h" #include "../GrGLXferProcessor.h" #include "../../GrPipeline.h" @@ -43,7 +42,7 @@ public: virtual ~GrGLUniformBuilder() {} typedef GrGLProgramDataManager::UniformHandle UniformHandle; - typedef GrGLPathProgramDataManager::SeparableVaryingHandle SeparableVaryingHandle; + typedef GrGLProgramDataManager::SeparableVaryingHandle SeparableVaryingHandle; /** Add a uniform variable to the current program, that has visibility in one or more shaders. visibility is a bitfield of ShaderVisibility values indicating from which shaders the @@ -281,8 +280,8 @@ public: protected: typedef GrGLProgramDataManager::UniformInfo UniformInfo; typedef GrGLProgramDataManager::UniformInfoArray UniformInfoArray; - - static GrGLProgramBuilder* CreateProgramBuilder(const DrawArgs&, GrGLGpu*); + typedef GrGLProgramDataManager::SeparableVaryingInfo SeparableVaryingInfo; + typedef GrGLProgramDataManager::SeparableVaryingInfoArray SeparableVaryingInfoArray; GrGLProgramBuilder(GrGLGpu*, const DrawArgs&); @@ -399,6 +398,7 @@ protected: GrGLPrimitiveProcessor::TransformsIn fCoordTransforms; GrGLPrimitiveProcessor::TransformsOut fOutCoords; SkTArray<UniformHandle> fSamplerUniforms; + SeparableVaryingInfoArray fSeparableVaryingInfos; friend class GrGLShaderBuilder; friend class GrGLVertexBuilder; |