1 /*
2  * Copyright 2014 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 GrGLXferProcessor_DEFINED
9 #define GrGLXferProcessor_DEFINED
10 
11 #include "GrGLProcessor.h"
12 
13 class GrGLXPBuilder;
14 class GrXferProcessor;
15 
16 class GrGLXferProcessor {
17 public:
GrGLXferProcessor()18     GrGLXferProcessor() {}
~GrGLXferProcessor()19     virtual ~GrGLXferProcessor() {}
20 
21     typedef GrGLProcessor::TextureSamplerArray TextureSamplerArray;
22     struct EmitArgs {
EmitArgsEmitArgs23         EmitArgs(GrGLXPBuilder* pb,
24                  const GrXferProcessor& xp,
25                  const char* inputColor,
26                  const char* inputCoverage,
27                  const char* outputPrimary,
28                  const char* outputSecondary,
29                  const TextureSamplerArray& samplers)
30             : fPB(pb)
31             , fXP(xp)
32             , fInputColor(inputColor)
33             , fInputCoverage(inputCoverage)
34             , fOutputPrimary(outputPrimary)
35             , fOutputSecondary(outputSecondary)
36             , fSamplers(samplers) {}
37 
38         GrGLXPBuilder* fPB;
39         const GrXferProcessor& fXP;
40         const char* fInputColor;
41         const char* fInputCoverage;
42         const char* fOutputPrimary;
43         const char* fOutputSecondary;
44         const TextureSamplerArray& fSamplers;
45     };
46     /**
47      * This is similar to emitCode() in the base class, except it takes a full shader builder.
48      * This allows the effect subclass to emit vertex code.
49      */
50     void emitCode(const EmitArgs&);
51 
52     /** A GrGLXferProcessor instance can be reused with any GrGLXferProcessor that produces
53         the same stage key; this function reads data from a GrGLXferProcessor and uploads any
54         uniform variables required  by the shaders created in emitCode(). The GrXferProcessor
55         parameter is guaranteed to be of the same type that created this GrGLXferProcessor and
56         to have an identical processor key as the one that created this GrGLXferProcessor. This
57         function calls onSetData on the subclass of GrGLXferProcessor
58      */
59     void setData(const GrGLProgramDataManager& pdm, const GrXferProcessor& xp);
60 
61 private:
62     virtual void onEmitCode(const EmitArgs&) = 0;
63 
64     virtual void onSetData(const GrGLProgramDataManager&, const GrXferProcessor&) = 0;
65 
66     GrGLProgramDataManager::UniformHandle fDstCopyTopLeftUni;
67     GrGLProgramDataManager::UniformHandle fDstCopyScaleUni;
68 
69     typedef GrGLProcessor INHERITED;
70 };
71 #endif
72