[graphite] Rearrange headers

There is no need for these headers to be in include/private:
SkPaintParamsKey.h
SkShaderCodeDictionary.h

Added the new header:
src/core/SkBuiltInCodeSnippetID.h

Bug: skia:12701
Change-Id: I413e9a21bc26d5df48765d16dd7390e324006368
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/505197
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2022-02-08 12:05:02 -05:00 committed by SkCQ
parent 77f1618a40
commit 61e7b64962
16 changed files with 157 additions and 126 deletions

View File

@ -19,8 +19,8 @@
#include "experimental/graphite/src/Renderer.h" #include "experimental/graphite/src/Renderer.h"
#include "experimental/graphite/src/ResourceProvider.h" #include "experimental/graphite/src/ResourceProvider.h"
#include "include/core/SkPathTypes.h" #include "include/core/SkPathTypes.h"
#include "include/private/SkShaderCodeDictionary.h"
#include "src/core/SkKeyHelpers.h" #include "src/core/SkKeyHelpers.h"
#include "src/core/SkShaderCodeDictionary.h"
#ifdef SK_METAL #ifdef SK_METAL
#include "experimental/graphite/src/mtl/MtlTrampoline.h" #include "experimental/graphite/src/mtl/MtlTrampoline.h"

View File

@ -12,10 +12,10 @@
#include "experimental/graphite/src/DrawTypes.h" #include "experimental/graphite/src/DrawTypes.h"
#include "experimental/graphite/src/PaintParams.h" #include "experimental/graphite/src/PaintParams.h"
#include "include/core/SkPaint.h" #include "include/core/SkPaint.h"
#include "include/private/SkShaderCodeDictionary.h"
#include "include/private/SkUniquePaintParamsID.h" #include "include/private/SkUniquePaintParamsID.h"
#include "src/core/SkBlenderBase.h" #include "src/core/SkBlenderBase.h"
#include "src/core/SkKeyHelpers.h" #include "src/core/SkKeyHelpers.h"
#include "src/core/SkShaderCodeDictionary.h"
#include "src/core/SkUniform.h" #include "src/core/SkUniform.h"
#include "src/core/SkUniformData.h" #include "src/core/SkUniformData.h"

View File

