blob: f4a8ebdfa029b0d6d5fbc11cf09463dbe8c2c019 [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"
cdalton3f6f76f2016-04-11 12:18:09 -070012#include "glsl/GrGLSLSampler.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
egdaniel09aa1fc2016-04-20 07:09:46 -070025 typedef GrGLSLProgramDataManager::UniformHandle SamplerHandle;
26
egdanielc2304142014-12-11 13:15:13 -080027 struct EmitArgs {
egdaniel7ea439b2015-12-03 09:20:44 -080028 EmitArgs(GrGLSLXPFragmentBuilder* fragBuilder,
29 GrGLSLUniformHandler* uniformHandler,
egdaniela2e3e0f2015-11-19 07:23:45 -080030 const GrGLSLCaps* caps,
egdanielc2304142014-12-11 13:15:13 -080031 const GrXferProcessor& xp,
32 const char* inputColor,
33 const char* inputCoverage,
34 const char* outputPrimary,
35 const char* outputSecondary,
egdaniel09aa1fc2016-04-20 07:09:46 -070036 const SamplerHandle* texSamplers,
37 const SamplerHandle* bufferSamplers,
ethannicholas22793252016-01-30 09:59:10 -080038 const bool usePLSDstRead)
egdaniel7ea439b2015-12-03 09:20:44 -080039 : fXPFragBuilder(fragBuilder)
40 , fUniformHandler(uniformHandler)
egdaniela2e3e0f2015-11-19 07:23:45 -080041 , fGLSLCaps(caps)
egdanielc2304142014-12-11 13:15:13 -080042 , fXP(xp)
43 , fInputColor(inputColor)
44 , fInputCoverage(inputCoverage)
45 , fOutputPrimary(outputPrimary)
46 , fOutputSecondary(outputSecondary)
cdalton3f6f76f2016-04-11 12:18:09 -070047 , fTexSamplers(texSamplers)
cdalton74b8d322016-04-11 14:47:28 -070048 , fBufferSamplers(bufferSamplers)
ethannicholas22793252016-01-30 09:59:10 -080049 , fUsePLSDstRead(usePLSDstRead) {}
egdanielc2304142014-12-11 13:15:13 -080050
egdaniel4ca2e602015-11-18 08:01:26 -080051 GrGLSLXPFragmentBuilder* fXPFragBuilder;
egdaniel7ea439b2015-12-03 09:20:44 -080052 GrGLSLUniformHandler* fUniformHandler;
egdaniela2e3e0f2015-11-19 07:23:45 -080053 const GrGLSLCaps* fGLSLCaps;
egdanielc2304142014-12-11 13:15:13 -080054 const GrXferProcessor& fXP;
55 const char* fInputColor;
56 const char* fInputCoverage;
57 const char* fOutputPrimary;
58 const char* fOutputSecondary;
egdaniel09aa1fc2016-04-20 07:09:46 -070059 const SamplerHandle* fTexSamplers;
60 const SamplerHandle* fBufferSamplers;
ethannicholas22793252016-01-30 09:59:10 -080061 bool fUsePLSDstRead;
egdanielc2304142014-12-11 13:15:13 -080062 };
63 /**
64 * This is similar to emitCode() in the base class, except it takes a full shader builder.
65 * This allows the effect subclass to emit vertex code.
66 */
bsalomon50785a32015-02-06 07:02:37 -080067 void emitCode(const EmitArgs&);
egdanielc2304142014-12-11 13:15:13 -080068
egdanielfa4cc8b2015-11-13 08:34:52 -080069 /** A GrGLSLXferProcessor instance can be reused with any GrGLSLXferProcessor that produces
70 the same stage key; this function reads data from a GrGLSLXferProcessor and uploads any
egdanielc2304142014-12-11 13:15:13 -080071 uniform variables required by the shaders created in emitCode(). The GrXferProcessor
egdanielfa4cc8b2015-11-13 08:34:52 -080072 parameter is guaranteed to be of the same type that created this GrGLSLXferProcessor and
73 to have an identical processor key as the one that created this GrGLSLXferProcessor. This
74 function calls onSetData on the subclass of GrGLSLXferProcessor
bsalomon50785a32015-02-06 07:02:37 -080075 */
egdaniel018fb622015-10-28 07:26:40 -070076 void setData(const GrGLSLProgramDataManager& pdm, const GrXferProcessor& xp);
bsalomon50785a32015-02-06 07:02:37 -080077
robertphillips727b7d22016-01-26 12:07:13 -080078protected:
79 static void DefaultCoverageModulation(GrGLSLXPFragmentBuilder* fragBuilder,
80 const char* srcCoverage,
81 const char* dstColor,
82 const char* outColor,
83 const char* outColorSecondary,
84 const GrXferProcessor& proc);
robertphillipsf42fca42016-01-27 05:00:04 -080085
egdanielc2304142014-12-11 13:15:13 -080086private:
cdaltonedbb31f2015-06-08 12:14:44 -070087 /**
88 * Called by emitCode() when the XP will not be performing a dst read. This method is
89 * responsible for both blending and coverage. A subclass only needs to implement this method if
90 * it can construct a GrXferProcessor that will not read the dst color.
91 */
92 virtual void emitOutputsForBlendState(const EmitArgs&) {
93 SkFAIL("emitOutputsForBlendState not implemented.");
94 }
95
96 /**
97 * Called by emitCode() when the XP will perform a dst read. This method only needs to supply
98 * the blending logic. The base class applies coverage. A subclass only needs to implement this
99 * method if it can construct a GrXferProcessor that reads the dst color.
100 */
egdaniel7ea439b2015-12-03 09:20:44 -0800101 virtual void emitBlendCodeForDstRead(GrGLSLXPFragmentBuilder*,
102 GrGLSLUniformHandler*,
egdaniel8dcdedc2015-11-11 06:27:20 -0800103 const char* srcColor,
egdanielf34b2932015-12-01 13:54:06 -0800104 const char* srcCoverage,
egdaniel8dcdedc2015-11-11 06:27:20 -0800105 const char* dstColor,
106 const char* outColor,
egdanielf34b2932015-12-01 13:54:06 -0800107 const char* outColorSecondary,
egdaniel8dcdedc2015-11-11 06:27:20 -0800108 const GrXferProcessor&) {
cdaltonedbb31f2015-06-08 12:14:44 -0700109 SkFAIL("emitBlendCodeForDstRead not implemented.");
110 }
bsalomon50785a32015-02-06 07:02:37 -0800111
egdaniel018fb622015-10-28 07:26:40 -0700112 virtual void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) = 0;
bsalomon50785a32015-02-06 07:02:37 -0800113
egdaniel018fb622015-10-28 07:26:40 -0700114 GrGLSLProgramDataManager::UniformHandle fDstTopLeftUni;
115 GrGLSLProgramDataManager::UniformHandle fDstScaleUni;
egdanielc2304142014-12-11 13:15:13 -0800116};
117#endif