Create GLSLUniformHandler class for gpu backend
[platform/upstream/libSkiaSharp.git] / src / gpu / glsl / GrGLSLXferProcessor.h
1 /*
2  * Copyright 2015 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 GrGLSLXferProcessor_DEFINED
9 #define GrGLSLXferProcessor_DEFINED
10
11 #include "glsl/GrGLSLProgramDataManager.h"
12 #include "glsl/GrGLSLTextureSampler.h"
13
14 class GrXferProcessor;
15 class GrGLSLCaps;
16 class GrGLSLUniformHandler;
17 class GrGLSLXPBuilder;
18 class GrGLSLXPFragmentBuilder;
19
20 class GrGLSLXferProcessor {
21 public:
22     GrGLSLXferProcessor() {}
23     virtual ~GrGLSLXferProcessor() {}
24
25     typedef GrGLSLTextureSampler::TextureSamplerArray TextureSamplerArray;
26     struct EmitArgs {
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)
38             , fGLSLCaps(caps)
39             , fXP(xp)
40             , fInputColor(inputColor)
41             , fInputCoverage(inputCoverage)
42             , fOutputPrimary(outputPrimary)
43             , fOutputSecondary(outputSecondary)
44             , fSamplers(samplers) {}
45
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;
55     };
56     /**
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.
59      */
60     void emitCode(const EmitArgs&);
61
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
68      */
69     void setData(const GrGLSLProgramDataManager& pdm, const GrXferProcessor& xp);
70
71 private:
72     /**
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.
76      */
77     virtual void emitOutputsForBlendState(const EmitArgs&) {
78         SkFAIL("emitOutputsForBlendState not implemented.");
79     }
80
81     /**
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.
85      */
86     virtual void emitBlendCodeForDstRead(GrGLSLXPFragmentBuilder*,
87                                          GrGLSLUniformHandler*,
88                                          const char* srcColor,
89                                          const char* srcCoverage,
90                                          const char* dstColor,
91                                          const char* outColor,
92                                          const char* outColorSecondary,
93                                          const GrXferProcessor&) {
94         SkFAIL("emitBlendCodeForDstRead not implemented.");
95     }
96
97     virtual void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) = 0;
98
99     GrGLSLProgramDataManager::UniformHandle fDstTopLeftUni;
100     GrGLSLProgramDataManager::UniformHandle fDstScaleUni;
101 };
102 #endif