@ -7,7 +7,7 @@
#include "experimental/graphite/src/GlobalCache.h" #include "experimental/graphite/src/GlobalCache.h"
#include "include/private/SkShaderCodeDictionary.h" #include "src/core/SkShaderCodeDictionary.h"
namespace skgpu { namespace skgpu {
@ -16,4 +16,3 @@ GlobalCache::GlobalCache() : fShaderCodeDictionary(std::make_unique<SkShaderCode
GlobalCache::~GlobalCache() {}; GlobalCache::~GlobalCache() {};
} // namespace skgpu } // namespace skgpu

View File

@ -8,9 +8,9 @@
#include "experimental/graphite/src/PaintParams.h" #include "experimental/graphite/src/PaintParams.h"
#include "include/core/SkShader.h" #include "include/core/SkShader.h"
#include "include/private/SkPaintParamsKey.h"
#include "src/core/SkBlenderBase.h" #include "src/core/SkBlenderBase.h"
#include "src/core/SkKeyHelpers.h" #include "src/core/SkKeyHelpers.h"
#include "src/core/SkPaintParamsKey.h"
#include "src/shaders/SkShaderBase.h" #include "src/shaders/SkShaderBase.h"
namespace skgpu { namespace skgpu {

View File

@ -17,7 +17,7 @@
#include "include/core/SkSpan.h" #include "include/core/SkSpan.h"
#include "include/gpu/ShaderErrorHandler.h" #include "include/gpu/ShaderErrorHandler.h"
#include "include/private/SkSLString.h" #include "include/private/SkSLString.h"
#include "include/private/SkShaderCodeDictionary.h" #include "src/core/SkShaderCodeDictionary.h"
namespace skgpu::mtl { namespace skgpu::mtl {

View File

@ -142,6 +142,7 @@ skia_core_sources = [
"$_src/core/SkBlurMask.cpp", "$_src/core/SkBlurMask.cpp",
"$_src/core/SkBlurMask.h", "$_src/core/SkBlurMask.h",
"$_src/core/SkBuffer.cpp", "$_src/core/SkBuffer.cpp",
"$_src/core/SkBuiltInCodeSnippetID.h",
"$_src/core/SkCachedData.cpp", "$_src/core/SkCachedData.cpp",
"$_src/core/SkCanvas.cpp", "$_src/core/SkCanvas.cpp",
"$_src/core/SkCanvasPriv.cpp", "$_src/core/SkCanvasPriv.cpp",
@ -295,6 +296,7 @@ skia_core_sources = [
"$_src/core/SkPaint.cpp", "$_src/core/SkPaint.cpp",
"$_src/core/SkPaintDefaults.h", "$_src/core/SkPaintDefaults.h",
"$_src/core/SkPaintParamsKey.cpp", "$_src/core/SkPaintParamsKey.cpp",
"$_src/core/SkPaintParamsKey.h",
"$_src/core/SkPaintPriv.cpp", "$_src/core/SkPaintPriv.cpp",
"$_src/core/SkPaintPriv.h", "$_src/core/SkPaintPriv.h",
"$_src/core/SkPath.cpp", "$_src/core/SkPath.cpp",
@ -354,6 +356,7 @@ skia_core_sources = [
"$_src/core/SkScopeExit.h", "$_src/core/SkScopeExit.h",
"$_src/core/SkSemaphore.cpp", "$_src/core/SkSemaphore.cpp",
"$_src/core/SkShaderCodeDictionary.cpp", "$_src/core/SkShaderCodeDictionary.cpp",
"$_src/core/SkShaderCodeDictionary.h",
"$_src/core/SkSharedMutex.cpp", "$_src/core/SkSharedMutex.cpp",
"$_src/core/SkSharedMutex.h", "$_src/core/SkSharedMutex.h",
"$_src/core/SkSpecialImage.cpp", "$_src/core/SkSpecialImage.cpp",
@ -490,10 +493,8 @@ skia_core_sources = [
"$_include/private/SkNx_neon.h", "$_include/private/SkNx_neon.h",
"$_include/private/SkNx_sse.h", "$_include/private/SkNx_sse.h",
"$_include/private/SkOnce.h", "$_include/private/SkOnce.h",
"$_include/private/SkPaintParamsKey.h",
"$_include/private/SkPathRef.h", "$_include/private/SkPathRef.h",
"$_include/private/SkSemaphore.h", "$_include/private/SkSemaphore.h",
"$_include/private/SkShaderCodeDictionary.h",
"$_include/private/SkShadowFlags.h", "$_include/private/SkShadowFlags.h",
"$_include/private/SkSpinlock.h", "$_include/private/SkSpinlock.h",
"$_include/private/SkStringView.h", "$_include/private/SkStringView.h",

View File

@ -0,0 +1,36 @@
/*
* Copyright 2022 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkBuiltInCodeSnippetID_DEFINED
#define SkBuiltInCodeSnippetID_DEFINED
#include "include/core/SkTypes.h"
// TODO: this needs to be expanded into a more flexible dictionary (esp. for user-supplied SkSL)
enum class SkBuiltInCodeSnippetID : uint8_t {
// TODO: It seems like this requires some refinement. Fundamentally this doesn't seem like a
// draw that originated from a PaintParams.
kDepthStencilOnlyDraw,
// SkShader code snippets
kSolidColorShader,
kLinearGradientShader,
kRadialGradientShader,
kSweepGradientShader,
kConicalGradientShader,
kImageShader,
kBlendShader, // aka ComposeShader
// BlendMode code snippets
kSimpleBlendMode,
kLast = kSimpleBlendMode
};
static constexpr int kBuiltInCodeSnippetIDCount = static_cast<int>(SkBuiltInCodeSnippetID::kLast)+1;
#endif // SkBuiltInCodeSnippetID_DEFINED

View File

@ -7,9 +7,9 @@
#include "src/core/SkKeyHelpers.h" #include "src/core/SkKeyHelpers.h"
#include "include/private/SkPaintParamsKey.h"
#include "include/private/SkShaderCodeDictionary.h"
#include "src/core/SkDebugUtils.h" #include "src/core/SkDebugUtils.h"
#include "src/core/SkPaintParamsKey.h"
#include "src/core/SkShaderCodeDictionary.h"
#include "src/core/SkUniform.h" #include "src/core/SkUniform.h"
#include "src/core/SkUniformData.h" #include "src/core/SkUniformData.h"
#include "src/shaders/SkShaderBase.h" #include "src/shaders/SkShaderBase.h"
@ -21,18 +21,18 @@
namespace { namespace {
#if defined(SK_DEBUG) && defined(SK_GRAPHITE_ENABLED) #if defined(SK_DEBUG) && defined(SK_GRAPHITE_ENABLED)
CodeSnippetID read_code_snippet_id(const SkPaintParamsKey& key, int headerOffset) { SkBuiltInCodeSnippetID read_code_snippet_id(const SkPaintParamsKey& key, int headerOffset) {
uint8_t byte = key.byte(headerOffset); uint8_t byte = key.byte(headerOffset);
SkASSERT(byte <= static_cast<int>(CodeSnippetID::kLast)); SkASSERT(byte <= static_cast<int>(SkBuiltInCodeSnippetID::kLast));
return static_cast<CodeSnippetID>(byte); return static_cast<SkBuiltInCodeSnippetID>(byte);
} }
#endif #endif
// This can be used to catch errors in blocks that have a fixed, known block data size // This can be used to catch errors in blocks that have a fixed, known block data size
void validate_block_header(const SkPaintParamsKey& key, int headerOffset, void validate_block_header(const SkPaintParamsKey& key, int headerOffset,
CodeSnippetID codeSnippetID, int blockDataSize) { SkBuiltInCodeSnippetID codeSnippetID, int blockDataSize) {
SkASSERT(key.byte(headerOffset) == static_cast<int>(codeSnippetID)); SkASSERT(key.byte(headerOffset) == static_cast<int>(codeSnippetID));
SkASSERT(key.byte(headerOffset+SkPaintParamsKey::kBlockSizeOffsetInBytes) == SkASSERT(key.byte(headerOffset+SkPaintParamsKey::kBlockSizeOffsetInBytes) ==
SkPaintParamsKey::kBlockHeaderSizeInBytes + blockDataSize); SkPaintParamsKey::kBlockHeaderSizeInBytes + blockDataSize);
@ -69,17 +69,21 @@ void AddToKey(SkShaderCodeDictionary* /* dict */,
SkBackend /* backend */, SkBackend /* backend */,
SkPaintParamsKey* key, SkPaintParamsKey* key,
SkUniformBlock* /* uniformBlock */) { SkUniformBlock* /* uniformBlock */) {
int headerOffset = key->beginBlock(CodeSnippetID::kDepthStencilOnlyDraw); int headerOffset = key->beginBlock(SkBuiltInCodeSnippetID::kDepthStencilOnlyDraw);
key->endBlock(headerOffset, CodeSnippetID::kDepthStencilOnlyDraw); key->endBlock(headerOffset, SkBuiltInCodeSnippetID::kDepthStencilOnlyDraw);
validate_block_header(*key, headerOffset, validate_block_header(*key,
CodeSnippetID::kDepthStencilOnlyDraw, kBlockDataSize); headerOffset,
SkBuiltInCodeSnippetID::kDepthStencilOnlyDraw,
kBlockDataSize);
} }
#ifdef SK_DEBUG #ifdef SK_DEBUG
void Dump(const SkPaintParamsKey& key, int headerOffset) { void Dump(const SkPaintParamsKey& key, int headerOffset) {
validate_block_header(key, headerOffset, validate_block_header(key,
CodeSnippetID::kDepthStencilOnlyDraw, kBlockDataSize); headerOffset,
SkBuiltInCodeSnippetID::kDepthStencilOnlyDraw,
kBlockDataSize);
SkDebugf("kDepthStencilOnlyDraw\n"); SkDebugf("kDepthStencilOnlyDraw\n");
} }
@ -98,7 +102,7 @@ static const int kBlockDataSize = 0;
sk_sp<SkUniformData> make_solid_uniform_data(SkShaderCodeDictionary* dict, SkColor4f color) { sk_sp<SkUniformData> make_solid_uniform_data(SkShaderCodeDictionary* dict, SkColor4f color) {
static constexpr size_t kExpectedNumUniforms = 1; static constexpr size_t kExpectedNumUniforms = 1;
SkSpan<const SkUniform> uniforms = dict->getUniforms(CodeSnippetID::kSolidColorShader); SkSpan<const SkUniform> uniforms = dict->getUniforms(SkBuiltInCodeSnippetID::kSolidColorShader);
SkASSERT(uniforms.size() == kExpectedNumUniforms); SkASSERT(uniforms.size() == kExpectedNumUniforms);
skgpu::UniformManager mgr(skgpu::Layout::kMetal); skgpu::UniformManager mgr(skgpu::Layout::kMetal);
@ -124,11 +128,13 @@ void AddToKey(SkShaderCodeDictionary* dict,
#ifdef SK_GRAPHITE_ENABLED #ifdef SK_GRAPHITE_ENABLED
if (backend == SkBackend::kGraphite) { if (backend == SkBackend::kGraphite) {
int headerOffset = key->beginBlock(CodeSnippetID::kSolidColorShader); int headerOffset = key->beginBlock(SkBuiltInCodeSnippetID::kSolidColorShader);
key->endBlock(headerOffset, CodeSnippetID::kSolidColorShader); key->endBlock(headerOffset, SkBuiltInCodeSnippetID::kSolidColorShader);
validate_block_header(*key, headerOffset, validate_block_header(*key,
CodeSnippetID::kSolidColorShader, kBlockDataSize); headerOffset,
SkBuiltInCodeSnippetID::kSolidColorShader,
kBlockDataSize);
if (uniformBlock) { if (uniformBlock) {
uniformBlock->add(make_solid_uniform_data(dict, color)); uniformBlock->add(make_solid_uniform_data(dict, color));
@ -147,8 +153,10 @@ void AddToKey(SkShaderCodeDictionary* dict,
void Dump(const SkPaintParamsKey& key, int headerOffset) { void Dump(const SkPaintParamsKey& key, int headerOffset) {
#ifdef SK_GRAPHITE_ENABLED #ifdef SK_GRAPHITE_ENABLED
validate_block_header(key, headerOffset, validate_block_header(key,
CodeSnippetID::kSolidColorShader, kBlockDataSize); headerOffset,
SkBuiltInCodeSnippetID::kSolidColorShader,
kBlockDataSize);
SkDebugf("kSolidColorShader\n"); SkDebugf("kSolidColorShader\n");
#endif #endif
@ -185,7 +193,7 @@ sk_sp<SkUniformData> make_gradient_uniform_data_common(
sk_sp<SkUniformData> make_linear_gradient_uniform_data(SkShaderCodeDictionary* dict, sk_sp<SkUniformData> make_linear_gradient_uniform_data(SkShaderCodeDictionary* dict,
const GradientData& gradData) { const GradientData& gradData) {
SkSpan<const SkUniform> uniforms = dict->getUniforms(CodeSnippetID::kLinearGradientShader); auto uniforms = dict->getUniforms(SkBuiltInCodeSnippetID::kLinearGradientShader);
SkASSERT(uniforms.size() == kExpectedNumGradientUniforms); SkASSERT(uniforms.size() == kExpectedNumGradientUniforms);
const void* srcs[kExpectedNumGradientUniforms] = { const void* srcs[kExpectedNumGradientUniforms] = {
@ -203,7 +211,7 @@ sk_sp<SkUniformData> make_linear_gradient_uniform_data(SkShaderCodeDictionary* d
sk_sp<SkUniformData> make_radial_gradient_uniform_data(SkShaderCodeDictionary* dict, sk_sp<SkUniformData> make_radial_gradient_uniform_data(SkShaderCodeDictionary* dict,
const GradientData& gradData) { const GradientData& gradData) {
SkSpan<const SkUniform> uniforms = dict->getUniforms(CodeSnippetID::kRadialGradientShader); auto uniforms = dict->getUniforms(SkBuiltInCodeSnippetID::kRadialGradientShader);
SkASSERT(uniforms.size() == kExpectedNumGradientUniforms); SkASSERT(uniforms.size() == kExpectedNumGradientUniforms);
const void* srcs[kExpectedNumGradientUniforms] = { const void* srcs[kExpectedNumGradientUniforms] = {
@ -221,7 +229,7 @@ sk_sp<SkUniformData> make_radial_gradient_uniform_data(SkShaderCodeDictionary* d
sk_sp<SkUniformData> make_sweep_gradient_uniform_data(SkShaderCodeDictionary* dict, sk_sp<SkUniformData> make_sweep_gradient_uniform_data(SkShaderCodeDictionary* dict,
const GradientData& gradData) { const GradientData& gradData) {
SkSpan<const SkUniform> uniforms = dict->getUniforms(CodeSnippetID::kSweepGradientShader); auto uniforms = dict->getUniforms(SkBuiltInCodeSnippetID::kSweepGradientShader);
SkASSERT(uniforms.size() == kExpectedNumGradientUniforms); SkASSERT(uniforms.size() == kExpectedNumGradientUniforms);
const void* srcs[kExpectedNumGradientUniforms] = { const void* srcs[kExpectedNumGradientUniforms] = {
@ -239,7 +247,7 @@ sk_sp<SkUniformData> make_sweep_gradient_uniform_data(SkShaderCodeDictionary* di
sk_sp<SkUniformData> make_conical_gradient_uniform_data(SkShaderCodeDictionary* dict, sk_sp<SkUniformData> make_conical_gradient_uniform_data(SkShaderCodeDictionary* dict,
const GradientData& gradData) { const GradientData& gradData) {
SkSpan<const SkUniform> uniforms = dict->getUniforms(CodeSnippetID::kConicalGradientShader); auto uniforms = dict->getUniforms(SkBuiltInCodeSnippetID::kConicalGradientShader);
SkASSERT(uniforms.size() == kExpectedNumGradientUniforms); SkASSERT(uniforms.size() == kExpectedNumGradientUniforms);
const void* srcs[kExpectedNumGradientUniforms] = { const void* srcs[kExpectedNumGradientUniforms] = {
@ -311,28 +319,28 @@ void AddToKey(SkShaderCodeDictionary* dict,
#ifdef SK_GRAPHITE_ENABLED #ifdef SK_GRAPHITE_ENABLED
if (backend == SkBackend::kGraphite) { if (backend == SkBackend::kGraphite) {
CodeSnippetID codeSnippetID = CodeSnippetID::kSolidColorShader; SkBuiltInCodeSnippetID codeSnippetID = SkBuiltInCodeSnippetID::kSolidColorShader;
switch (gradData.fType) { switch (gradData.fType) {
case SkShader::kLinear_GradientType: case SkShader::kLinear_GradientType:
codeSnippetID = CodeSnippetID::kLinearGradientShader; codeSnippetID = SkBuiltInCodeSnippetID::kLinearGradientShader;
if (uniformBlock) { if (uniformBlock) {
uniformBlock->add(make_linear_gradient_uniform_data(dict, gradData)); uniformBlock->add(make_linear_gradient_uniform_data(dict, gradData));
} }
break; break;
case SkShader::kRadial_GradientType: case SkShader::kRadial_GradientType:
codeSnippetID = CodeSnippetID::kRadialGradientShader; codeSnippetID = SkBuiltInCodeSnippetID::kRadialGradientShader;
if (uniformBlock) { if (uniformBlock) {
uniformBlock->add(make_radial_gradient_uniform_data(dict, gradData)); uniformBlock->add(make_radial_gradient_uniform_data(dict, gradData));
} }
break; break;
case SkShader::kSweep_GradientType: case SkShader::kSweep_GradientType:
codeSnippetID = CodeSnippetID::kSweepGradientShader; codeSnippetID = SkBuiltInCodeSnippetID::kSweepGradientShader;
if (uniformBlock) { if (uniformBlock) {
uniformBlock->add(make_sweep_gradient_uniform_data(dict, gradData)); uniformBlock->add(make_sweep_gradient_uniform_data(dict, gradData));
} }
break; break;
case SkShader::GradientType::kConical_GradientType: case SkShader::GradientType::kConical_GradientType:
codeSnippetID = CodeSnippetID::kConicalGradientShader; codeSnippetID = SkBuiltInCodeSnippetID::kConicalGradientShader;
if (uniformBlock) { if (uniformBlock) {
uniformBlock->add(make_conical_gradient_uniform_data(dict, gradData)); uniformBlock->add(make_conical_gradient_uniform_data(dict, gradData));
} }
@ -366,14 +374,14 @@ void AddToKey(SkShaderCodeDictionary* dict,
#ifdef SK_GRAPHITE_ENABLED #ifdef SK_GRAPHITE_ENABLED
std::pair<CodeSnippetID, SkTileMode> ExtractFromKey(const SkPaintParamsKey& key, std::pair<SkBuiltInCodeSnippetID, SkTileMode> ExtractFromKey(const SkPaintParamsKey& key,
uint32_t headerOffset) { uint32_t headerOffset) {
CodeSnippetID id = read_code_snippet_id(key, headerOffset); SkBuiltInCodeSnippetID id = read_code_snippet_id(key, headerOffset);
SkASSERT(id == CodeSnippetID::kLinearGradientShader || SkASSERT(id == SkBuiltInCodeSnippetID::kLinearGradientShader ||
id == CodeSnippetID::kRadialGradientShader || id == SkBuiltInCodeSnippetID::kRadialGradientShader ||
id == CodeSnippetID::kSweepGradientShader || id == SkBuiltInCodeSnippetID::kSweepGradientShader ||
id == CodeSnippetID::kConicalGradientShader); id == SkBuiltInCodeSnippetID::kConicalGradientShader);
SkASSERT(key.byte(headerOffset+SkPaintParamsKey::kBlockSizeOffsetInBytes) == SkASSERT(key.byte(headerOffset+SkPaintParamsKey::kBlockSizeOffsetInBytes) ==
SkPaintParamsKey::kBlockHeaderSizeInBytes+kBlockDataSize); SkPaintParamsKey::kBlockHeaderSizeInBytes+kBlockDataSize);
@ -391,16 +399,16 @@ void Dump(const SkPaintParamsKey& key, int headerOffset) {
auto [id, tm] = ExtractFromKey(key, headerOffset); auto [id, tm] = ExtractFromKey(key, headerOffset);
switch (id) { switch (id) {
case CodeSnippetID::kLinearGradientShader: case SkBuiltInCodeSnippetID::kLinearGradientShader:
SkDebugf("kLinearGradientShader: %s\n", SkTileModeToStr(tm)); SkDebugf("kLinearGradientShader: %s\n", SkTileModeToStr(tm));
break; break;
case CodeSnippetID::kRadialGradientShader: case SkBuiltInCodeSnippetID::kRadialGradientShader:
SkDebugf("kRadialGradientShader: %s\n", SkTileModeToStr(tm)); SkDebugf("kRadialGradientShader: %s\n", SkTileModeToStr(tm));
break; break;
case CodeSnippetID::kSweepGradientShader: case SkBuiltInCodeSnippetID::kSweepGradientShader:
SkDebugf("kSweepGradientShader: %s\n", SkTileModeToStr(tm)); SkDebugf("kSweepGradientShader: %s\n", SkTileModeToStr(tm));
break; break;
case CodeSnippetID::kConicalGradientShader: case SkBuiltInCodeSnippetID::kConicalGradientShader:
SkDebugf("kConicalGradientShader: %s\n", SkTileModeToStr(tm)); SkDebugf("kConicalGradientShader: %s\n", SkTileModeToStr(tm));
break; break;
default: default:
@ -432,8 +440,10 @@ static const int kBlockDataSize = 1;
inline static constexpr int kTileModeMask = 0x3; inline static constexpr int kTileModeMask = 0x3;
ImageData ExtractFromKey(const SkPaintParamsKey& key, uint32_t headerOffset) { ImageData ExtractFromKey(const SkPaintParamsKey& key, uint32_t headerOffset) {
validate_block_header(key, headerOffset, validate_block_header(key,
CodeSnippetID::kImageShader, kBlockDataSize); headerOffset,
SkBuiltInCodeSnippetID::kImageShader,
kBlockDataSize);
uint8_t data = key.byte(headerOffset+SkPaintParamsKey::kBlockHeaderSizeInBytes); uint8_t data = key.byte(headerOffset+SkPaintParamsKey::kBlockHeaderSizeInBytes);
@ -448,7 +458,7 @@ sk_sp<SkUniformData> make_image_uniform_data(SkShaderCodeDictionary* dict,
const ImageData& imgData) { const ImageData& imgData) {
SkDEBUGCODE(static constexpr size_t kExpectedNumUniforms = 0;) SkDEBUGCODE(static constexpr size_t kExpectedNumUniforms = 0;)
SkSpan<const SkUniform> uniforms = dict->getUniforms(CodeSnippetID::kImageShader); SkSpan<const SkUniform> uniforms = dict->getUniforms(SkBuiltInCodeSnippetID::kImageShader);
SkASSERT(uniforms.size() == kExpectedNumUniforms); SkASSERT(uniforms.size() == kExpectedNumUniforms);
skgpu::UniformManager mgr(skgpu::Layout::kMetal); skgpu::UniformManager mgr(skgpu::Layout::kMetal);
@ -479,11 +489,11 @@ void AddToKey(SkShaderCodeDictionary* dict,
uint8_t data = (static_cast<uint8_t>(imgData.fTileModes[0]) << kXTileModeShift) | uint8_t data = (static_cast<uint8_t>(imgData.fTileModes[0]) << kXTileModeShift) |
(static_cast<uint8_t>(imgData.fTileModes[1]) << kYTileModeShift); (static_cast<uint8_t>(imgData.fTileModes[1]) << kYTileModeShift);
int headerOffset = key->beginBlock(CodeSnippetID::kImageShader); int headerOffset = key->beginBlock(SkBuiltInCodeSnippetID::kImageShader);
key->addByte(data); key->addByte(data);
key->endBlock(headerOffset, CodeSnippetID::kImageShader); key->endBlock(headerOffset, SkBuiltInCodeSnippetID::kImageShader);
SkASSERT(imgData == ExtractFromKey(*key, headerOffset)); SkASSERT(imgData == ExtractFromKey(*key, headerOffset));
@ -527,7 +537,7 @@ void AddToKey(SkShaderCodeDictionary* dict,
#ifdef SK_GRAPHITE_ENABLED #ifdef SK_GRAPHITE_ENABLED
if (backend == SkBackend::kGraphite) { if (backend == SkBackend::kGraphite) {
int headerOffset = key->beginBlock(CodeSnippetID::kBlendShader); int headerOffset = key->beginBlock(SkBuiltInCodeSnippetID::kBlendShader);
add_blendmode_to_key(key, blendData.fBM); add_blendmode_to_key(key, blendData.fBM);
int start = key->sizeInBytes(); int start = key->sizeInBytes();
@ -538,10 +548,13 @@ void AddToKey(SkShaderCodeDictionary* dict,
as_SB(blendData.fSrc)->addToKey(dict, backend, key, uniformBlock); as_SB(blendData.fSrc)->addToKey(dict, backend, key, uniformBlock);
int secondShaderSize = key->sizeInBytes() - start; int secondShaderSize = key->sizeInBytes() - start;
key->endBlock(headerOffset, CodeSnippetID::kBlendShader); key->endBlock(headerOffset, SkBuiltInCodeSnippetID::kBlendShader);
int expectedBlockSize = 1 + firstShaderSize + secondShaderSize; int expectedBlockSize = 1 + firstShaderSize + secondShaderSize;
validate_block_header(*key, headerOffset, CodeSnippetID::kBlendShader, expectedBlockSize); validate_block_header(*key,
headerOffset,
SkBuiltInCodeSnippetID::kBlendShader,
expectedBlockSize);
return; return;
} }
#endif // SK_GRAPHITE_ENABLED #endif // SK_GRAPHITE_ENABLED
@ -556,7 +569,7 @@ void AddToKey(SkShaderCodeDictionary* dict,
void Dump(const SkPaintParamsKey& key, int headerOffset) { void Dump(const SkPaintParamsKey& key, int headerOffset) {
#ifdef SK_GRAPHITE_ENABLED #ifdef SK_GRAPHITE_ENABLED
auto [id, storedBlockSize] = key.readCodeSnippetID(headerOffset); auto [id, storedBlockSize] = key.readCodeSnippetID(headerOffset);
SkASSERT(id == CodeSnippetID::kBlendShader); SkASSERT(id == SkBuiltInCodeSnippetID::kBlendShader);
int runningOffset = headerOffset + SkPaintParamsKey::kBlockHeaderSizeInBytes; int runningOffset = headerOffset + SkPaintParamsKey::kBlockHeaderSizeInBytes;
@ -597,12 +610,14 @@ void AddToKey(SkShaderCodeDictionary* dict,
#ifdef SK_GRAPHITE_ENABLED #ifdef SK_GRAPHITE_ENABLED
if (backend == SkBackend::kGraphite) { if (backend == SkBackend::kGraphite) {
int headerOffset = key->beginBlock(CodeSnippetID::kSimpleBlendMode); int headerOffset = key->beginBlock(SkBuiltInCodeSnippetID::kSimpleBlendMode);
add_blendmode_to_key(key, bm); add_blendmode_to_key(key, bm);
key->endBlock(headerOffset, CodeSnippetID::kSimpleBlendMode); key->endBlock(headerOffset, SkBuiltInCodeSnippetID::kSimpleBlendMode);
validate_block_header(*key, headerOffset, validate_block_header(*key,
CodeSnippetID::kSimpleBlendMode, kBlockDataSize); headerOffset,
SkBuiltInCodeSnippetID::kSimpleBlendMode,
kBlockDataSize);
return; return;
} }
#endif// SK_GRAPHITE_ENABLED #endif// SK_GRAPHITE_ENABLED
@ -617,7 +632,10 @@ void AddToKey(SkShaderCodeDictionary* dict,
#ifdef SK_GRAPHITE_ENABLED #ifdef SK_GRAPHITE_ENABLED
SkBlendMode ExtractFromKey(const SkPaintParamsKey& key, uint32_t headerOffset) { SkBlendMode ExtractFromKey(const SkPaintParamsKey& key, uint32_t headerOffset) {
validate_block_header(key, headerOffset, CodeSnippetID::kSimpleBlendMode, kBlockDataSize); validate_block_header(key,
headerOffset,
SkBuiltInCodeSnippetID::kSimpleBlendMode,
kBlockDataSize);
uint8_t data = key.byte(headerOffset + SkPaintParamsKey::kBlockHeaderSizeInBytes); uint8_t data = key.byte(headerOffset + SkPaintParamsKey::kBlockHeaderSizeInBytes);
return to_blendmode(data); return to_blendmode(data);

View File

@ -5,11 +5,11 @@
* found in the LICENSE file. * found in the LICENSE file.
*/ */
#include "include/private/SkPaintParamsKey.h" #include "src/core/SkPaintParamsKey.h"
#include <cstring> #include <cstring>
#include "include/private/SkShaderCodeDictionary.h"
#include "src/core/SkKeyHelpers.h" #include "src/core/SkKeyHelpers.h"
#include "src/core/SkShaderCodeDictionary.h"
bool SkPaintParamsKey::operator==(const SkPaintParamsKey& that) const { bool SkPaintParamsKey::operator==(const SkPaintParamsKey& that) const {
return fNumBytes == that.fNumBytes && return fNumBytes == that.fNumBytes &&
@ -29,25 +29,25 @@ void dump_unknown_block(const SkPaintParamsKey& key, int headerOffset) {
SkDebugf("Unknown block - id: %d size: %dB\n", id, blockSize); SkDebugf("Unknown block - id: %d size: %dB\n", id, blockSize);
} }
DumpMethod get_dump_method(CodeSnippetID id) { DumpMethod get_dump_method(SkBuiltInCodeSnippetID id) {
switch (id) { switch (id) {
case CodeSnippetID::kDepthStencilOnlyDraw: return DepthStencilOnlyBlock::Dump; case SkBuiltInCodeSnippetID::kDepthStencilOnlyDraw: return DepthStencilOnlyBlock::Dump;
// SkShader code snippets // SkShader code snippets
case CodeSnippetID::kSolidColorShader: return SolidColorShaderBlock::Dump; case SkBuiltInCodeSnippetID::kSolidColorShader: return SolidColorShaderBlock::Dump;
case CodeSnippetID::kLinearGradientShader: [[fallthrough]]; case SkBuiltInCodeSnippetID::kLinearGradientShader: [[fallthrough]];
case CodeSnippetID::kRadialGradientShader: [[fallthrough]]; case SkBuiltInCodeSnippetID::kRadialGradientShader: [[fallthrough]];
case CodeSnippetID::kSweepGradientShader: [[fallthrough]]; case SkBuiltInCodeSnippetID::kSweepGradientShader: [[fallthrough]];
case CodeSnippetID::kConicalGradientShader: return GradientShaderBlocks::Dump; case SkBuiltInCodeSnippetID::kConicalGradientShader: return GradientShaderBlocks::Dump;
case CodeSnippetID::kImageShader: return ImageShaderBlock::Dump; case SkBuiltInCodeSnippetID::kImageShader: return ImageShaderBlock::Dump;
case CodeSnippetID::kBlendShader: return BlendShaderBlock::Dump; case SkBuiltInCodeSnippetID::kBlendShader: return BlendShaderBlock::Dump;
// BlendMode code snippets // BlendMode code snippets
case CodeSnippetID::kSimpleBlendMode: return BlendModeBlock::Dump; case SkBuiltInCodeSnippetID::kSimpleBlendMode: return BlendModeBlock::Dump;
default: return dump_unknown_block; default: return dump_unknown_block;
} }
} }
@ -79,12 +79,12 @@ int SkPaintParamsKey::AddBlockToShaderInfo(SkShaderCodeDictionary* dict,
SkShaderInfo* result) { SkShaderInfo* result) {
auto [codeSnippetID, blockSize] = key.readCodeSnippetID(headerOffset); auto [codeSnippetID, blockSize] = key.readCodeSnippetID(headerOffset);
if (codeSnippetID != CodeSnippetID::kSimpleBlendMode) { if (codeSnippetID != SkBuiltInCodeSnippetID::kSimpleBlendMode) {
auto entry = dict->getEntry(codeSnippetID); auto entry = dict->getEntry(codeSnippetID);
result->add(*entry); result->add(*entry);
if (codeSnippetID != CodeSnippetID::kDepthStencilOnlyDraw) { if (codeSnippetID != SkBuiltInCodeSnippetID::kDepthStencilOnlyDraw) {
result->setWritesColor(); result->setWritesColor();
} }
} }

View File

@ -11,6 +11,7 @@
#include <array> #include <array>
#include <limits> #include <limits>
#include "include/core/SkTypes.h" #include "include/core/SkTypes.h"
#include "src/core/SkBuiltInCodeSnippetID.h"
enum class SkBackend : uint8_t { enum class SkBackend : uint8_t {
kGanesh, kGanesh,
@ -20,30 +21,6 @@ enum class SkBackend : uint8_t {
class SkShaderCodeDictionary; class SkShaderCodeDictionary;
class SkShaderInfo; class SkShaderInfo;
// TODO: this needs to be expanded into a more flexible dictionary (esp. for user-supplied SkSL)
// TODO: rename to SkBuiltInCodeSnippetID and move to its own header
enum class CodeSnippetID : uint8_t {
// TODO: It seems like this requires some refinement. Fundamentally this doesn't seem like a
// draw that originated from a PaintParams.
kDepthStencilOnlyDraw,
// SkShader code snippets
kSolidColorShader,
kLinearGradientShader,
kRadialGradientShader,
kSweepGradientShader,
kConicalGradientShader,
kImageShader,
kBlendShader, // aka ComposeShader
// BlendMode code snippets
kSimpleBlendMode,
kLast = kSimpleBlendMode
};
static constexpr int kCodeSnippetIDCount = static_cast<int>(CodeSnippetID::kLast) + 1;
// This class is a compact representation of the shader needed to implement a given // This class is a compact representation of the shader needed to implement a given
// PaintParams. Its structure is a series of blocks where each block has a // PaintParams. Its structure is a series of blocks where each block has a
// header that consists of 2-bytes - a 1-byte code-snippet ID and a 1-byte number-of-bytes-in-the- // header that consists of 2-bytes - a 1-byte code-snippet ID and a 1-byte number-of-bytes-in-the-
@ -57,7 +34,7 @@ public:
// 1st byte: codeSnippetID // 1st byte: codeSnippetID
// 2nd byte: total blockSize in bytes // 2nd byte: total blockSize in bytes
// Returns the header's offset in the key - to be passed back into endBlock // Returns the header's offset in the key - to be passed back into endBlock
int beginBlock(CodeSnippetID codeSnippetID) { int beginBlock(SkBuiltInCodeSnippetID codeSnippetID) {
SkASSERT(fNumBytes < kMaxKeySize); SkASSERT(fNumBytes < kMaxKeySize);
this->addByte((uint8_t) codeSnippetID); this->addByte((uint8_t) codeSnippetID);
@ -66,17 +43,17 @@ public:
} }
// Update the size byte of a block header // Update the size byte of a block header
void endBlock(int headerOffset, CodeSnippetID codeSnippetID) { void endBlock(int headerOffset, SkBuiltInCodeSnippetID codeSnippetID) {
SkASSERT(fData[headerOffset] == (uint32_t) codeSnippetID); SkASSERT(fData[headerOffset] == (uint32_t) codeSnippetID);
int blockSize = fNumBytes - headerOffset; int blockSize = fNumBytes - headerOffset;
SkASSERT(blockSize <= kMaxBlockSize); SkASSERT(blockSize <= kMaxBlockSize);
fData[headerOffset+1] = blockSize; fData[headerOffset+1] = blockSize;
} }
std::pair<CodeSnippetID, uint8_t> readCodeSnippetID(int headerOffset) const { std::pair<SkBuiltInCodeSnippetID, uint8_t> readCodeSnippetID(int headerOffset) const {
SkASSERT(headerOffset < kMaxKeySize - kBlockHeaderSizeInBytes); SkASSERT(headerOffset < kMaxKeySize - kBlockHeaderSizeInBytes);
CodeSnippetID id = static_cast<CodeSnippetID>(fData[headerOffset]); SkBuiltInCodeSnippetID id = static_cast<SkBuiltInCodeSnippetID>(fData[headerOffset]);
uint8_t blockSize = fData[headerOffset+1]; uint8_t blockSize = fData[headerOffset+1];
SkASSERT(headerOffset + blockSize <= this->sizeInBytes()); SkASSERT(headerOffset + blockSize <= this->sizeInBytes());

View File

@ -6,11 +6,11 @@
*/ */
#include "include/core/SkPaint.h" #include "include/core/SkPaint.h"
#include "include/private/SkPaintParamsKey.h"
#include "src/core/SkBlenderBase.h" #include "src/core/SkBlenderBase.h"
#include "src/core/SkColorFilterBase.h" #include "src/core/SkColorFilterBase.h"
#include "src/core/SkColorSpacePriv.h" #include "src/core/SkColorSpacePriv.h"
#include "src/core/SkKeyHelpers.h" #include "src/core/SkKeyHelpers.h"
#include "src/core/SkPaintParamsKey.h"
#include "src/core/SkPaintPriv.h" #include "src/core/SkPaintPriv.h"
#include "src/core/SkXfermodePriv.h" #include "src/core/SkXfermodePriv.h"
#include "src/shaders/SkColorFilterShader.h" #include "src/shaders/SkColorFilterShader.h"

View File

@ -5,7 +5,7 @@
* found in the LICENSE file. * found in the LICENSE file.
*/ */
#include "include/private/SkShaderCodeDictionary.h" #include "src/core/SkShaderCodeDictionary.h"
#include "src/core/SkOpts.h" #include "src/core/SkOpts.h"
@ -89,17 +89,17 @@ const SkShaderCodeDictionary::Entry* SkShaderCodeDictionary::lookup(
return fEntryVector[codeID.asUInt()]; return fEntryVector[codeID.asUInt()];
} }
SkSpan<const SkUniform> SkShaderCodeDictionary::getUniforms(CodeSnippetID id) const { SkSpan<const SkUniform> SkShaderCodeDictionary::getUniforms(SkBuiltInCodeSnippetID id) const {
return fCodeSnippets[(int) id].fUniforms; return fCodeSnippets[(int) id].fUniforms;
} }
const SkShaderInfo::SnippetEntry* SkShaderCodeDictionary::getEntry(CodeSnippetID id) const { const SkShaderInfo::SnippetEntry* SkShaderCodeDictionary::getEntry(SkBuiltInCodeSnippetID id) const {
if (fCodeSnippets[(int) id].fCode) { if (fCodeSnippets[(int) id].fCode) {
return &fCodeSnippets[(int) id]; return &fCodeSnippets[(int) id];
} }
// If we're missing a code snippet just draw solid blue // If we're missing a code snippet just draw solid blue
return this->getEntry(CodeSnippetID::kDepthStencilOnlyDraw); return this->getEntry(SkBuiltInCodeSnippetID::kDepthStencilOnlyDraw);
} }
void SkShaderCodeDictionary::getShaderInfo(SkUniquePaintParamsID uniqueID, SkShaderInfo* info) { void SkShaderCodeDictionary::getShaderInfo(SkUniquePaintParamsID uniqueID, SkShaderInfo* info) {
@ -185,37 +185,37 @@ SkShaderCodeDictionary::SkShaderCodeDictionary() {
// The 0th index is reserved as invalid // The 0th index is reserved as invalid
fEntryVector.push_back(nullptr); fEntryVector.push_back(nullptr);
fCodeSnippets[(int) CodeSnippetID::kDepthStencilOnlyDraw] = { fCodeSnippets[(int) SkBuiltInCodeSnippetID::kDepthStencilOnlyDraw] = {
{}, kNoneName, kNoneSkSL {}, kNoneName, kNoneSkSL
}; };
fCodeSnippets[(int) CodeSnippetID::kSolidColorShader] = { fCodeSnippets[(int) SkBuiltInCodeSnippetID::kSolidColorShader] = {
SkMakeSpan(kSolidUniforms, kNumSolidUniforms), SkMakeSpan(kSolidUniforms, kNumSolidUniforms),
kSolidColorName, kSolidColorSkSL kSolidColorName, kSolidColorSkSL
}; };
fCodeSnippets[(int) CodeSnippetID::kLinearGradientShader] = { fCodeSnippets[(int) SkBuiltInCodeSnippetID::kLinearGradientShader] = {
SkMakeSpan(kGradientUniforms, kNumGradientUniforms), SkMakeSpan(kGradientUniforms, kNumGradientUniforms),
kLinearGradient4Name, kLinearGradient4SkSL kLinearGradient4Name, kLinearGradient4SkSL
}; };
fCodeSnippets[(int) CodeSnippetID::kRadialGradientShader] = { fCodeSnippets[(int) SkBuiltInCodeSnippetID::kRadialGradientShader] = {
SkMakeSpan(kGradientUniforms, kNumGradientUniforms), SkMakeSpan(kGradientUniforms, kNumGradientUniforms),
kLinearGradient4Name, kLinearGradient4SkSL kLinearGradient4Name, kLinearGradient4SkSL
}; };
fCodeSnippets[(int) CodeSnippetID::kSweepGradientShader] = { fCodeSnippets[(int) SkBuiltInCodeSnippetID::kSweepGradientShader] = {
SkMakeSpan(kGradientUniforms, kNumGradientUniforms), SkMakeSpan(kGradientUniforms, kNumGradientUniforms),
kLinearGradient4Name, kLinearGradient4SkSL kLinearGradient4Name, kLinearGradient4SkSL
}; };
fCodeSnippets[(int) CodeSnippetID::kConicalGradientShader] = { fCodeSnippets[(int) SkBuiltInCodeSnippetID::kConicalGradientShader] = {
SkMakeSpan(kGradientUniforms, kNumGradientUniforms), SkMakeSpan(kGradientUniforms, kNumGradientUniforms),
kLinearGradient4Name, kLinearGradient4SkSL kLinearGradient4Name, kLinearGradient4SkSL
}; };
fCodeSnippets[(int) CodeSnippetID::kImageShader] = { fCodeSnippets[(int) SkBuiltInCodeSnippetID::kImageShader] = {
{ nullptr, kNumImageUniforms }, { nullptr, kNumImageUniforms },
kImageName, kImageSkSL kImageName, kImageSkSL
}; };
fCodeSnippets[(int) CodeSnippetID::kBlendShader] = { fCodeSnippets[(int) SkBuiltInCodeSnippetID::kBlendShader] = {
{}, nullptr, nullptr {}, nullptr, nullptr
}; };
fCodeSnippets[(int) CodeSnippetID::kSimpleBlendMode] = { fCodeSnippets[(int) SkBuiltInCodeSnippetID::kSimpleBlendMode] = {
{}, nullptr, nullptr {}, nullptr, nullptr
}; };
} }

View File

@ -12,10 +12,10 @@
#include <unordered_map> #include <unordered_map>
#include <vector> #include <vector>
#include "include/core/SkSpan.h" #include "include/core/SkSpan.h"
#include "include/private/SkPaintParamsKey.h"
#include "include/private/SkSpinlock.h" #include "include/private/SkSpinlock.h"
#include "include/private/SkUniquePaintParamsID.h" #include "include/private/SkUniquePaintParamsID.h"
#include "src/core/SkArenaAlloc.h" #include "src/core/SkArenaAlloc.h"
#include "src/core/SkPaintParamsKey.h"
#include "src/core/SkUniform.h" #include "src/core/SkUniform.h"
class SkShaderInfo { class SkShaderInfo {
@ -74,8 +74,8 @@ public:
const Entry* lookup(SkUniquePaintParamsID) const SK_EXCLUDES(fSpinLock); const Entry* lookup(SkUniquePaintParamsID) const SK_EXCLUDES(fSpinLock);
SkSpan<const SkUniform> getUniforms(CodeSnippetID) const; SkSpan<const SkUniform> getUniforms(SkBuiltInCodeSnippetID) const;
const SkShaderInfo::SnippetEntry* getEntry(CodeSnippetID) const; const SkShaderInfo::SnippetEntry* getEntry(SkBuiltInCodeSnippetID) const;
void getShaderInfo(SkUniquePaintParamsID, SkShaderInfo*); void getShaderInfo(SkUniquePaintParamsID, SkShaderInfo*);
@ -86,7 +86,7 @@ private:
size_t operator()(const SkPaintParamsKey&) const; size_t operator()(const SkPaintParamsKey&) const;
}; };
std::array<SkShaderInfo::SnippetEntry, kCodeSnippetIDCount> fCodeSnippets; std::array<SkShaderInfo::SnippetEntry, kBuiltInCodeSnippetIDCount> fCodeSnippets;
// TODO: can we do something better given this should have write-seldom/read-often behavior? // TODO: can we do something better given this should have write-seldom/read-often behavior?
mutable SkSpinlock fSpinLock; mutable SkSpinlock fSpinLock;

View File

@ -8,9 +8,9 @@
#include "include/core/SkCanvas.h" #include "include/core/SkCanvas.h"
#include "include/core/SkSurface.h" #include "include/core/SkSurface.h"
#include "include/effects/SkGradientShader.h" #include "include/effects/SkGradientShader.h"
#include "include/private/SkPaintParamsKey.h" #include "src/core/SkPaintParamsKey.h"
#include "include/private/SkShaderCodeDictionary.h"
#include "src/core/SkPaintPriv.h" #include "src/core/SkPaintPriv.h"
#include "src/core/SkShaderCodeDictionary.h"
#include "tests/Test.h" #include "tests/Test.h"
namespace { namespace {

View File

@ -28,8 +28,8 @@
#include "experimental/graphite/src/UniformManager.h" #include "experimental/graphite/src/UniformManager.h"
#include "experimental/graphite/src/geom/Shape.h" #include "experimental/graphite/src/geom/Shape.h"
#include "experimental/graphite/src/geom/Transform_graphite.h" #include "experimental/graphite/src/geom/Transform_graphite.h"
#include "include/private/SkShaderCodeDictionary.h"
#include "src/core/SkKeyHelpers.h" #include "src/core/SkKeyHelpers.h"
#include "src/core/SkShaderCodeDictionary.h"
#include "src/core/SkUniformData.h" #include "src/core/SkUniformData.h"
#if GRAPHITE_TEST_UTILS #if GRAPHITE_TEST_UTILS

View File

@ -16,9 +16,9 @@
#include "experimental/graphite/src/ResourceProvider.h" #include "experimental/graphite/src/ResourceProvider.h"
#include "include/core/SkPaint.h" #include "include/core/SkPaint.h"
#include "include/effects/SkGradientShader.h" #include "include/effects/SkGradientShader.h"
#include "include/private/SkShaderCodeDictionary.h"
#include "include/private/SkUniquePaintParamsID.h" #include "include/private/SkUniquePaintParamsID.h"
#include "src/core/SkKeyHelpers.h" #include "src/core/SkKeyHelpers.h"
#include "src/core/SkShaderCodeDictionary.h"
#include "src/core/SkUniformData.h" #include "src/core/SkUniformData.h"
namespace { namespace {