blob: 478956df3477b9dcf1a712bb262aa4299da489a2 [file] [log] [blame]
egdanielc2304142014-12-11 13:15:13 -08001/*
egdanielfa4cc8b2015-11-13 08:34:52 -08002 * Copyright 2015 Google Inc.
egdanielc2304142014-12-11 13:15:13 -08003 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
egdanielfa4cc8b2015-11-13 08:34:52 -08008#ifndef GrGLSLXferProcessor_DEFINED
9#define GrGLSLXferProcessor_DEFINED
egdanielc2304142014-12-11 13:15:13 -080010
egdaniel018fb622015-10-28 07:26:40 -070011#include "glsl/GrGLSLProgramDataManager.h"
egdaniel7dc4bd02015-10-29 07:57:01 -070012#include "glsl/GrGLSLTextureSampler.h"
egdanielc2304142014-12-11 13:15:13 -080013
bsalomon50785a32015-02-06 07:02:37 -080014class GrXferProcessor;
egdaniel7ea439b2015-12-03 09:20:44 -080015class GrGLSLCaps;
16class GrGLSLUniformHandler;
egdaniela2e3e0f2015-11-19 07:23:45 -080017class GrGLSLXPBuilder;
18class GrGLSLXPFragmentBuilder;
egdanielc2304142014-12-11 13:15:13 -080019
egdanielfa4cc8b2015-11-13 08:34:52 -080020class GrGLSLXferProcessor {
egdanielc2304142014-12-11 13:15:13 -080021public:
egdanielfa4cc8b2015-11-13 08:34:52 -080022 GrGLSLXferProcessor() {}
23 virtual ~GrGLSLXferProcessor() {}
egdanielc2304142014-12-11 13:15:13 -080024
egdaniel7dc4bd02015-10-29 07:57:01 -070025 typedef GrGLSLTextureSampler::TextureSamplerArray TextureSamplerArray;
egdanielc2304142014-12-11 13:15:13 -080026 struct EmitArgs {
egdaniel7ea439b2015-12-03 09:20:44 -080027 EmitArgs(GrGLSLXPFragmentBuilder* fragBuilder,
28 GrGLSLUniformHandler* uniformHandler,
egdaniela2e3e0f2015-11-19 07:23:45 -080029 const GrGLSLCaps* caps,
egdanielc2304142014-12-11 13:15:13 -080030 const GrXferProcessor& xp,
31 const char* inputColor,
32 const char* inputCoverage,
33 const char* outputPrimary,
34 const char* outputSecondary,
ethannicholas22793252016-01-30 09:59:10 -080035 const TextureSamplerArray& samplers,
36 const bool usePLSDstRead)
egdaniel7ea439b2015-12-03 09:20:44 -080037 : fXPFragBuilder(fragBuilder)
38 , fUniformHandler(uniformHandler)
egdaniela2e3e0f2015-11-19 07:23:45 -080039 , fGLSLCaps(caps)
egdanielc2304142014-12-11 13:15:13 -080040 , fXP(xp)
41 , fInputColor(inputColor)
42 , fInputCoverage(inputCoverage)
43 , fOutputPrimary(outputPrimary)
44 , fOutputSecondary(outputSecondary)
ethannicholas22793252016-01-30 09:59:10 -080045 , fSamplers(samplers)
46 , fUsePLSDstRead(usePLSDstRead) {}
egdanielc2304142014-12-11 13:15:13 -080047
egdaniel4ca2e602015-11-18 08:01:26 -080048 GrGLSLXPFragmentBuilder* fXPFragBuilder;
egdaniel7ea439b2015-12-03 09:20:44 -080049 GrGLSLUniformHandler* fUniformHandler;
egdaniela2e3e0f2015-11-19 07:23:45 -080050 const GrGLSLCaps* fGLSLCaps;
egdanielc2304142014-12-11 13:15:13 -080051 const GrXferProcessor& fXP;
52 const char* fInputColor;
53 const char* fInputCoverage;
54 const char* fOutputPrimary;
55 const char* fOutputSecondary;
56 const TextureSamplerArray& fSamplers;
ethannicholas22793252016-01-30 09:59:10 -080057 bool fUsePLSDstRead;
egdanielc2304142014-12-11 13:15:13 -080058 };
59 /**
60 * This is similar to emitCode() in the base class, except it takes a full shader builder.
61 * This allows the effect subclass to emit vertex code.
62 */
bsalomon50785a32015-02-06 07:02:37 -080063 void emitCode(const EmitArgs&);
egdanielc2304142014-12-11 13:15:13 -080064
egdanielfa4cc8b2015-11-13 08:34:52 -080065 /** A GrGLSLXferProcessor instance can be reused with any GrGLSLXferProcessor that produces
66 the same stage key; this function reads data from a GrGLSLXferProcessor and uploads any
egdanielc2304142014-12-11 13:15:13 -080067 uniform variables required by the shaders created in emitCode(). The GrXferProcessor
egdanielfa4cc8b2015-11-13 08:34:52 -080068 parameter is guaranteed to be of the same type that created this GrGLSLXferProcessor and
69 to have an identical processor key as the one that created this GrGLSLXferProcessor. This
70 function calls onSetData on the subclass of GrGLSLXferProcessor
bsalomon50785a32015-02-06 07:02:37 -080071 */
egdaniel018fb622015-10-28 07:26:40 -070072 void setData(const GrGLSLProgramDataManager& pdm, const GrXferProcessor& xp);
bsalomon50785a32015-02-06 07:02:37 -080073
robertphillips727b7d22016-01-26 12:07:13 -080074protected:
75 static void DefaultCoverageModulation(GrGLSLXPFragmentBuilder* fragBuilder,
76 const char* srcCoverage,
77 const char* dstColor,
78 const char* outColor,
79 const char* outColorSecondary,
80 const GrXferProcessor& proc);
robertphillipsf42fca42016-01-27 05:00:04 -080081
egdanielc2304142014-12-11 13:15:13 -080082private:
cdaltonedbb31f2015-06-08 12:14:44 -070083 /**
84 * Called by emitCode() when the XP will not be performing a dst read. This method is
85 * responsible for both blending and coverage. A subclass only needs to implement this method if
86 * it can construct a GrXferProcessor that will not read the dst color.
87 */
88 virtual void emitOutputsForBlendState(const EmitArgs&) {
89 SkFAIL("emitOutputsForBlendState not implemented.");
90 }
91
92 /**
93 * Called by emitCode() when the XP will perform a dst read. This method only needs to supply
94 * the blending logic. The base class applies coverage. A subclass only needs to implement this
95 * method if it can construct a GrXferProcessor that reads the dst color.
96 */
egdaniel7ea439b2015-12-03 09:20:44 -080097 virtual void emitBlendCodeForDstRead(GrGLSLXPFragmentBuilder*,
98 GrGLSLUniformHandler*,
egdaniel8dcdedc2015-11-11 06:27:20 -080099 const char* srcColor,
egdanielf34b2932015-12-01 13:54:06 -0800100 const char* srcCoverage,
egdaniel8dcdedc2015-11-11 06:27:20 -0800101 const char* dstColor,
102 const char* outColor,
egdanielf34b2932015-12-01 13:54:06 -0800103 const char* outColorSecondary,
egdaniel8dcdedc2015-11-11 06:27:20 -0800104 const GrXferProcessor&) {
cdaltonedbb31f2015-06-08 12:14:44 -0700105 SkFAIL("emitBlendCodeForDstRead not implemented.");
106 }
bsalomon50785a32015-02-06 07:02:37 -0800107
egdaniel018fb622015-10-28 07:26:40 -0700108 virtual void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) = 0;
bsalomon50785a32015-02-06 07:02:37 -0800109
egdaniel018fb622015-10-28 07:26:40 -0700110 GrGLSLProgramDataManager::UniformHandle fDstTopLeftUni;
111 GrGLSLProgramDataManager::UniformHandle fDstScaleUni;
egdanielc2304142014-12-11 13:15:13 -0800112};
113#endif