Move BlendFuncName into shared code.

This will allow Graphite to use it.

Change-Id: I99cf9c18842031619aa1a008c9f35adbaaa5156b
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/532776
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2022-04-22 09:59:05 -04:00 committed by SkCQ
parent 56217f0722
commit 16eed2b89a
10 changed files with 77 additions and 47 deletions

View File

@ -805,6 +805,7 @@ skia_shared_gpu_sources = [
"$_include/gpu/ShaderErrorHandler.h",
"$_include/private/SingleOwner.h",
"$_src/gpu/AtlasTypes.h",
"$_src/gpu/Blend.cpp",
"$_src/gpu/Blend.h",
"$_src/gpu/BufferWriter.h",
"$_src/gpu/KeyBuilder.h",

View File

@ -5,6 +5,7 @@ licenses(["notice"])
cc_library(
name = "core_srcs",
deps = [
":Blend_src",
":RectanizerPow2_src",
":RectanizerSkyline_src",
":ResourceKey_src",
@ -184,3 +185,13 @@ generated_cc_atom(
visibility = ["//:__subpackages__"],
deps = ["//include/gpu:GrTypes_hdr"],
)
generated_cc_atom(
name = "Blend_src",
srcs = ["Blend.cpp"],
visibility = ["//:__subpackages__"],
deps = [
":Blend_hdr",
"//include/core:SkBlendMode_hdr",
],
)

49
src/gpu/Blend.cpp Normal file
View File

@ -0,0 +1,49 @@
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "src/gpu/Blend.h"
#include "include/core/SkBlendMode.h"
namespace skgpu {
const char* BlendFuncName(SkBlendMode mode) {
switch (mode) {
case SkBlendMode::kClear: return "blend_clear";
case SkBlendMode::kSrc: return "blend_src";
case SkBlendMode::kDst: return "blend_dst";
case SkBlendMode::kSrcOver: return "blend_src_over";
case SkBlendMode::kDstOver: return "blend_dst_over";
case SkBlendMode::kSrcIn: return "blend_src_in";
case SkBlendMode::kDstIn: return "blend_dst_in";
case SkBlendMode::kSrcOut: return "blend_src_out";
case SkBlendMode::kDstOut: return "blend_dst_out";
case SkBlendMode::kSrcATop: return "blend_src_atop";
case SkBlendMode::kDstATop: return "blend_dst_atop";
case SkBlendMode::kXor: return "blend_xor";
case SkBlendMode::kPlus: return "blend_plus";
case SkBlendMode::kModulate: return "blend_modulate";
case SkBlendMode::kScreen: return "blend_screen";
case SkBlendMode::kOverlay: return "blend_overlay";
case SkBlendMode::kDarken: return "blend_darken";
case SkBlendMode::kLighten: return "blend_lighten";
case SkBlendMode::kColorDodge: return "blend_color_dodge";
case SkBlendMode::kColorBurn: return "blend_color_burn";
case SkBlendMode::kHardLight: return "blend_hard_light";
case SkBlendMode::kSoftLight: return "blend_soft_light";
case SkBlendMode::kDifference: return "blend_difference";
case SkBlendMode::kExclusion: return "blend_exclusion";
case SkBlendMode::kMultiply: return "blend_multiply";
case SkBlendMode::kHue: return "blend_hue";
case SkBlendMode::kSaturation: return "blend_saturation";
case SkBlendMode::kColor: return "blend_color";
case SkBlendMode::kLuminosity: return "blend_luminosity";
}
SkUNREACHABLE;
}
} // namespace skgpu

View File

@ -1,4 +1,3 @@
/*
* Copyright 2013 Google Inc.
*
@ -11,6 +10,8 @@
#include "include/core/SkTypes.h"
enum class SkBlendMode;
namespace skgpu {
/**
@ -47,7 +48,6 @@ enum class BlendEquation : uint8_t {
static const int kBlendEquationCnt = static_cast<int>(BlendEquation::kLast) + 1;
/**
* Coefficients for alpha-blending.
*/
@ -163,6 +163,11 @@ static constexpr bool BlendAllowsCoverageAsAlpha(BlendEquation equation,
BlendCoeff::kISA == dstCoeff));
}
/**
* Returns the name of the SkSL built-in blend function for a SkBlendMode.
*/
const char* BlendFuncName(SkBlendMode mode);
} // namespace skgpu
#endif // skgpu_Blend_DEFINED

View File

