Flutter Engine
The Flutter Engine
GrGLSLFragmentShaderBuilder.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
8
12#include "src/gpu/Blend.h"
17
19 : GrGLSLShaderBuilder(program) {}
20
22 SkDEBUGCODE(fHasReadDstColorThisStage_DebugOnly = true;)
23
24 const GrShaderCaps* shaderCaps = fProgramBuilder->shaderCaps();
25 if (shaderCaps->fFBFetchSupport) {
27 shaderCaps->fFBFetchExtensionString);
28
29 // Some versions of this extension string require declaring custom color output on ES 3.0+
30 const char* fbFetchColorName = "sk_LastFragColor";
31 if (shaderCaps->fFBFetchNeedsCustomOutput) {
32 fPrimaryColorIsInOut = true;
33 fbFetchColorName = DeclaredColorOutputName();
34 // Set the dstColor to an intermediate variable so we don't override it with the output
35 this->codeAppendf("half4 %s = %s;", kDstColorName, fbFetchColorName);
36 } else {
37 return fbFetchColorName;
38 }
39 }
40 return kDstColorName;
41}
42
44 skgpu::BlendEquation equation) {
46
49 "GL_KHR_blend_equation_advanced");
50 this->addLayoutQualifier("blend_support_all_equations", kOut_InterfaceQualifier);
51 }
52}
53
54void GrGLSLFragmentShaderBuilder::enableSecondaryOutput() {
55 SkASSERT(!fHasSecondaryOutput);
56 fHasSecondaryOutput = true;
57 const GrShaderCaps& caps = *fProgramBuilder->shaderCaps();
58 if (const char* extension = caps.fSecondaryOutputExtensionString) {
60 }
61
62 // If the primary output is declared, we must declare also the secondary output
63 // and vice versa, since it is not allowed to use a built-in gl_FragColor and a custom
64 // output. The condition also co-incides with the condition in which GLSL ES 2.0
65 // requires the built-in gl_SecondaryFragColorEXT, whereas 3.0 requires a custom output.
67 fOutputs.emplace_back(DeclaredSecondaryColorOutputName(), SkSLType::kHalf4,
70 }
71}
72
73const char* GrGLSLFragmentShaderBuilder::getPrimaryColorOutputName() const {
74 return DeclaredColorOutputName();
75}
76
77bool GrGLSLFragmentShaderBuilder::primaryColorOutputIsInOut() const {
78 return fPrimaryColorIsInOut;
79}
80
81const char* GrGLSLFragmentShaderBuilder::getSecondaryColorOutputName() const {
82 if (this->hasSecondaryOutput()) {
84 ? DeclaredSecondaryColorOutputName()
85 : "sk_SecondaryFragColor";
86 }
87 return nullptr;
88}
89
90GrSurfaceOrigin GrGLSLFragmentShaderBuilder::getSurfaceOrigin() const {
91 return fProgramBuilder->origin();
92}
93
94void GrGLSLFragmentShaderBuilder::onFinalize() {
96}
GrSurfaceOrigin
Definition: GrTypes.h:147
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
void enableAdvancedBlendEquationIfNeeded(skgpu::BlendEquation) override
GrGLSLFragmentShaderBuilder(GrGLSLProgramBuilder *program)
virtual void finalizeFragmentSecondaryColor(GrShaderVar &outputColor)
const GrShaderCaps * shaderCaps() const
virtual GrGLSLVaryingHandler * varyingHandler()=0
GrSurfaceOrigin origin() const
void addLayoutQualifier(const char *param, InterfaceQualifier)
bool addFeature(uint32_t featureBit, const char *extensionName)
void codeAppendf(const char format[],...) SK_PRINTF_LIKE(2
GrGLSLProgramBuilder * fProgramBuilder
void getFragDecls(SkString *inputDecls, SkString *outputDecls) const
T & emplace_back(Args &&... args)
Definition: SkTBlockList.h:101
static constexpr bool BlendEquationIsAdvanced(BlendEquation equation)
Definition: Blend.h:129
BlendEquation
Definition: Blend.h:26
const char * fSecondaryOutputExtensionString
Definition: GrShaderCaps.h:64
bool mustDeclareFragmentShaderOutput() const
Definition: SkSLUtil.h:43
bool mustEnableAdvBlendEqs() const
Definition: SkSLUtil.h:39