[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/ResourceProvider.h"
#include "include/core/SkPathTypes.h"
#include "include/private/SkShaderCodeDictionary.h"
#include "src/core/SkKeyHelpers.h"
#include "src/core/SkShaderCodeDictionary.h"
#ifdef SK_METAL
#include "experimental/graphite/src/mtl/MtlTrampoline.h"

View File

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

View File

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

View File

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

View File

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

View File

@ -142,6 +142,7 @@ skia_core_sources = [
"$_src/core/SkBlurMask.cpp",
"$_src/core/SkBlurMask.h",
"$_src/core/SkBuffer.cpp",
"$_src/core/SkBuiltInCodeSnippetID.h",
"$_src/core/SkCachedData.cpp",
"$_src/core/SkCanvas.cpp",
"$_src/core/SkCanvasPriv.cpp",
@ -295,6 +296,7 @@ skia_core_sources = [
"$_src/core/SkPaint.cpp",
"$_src/core/SkPaintDefaults.h",
"$_src/core/SkPaintParamsKey.cpp",
"$_src/core/SkPaintParamsKey.h",
"$_src/core/SkPaintPriv.cpp",
"$_src/core/SkPaintPriv.h",
"$_src/core/SkPath.cpp",
@ -354,6 +356,7 @@ skia_core_sources = [
"$_src/core/SkScopeExit.h",
"$_src/core/SkSemaphore.cpp",
"$_src/core/SkShaderCodeDictionary.cpp",
"$_src/core/SkShaderCodeDictionary.h",
"$_src/core/SkSharedMutex.cpp",
"$_src/core/SkSharedMutex.h",
"$_src/core/SkSpecialImage.cpp",
@ -490,10 +493,8 @@ skia_core_sources = [
"$_include/private/SkNx_neon.h",
"$_include/private/SkNx_sse.h",
"$_include/private/SkOnce.h",
"$_include/private/SkPaintParamsKey.h",
"$_include/private/SkPathRef.h",
"$_include/private/SkSemaphore.h",
"$_include/private/SkShaderCodeDictionary.h",
"$_include/private/SkShadowFlags.h",
"$_include/private/SkSpinlock.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 "include/private/SkPaintParamsKey.h"
#include "include/private/SkShaderCodeDictionary.h"
#include "src/core/SkDebugUtils.h"
#include "src/core/SkPaintParamsKey.h"
#include "src/core/SkShaderCodeDictionary.h"
#include "src/core/SkUniform.h"
#include "src/core/SkUniformData.h"
#include "src/shaders/SkShaderBase.h"
@ -21,18 +21,18 @@
namespace {
#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);
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
// 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,
CodeSnippetID codeSnippetID, int blockDataSize) {
SkBuiltInCodeSnippetID codeSnippetID, int blockDataSize) {
SkASSERT(key.byte(headerOffset) == static_cast<int>(codeSnippetID));
SkASSERT(key.byte(headerOffset+SkPaintParamsKey::kBlockSizeOffsetInBytes) ==
SkPaintParamsKey::kBlockHeaderSizeInBytes + blockDataSize);
@ -69,17 +69,21 @@ void AddToKey(SkShaderCodeDictionary* /* dict */,
SkBackend /* backend */,
SkPaintParamsKey* key,
SkUniformBlock* /* uniformBlock */) {
int headerOffset = key->beginBlock(CodeSnippetID::kDepthStencilOnlyDraw);
key->endBlock(headerOffset, CodeSnippetID::kDepthStencilOnlyDraw);
int headerOffset = key->beginBlock(SkBuiltInCodeSnippetID::kDepthStencilOnlyDraw);
key->endBlock(headerOffset, SkBuiltInCodeSnippetID::kDepthStencilOnlyDraw);
validate_block_header(*key, headerOffset,
CodeSnippetID::kDepthStencilOnlyDraw, kBlockDataSize);
validate_block_header(*key,
headerOffset,
SkBuiltInCodeSnippetID::kDepthStencilOnlyDraw,
kBlockDataSize);
}
#ifdef SK_DEBUG
void Dump(const SkPaintParamsKey& key, int headerOffset) {
validate_block_header(key, headerOffset,
CodeSnippetID::kDepthStencilOnlyDraw, kBlockDataSize);
validate_block_header(key,
headerOffset,
SkBuiltInCodeSnippetID::kDepthStencilOnlyDraw,
kBlockDataSize);
SkDebugf("kDepthStencilOnlyDraw\n");
}
@ -98,7 +102,7 @@ static const int kBlockDataSize = 0;
sk_sp<SkUniformData> make_solid_uniform_data(SkShaderCodeDictionary* dict, SkColor4f color) {
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);
skgpu::UniformManager mgr(skgpu::Layout::kMetal);
@ -124,11 +128,13 @@ void AddToKey(SkShaderCodeDictionary* dict,
#ifdef SK_GRAPHITE_ENABLED
if (backend == SkBackend::kGraphite) {
int headerOffset = key->beginBlock(CodeSnippetID::kSolidColorShader);
key->endBlock(headerOffset, CodeSnippetID::kSolidColorShader);
int headerOffset = key->beginBlock(SkBuiltInCodeSnippetID::kSolidColorShader);
key->endBlock(headerOffset, SkBuiltInCodeSnippetID::kSolidColorShader);
validate_block_header(*key, headerOffset,
CodeSnippetID::kSolidColorShader, kBlockDataSize);
validate_block_header(*key,
headerOffset,
SkBuiltInCodeSnippetID::kSolidColorShader,
kBlockDataSize);
if (uniformBlock) {
uniformBlock->add(make_solid_uniform_data(dict, color));
@ -147,8 +153,10 @@ void AddToKey(SkShaderCodeDictionary* dict,
void Dump(const SkPaintParamsKey& key, int headerOffset) {
#ifdef SK_GRAPHITE_ENABLED
validate_block_header(key, headerOffset,
CodeSnippetID::kSolidColorShader, kBlockDataSize);
validate_block_header(key,
headerOffset,
SkBuiltInCodeSnippetID::kSolidColorShader,
kBlockDataSize);
SkDebugf("kSolidColorShader\n");
#endif
@ -185,7 +193,7 @@ sk_sp<SkUniformData> make_gradient_uniform_data_common(
sk_sp<SkUniformData> make_linear_gradient_uniform_data(SkShaderCodeDictionary* dict,
const GradientData& gradData) {
SkSpan<const SkUniform> uniforms = dict->getUniforms(CodeSnippetID::kLinearGradientShader);
auto uniforms = dict->getUniforms(SkBuiltInCodeSnippetID::kLinearGradientShader);
SkASSERT(uniforms.size() == 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,
const GradientData& gradData) {
SkSpan<const SkUniform> uniforms = dict->getUniforms(CodeSnippetID::kRadialGradientShader);
auto uniforms = dict->getUniforms(SkBuiltInCodeSnippetID::kRadialGradientShader);
SkASSERT(uniforms.size() == 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,
const GradientData& gradData) {
SkSpan<const SkUniform> uniforms = dict->getUniforms(CodeSnippetID::kSweepGradientShader);
auto uniforms = dict->getUniforms(SkBuiltInCodeSnippetID::kSweepGradientShader);
SkASSERT(uniforms.size() == 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,
const GradientData& gradData) {
SkSpan<const SkUniform> uniforms = dict->getUniforms(CodeSnippetID::kConicalGradientShader);
auto uniforms = dict->getUniforms(SkBuiltInCodeSnippetID::kConicalGradientShader);
SkASSERT(uniforms.size() == kExpectedNumGradientUniforms);
const void* srcs[kExpectedNumGradientUniforms] = {
@ -311,28 +319,28 @@ void AddToKey(SkShaderCodeDictionary* dict,
#ifdef SK_GRAPHITE_ENABLED
if (backend == SkBackend::kGraphite) {
CodeSnippetID codeSnippetID = CodeSnippetID::kSolidColorShader;
SkBuiltInCodeSnippetID codeSnippetID = SkBuiltInCodeSnippetID::kSolidColorShader;
switch (gradData.fType) {
case SkShader::kLinear_GradientType:
codeSnippetID = CodeSnippetID::kLinearGradientShader;
codeSnippetID = SkBuiltInCodeSnippetID::kLinearGradientShader;
if (uniformBlock) {
uniformBlock->add(make_linear_gradient_uniform_data(dict, gradData));
}
break;
case SkShader::kRadial_GradientType:
codeSnippetID = CodeSnippetID::kRadialGradientShader;
codeSnippetID = SkBuiltInCodeSnippetID::kRadialGradientShader;
if (uniformBlock) {
uniformBlock->add(make_radial_gradient_uniform_data(dict, gradData));
}
break;
case SkShader::kSweep_GradientType:
codeSnippetID = CodeSnippetID::kSweepGradientShader;
codeSnippetID = SkBuiltInCodeSnippetID::kSweepGradientShader;
if (uniformBlock) {
uniformBlock->add(make_sweep_gradient_uniform_data(dict, gradData));
}
break;
case SkShader::GradientType::kConical_GradientType:
codeSnippetID = CodeSnippetID::kConicalGradientShader;
codeSnippetID = SkBuiltInCodeSnippetID::kConicalGradientShader;
if (uniformBlock) {
uniformBlock->add(make_conical_gradient_uniform_data(dict, gradData));
}
@ -366,14 +374,14 @@ void AddToKey(SkShaderCodeDictionary* dict,
#ifdef SK_GRAPHITE_ENABLED
std::pair<CodeSnippetID, SkTileMode> ExtractFromKey(const SkPaintParamsKey& key,
uint32_t headerOffset) {
CodeSnippetID id = read_code_snippet_id(key, headerOffset);
std::pair<SkBuiltInCodeSnippetID, SkTileMode> ExtractFromKey(const SkPaintParamsKey& key,
uint32_t headerOffset) {
SkBuiltInCodeSnippetID id = read_code_snippet_id(key, headerOffset);
SkASSERT(id == CodeSnippetID::kLinearGradientShader ||
id == CodeSnippetID::kRadialGradientShader ||
id == CodeSnippetID::kSweepGradientShader ||
id == CodeSnippetID::kConicalGradientShader);
SkASSERT(id == SkBuiltInCodeSnippetID::kLinearGradientShader ||
id == SkBuiltInCodeSnippetID::kRadialGradientShader ||
id == SkBuiltInCodeSnippetID::kSweepGradientShader ||
id == SkBuiltInCodeSnippetID::kConicalGradientShader);
SkASSERT(key.byte(headerOffset+SkPaintParamsKey::kBlockSizeOffsetInBytes) ==
SkPaintParamsKey::kBlockHeaderSizeInBytes+kBlockDataSize);
@ -391,16 +399,16 @@ void Dump(const SkPaintParamsKey& key, int headerOffset) {
auto [id, tm] = ExtractFromKey(key, headerOffset);
switch (id) {
case CodeSnippetID::kLinearGradientShader:
case SkBuiltInCodeSnippetID::kLinearGradientShader:
SkDebugf("kLinearGradientShader: %s\n", SkTileModeToStr(tm));
break;
case CodeSnippetID::kRadialGradientShader:
case SkBuiltInCodeSnippetID::kRadialGradientShader:
SkDebugf("kRadialGradientShader: %s\n", SkTileModeToStr(tm));
break;
case CodeSnippetID::kSweepGradientShader:
case SkBuiltInCodeSnippetID::kSweepGradientShader:
SkDebugf("kSweepGradientShader: %s\n", SkTileModeToStr(tm));
break;
case CodeSnippetID::kConicalGradientShader:
case SkBuiltInCodeSnippetID::kConicalGradientShader:
SkDebugf("kConicalGradientShader: %s\n", SkTileModeToStr(tm));
break;
default:
@ -432,8 +440,10 @@ static const int kBlockDataSize = 1;
inline static constexpr int kTileModeMask = 0x3;
ImageData ExtractFromKey(const SkPaintParamsKey& key, uint32_t headerOffset) {
validate_block_header(key, headerOffset,
CodeSnippetID::kImageShader, kBlockDataSize);
validate_block_header(key,
headerOffset,
SkBuiltInCodeSnippetID::kImageShader,
kBlockDataSize);
uint8_t data = key.byte(headerOffset+SkPaintParamsKey::kBlockHeaderSizeInBytes);
@ -448,7 +458,7 @@ sk_sp<SkUniformData> make_image_uniform_data(SkShaderCodeDictionary* dict,
const ImageData& imgData) {
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);
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) |
(static_cast<uint8_t>(imgData.fTileModes[1]) << kYTileModeShift);
int headerOffset = key->beginBlock(CodeSnippetID::kImageShader);
int headerOffset = key->beginBlock(SkBuiltInCodeSnippetID::kImageShader);
key->addByte(data);
key->endBlock(headerOffset, CodeSnippetID::kImageShader);
key->endBlock(headerOffset, SkBuiltInCodeSnippetID::kImageShader);
SkASSERT(imgData == ExtractFromKey(*key, headerOffset));
@ -527,7 +537,7 @@ void AddToKey(SkShaderCodeDictionary* dict,
#ifdef SK_GRAPHITE_ENABLED
if (backend == SkBackend::kGraphite) {
int headerOffset = key->beginBlock(CodeSnippetID::kBlendShader);
int headerOffset = key->beginBlock(SkBuiltInCodeSnippetID::kBlendShader);
add_blendmode_to_key(key, blendData.fBM);
int start = key->sizeInBytes();
@ -538,10 +548,13 @@ void AddToKey(SkShaderCodeDictionary* dict,
as_SB(blendData.fSrc)->addToKey(dict, backend, key, uniformBlock);
int secondShaderSize = key->sizeInBytes() - start;
key->endBlock(headerOffset, CodeSnippetID::kBlendShader);
key->endBlock(headerOffset, SkBuiltInCodeSnippetID::kBlendShader);
int expectedBlockSize = 1 + firstShaderSize + secondShaderSize;
validate_block_header(*key, headerOffset, CodeSnippetID::kBlendShader, expectedBlockSize);
validate_block_header(*key,
headerOffset,
SkBuiltInCodeSnippetID::kBlendShader,
expectedBlockSize);
return;
}
#endif // SK_GRAPHITE_ENABLED
@ -556,7 +569,7 @@ void AddToKey(SkShaderCodeDictionary* dict,
void Dump(const SkPaintParamsKey& key, int headerOffset) {
#ifdef SK_GRAPHITE_ENABLED
auto [id, storedBlockSize] = key.readCodeSnippetID(headerOffset);
SkASSERT(id == CodeSnippetID::kBlendShader);
SkASSERT(id == SkBuiltInCodeSnippetID::kBlendShader);
int runningOffset = headerOffset + SkPaintParamsKey::kBlockHeaderSizeInBytes;
@ -597,12 +610,14 @@ void AddToKey(SkShaderCodeDictionary* dict,
#ifdef SK_GRAPHITE_ENABLED
if (backend == SkBackend::kGraphite) {
int headerOffset = key->beginBlock(CodeSnippetID::kSimpleBlendMode);
int headerOffset = key->beginBlock(SkBuiltInCodeSnippetID::kSimpleBlendMode);
add_blendmode_to_key(key, bm);
key->endBlock(headerOffset, CodeSnippetID::kSimpleBlendMode);
key->endBlock(headerOffset, SkBuiltInCodeSnippetID::kSimpleBlendMode);
validate_block_header(*key, headerOffset,
CodeSnippetID::kSimpleBlendMode, kBlockDataSize);
validate_block_header(*key,
headerOffset,
SkBuiltInCodeSnippetID::kSimpleBlendMode,
kBlockDataSize);
return;
}
#endif// SK_GRAPHITE_ENABLED
@ -617,7 +632,10 @@ void AddToKey(SkShaderCodeDictionary* dict,
#ifdef SK_GRAPHITE_ENABLED
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);
return to_blendmode(data);

View File

@ -5,11 +5,11 @@
* found in the LICENSE file.
*/
#include "include/private/SkPaintParamsKey.h"
#include "src/core/SkPaintParamsKey.h"
#include <cstring>
#include "include/private/SkShaderCodeDictionary.h"
#include "src/core/SkKeyHelpers.h"
#include "src/core/SkShaderCodeDictionary.h"
bool SkPaintParamsKey::operator==(const SkPaintParamsKey& that) const {
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);
}
DumpMethod get_dump_method(CodeSnippetID id) {
DumpMethod get_dump_method(SkBuiltInCodeSnippetID id) {
switch (id) {
case CodeSnippetID::kDepthStencilOnlyDraw: return DepthStencilOnlyBlock::Dump;
case SkBuiltInCodeSnippetID::kDepthStencilOnlyDraw: return DepthStencilOnlyBlock::Dump;
// SkShader code snippets
case CodeSnippetID::kSolidColorShader: return SolidColorShaderBlock::Dump;
case SkBuiltInCodeSnippetID::kSolidColorShader: return SolidColorShaderBlock::Dump;
case CodeSnippetID::kLinearGradientShader: [[fallthrough]];
case CodeSnippetID::kRadialGradientShader: [[fallthrough]];
case CodeSnippetID::kSweepGradientShader: [[fallthrough]];
case CodeSnippetID::kConicalGradientShader: return GradientShaderBlocks::Dump;
case SkBuiltInCodeSnippetID::kLinearGradientShader: [[fallthrough]];
case SkBuiltInCodeSnippetID::kRadialGradientShader: [[fallthrough]];
case SkBuiltInCodeSnippetID::kSweepGradientShader: [[fallthrough]];
case SkBuiltInCodeSnippetID::kConicalGradientShader: return GradientShaderBlocks::Dump;
case CodeSnippetID::kImageShader: return ImageShaderBlock::Dump;
case CodeSnippetID::kBlendShader: return BlendShaderBlock::Dump;
case SkBuiltInCodeSnippetID::kImageShader: return ImageShaderBlock::Dump;
case SkBuiltInCodeSnippetID::kBlendShader: return BlendShaderBlock::Dump;
// 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) {
auto [codeSnippetID, blockSize] = key.readCodeSnippetID(headerOffset);
if (codeSnippetID != CodeSnippetID::kSimpleBlendMode) {
if (codeSnippetID != SkBuiltInCodeSnippetID::kSimpleBlendMode) {
auto entry = dict->getEntry(codeSnippetID);
result->add(*entry);
if (codeSnippetID != CodeSnippetID::kDepthStencilOnlyDraw) {
if (codeSnippetID != SkBuiltInCodeSnippetID::kDepthStencilOnlyDraw) {
result->setWritesColor();
}
}

View File

@ -11,6 +11,7 @@
#include <array>
#include <limits>
#include "include/core/SkTypes.h"
#include "src/core/SkBuiltInCodeSnippetID.h"
enum class SkBackend : uint8_t {
kGanesh,
@ -20,30 +21,6 @@ enum class SkBackend : uint8_t {
class SkShaderCodeDictionary;
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
// 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-
@ -57,7 +34,7 @@ public:
// 1st byte: codeSnippetID
// 2nd byte: total blockSize in bytes
// 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);
this->addByte((uint8_t) codeSnippetID);
@ -66,17 +43,17 @@ public:
}
// 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);
int blockSize = fNumBytes - headerOffset;
SkASSERT(blockSize <= kMaxBlockSize);
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);
CodeSnippetID id = static_cast<CodeSnippetID>(fData[headerOffset]);
SkBuiltInCodeSnippetID id = static_cast<SkBuiltInCodeSnippetID>(fData[headerOffset]);
uint8_t blockSize = fData[headerOffset+1];
SkASSERT(headerOffset + blockSize <= this->sizeInBytes());

View File

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

View File

@ -5,7 +5,7 @@
* found in the LICENSE file.
*/
#include "include/private/SkShaderCodeDictionary.h"
#include "src/core/SkShaderCodeDictionary.h"
#include "src/core/SkOpts.h"
@ -89,17 +89,17 @@ const SkShaderCodeDictionary::Entry* SkShaderCodeDictionary::lookup(
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;
}
const SkShaderInfo::SnippetEntry* SkShaderCodeDictionary::getEntry(CodeSnippetID id) const {
const SkShaderInfo::SnippetEntry* SkShaderCodeDictionary::getEntry(SkBuiltInCodeSnippetID id) const {
if (fCodeSnippets[(int) id].fCode) {
return &fCodeSnippets[(int) id];
}
// 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) {
@ -185,37 +185,37 @@ SkShaderCodeDictionary::SkShaderCodeDictionary() {
// The 0th index is reserved as invalid
fEntryVector.push_back(nullptr);
fCodeSnippets[(int) CodeSnippetID::kDepthStencilOnlyDraw] = {
fCodeSnippets[(int) SkBuiltInCodeSnippetID::kDepthStencilOnlyDraw] = {
{}, kNoneName, kNoneSkSL
};
fCodeSnippets[(int) CodeSnippetID::kSolidColorShader] = {
fCodeSnippets[(int) SkBuiltInCodeSnippetID::kSolidColorShader] = {
SkMakeSpan(kSolidUniforms, kNumSolidUniforms),
kSolidColorName, kSolidColorSkSL
};
fCodeSnippets[(int) CodeSnippetID::kLinearGradientShader] = {
fCodeSnippets[(int) SkBuiltInCodeSnippetID::kLinearGradientShader] = {
SkMakeSpan(kGradientUniforms, kNumGradientUniforms),
kLinearGradient4Name, kLinearGradient4SkSL
};
fCodeSnippets[(int) CodeSnippetID::kRadialGradientShader] = {
fCodeSnippets[(int) SkBuiltInCodeSnippetID::kRadialGradientShader] = {
SkMakeSpan(kGradientUniforms, kNumGradientUniforms),
kLinearGradient4Name, kLinearGradient4SkSL
};
fCodeSnippets[(int) CodeSnippetID::kSweepGradientShader] = {
fCodeSnippets[(int) SkBuiltInCodeSnippetID::kSweepGradientShader] = {
SkMakeSpan(kGradientUniforms, kNumGradientUniforms),
kLinearGradient4Name, kLinearGradient4SkSL
};
fCodeSnippets[(int) CodeSnippetID::kConicalGradientShader] = {
fCodeSnippets[(int) SkBuiltInCodeSnippetID::kConicalGradientShader] = {
SkMakeSpan(kGradientUniforms, kNumGradientUniforms),
kLinearGradient4Name, kLinearGradient4SkSL
};
fCodeSnippets[(int) CodeSnippetID::kImageShader] = {
fCodeSnippets[(int) SkBuiltInCodeSnippetID::kImageShader] = {
{ nullptr, kNumImageUniforms },
kImageName, kImageSkSL
};
fCodeSnippets[(int) CodeSnippetID::kBlendShader] = {
fCodeSnippets[(int) SkBuiltInCodeSnippetID::kBlendShader] = {
{}, nullptr, nullptr
};
fCodeSnippets[(int) CodeSnippetID::kSimpleBlendMode] = {
fCodeSnippets[(int) SkBuiltInCodeSnippetID::kSimpleBlendMode] = {
{}, nullptr, nullptr
};
}

View File

@ -12,10 +12,10 @@
#include <unordered_map>
#include <vector>
#include "include/core/SkSpan.h"
#include "include/private/SkPaintParamsKey.h"
#include "include/private/SkSpinlock.h"
#include "include/private/SkUniquePaintParamsID.h"
#include "src/core/SkArenaAlloc.h"
#include "src/core/SkPaintParamsKey.h"
#include "src/core/SkUniform.h"
class SkShaderInfo {
@ -74,8 +74,8 @@ public:
const Entry* lookup(SkUniquePaintParamsID) const SK_EXCLUDES(fSpinLock);
SkSpan<const SkUniform> getUniforms(CodeSnippetID) const;
const SkShaderInfo::SnippetEntry* getEntry(CodeSnippetID) const;
SkSpan<const SkUniform> getUniforms(SkBuiltInCodeSnippetID) const;
const SkShaderInfo::SnippetEntry* getEntry(SkBuiltInCodeSnippetID) const;
void getShaderInfo(SkUniquePaintParamsID, SkShaderInfo*);
@ -86,7 +86,7 @@ private:
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?
mutable SkSpinlock fSpinLock;

View File

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

View File

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

View File

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