blob: 474b5f460c08747ca60235fdc4cf001d7fdf2b6e [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
8#ifndef GrGLPrimitiveProcessor_DEFINED
9#define GrGLPrimitiveProcessor_DEFINED
10
11#include "GrPrimitiveProcessor.h"
12#include "GrGLProcessor.h"
kkinnunen7aedda52015-06-29 23:01:28 -070013#include "GrGLPathProgramDataManager.h"
joshualitt8072caa2015-02-12 14:20:52 -080014
15class GrBatchTracker;
16class GrPrimitiveProcessor;
17class GrGLGPBuilder;
18
19class GrGLPrimitiveProcessor {
20public:
joshualitt8072caa2015-02-12 14:20:52 -080021 virtual ~GrGLPrimitiveProcessor() {}
22
23 typedef GrGLProgramDataManager::UniformHandle UniformHandle;
kkinnunen7aedda52015-06-29 23:01:28 -070024 typedef GrGLPathProgramDataManager::SeparableVaryingHandle SeparableVaryingHandle;
joshualitt8072caa2015-02-12 14:20:52 -080025 typedef GrGLProcessor::TextureSamplerArray TextureSamplerArray;
26
27 typedef SkSTArray<2, const GrCoordTransform*, true> ProcCoords;
28 typedef SkSTArray<8, ProcCoords> TransformsIn;
29 typedef SkSTArray<8, GrGLProcessor::TransformedCoordsArray> TransformsOut;
30
31 struct EmitArgs {
32 EmitArgs(GrGLGPBuilder* pb,
33 const GrPrimitiveProcessor& gp,
34 const GrBatchTracker& bt,
35 const char* outputColor,
36 const char* outputCoverage,
37 const TextureSamplerArray& samplers,
38 const TransformsIn& transformsIn,
39 TransformsOut* transformsOut)
40 : fPB(pb)
41 , fGP(gp)
42 , fBT(bt)
43 , fOutputColor(outputColor)
44 , fOutputCoverage(outputCoverage)
45 , fSamplers(samplers)
46 , fTransformsIn(transformsIn)
47 , fTransformsOut(transformsOut) {}
48 GrGLGPBuilder* fPB;
49 const GrPrimitiveProcessor& fGP;
50 const GrBatchTracker& fBT;
51 const char* fOutputColor;
52 const char* fOutputCoverage;
53 const TextureSamplerArray& fSamplers;
54 const TransformsIn& fTransformsIn;
55 TransformsOut* fTransformsOut;
56 };
57
58 /**
59 * This is similar to emitCode() in the base class, except it takes a full shader builder.
60 * This allows the effect subclass to emit vertex code.
61 */
62 virtual void emitCode(EmitArgs&) = 0;
63
64
65 /** A GrGLPrimitiveProcessor instance can be reused with any GrGLPrimitiveProcessor that
66 produces the same stage key; this function reads data from a GrGLPrimitiveProcessor and
67 uploads any uniform variables required by the shaders created in emitCode(). The
68 GrPrimitiveProcessor parameter is guaranteed to be of the same type that created this
69 GrGLPrimitiveProcessor and to have an identical processor key as the one that created this
70 GrGLPrimitiveProcessor. */
71 virtual void setData(const GrGLProgramDataManager&,
72 const GrPrimitiveProcessor&,
73 const GrBatchTracker&) = 0;
74
75 static SkMatrix GetTransformMatrix(const SkMatrix& localMatrix, const GrCoordTransform&);
76
77protected:
joshualittb8c241a2015-05-19 08:23:30 -070078 void setupUniformColor(GrGLGPBuilder* pb, const char* outputName, UniformHandle* colorUniform);
joshualitt8072caa2015-02-12 14:20:52 -080079
joshualitt8072caa2015-02-12 14:20:52 -080080 class ShaderVarHandle {
81 public:
82 bool isValid() const { return fHandle > -1; }
83 ShaderVarHandle() : fHandle(-1) {}
84 ShaderVarHandle(int value) : fHandle(value) { SkASSERT(this->isValid()); }
85 int handle() const { SkASSERT(this->isValid()); return fHandle; }
86 UniformHandle convertToUniformHandle() {
87 SkASSERT(this->isValid());
88 return GrGLProgramDataManager::UniformHandle::CreateFromUniformIndex(fHandle);
89 }
kkinnunen7aedda52015-06-29 23:01:28 -070090 SeparableVaryingHandle convertToSeparableVaryingHandle() {
91 SkASSERT(this->isValid());
92 return SeparableVaryingHandle::CreateFromSeparableVaryingIndex(fHandle);
93 }
joshualitt8072caa2015-02-12 14:20:52 -080094
95 private:
96 int fHandle;
97 };
98
99 struct Transform {
100 Transform() : fType(kVoid_GrSLType) { fCurrentValue = SkMatrix::InvalidMatrix(); }
101 ShaderVarHandle fHandle;
102 SkMatrix fCurrentValue;
103 GrSLType fType;
104 };
105
106 SkSTArray<8, SkSTArray<2, Transform, true> > fInstalledTransforms;
joshualitt8072caa2015-02-12 14:20:52 -0800107};
108
109#endif