blob: b2f018e0aad01af5ea2e36f210f79d479f1af834 [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
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/core/SkPoint.h"
12#include "src/gpu/glsl/GrGLSLProgramDataManager.h"
13#include "src/gpu/glsl/GrGLSLUniformHandler.h"
egdanielc2304142014-12-11 13:15:13 -080014
bsalomon50785a32015-02-06 07:02:37 -080015class GrXferProcessor;
egdaniela2e3e0f2015-11-19 07:23:45 -080016class GrGLSLXPBuilder;
17class GrGLSLXPFragmentBuilder;
Brian Salomon94efbf52016-11-29 13:43:05 -050018class GrShaderCaps;
Brian Salomon18dfa982017-04-03 16:57:43 -040019class GrTexture;
egdanielc2304142014-12-11 13:15:13 -080020
egdanielfa4cc8b2015-11-13 08:34:52 -080021class GrGLSLXferProcessor {
egdanielc2304142014-12-11 13:15:13 -080022public:
egdanielfa4cc8b2015-11-13 08:34:52 -080023 GrGLSLXferProcessor() {}
24 virtual ~GrGLSLXferProcessor() {}
egdanielc2304142014-12-11 13:15:13 -080025
Brian Salomon18dfa982017-04-03 16:57:43 -040026 using SamplerHandle = GrGLSLUniformHandler::SamplerHandle;
egdaniel09aa1fc2016-04-20 07:09:46 -070027
egdanielc2304142014-12-11 13:15:13 -080028 struct EmitArgs {
egdaniel7ea439b2015-12-03 09:20:44 -080029 EmitArgs(GrGLSLXPFragmentBuilder* fragBuilder,
30 GrGLSLUniformHandler* uniformHandler,
Brian Salomon94efbf52016-11-29 13:43:05 -050031 const GrShaderCaps* caps,
egdanielc2304142014-12-11 13:15:13 -080032 const GrXferProcessor& xp,
33 const char* inputColor,
34 const char* inputCoverage,
35 const char* outputPrimary,
36 const char* outputSecondary,
Brian Salomon18dfa982017-04-03 16:57:43 -040037 const SamplerHandle dstTextureSamplerHandle,
Chris Dalton6b76df02019-04-08 11:01:34 -060038 GrSurfaceOrigin dstTextureOrigin,
39 uint16_t outputSwizzleKey)
Brian Salomon42c456f2017-03-06 11:29:48 -050040 : fXPFragBuilder(fragBuilder)
41 , fUniformHandler(uniformHandler)
42 , fShaderCaps(caps)
43 , fXP(xp)
Michael Ludwig231de032018-08-30 14:33:01 -040044 , fInputColor(inputColor ? inputColor : "half4(1.0)")
Brian Salomon42c456f2017-03-06 11:29:48 -050045 , fInputCoverage(inputCoverage)
46 , fOutputPrimary(outputPrimary)
47 , fOutputSecondary(outputSecondary)
Brian Salomon18dfa982017-04-03 16:57:43 -040048 , fDstTextureSamplerHandle(dstTextureSamplerHandle)
Chris Dalton6b76df02019-04-08 11:01:34 -060049 , fDstTextureOrigin(dstTextureOrigin) {
50 fOutputSwizzle.setFromKey(outputSwizzleKey);
51 }
egdaniel4ca2e602015-11-18 08:01:26 -080052 GrGLSLXPFragmentBuilder* fXPFragBuilder;
egdaniel7ea439b2015-12-03 09:20:44 -080053 GrGLSLUniformHandler* fUniformHandler;
Brian Salomon1edc5b92016-11-29 13:43:46 -050054 const GrShaderCaps* fShaderCaps;
egdanielc2304142014-12-11 13:15:13 -080055 const GrXferProcessor& fXP;
56 const char* fInputColor;
57 const char* fInputCoverage;
58 const char* fOutputPrimary;
59 const char* fOutputSecondary;
Brian Salomon18dfa982017-04-03 16:57:43 -040060 const SamplerHandle fDstTextureSamplerHandle;
61 GrSurfaceOrigin fDstTextureOrigin;
Chris Dalton6b76df02019-04-08 11:01:34 -060062 GrSwizzle fOutputSwizzle;
egdanielc2304142014-12-11 13:15:13 -080063 };
64 /**
65 * This is similar to emitCode() in the base class, except it takes a full shader builder.
66 * This allows the effect subclass to emit vertex code.
67 */
bsalomon50785a32015-02-06 07:02:37 -080068 void emitCode(const EmitArgs&);
egdanielc2304142014-12-11 13:15:13 -080069
egdanielfa4cc8b2015-11-13 08:34:52 -080070 /** A GrGLSLXferProcessor instance can be reused with any GrGLSLXferProcessor that produces
71 the same stage key; this function reads data from a GrGLSLXferProcessor and uploads any
egdanielc2304142014-12-11 13:15:13 -080072 uniform variables required by the shaders created in emitCode(). The GrXferProcessor
egdanielfa4cc8b2015-11-13 08:34:52 -080073 parameter is guaranteed to be of the same type that created this GrGLSLXferProcessor and
74 to have an identical processor key as the one that created this GrGLSLXferProcessor. This
75 function calls onSetData on the subclass of GrGLSLXferProcessor
bsalomon50785a32015-02-06 07:02:37 -080076 */
Brian Salomon18dfa982017-04-03 16:57:43 -040077 void setData(const GrGLSLProgramDataManager& pdm, const GrXferProcessor& xp,
78 const GrTexture* dstTexture, const SkIPoint& dstTextureOffset);
bsalomon50785a32015-02-06 07:02:37 -080079
robertphillips727b7d22016-01-26 12:07:13 -080080protected:
81 static void DefaultCoverageModulation(GrGLSLXPFragmentBuilder* fragBuilder,
82 const char* srcCoverage,
83 const char* dstColor,
84 const char* outColor,
85 const char* outColorSecondary,
86 const GrXferProcessor& proc);
robertphillipsf42fca42016-01-27 05:00:04 -080087
egdanielc2304142014-12-11 13:15:13 -080088private:
cdaltonedbb31f2015-06-08 12:14:44 -070089 /**
90 * Called by emitCode() when the XP will not be performing a dst read. This method is
91 * responsible for both blending and coverage. A subclass only needs to implement this method if
92 * it can construct a GrXferProcessor that will not read the dst color.
93 */
94 virtual void emitOutputsForBlendState(const EmitArgs&) {
Ben Wagnerb4aab9a2017-08-16 10:53:04 -040095 SK_ABORT("emitOutputsForBlendState not implemented.");
cdaltonedbb31f2015-06-08 12:14:44 -070096 }
97
98 /**
99 * Called by emitCode() when the XP will perform a dst read. This method only needs to supply
100 * the blending logic. The base class applies coverage. A subclass only needs to implement this
101 * method if it can construct a GrXferProcessor that reads the dst color.
102 */
egdaniel7ea439b2015-12-03 09:20:44 -0800103 virtual void emitBlendCodeForDstRead(GrGLSLXPFragmentBuilder*,
104 GrGLSLUniformHandler*,
egdaniel8dcdedc2015-11-11 06:27:20 -0800105 const char* srcColor,
egdanielf34b2932015-12-01 13:54:06 -0800106 const char* srcCoverage,
egdaniel8dcdedc2015-11-11 06:27:20 -0800107 const char* dstColor,
108 const char* outColor,
egdanielf34b2932015-12-01 13:54:06 -0800109 const char* outColorSecondary,
egdaniel8dcdedc2015-11-11 06:27:20 -0800110 const GrXferProcessor&) {
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400111 SK_ABORT("emitBlendCodeForDstRead not implemented.");
cdaltonedbb31f2015-06-08 12:14:44 -0700112 }
bsalomon50785a32015-02-06 07:02:37 -0800113
Chris Dalton6b76df02019-04-08 11:01:34 -0600114 virtual void emitOutputSwizzle(GrGLSLXPFragmentBuilder*,
115 const GrSwizzle&,
116 const char* outColor,
117 const char* outColorSecondary) const;
118
egdaniel018fb622015-10-28 07:26:40 -0700119 virtual void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) = 0;
bsalomon50785a32015-02-06 07:02:37 -0800120
egdaniel018fb622015-10-28 07:26:40 -0700121 GrGLSLProgramDataManager::UniformHandle fDstTopLeftUni;
122 GrGLSLProgramDataManager::UniformHandle fDstScaleUni;
egdanielc2304142014-12-11 13:15:13 -0800123};
124#endif