blob: 763fcfa87de677070574cb45f5df97735721c75e [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;
27 using ImageStorageHandle = GrGLSLUniformHandler::ImageStorageHandle;
egdaniel09aa1fc2016-04-20 07:09:46 -070028
egdanielc2304142014-12-11 13:15:13 -080029 struct EmitArgs {
egdaniel7ea439b2015-12-03 09:20:44 -080030 EmitArgs(GrGLSLXPFragmentBuilder* fragBuilder,
31 GrGLSLUniformHandler* uniformHandler,
Brian Salomon94efbf52016-11-29 13:43:05 -050032 const GrShaderCaps* caps,
egdanielc2304142014-12-11 13:15:13 -080033 const GrXferProcessor& xp,
34 const char* inputColor,
35 const char* inputCoverage,
36 const char* outputPrimary,
37 const char* outputSecondary,
Brian Salomon18dfa982017-04-03 16:57:43 -040038 const SamplerHandle dstTextureSamplerHandle,
39 GrSurfaceOrigin dstTextureOrigin)
Brian Salomon42c456f2017-03-06 11:29:48 -050040 : fXPFragBuilder(fragBuilder)
41 , fUniformHandler(uniformHandler)
42 , fShaderCaps(caps)
43 , fXP(xp)
44 , fInputColor(inputColor)
45 , fInputCoverage(inputCoverage)
46 , fOutputPrimary(outputPrimary)
47 , fOutputSecondary(outputSecondary)
Brian Salomon18dfa982017-04-03 16:57:43 -040048 , fDstTextureSamplerHandle(dstTextureSamplerHandle)
49 , fDstTextureOrigin(dstTextureOrigin) {}
egdaniel4ca2e602015-11-18 08:01:26 -080050 GrGLSLXPFragmentBuilder* fXPFragBuilder;
egdaniel7ea439b2015-12-03 09:20:44 -080051 GrGLSLUniformHandler* fUniformHandler;
Brian Salomon1edc5b92016-11-29 13:43:46 -050052 const GrShaderCaps* fShaderCaps;
egdanielc2304142014-12-11 13:15:13 -080053 const GrXferProcessor& fXP;
54 const char* fInputColor;
55 const char* fInputCoverage;
56 const char* fOutputPrimary;
57 const char* fOutputSecondary;
Brian Salomon18dfa982017-04-03 16:57:43 -040058 const SamplerHandle fDstTextureSamplerHandle;
59 GrSurfaceOrigin fDstTextureOrigin;
egdanielc2304142014-12-11 13:15:13 -080060 };
61 /**
62 * This is similar to emitCode() in the base class, except it takes a full shader builder.
63 * This allows the effect subclass to emit vertex code.
64 */
bsalomon50785a32015-02-06 07:02:37 -080065 void emitCode(const EmitArgs&);
egdanielc2304142014-12-11 13:15:13 -080066
egdanielfa4cc8b2015-11-13 08:34:52 -080067 /** A GrGLSLXferProcessor instance can be reused with any GrGLSLXferProcessor that produces
68 the same stage key; this function reads data from a GrGLSLXferProcessor and uploads any
egdanielc2304142014-12-11 13:15:13 -080069 uniform variables required by the shaders created in emitCode(). The GrXferProcessor
egdanielfa4cc8b2015-11-13 08:34:52 -080070 parameter is guaranteed to be of the same type that created this GrGLSLXferProcessor and
71 to have an identical processor key as the one that created this GrGLSLXferProcessor. This
72 function calls onSetData on the subclass of GrGLSLXferProcessor
bsalomon50785a32015-02-06 07:02:37 -080073 */
Brian Salomon18dfa982017-04-03 16:57:43 -040074 void setData(const GrGLSLProgramDataManager& pdm, const GrXferProcessor& xp,
75 const GrTexture* dstTexture, const SkIPoint& dstTextureOffset);
bsalomon50785a32015-02-06 07:02:37 -080076
robertphillips727b7d22016-01-26 12:07:13 -080077protected:
78 static void DefaultCoverageModulation(GrGLSLXPFragmentBuilder* fragBuilder,
79 const char* srcCoverage,
80 const char* dstColor,
81 const char* outColor,
82 const char* outColorSecondary,
83 const GrXferProcessor& proc);
robertphillipsf42fca42016-01-27 05:00:04 -080084
egdanielc2304142014-12-11 13:15:13 -080085private:
cdaltonedbb31f2015-06-08 12:14:44 -070086 /**
87 * Called by emitCode() when the XP will not be performing a dst read. This method is
88 * responsible for both blending and coverage. A subclass only needs to implement this method if
89 * it can construct a GrXferProcessor that will not read the dst color.
90 */
91 virtual void emitOutputsForBlendState(const EmitArgs&) {
Ben Wagnerb4aab9a2017-08-16 10:53:04 -040092 SK_ABORT("emitOutputsForBlendState not implemented.");
cdaltonedbb31f2015-06-08 12:14:44 -070093 }
94
95 /**
96 * Called by emitCode() when the XP will perform a dst read. This method only needs to supply
97 * the blending logic. The base class applies coverage. A subclass only needs to implement this
98 * method if it can construct a GrXferProcessor that reads the dst color.
99 */
egdaniel7ea439b2015-12-03 09:20:44 -0800100 virtual void emitBlendCodeForDstRead(GrGLSLXPFragmentBuilder*,
101 GrGLSLUniformHandler*,
egdaniel8dcdedc2015-11-11 06:27:20 -0800102 const char* srcColor,
egdanielf34b2932015-12-01 13:54:06 -0800103 const char* srcCoverage,
egdaniel8dcdedc2015-11-11 06:27:20 -0800104 const char* dstColor,
105 const char* outColor,
egdanielf34b2932015-12-01 13:54:06 -0800106 const char* outColorSecondary,
egdaniel8dcdedc2015-11-11 06:27:20 -0800107 const GrXferProcessor&) {
Ben Wagnerb4aab9a2017-08-16 10:53:04 -0400108 SK_ABORT("emitBlendCodeForDstRead not implemented.");
cdaltonedbb31f2015-06-08 12:14:44 -0700109 }
bsalomon50785a32015-02-06 07:02:37 -0800110
egdaniel018fb622015-10-28 07:26:40 -0700111 virtual void onSetData(const GrGLSLProgramDataManager&, const GrXferProcessor&) = 0;
bsalomon50785a32015-02-06 07:02:37 -0800112
egdaniel018fb622015-10-28 07:26:40 -0700113 GrGLSLProgramDataManager::UniformHandle fDstTopLeftUni;
114 GrGLSLProgramDataManager::UniformHandle fDstScaleUni;
egdanielc2304142014-12-11 13:15:13 -0800115};
116#endif