2 * Copyright 2015 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef GrGLSLXferProcessor_DEFINED
9 #define GrGLSLXferProcessor_DEFINED
11 #include "glsl/GrGLSLProgramDataManager.h"
12 #include "glsl/GrGLSLTextureSampler.h"
14 class GrXferProcessor;
16 class GrGLSLUniformHandler;
17 class GrGLSLXPBuilder;
18 class GrGLSLXPFragmentBuilder;
20 class GrGLSLXferProcessor {
22 GrGLSLXferProcessor() {}
23 virtual ~GrGLSLXferProcessor() {}
25 typedef GrGLSLTextureSampler::TextureSamplerArray TextureSamplerArray;
27 EmitArgs(GrGLSLXPFragmentBuilder* fragBuilder,
28 GrGLSLUniformHandler* uniformHandler,
29 const GrGLSLCaps* caps,
30 const GrXferProcessor& xp,
31 const char* inputColor,
32 const char* inputCoverage,
33 const char* outputPrimary,
34 const char* outputSecondary,
35 const TextureSamplerArray& samplers)
36 : fXPFragBuilder(fragBuilder)
37 , fUniformHandler(uniformHandler)
40 , fInputColor(inputColor)
41 , fInputCoverage(inputCoverage)
42 , fOutputPrimary(outputPrimary)
43 , fOutputSecondary(outputSecondary)
44 , fSamplers(samplers) {}
46 GrGLSLXPFragmentBuilder* fXPFragBuilder;
47 GrGLSLUniformHandler* fUniformHandler;
48 const GrGLSLCaps* fGLSLCaps;
49 const GrXferProcessor& fXP;
50 const char* fInputColor;
51 const char* fInputCoverage;
52 const char* fOutputPrimary;
53 const char* fOutputSecondary;
54 const TextureSamplerArray& fSamplers;
57 * This is similar to emitCode() in the base class, except it takes a full shader builder.
58 * This allows the effect subclass to emit vertex code.
60 void emitCode(const EmitArgs&);
62 /** A GrGLSLXferProcessor instance can be reused with any GrGLSLXferProcessor that produces
63 the same stage key; this function reads data from a GrGLSLXferProcessor and uploads any
64 uniform variables required by the shaders created in emitCode(). The GrXferProcessor
65 parameter is guaranteed to be of the same type that created this GrGLSLXferProcessor and
66 to have an identical processor key as the one that created this GrGLSLXferProcessor. This
67 function calls onSetData on the subclass of GrGLSLXferProcessor
69 void setData(const GrGLSLProgramDataManager& pdm, const GrXferProcessor& xp);
73 * Called by emitCode() when the XP will not be performing a dst read. This method is
74 * responsible for both blending and coverage. A subclass only needs to implement this method if
75 * it can construct a GrXferProcessor that will not read the dst color.
77 virtual void emitOutputsForBlendState(const EmitArgs&) {
78 SkFAIL("emitOutputsForBlendState not implemented.");
82 * Called by emitCode() when the XP will perform a dst read. This method only needs to supply
83 * the blending logic. The base class applies coverage. A subclass only needs to implement this
84 * method if it can construct a GrXferProcessor that reads the dst color.
86 virtual void emitBlendCodeForDstRead(GrGLSLXPFragmentBuilder*,
87 GrGLSLUniformHandler*,
89 const char* srcCoverage,
92 const char* outColorSecondary,
93 const GrXferProcessor&) {
94 SkFAIL("emitBlendCodeForDstRead not implemented.");
97 virtual void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) = 0;
99 GrGLSLProgramDataManager::UniformHandle fDstTopLeftUni;
100 GrGLSLProgramDataManager::UniformHandle fDstScaleUni;