blob: 90c1bce5b2d409cb74ffe2521999b70a899f568d [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"
Brian Salomonf9f45122016-11-29 11:59:17 -050012#include "glsl/GrGLSLUniformHandler.h"
egdanielc2304142014-12-11 13:15:13 -080013
bsalomon50785a32015-02-06 07:02:37 -080014class GrXferProcessor;
egdaniela2e3e0f2015-11-19 07:23:45 -080015class GrGLSLXPBuilder;
16class GrGLSLXPFragmentBuilder;
Brian Salomon94efbf52016-11-29 13:43:05 -050017class GrShaderCaps;
egdanielc2304142014-12-11 13:15:13 -080018
egdanielfa4cc8b2015-11-13 08:34:52 -080019class GrGLSLXferProcessor {
egdanielc2304142014-12-11 13:15:13 -080020public:
egdanielfa4cc8b2015-11-13 08:34:52 -080021 GrGLSLXferProcessor() {}
22 virtual ~GrGLSLXferProcessor() {}
egdanielc2304142014-12-11 13:15:13 -080023
Brian Salomonf9f45122016-11-29 11:59:17 -050024 using SamplerHandle = GrGLSLUniformHandler::SamplerHandle;
25 using ImageStorageHandle = GrGLSLUniformHandler::ImageStorageHandle;
egdaniel09aa1fc2016-04-20 07:09:46 -070026
egdanielc2304142014-12-11 13:15:13 -080027 struct EmitArgs {
egdaniel7ea439b2015-12-03 09:20:44 -080028 EmitArgs(GrGLSLXPFragmentBuilder* fragBuilder,
29 GrGLSLUniformHandler* uniformHandler,
Brian Salomon94efbf52016-11-29 13:43:05 -050030 const GrShaderCaps* 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,
Brian Salomonf9f45122016-11-29 11:59:17 -050038 const ImageStorageHandle* imageStorages,
ethannicholas22793252016-01-30 09:59:10 -080039 const bool usePLSDstRead)
egdaniel7ea439b2015-12-03 09:20:44 -080040 : fXPFragBuilder(fragBuilder)
41 , fUniformHandler(uniformHandler)
Brian Salomon1edc5b92016-11-29 13:43:46 -050042 , fShaderCaps(caps)
egdanielc2304142014-12-11 13:15:13 -080043 , fXP(xp)
44 , fInputColor(inputColor)
45 , fInputCoverage(inputCoverage)
46 , fOutputPrimary(outputPrimary)
47 , fOutputSecondary(outputSecondary)
cdalton3f6f76f2016-04-11 12:18:09 -070048 , fTexSamplers(texSamplers)
cdalton74b8d322016-04-11 14:47:28 -070049 , fBufferSamplers(bufferSamplers)
Brian Salomonf9f45122016-11-29 11:59:17 -050050 , fImageStorages(imageStorages)
ethannicholas22793252016-01-30 09:59:10 -080051 , fUsePLSDstRead(usePLSDstRead) {}
egdanielc2304142014-12-11 13:15:13 -080052
egdaniel4ca2e602015-11-18 08:01:26 -080053 GrGLSLXPFragmentBuilder* fXPFragBuilder;
egdaniel7ea439b2015-12-03 09:20:44 -080054 GrGLSLUniformHandler* fUniformHandler;
Brian Salomon1edc5b92016-11-29 13:43:46 -050055 const GrShaderCaps* fShaderCaps;
egdanielc2304142014-12-11 13:15:13 -080056 const GrXferProcessor& fXP;
57 const char* fInputColor;
58 const char* fInputCoverage;
59 const char* fOutputPrimary;
60 const char* fOutputSecondary;
egdaniel09aa1fc2016-04-20 07:09:46 -070061 const SamplerHandle* fTexSamplers;
62 const SamplerHandle* fBufferSamplers;
Brian Salomonf9f45122016-11-29 11:59:17 -050063 const ImageStorageHandle* fImageStorages;
ethannicholas22793252016-01-30 09:59:10 -080064 bool fUsePLSDstRead;
egdanielc2304142014-12-11 13:15:13 -080065 };
66 /**
67 * This is similar to emitCode() in the base class, except it takes a full shader builder.
68 * This allows the effect subclass to emit vertex code.
69 */
bsalomon50785a32015-02-06 07:02:37 -080070 void emitCode(const EmitArgs&);
egdanielc2304142014-12-11 13:15:13 -080071
egdanielfa4cc8b2015-11-13 08:34:52 -080072 /** A GrGLSLXferProcessor instance can be reused with any GrGLSLXferProcessor that produces
73 the same stage key; this function reads data from a GrGLSLXferProcessor and uploads any
egdanielc2304142014-12-11 13:15:13 -080074 uniform variables required by the shaders created in emitCode(). The GrXferProcessor
egdanielfa4cc8b2015-11-13 08:34:52 -080075 parameter is guaranteed to be of the same type that created this GrGLSLXferProcessor and
76 to have an identical processor key as the one that created this GrGLSLXferProcessor. This
77 function calls onSetData on the subclass of GrGLSLXferProcessor
bsalomon50785a32015-02-06 07:02:37 -080078 */
egdaniel018fb622015-10-28 07:26:40 -070079 void setData(const GrGLSLProgramDataManager& pdm, const GrXferProcessor& xp);
bsalomon50785a32015-02-06 07:02:37 -080080
robertphillips727b7d22016-01-26 12:07:13 -080081protected:
82 static void DefaultCoverageModulation(GrGLSLXPFragmentBuilder* fragBuilder,
83 const char* srcCoverage,
84 const char* dstColor,
85 const char* outColor,
86 const char* outColorSecondary,
87 const GrXferProcessor& proc);
robertphillipsf42fca42016-01-27 05:00:04 -080088
egdanielc2304142014-12-11 13:15:13 -080089private:
cdaltonedbb31f2015-06-08 12:14:44 -070090 /**
91 * Called by emitCode() when the XP will not be performing a dst read. This method is
92 * responsible for both blending and coverage. A subclass only needs to implement this method if
93 * it can construct a GrXferProcessor that will not read the dst color.
94 */
95 virtual void emitOutputsForBlendState(const EmitArgs&) {
96 SkFAIL("emitOutputsForBlendState not implemented.");
97 }
98
99 /**
100 * Called by emitCode() when the XP will perform a dst read. This method only needs to supply
101 * the blending logic. The base class applies coverage. A subclass only needs to implement this
102 * method if it can construct a GrXferProcessor that reads the dst color.
103 */
egdaniel7ea439b2015-12-03 09:20:44 -0800104 virtual void emitBlendCodeForDstRead(GrGLSLXPFragmentBuilder*,
105 GrGLSLUniformHandler*,
egdaniel8dcdedc2015-11-11 06:27:20 -0800106 const char* srcColor,
egdanielf34b2932015-12-01 13:54:06 -0800107 const char* srcCoverage,
egdaniel8dcdedc2015-11-11 06:27:20 -0800108 const char* dstColor,
109 const char* outColor,
egdanielf34b2932015-12-01 13:54:06 -0800110 const char* outColorSecondary,
egdaniel8dcdedc2015-11-11 06:27:20 -0800111 const GrXferProcessor&) {
cdaltonedbb31f2015-06-08 12:14:44 -0700112 SkFAIL("emitBlendCodeForDstRead not implemented.");
113 }
bsalomon50785a32015-02-06 07:02:37 -0800114
egdaniel018fb622015-10-28 07:26:40 -0700115 virtual void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) = 0;
bsalomon50785a32015-02-06 07:02:37 -0800116
egdaniel018fb622015-10-28 07:26:40 -0700117 GrGLSLProgramDataManager::UniformHandle fDstTopLeftUni;
118 GrGLSLProgramDataManager::UniformHandle fDstScaleUni;
egdanielc2304142014-12-11 13:15:13 -0800119};
120#endif