Flutter Engine
The Flutter Engine
GrGLSLBlend.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 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
10#include "include/core/SkSpan.h"
14#include "src/gpu/Blend.h"
16#include "src/sksl/SkSLString.h"
17
18namespace GrGLSLBlend {
19
20std::string BlendExpression(const GrProcessor* processor,
21 GrGLSLUniformHandler* uniformHandler,
22 GrGLSLProgramDataManager::UniformHandle* blendUniform,
23 const char* srcColor,
24 const char* dstColor,
27 if (info.fUniformData.empty()) {
28 return SkSL::String::printf("%s(%s, %s)", info.fFunction, srcColor, dstColor);
29 }
30
31 SkSLType skslType = (SkSLType)((int)SkSLType::kHalf + info.fUniformData.size() - 1);
32 SkASSERT(skslType >= SkSLType::kHalf && skslType <= SkSLType::kHalf4);
33
34 const char* blendUniName;
35 *blendUniform = uniformHandler->addUniform(processor, kFragment_GrShaderFlag,
36 skslType, "blend", &blendUniName);
37 return SkSL::String::printf("%s(%s, %s, %s)", info.fFunction, blendUniName, srcColor, dstColor);
38}
39
41 switch (mode) {
52 return -1;
53
58 return -2;
59
62 return -3;
63
66 return -4;
67
68 default:
69 return (int)mode;
70 }
71}
72
74 GrGLSLProgramDataManager::UniformHandle blendUniform,
77 switch (info.fUniformData.size()) {
78 case 0:
79 /* no uniform data necessary */
80 break;
81 case 1:
82 pdman.set1f(blendUniform, info.fUniformData[0]);
83 break;
84 case 2:
85 pdman.set2f(blendUniform, info.fUniformData[0], info.fUniformData[1]);
86 break;
87 case 3:
88 pdman.set3f(blendUniform, info.fUniformData[0], info.fUniformData[1],
89 info.fUniformData[2]);
90 break;
91 case 4:
92 pdman.set4f(blendUniform, info.fUniformData[0], info.fUniformData[1],
93 info.fUniformData[2], info.fUniformData[3]);
94 break;
95 }
96}
97
98} // namespace GrGLSLBlend
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
@ kFragment_GrShaderFlag
Definition: GrTypesPriv.h:287
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkBlendMode
Definition: SkBlendMode.h:38
@ kSrcOut
r = s * (1-da)
@ kSaturation
saturation of source with hue and luminosity of destination
@ kPlus
r = min(s + d, 1)
@ kLighten
rc = s + d - min(s*da, d*sa), ra = kSrcOver
@ kHue
hue of source with saturation and luminosity of destination
@ kDstIn
r = d * sa
@ kSrcOver
r = s + (1-sa)*d
@ kXor
r = s*(1-da) + d*(1-sa)
@ kLuminosity
luminosity of source with hue and saturation of destination
@ kOverlay
multiply or screen, depending on destination
@ kSrcATop
r = s*da + d*(1-sa)
@ kDstATop
r = d*sa + s*(1-da)
@ kDstOver
r = d + (1-da)*s
@ kColor
hue and saturation of source with luminosity of destination
@ kHardLight
multiply or screen, depending on source
@ kDstOut
r = d * (1-sa)
@ kDarken
rc = s + d - max(s*da, d*sa), ra = kSrcOver
@ kSrcIn
r = s * da
SkSLType
virtual void set2f(UniformHandle, float, float) const =0
virtual void set4f(UniformHandle, float, float, float, float) const =0
virtual void set3f(UniformHandle, float, float, float) const =0
virtual void set1f(UniformHandle, float v0) const =0
UniformHandle addUniform(const GrProcessor *owner, uint32_t visibility, SkSLType type, const char *name, const char **outName=nullptr)
std::string BlendExpression(const GrProcessor *processor, GrGLSLUniformHandler *uniformHandler, GrGLSLProgramDataManager::UniformHandle *blendUniform, const char *srcColor, const char *dstColor, SkBlendMode mode)
Definition: GrGLSLBlend.cpp:20
int BlendKey(SkBlendMode mode)
Definition: GrGLSLBlend.cpp:40
void SetBlendModeUniformData(const GrGLSLProgramDataManager &pdman, GrGLSLProgramDataManager::UniformHandle blendUniform, SkBlendMode mode)
Definition: GrGLSLBlend.cpp:73
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: SkSLString.cpp:83
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228
ReducedBlendModeInfo GetReducedBlendModeInfo(SkBlendMode mode)
Definition: Blend.cpp:86