blob: ccfbc3e3a58c1f0d353260ab58f63021ae696447 [file] [log] [blame]
joshualitt8072caa2015-02-12 14:20:52 -08001/*
2 * Copyright 2013 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
egdaniele659a582015-11-13 09:55:43 -08008#ifndef GrGLSLPrimitiveProcessor_DEFINED
9#define GrGLSLPrimitiveProcessor_DEFINED
joshualitt8072caa2015-02-12 14:20:52 -080010
11#include "GrPrimitiveProcessor.h"
egdaniel7dc4bd02015-10-29 07:57:01 -070012#include "glsl/GrGLSLProcessorTypes.h"
egdaniel018fb622015-10-28 07:26:40 -070013#include "glsl/GrGLSLProgramDataManager.h"
egdaniel7dc4bd02015-10-29 07:57:01 -070014#include "glsl/GrGLSLTextureSampler.h"
joshualitt8072caa2015-02-12 14:20:52 -080015
16class GrBatchTracker;
17class GrPrimitiveProcessor;
egdaniela2e3e0f2015-11-19 07:23:45 -080018class GrGLSLCaps;
cdalton85285412016-02-18 12:37:07 -080019class GrGLSLPPFragmentBuilder;
egdaniel8dcdedc2015-11-11 06:27:20 -080020class GrGLSLGPBuilder;
egdaniel7ea439b2015-12-03 09:20:44 -080021class GrGLSLUniformHandler;
egdaniel0eafe792015-11-20 14:01:22 -080022class GrGLSLVaryingHandler;
egdaniela2e3e0f2015-11-19 07:23:45 -080023class GrGLSLVertexBuilder;
joshualitt8072caa2015-02-12 14:20:52 -080024
egdaniele659a582015-11-13 09:55:43 -080025class GrGLSLPrimitiveProcessor {
joshualitt8072caa2015-02-12 14:20:52 -080026public:
egdaniele659a582015-11-13 09:55:43 -080027 virtual ~GrGLSLPrimitiveProcessor() {}
joshualitt8072caa2015-02-12 14:20:52 -080028
egdaniel018fb622015-10-28 07:26:40 -070029 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle;
egdaniel7dc4bd02015-10-29 07:57:01 -070030 typedef GrGLSLTextureSampler::TextureSamplerArray TextureSamplerArray;
joshualitt8072caa2015-02-12 14:20:52 -080031
32 typedef SkSTArray<2, const GrCoordTransform*, true> ProcCoords;
33 typedef SkSTArray<8, ProcCoords> TransformsIn;
egdaniel7dc4bd02015-10-29 07:57:01 -070034 typedef SkSTArray<8, GrGLSLTransformedCoordsArray> TransformsOut;
joshualitt8072caa2015-02-12 14:20:52 -080035
36 struct EmitArgs {
egdaniel7ea439b2015-12-03 09:20:44 -080037 EmitArgs(GrGLSLVertexBuilder* vertBuilder,
cdalton85285412016-02-18 12:37:07 -080038 GrGLSLPPFragmentBuilder* fragBuilder,
egdaniel0eafe792015-11-20 14:01:22 -080039 GrGLSLVaryingHandler* varyingHandler,
egdaniel7ea439b2015-12-03 09:20:44 -080040 GrGLSLUniformHandler* uniformHandler,
egdaniela2e3e0f2015-11-19 07:23:45 -080041 const GrGLSLCaps* caps,
joshualitt8072caa2015-02-12 14:20:52 -080042 const GrPrimitiveProcessor& gp,
joshualitt8072caa2015-02-12 14:20:52 -080043 const char* outputColor,
44 const char* outputCoverage,
45 const TextureSamplerArray& samplers,
46 const TransformsIn& transformsIn,
47 TransformsOut* transformsOut)
egdaniel7ea439b2015-12-03 09:20:44 -080048 : fVertBuilder(vertBuilder)
egdaniel4ca2e602015-11-18 08:01:26 -080049 , fFragBuilder(fragBuilder)
egdaniel0eafe792015-11-20 14:01:22 -080050 , fVaryingHandler(varyingHandler)
egdaniel7ea439b2015-12-03 09:20:44 -080051 , fUniformHandler(uniformHandler)
egdaniela2e3e0f2015-11-19 07:23:45 -080052 , fGLSLCaps(caps)
joshualitt8072caa2015-02-12 14:20:52 -080053 , fGP(gp)
joshualitt8072caa2015-02-12 14:20:52 -080054 , fOutputColor(outputColor)
55 , fOutputCoverage(outputCoverage)
56 , fSamplers(samplers)
57 , fTransformsIn(transformsIn)
58 , fTransformsOut(transformsOut) {}
egdaniel4ca2e602015-11-18 08:01:26 -080059 GrGLSLVertexBuilder* fVertBuilder;
cdalton85285412016-02-18 12:37:07 -080060 GrGLSLPPFragmentBuilder* fFragBuilder;
egdaniel0eafe792015-11-20 14:01:22 -080061 GrGLSLVaryingHandler* fVaryingHandler;
egdaniel7ea439b2015-12-03 09:20:44 -080062 GrGLSLUniformHandler* fUniformHandler;
egdaniela2e3e0f2015-11-19 07:23:45 -080063 const GrGLSLCaps* fGLSLCaps;
joshualitt8072caa2015-02-12 14:20:52 -080064 const GrPrimitiveProcessor& fGP;
joshualitt8072caa2015-02-12 14:20:52 -080065 const char* fOutputColor;
66 const char* fOutputCoverage;
67 const TextureSamplerArray& fSamplers;
68 const TransformsIn& fTransformsIn;
69 TransformsOut* fTransformsOut;
70 };
71
72 /**
73 * This is similar to emitCode() in the base class, except it takes a full shader builder.
74 * This allows the effect subclass to emit vertex code.
75 */
76 virtual void emitCode(EmitArgs&) = 0;
77
78
egdaniele659a582015-11-13 09:55:43 -080079 /** A GrGLSLPrimitiveProcessor instance can be reused with any GrGLSLPrimitiveProcessor that
80 produces the same stage key; this function reads data from a GrGLSLPrimitiveProcessor and
joshualitt8072caa2015-02-12 14:20:52 -080081 uploads any uniform variables required by the shaders created in emitCode(). The
82 GrPrimitiveProcessor parameter is guaranteed to be of the same type that created this
egdaniele659a582015-11-13 09:55:43 -080083 GrGLSLPrimitiveProcessor and to have an identical processor key as the one that created this
84 GrGLSLPrimitiveProcessor. */
egdaniel018fb622015-10-28 07:26:40 -070085 virtual void setData(const GrGLSLProgramDataManager&, const GrPrimitiveProcessor&) = 0;
joshualitt8072caa2015-02-12 14:20:52 -080086
87 static SkMatrix GetTransformMatrix(const SkMatrix& localMatrix, const GrCoordTransform&);
88
joshualittd8dd47b2015-09-11 11:45:01 -070089 virtual void setTransformData(const GrPrimitiveProcessor&,
egdaniel018fb622015-10-28 07:26:40 -070090 const GrGLSLProgramDataManager& pdman,
joshualittd8dd47b2015-09-11 11:45:01 -070091 int index,
92 const SkTArray<const GrCoordTransform*, true>& transforms) = 0;
93
joshualitt8072caa2015-02-12 14:20:52 -080094protected:
cdalton85285412016-02-18 12:37:07 -080095 void setupUniformColor(GrGLSLPPFragmentBuilder* fragBuilder,
egdaniel7ea439b2015-12-03 09:20:44 -080096 GrGLSLUniformHandler* uniformHandler,
egdaniel8dcdedc2015-11-11 06:27:20 -080097 const char* outputName,
98 UniformHandle* colorUniform);
joshualitt8072caa2015-02-12 14:20:52 -080099
joshualitt8072caa2015-02-12 14:20:52 -0800100 struct Transform {
101 Transform() : fType(kVoid_GrSLType) { fCurrentValue = SkMatrix::InvalidMatrix(); }
egdaniel7dc4bd02015-10-29 07:57:01 -0700102 UniformHandle fHandle;
103 SkMatrix fCurrentValue;
104 GrSLType fType;
joshualitt8072caa2015-02-12 14:20:52 -0800105 };
106
107 SkSTArray<8, SkSTArray<2, Transform, true> > fInstalledTransforms;
joshualitt8072caa2015-02-12 14:20:52 -0800108};
109
110#endif