@ -116,6 +116,7 @@ generated_cc_atom(
visibility = ["//:__subpackages__"],
deps = [
":GrBlendFragmentProcessor_hdr",
"//src/gpu:Blend_hdr",
"//src/gpu:KeyBuilder_hdr",
"//src/gpu/ganesh:GrFragmentProcessor_hdr",
"//src/gpu/ganesh:SkGr_hdr",

View File

@ -7,6 +7,7 @@
#include "src/gpu/ganesh/effects/GrBlendFragmentProcessor.h"
#include "src/gpu/Blend.h"
#include "src/gpu/KeyBuilder.h"
#include "src/gpu/ganesh/GrFragmentProcessor.h"
#include "src/gpu/ganesh/SkGr.h"
@ -229,7 +230,7 @@ std::unique_ptr<GrFragmentProcessor::ProgramImpl> BlendFragmentProcessor::onMake
} else {
// Blend src and dst colors together using a hardwired built-in blend function.
fragBuilder->codeAppendf("return %s(%s, %s);",
GrGLSLBlend::BlendFuncName(mode),
skgpu::BlendFuncName(mode),
srcColor.c_str(),
dstColor.c_str());
}

View File

@ -21,6 +21,7 @@ generated_cc_atom(
":GrGLSLFragmentShaderBuilder_hdr",
":GrGLSLProgramBuilder_hdr",
"//include/private:SkSLString_hdr",
"//src/gpu:Blend_hdr",
],
)
@ -145,11 +146,11 @@ generated_cc_atom(
srcs = ["GrGLSLShaderBuilder.cpp"],
visibility = ["//:__subpackages__"],
deps = [
":GrGLSLBlend_hdr",
":GrGLSLColorSpaceXformHelper_hdr",
":GrGLSLProgramBuilder_hdr",
":GrGLSLShaderBuilder_hdr",
"//include/sksl:DSL_hdr",
"//src/gpu:Blend_hdr",
"//src/gpu:Swizzle_hdr",
"//src/gpu/ganesh:GrShaderCaps_hdr",
"//src/gpu/ganesh:GrShaderVar_hdr",

View File

@ -6,47 +6,13 @@
*/
#include "include/private/SkSLString.h"
#include "src/gpu/Blend.h"
#include "src/gpu/ganesh/glsl/GrGLSLBlend.h"
#include "src/gpu/ganesh/glsl/GrGLSLFragmentShaderBuilder.h"
#include "src/gpu/ganesh/glsl/GrGLSLProgramBuilder.h"
namespace GrGLSLBlend {
const char* BlendFuncName(SkBlendMode mode) {
switch (mode) {
case SkBlendMode::kClear: return "blend_clear";
case SkBlendMode::kSrc: return "blend_src";
case SkBlendMode::kDst: return "blend_dst";
case SkBlendMode::kSrcOver: return "blend_src_over";
case SkBlendMode::kDstOver: return "blend_dst_over";
case SkBlendMode::kSrcIn: return "blend_src_in";
case SkBlendMode::kDstIn: return "blend_dst_in";
case SkBlendMode::kSrcOut: return "blend_src_out";
case SkBlendMode::kDstOut: return "blend_dst_out";
case SkBlendMode::kSrcATop: return "blend_src_atop";
case SkBlendMode::kDstATop: return "blend_dst_atop";
case SkBlendMode::kXor: return "blend_xor";
case SkBlendMode::kPlus: return "blend_plus";
case SkBlendMode::kModulate: return "blend_modulate";
case SkBlendMode::kScreen: return "blend_screen";
case SkBlendMode::kOverlay: return "blend_overlay";
case SkBlendMode::kDarken: return "blend_darken";
case SkBlendMode::kLighten: return "blend_lighten";
case SkBlendMode::kColorDodge: return "blend_color_dodge";
case SkBlendMode::kColorBurn: return "blend_color_burn";
case SkBlendMode::kHardLight: return "blend_hard_light";
case SkBlendMode::kSoftLight: return "blend_soft_light";
case SkBlendMode::kDifference: return "blend_difference";
case SkBlendMode::kExclusion: return "blend_exclusion";
case SkBlendMode::kMultiply: return "blend_multiply";
case SkBlendMode::kHue: return "blend_hue";
case SkBlendMode::kSaturation: return "blend_saturation";
case SkBlendMode::kColor: return "blend_color";
case SkBlendMode::kLuminosity: return "blend_luminosity";
}
SkUNREACHABLE;
}
std::string BlendExpression(const GrProcessor* processor,
GrGLSLUniformHandler* uniformHandler,
GrGLSLProgramDataManager::UniformHandle* blendUniform,
@ -97,7 +63,7 @@ std::string BlendExpression(const GrProcessor* processor,
}
default: {
return SkSL::String::printf("%s(%s, %s)",
BlendFuncName(mode), srcColor, dstColor);
skgpu::BlendFuncName(mode), srcColor, dstColor);
}
}
}

View File

@ -17,11 +17,6 @@ class GrProcessor;
namespace GrGLSLBlend {
/**
* Returns the name of the built in blend function for a SkBlendMode.
*/
const char* BlendFuncName(SkBlendMode mode);
/**
* Returns an SkSL expression that blends the passed-in srcColor and dstColor values.
* Matching calls to SetBlendModeUniformData and BlendKey must be made from your GrProcessor.

View File

@ -8,10 +8,10 @@
#include "src/gpu/ganesh/glsl/GrGLSLShaderBuilder.h"
#include "include/sksl/DSL.h"
#include "src/gpu/Blend.h"
#include "src/gpu/Swizzle.h"
#include "src/gpu/ganesh/GrShaderCaps.h"
#include "src/gpu/ganesh/GrShaderVar.h"
#include "src/gpu/ganesh/glsl/GrGLSLBlend.h"
#include "src/gpu/ganesh/glsl/GrGLSLColorSpaceXformHelper.h"
#include "src/gpu/ganesh/glsl/GrGLSLProgramBuilder.h"
#include "src/sksl/SkSLThreadContext.h"
@ -139,7 +139,7 @@ void GrGLSLShaderBuilder::appendTextureLookupAndBlend(
this->appendColorGamutXform(lookup.c_str(), colorXformHelper);
this->codeAppendf(" * %s)", dst);
} else {
this->codeAppendf("%s(", GrGLSLBlend::BlendFuncName(mode));
this->codeAppendf("%s(", skgpu::BlendFuncName(mode));
this->appendTextureLookup(&lookup, samplerHandle, coordName);
this->appendColorGamutXform(lookup.c_str(), colorXformHelper);
this->codeAppendf(", %s)", dst);