[graphite] Push SkBackend into SkKeyHelpers
Bug: skia:12701 Change-Id: Ifa6b600b445a78f4ba936bf763adb2a5bf4d7542 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/496299 Reviewed-by: Michael Ludwig <michaelludwig@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
ef189dd340
commit
896d278a5c
@ -76,7 +76,7 @@ void Context::preCompile(const PaintCombo& paintCombo) {
|
||||
for (auto& shaderCombo: paintCombo.fShaders) {
|
||||
for (auto shaderType: shaderCombo.fTypes) {
|
||||
for (auto tm: shaderCombo.fTileModes) {
|
||||
SkPaintParamsKey key = CreateKey(shaderType, tm, bm);
|
||||
SkPaintParamsKey key = CreateKey(SkBackend::kGraphite, shaderType, tm, bm);
|
||||
|
||||
GraphicsPipelineDesc desc;
|
||||
|
||||
|
@ -235,7 +235,10 @@ std::tuple<SkUniquePaintParamsID, sk_sp<UniformData>> ExtractPaintData(Context*
|
||||
to_color4fs(gradInfo.fColorCount, colors, color4fs);
|
||||
expand_stops(gradInfo.fColorCount, offsets);
|
||||
|
||||
GradientShaderBlocks::AddToKey(&key, type, gradInfo.fTileMode);
|
||||
GradientShaderBlocks::AddToKey(SkBackend::kGraphite,
|
||||
&key,
|
||||
type,
|
||||
gradInfo.fTileMode);
|
||||
|
||||
uniforms = make_linear_gradient_uniform_data(gradInfo.fPoint[0],
|
||||
gradInfo.fPoint[1],
|
||||
@ -246,7 +249,10 @@ std::tuple<SkUniquePaintParamsID, sk_sp<UniformData>> ExtractPaintData(Context*
|
||||
to_color4fs(gradInfo.fColorCount, colors, color4fs);
|
||||
expand_stops(gradInfo.fColorCount, offsets);
|
||||
|
||||
GradientShaderBlocks::AddToKey(&key, type, gradInfo.fTileMode);
|
||||
GradientShaderBlocks::AddToKey(SkBackend::kGraphite,
|
||||
&key,
|
||||
type,
|
||||
gradInfo.fTileMode);
|
||||
|
||||
uniforms = make_radial_gradient_uniform_data(gradInfo.fPoint[0],
|
||||
gradInfo.fRadius[0],
|
||||
@ -257,7 +263,10 @@ std::tuple<SkUniquePaintParamsID, sk_sp<UniformData>> ExtractPaintData(Context*
|
||||
to_color4fs(gradInfo.fColorCount, colors, color4fs);
|
||||
expand_stops(gradInfo.fColorCount, offsets);
|
||||
|
||||
GradientShaderBlocks::AddToKey(&key, type, gradInfo.fTileMode);
|
||||
GradientShaderBlocks::AddToKey(SkBackend::kGraphite,
|
||||
&key,
|
||||
type,
|
||||
gradInfo.fTileMode);
|
||||
|
||||
uniforms = make_sweep_gradient_uniform_data(gradInfo.fPoint[0],
|
||||
color4fs,
|
||||
@ -267,7 +276,10 @@ std::tuple<SkUniquePaintParamsID, sk_sp<UniformData>> ExtractPaintData(Context*
|
||||
to_color4fs(gradInfo.fColorCount, colors, color4fs);
|
||||
expand_stops(gradInfo.fColorCount, offsets);
|
||||
|
||||
GradientShaderBlocks::AddToKey(&key, type, gradInfo.fTileMode);
|
||||
GradientShaderBlocks::AddToKey(SkBackend::kGraphite,
|
||||
&key,
|
||||
type,
|
||||
gradInfo.fTileMode);
|
||||
|
||||
uniforms = make_conical_gradient_uniform_data(gradInfo.fPoint[0],
|
||||
gradInfo.fPoint[1],
|
||||
@ -281,14 +293,14 @@ std::tuple<SkUniquePaintParamsID, sk_sp<UniformData>> ExtractPaintData(Context*
|
||||
// the paint color
|
||||
case SkShader::GradientType::kNone_GradientType:
|
||||
default:
|
||||
SolidColorShaderBlock::AddToKey(&key);
|
||||
SolidColorShaderBlock::AddToKey(SkBackend::kGraphite, &key);
|
||||
|
||||
uniforms = make_solid_uniform_data(p.color());
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// Solid colored paint
|
||||
SolidColorShaderBlock::AddToKey(&key);
|
||||
SolidColorShaderBlock::AddToKey(SkBackend::kGraphite, &key);
|
||||
|
||||
uniforms = make_solid_uniform_data(p.color());
|
||||
}
|
||||
@ -296,7 +308,7 @@ std::tuple<SkUniquePaintParamsID, sk_sp<UniformData>> ExtractPaintData(Context*
|
||||
if (p.blender()) {
|
||||
as_BB(p.blender())->addToKey(dict, SkBackend::kGraphite, &key);
|
||||
} else {
|
||||
BlendModeBlock::AddToKey(&key, SkBlendMode::kSrcOver);
|
||||
BlendModeBlock::AddToKey(SkBackend::kGraphite, &key, SkBlendMode::kSrcOver);
|
||||
}
|
||||
|
||||
auto entry = context->priv().shaderCodeDictionary()->findOrCreate(key);
|
||||
|
@ -47,13 +47,13 @@ void PaintParams::toKey(SkShaderCodeDictionary* dict,
|
||||
if (fShader) {
|
||||
as_SB(fShader)->addToKey(dict, backend, key);
|
||||
} else {
|
||||
SolidColorShaderBlock::AddToKey(key);
|
||||
SolidColorShaderBlock::AddToKey(backend, key);
|
||||
}
|
||||
|
||||
if (fBlender) {
|
||||
as_BB(fBlender)->addToKey(dict, backend, key);
|
||||
} else {
|
||||
BlendModeBlock::AddToKey(key, SkBlendMode::kSrcOver);
|
||||
BlendModeBlock::AddToKey(backend, key, SkBlendMode::kSrcOver);
|
||||
}
|
||||
|
||||
SkASSERT(key->sizeInBytes() > 0);
|
||||
|
@ -65,9 +65,9 @@ void SkBlenderBase::addToKey(SkShaderCodeDictionary* dict,
|
||||
SkPaintParamsKey* key) const {
|
||||
|
||||
if (skstd::optional<SkBlendMode> bm = as_BB(this)->asBlendMode(); bm.has_value()) {
|
||||
BlendModeBlock::AddToKey(key, bm.value());
|
||||
BlendModeBlock::AddToKey(backend, key, bm.value());
|
||||
} else {
|
||||
BlendModeBlock::AddToKey(key, SkBlendMode::kSrcOver);
|
||||
BlendModeBlock::AddToKey(backend, key, SkBlendMode::kSrcOver);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,9 +13,9 @@
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
namespace DepthStencilOnlyBlock {
|
||||
|
||||
void AddToKey(SkPaintParamsKey* key) {
|
||||
int blockIndex = key->beginBlock(CodeSnippetID::kDepthStencilOnlyDraw);
|
||||
key->endBlock(blockIndex, CodeSnippetID::kDepthStencilOnlyDraw);
|
||||
void AddToKey(SkBackend backend, SkPaintParamsKey* key) {
|
||||
int headerOffset = key->beginBlock(CodeSnippetID::kDepthStencilOnlyDraw);
|
||||
key->endBlock(headerOffset, CodeSnippetID::kDepthStencilOnlyDraw);
|
||||
}
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
@ -32,9 +32,9 @@ void Dump(const SkPaintParamsKey& key, int headerOffset) {
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
namespace SolidColorShaderBlock {
|
||||
|
||||
void AddToKey(SkPaintParamsKey* key) {
|
||||
int blockIndex = key->beginBlock(CodeSnippetID::kSolidColorShader);
|
||||
key->endBlock(blockIndex, CodeSnippetID::kSolidColorShader);
|
||||
void AddToKey(SkBackend backend, SkPaintParamsKey* key) {
|
||||
int headerOffset = key->beginBlock(CodeSnippetID::kSolidColorShader);
|
||||
key->endBlock(headerOffset, CodeSnippetID::kSolidColorShader);
|
||||
}
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
@ -51,34 +51,42 @@ void Dump(const SkPaintParamsKey& key, int headerOffset) {
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
namespace GradientShaderBlocks {
|
||||
|
||||
void AddToKey(SkPaintParamsKey *key, SkShader::GradientType type, SkTileMode tm) {
|
||||
void AddToKey(SkBackend backend,
|
||||
SkPaintParamsKey *key,
|
||||
SkShader::GradientType type,
|
||||
SkTileMode tm) {
|
||||
|
||||
CodeSnippetID id = CodeSnippetID::kSolidColorShader;
|
||||
switch (type) {
|
||||
case SkShader::kLinear_GradientType:
|
||||
id = CodeSnippetID::kLinearGradientShader;
|
||||
break;
|
||||
case SkShader::kRadial_GradientType:
|
||||
id = CodeSnippetID::kRadialGradientShader;
|
||||
break;
|
||||
case SkShader::kSweep_GradientType:
|
||||
id = CodeSnippetID::kSweepGradientShader;
|
||||
break;
|
||||
case SkShader::GradientType::kConical_GradientType:
|
||||
id = CodeSnippetID::kConicalGradientShader;
|
||||
break;
|
||||
case SkShader::GradientType::kColor_GradientType:
|
||||
case SkShader::GradientType::kNone_GradientType:
|
||||
default:
|
||||
SkASSERT(0);
|
||||
break;
|
||||
if (backend == SkBackend::kGraphite) {
|
||||
CodeSnippetID codeSnippetID = CodeSnippetID::kSolidColorShader;
|
||||
switch (type) {
|
||||
case SkShader::kLinear_GradientType:
|
||||
codeSnippetID = CodeSnippetID::kLinearGradientShader;
|
||||
break;
|
||||
case SkShader::kRadial_GradientType:
|
||||
codeSnippetID = CodeSnippetID::kRadialGradientShader;
|
||||
break;
|
||||
case SkShader::kSweep_GradientType:
|
||||
codeSnippetID = CodeSnippetID::kSweepGradientShader;
|
||||
break;
|
||||
case SkShader::GradientType::kConical_GradientType:
|
||||
codeSnippetID = CodeSnippetID::kConicalGradientShader;
|
||||
break;
|
||||
case SkShader::GradientType::kColor_GradientType:
|
||||
case SkShader::GradientType::kNone_GradientType:
|
||||
default:
|
||||
SkASSERT(0);
|
||||
break;
|
||||
}
|
||||
|
||||
int headerOffset = key->beginBlock(codeSnippetID);
|
||||
|
||||
key->addByte(static_cast<uint8_t>(tm));
|
||||
|
||||
key->endBlock(headerOffset, codeSnippetID);
|
||||
} else {
|
||||
// TODO: add implementation of other backends
|
||||
SolidColorShaderBlock::AddToKey(backend, key);
|
||||
}
|
||||
|
||||
int blockIndex = key->beginBlock(id);
|
||||
|
||||
key->addByte(static_cast<uint8_t>(tm));
|
||||
|
||||
key->endBlock(blockIndex, id);
|
||||
}
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
@ -125,12 +133,12 @@ void Dump(const SkPaintParamsKey& key, int headerOffset) {
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
namespace BlendModeBlock {
|
||||
|
||||
void AddToKey(SkPaintParamsKey *key, SkBlendMode bm) {
|
||||
int blockIndex = key->beginBlock(CodeSnippetID::kSimpleBlendMode);
|
||||
void AddToKey(SkBackend backend, SkPaintParamsKey *key, SkBlendMode bm) {
|
||||
int headerOffset = key->beginBlock(CodeSnippetID::kSimpleBlendMode);
|
||||
|
||||
key->addByte(static_cast<uint8_t>(bm));
|
||||
|
||||
key->endBlock(blockIndex, CodeSnippetID::kSimpleBlendMode);
|
||||
key->endBlock(headerOffset, CodeSnippetID::kSimpleBlendMode);
|
||||
}
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
@ -151,31 +159,34 @@ void Dump(const SkPaintParamsKey& key, int headerOffset) {
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
#ifdef SK_GRAPHITE_ENABLED
|
||||
SkPaintParamsKey CreateKey(skgpu::ShaderCombo::ShaderType s, SkTileMode tm, SkBlendMode bm) {
|
||||
SkPaintParamsKey CreateKey(SkBackend backend,
|
||||
skgpu::ShaderCombo::ShaderType s,
|
||||
SkTileMode tm,
|
||||
SkBlendMode bm) {
|
||||
SkPaintParamsKey key;
|
||||
|
||||
switch (s) {
|
||||
case skgpu::ShaderCombo::ShaderType::kNone:
|
||||
DepthStencilOnlyBlock::AddToKey(&key);
|
||||
DepthStencilOnlyBlock::AddToKey(backend, &key);
|
||||
break;
|
||||
case skgpu::ShaderCombo::ShaderType::kSolidColor:
|
||||
SolidColorShaderBlock::AddToKey(&key);
|
||||
SolidColorShaderBlock::AddToKey(backend, &key);
|
||||
break;
|
||||
case skgpu::ShaderCombo::ShaderType::kLinearGradient:
|
||||
GradientShaderBlocks::AddToKey(&key, SkShader::kLinear_GradientType, tm);
|
||||
GradientShaderBlocks::AddToKey(backend, &key, SkShader::kLinear_GradientType, tm);
|
||||
break;
|
||||
case skgpu::ShaderCombo::ShaderType::kRadialGradient:
|
||||
GradientShaderBlocks::AddToKey(&key, SkShader::kRadial_GradientType, tm);
|
||||
GradientShaderBlocks::AddToKey(backend, &key, SkShader::kRadial_GradientType, tm);
|
||||
break;
|
||||
case skgpu::ShaderCombo::ShaderType::kSweepGradient:
|
||||
GradientShaderBlocks::AddToKey(&key, SkShader::kSweep_GradientType, tm);
|
||||
GradientShaderBlocks::AddToKey(backend, &key, SkShader::kSweep_GradientType, tm);
|
||||
break;
|
||||
case skgpu::ShaderCombo::ShaderType::kConicalGradient:
|
||||
GradientShaderBlocks::AddToKey(&key, SkShader::kConical_GradientType, tm);
|
||||
GradientShaderBlocks::AddToKey(backend, &key, SkShader::kConical_GradientType, tm);
|
||||
break;
|
||||
}
|
||||
|
||||
BlendModeBlock::AddToKey(&key, bm);
|
||||
BlendModeBlock::AddToKey(backend, &key, bm);
|
||||
return key;
|
||||
}
|
||||
#endif
|
||||
|
@ -16,13 +16,14 @@
|
||||
#include "include/core/SkShader.h"
|
||||
#include "include/core/SkTileMode.h"
|
||||
|
||||
enum class SkBackend : uint8_t;
|
||||
class SkPaintParamsKey;
|
||||
|
||||
// The KeyHelpers can be used to manually construct an SkPaintParamsKey
|
||||
|
||||
namespace DepthStencilOnlyBlock {
|
||||
|
||||
void AddToKey(SkPaintParamsKey*);
|
||||
void AddToKey(SkBackend, SkPaintParamsKey*);
|
||||
#ifdef SK_DEBUG
|
||||
void Dump(const SkPaintParamsKey&, int headerOffset);
|
||||
#endif
|
||||
@ -31,7 +32,7 @@ namespace DepthStencilOnlyBlock {
|
||||
|
||||
namespace SolidColorShaderBlock {
|
||||
|
||||
void AddToKey(SkPaintParamsKey*);
|
||||
void AddToKey(SkBackend, SkPaintParamsKey*);
|
||||
#ifdef SK_DEBUG
|
||||
void Dump(const SkPaintParamsKey&, int headerOffset);
|
||||
#endif
|
||||
@ -41,7 +42,7 @@ namespace SolidColorShaderBlock {
|
||||
// TODO: move this functionality to the SkLinearGradient, SkRadialGradient, etc classes
|
||||
namespace GradientShaderBlocks {
|
||||
|
||||
void AddToKey(SkPaintParamsKey*, SkShader::GradientType, SkTileMode);
|
||||
void AddToKey(SkBackend, SkPaintParamsKey*, SkShader::GradientType, SkTileMode);
|
||||
#ifdef SK_DEBUG
|
||||
void Dump(const SkPaintParamsKey&, int headerOffset);
|
||||
#endif
|
||||
@ -50,7 +51,7 @@ namespace GradientShaderBlocks {
|
||||
|
||||
namespace BlendModeBlock {
|
||||
|
||||
void AddToKey(SkPaintParamsKey*, SkBlendMode);
|
||||
void AddToKey(SkBackend, SkPaintParamsKey*, SkBlendMode);
|
||||
#ifdef SK_DEBUG
|
||||
void Dump(const SkPaintParamsKey&, int headerOffset);
|
||||
#endif
|
||||
@ -59,7 +60,7 @@ namespace BlendModeBlock {
|
||||
|
||||
#ifdef SK_GRAPHITE_ENABLED
|
||||
// Bridge between the combinations system and the SkPaintParamsKey
|
||||
SkPaintParamsKey CreateKey(skgpu::ShaderCombo::ShaderType, SkTileMode, SkBlendMode);
|
||||
SkPaintParamsKey CreateKey(SkBackend, skgpu::ShaderCombo::ShaderType, SkTileMode, SkBlendMode);
|
||||
#endif
|
||||
|
||||
#endif // SkKeyHelpers_DEFINED
|
||||
|
@ -136,13 +136,13 @@ std::vector<SkPaintParamsKey> SkPaintPriv::ToKeys(const SkPaint& paint,
|
||||
if (paint.getShader()) {
|
||||
as_SB(paint.getShader())->addToKey(dict, backend, &key);
|
||||
} else {
|
||||
SolidColorShaderBlock::AddToKey(&key);
|
||||
SolidColorShaderBlock::AddToKey(backend, &key);
|
||||
}
|
||||
|
||||
if (paint.getBlender()) {
|
||||
as_BB(paint.getBlender())->addToKey(dict, backend, &key);
|
||||
} else {
|
||||
BlendModeBlock::AddToKey(&key, SkBlendMode::kSrcOver);
|
||||
BlendModeBlock::AddToKey(backend, &key, SkBlendMode::kSrcOver);
|
||||
}
|
||||
|
||||
SkASSERT(key.sizeInBytes() > 0);
|
||||
|
@ -153,7 +153,7 @@ SkUpdatableShader* SkShaderBase::onUpdatableShader(SkArenaAlloc* alloc) const {
|
||||
void SkShaderBase::addToKey(SkShaderCodeDictionary* dictionary,
|
||||
SkBackend backend,
|
||||
SkPaintParamsKey* key) const {
|
||||
SolidColorShaderBlock::AddToKey(key);
|
||||
SolidColorShaderBlock::AddToKey(backend, key);
|
||||
}
|
||||
|
||||
sk_sp<SkShader> SkShaders::Empty() { return sk_make_sp<SkEmptyShader>(); }
|
||||
|
@ -249,7 +249,8 @@ DEF_GRAPHITE_TEST_FOR_CONTEXTS(CommandBufferTest, reporter, context) {
|
||||
TextureInfo textureInfo;
|
||||
#endif
|
||||
|
||||
SkPaintParamsKey key = CreateKey(ShaderCombo::ShaderType::kSolidColor,
|
||||
SkPaintParamsKey key = CreateKey(SkBackend::kGraphite,
|
||||
ShaderCombo::ShaderType::kSolidColor,
|
||||
SkTileMode::kClamp,
|
||||
SkBlendMode::kSrc);
|
||||
|
||||
|
@ -83,7 +83,7 @@ DEF_GRAPHITE_TEST_FOR_CONTEXTS(UniformTest, reporter, context) {
|
||||
}
|
||||
|
||||
for (auto bm : { SkBlendMode::kSrc, SkBlendMode::kSrcOver }) {
|
||||
SkPaintParamsKey expected = CreateKey(s, tm, bm);
|
||||
SkPaintParamsKey expected = CreateKey(SkBackend::kGraphite, s, tm, bm);
|
||||
|
||||
auto [ p, expectedNumUniforms ] = create_paint(s, tm, bm);
|
||||
auto [ actualID, ud] = ExtractPaintData(context, PaintParams(p));
|
||||
|
Loading…
Reference in New Issue
Block a user