blob: 465e2a7f9c707f3ec631f14f95d23a70bc6e9063 [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
Brian Salomon18dfa982017-04-03 16:57:43 -040011#include "SkPoint.h"
egdaniel018fb622015-10-28 07:26:40 -070012#include "glsl/GrGLSLProgramDataManager.h"
Brian Salomonf9f45122016-11-29 11:59:17 -050013#include "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,
38 GrSurfaceOrigin dstTextureOrigin)
Brian Salomon42c456f2017-03-06 11:29:48 -050039 : fXPFragBuilder(fragBuilder)
40 , fUniformHandler(uniformHandler)
41 , fShaderCaps(caps)
42 , fXP(xp)
Michael Ludwig231de032018-08-30 14:33:01 -040043 , fInputColor(inputColor ? inputColor : "half4(1.0)")
Brian Salomon42c456f2017-03-06 11:29:48 -050044 , fInputCoverage(inputCoverage)
45 , fOutputPrimary(outputPrimary)
46 , fOutputSecondary(outputSecondary)
Brian Salomon18dfa982017-04-03 16:57:43 -040047 , fDstTextureSamplerHandle(dstTextureSamplerHandle)
48 , fDstTextureOrigin(dstTextureOrigin) {}
egdaniel4ca2e602015-11-18 08:01:26 -080049 GrGLSLXPFragmentBuilder* fXPFragBuilder;
egdaniel7ea439b2015-12-03 09:20:44 -080050 GrGLSLUniformHandler* fUniformHandler;
Brian Salomon1edc5b92016-11-29 13:43:46 -050051 const GrShaderCaps* fShaderCaps;
egdanielc2304142014-12-11 13:15:13 -080052 const GrXferProcessor& fXP;
53 const char* fInputColor;
54 const char* fInputCoverage;
55 const char* fOutputPrimary;
56 const char* fOutputSecondary;
Brian Salomon18dfa982017-04-03 16:57:43 -040057 const SamplerHandle fDstTextureSamplerHandle;
58 GrSurfaceOrigin fDstTextureOrigin;
egdanielc2304142014-12-11 13:15:13 -080059 };
60 /**
61 * This is similar to emitCode() in the base class, except it takes a full shader builder.
62 * This allows the effect subclass to emit vertex code.
63 */
bsalomon50785a32015-02-06 07:02:37 -080064 void emitCode(const EmitArgs&);
egdanielc2304142014-12-11 13:15:13 -080065
egdanielfa4cc8b2015-11-13 08:34:52 -080066 /** A GrGLSLXferProcessor instance can be reused with any GrGLSLXferProcessor that produces
67 the same stage key; this function reads data from a GrGLSLXferProcessor and uploads any
egdanielc2304142014-12-11 13:15:13 -080068 uniform variables required by the shaders created in emitCode(). The GrXferProcessor
egdanielfa4cc8b2015-11-13 08:34:52 -080069 parameter is guaranteed to be of the same type that created this GrGLSLXferProcessor and
70 to have an identical processor key as the one that created this GrGLSLXferProcessor. This
71 function calls onSetData on the subclass of GrGLSLXferProcessor
bsalomon50785a32015-02-06 07:02:37 -080072 */
Brian Salomon18dfa982017-04-03 16:57:43 -040073 void setData(const GrGLSLProgramDataManager& pdm, const GrXferProcessor& xp,
74 const GrTexture* dstTexture, const SkIPoint& dstTextureOffset);
bsalomon50785a32015-02-06 07:02:37 -080075
robertphillips727b7d22016-01-26 12:07:13 -080076protected:
77 static void DefaultCoverageModulation(GrGLSLXPFragmentBuilder* fragBuilder,
78 const char* srcCoverage,
79 const char* dstColor,
80 const char* outColor,
81 const char* outColorSecondary,
82 const GrXferProcessor& proc);
robertphillipsf42fca42016-01-27 05:00:04 -080083
egdanielc2304142014-12-11 13:15:13 -080084private:
cdaltonedbb31f2015-06-08 12:14:44 -070085 /**
86 * Called by emitCode() when the XP will not be performing a dst read. This method is
87 * responsible for both blending and coverage. A subclass only needs to implement this method if
88 * it can construct a GrXferProcessor that will not read the dst color.
89 */
90 virtual void emitOutputsForBlendState(const EmitArgs&) {
Ben Wagnerb4aab9a2017-08-16 10:53:04 -040091 SK_ABORT("emitOutputsForBlendState not implemented.");
cdaltonedbb31f2015-06-08 12:14:44 -070092 }
93
94 /**
95 * Called by emitCode() when the XP will perform a dst read. This method only needs to supply
96 * the blending logic. The base class applies coverage. A subclass only needs to implement this
97 * method if it can construct a GrXferProcessor that reads the dst color.
98 */
egdaniel7ea439b2015-12-03 09:20:44 -080099 virtual void emitBlendCodeForDstRead(GrGLSLXPFragmentBuilder*,
100 GrGLSLUniformHandler*,
egdaniel8dcdedc2015-11-11 06:27:20 -0800101 const char* srcColor,
egdanielf34b2932015-12-01 13:54:06 -0800102 const char* srcCoverage,
egdaniel8dcdedc2015-11-11 06:27:20 -0800103 const char* dstColor,
104 const char* outColor,
egdanielf34b2932015-12-01 13:54:06 -0800105 const char* outColorSecondary,
egdaniel8dcdedc2015-11-11 06:27:20 -0800106 const GrXferProcessor&) {
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400107 SK_ABORT("emitBlendCodeForDstRead not implemented.");
cdaltonedbb31f2015-06-08 12:14:44 -0700108 }
bsalomon50785a32015-02-06 07:02:37 -0800109
egdaniel018fb622015-10-28 07:26:40 -0700110 virtual void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) = 0;
bsalomon50785a32015-02-06 07:02:37 -0800111
egdaniel018fb622015-10-28 07:26:40 -0700112 GrGLSLProgramDataManager::UniformHandle fDstTopLeftUni;
113 GrGLSLProgramDataManager::UniformHandle fDstScaleUni;
egdanielc2304142014-12-11 13:15:13 -0800114};
115#endif