From 61e7b64962a5a4432c111909e0915cc15778088a Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Tue, 8 Feb 2022 12:05:02 -0500 Subject: [PATCH] [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 Commit-Queue: Robert Phillips --- experimental/graphite/src/Context.cpp | 2 +- experimental/graphite/src/ContextUtils.cpp | 2 +- experimental/graphite/src/GlobalCache.cpp | 3 +- experimental/graphite/src/PaintParams.cpp | 2 +- .../graphite/src/mtl/MtlGraphicsPipeline.mm | 2 +- gn/core.gni | 5 +- src/core/SkBuiltInCodeSnippetID.h | 36 +++++ src/core/SkKeyHelpers.cpp | 124 ++++++++++-------- src/core/SkPaintParamsKey.cpp | 30 ++--- .../private => src/core}/SkPaintParamsKey.h | 33 +---- src/core/SkPaintPriv.cpp | 2 +- src/core/SkShaderCodeDictionary.cpp | 26 ++-- .../core}/SkShaderCodeDictionary.h | 8 +- tests/graphite/ComboTest.cpp | 4 +- tests/graphite/CommandBufferTest.cpp | 2 +- tests/graphite/UniformTest.cpp | 2 +- 16 files changed, 157 insertions(+), 126 deletions(-) create mode 100644 src/core/SkBuiltInCodeSnippetID.h rename {include/private => src/core}/SkPaintParamsKey.h (74%) rename {include/private => src/core}/SkShaderCodeDictionary.h (90%) diff --git a/experimental/graphite/src/Context.cpp b/experimental/graphite/src/Context.cpp index e85656654e..a6fb7eebdf 100644 --- a/experimental/graphite/src/Context.cpp +++ b/experimental/graphite/src/Context.cpp @@ -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" diff --git a/experimental/graphite/src/ContextUtils.cpp b/experimental/graphite/src/ContextUtils.cpp index 8e5b7bb1d9..4383c6cef6 100644 --- a/experimental/graphite/src/ContextUtils.cpp +++ b/experimental/graphite/src/ContextUtils.cpp @@ -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" diff --git a/experimental/graphite/src/GlobalCache.cpp b/experimental/graphite/src/GlobalCache.cpp index 663ece61fb..9950f44980 100644 --- a/experimental/graphite/src/GlobalCache.cpp +++ b/experimental/graphite/src/GlobalCache.cpp @@ -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(SkBuiltInCodeSnippetID::kLast)+1; + +#endif // SkBuiltInCodeSnippetID_DEFINED diff --git a/src/core/SkKeyHelpers.cpp b/src/core/SkKeyHelpers.cpp index 35a1951e46..608149e068 100644 --- a/src/core/SkKeyHelpers.cpp +++ b/src/core/SkKeyHelpers.cpp @@ -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(CodeSnippetID::kLast)); + SkASSERT(byte <= static_cast(SkBuiltInCodeSnippetID::kLast)); - return static_cast(byte); + return static_cast(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(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 make_solid_uniform_data(SkShaderCodeDictionary* dict, SkColor4f color) { static constexpr size_t kExpectedNumUniforms = 1; - SkSpan uniforms = dict->getUniforms(CodeSnippetID::kSolidColorShader); + SkSpan 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 make_gradient_uniform_data_common( sk_sp make_linear_gradient_uniform_data(SkShaderCodeDictionary* dict, const GradientData& gradData) { - SkSpan 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 make_linear_gradient_uniform_data(SkShaderCodeDictionary* d sk_sp make_radial_gradient_uniform_data(SkShaderCodeDictionary* dict, const GradientData& gradData) { - SkSpan 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 make_radial_gradient_uniform_data(SkShaderCodeDictionary* d sk_sp make_sweep_gradient_uniform_data(SkShaderCodeDictionary* dict, const GradientData& gradData) { - SkSpan 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 make_sweep_gradient_uniform_data(SkShaderCodeDictionary* di sk_sp make_conical_gradient_uniform_data(SkShaderCodeDictionary* dict, const GradientData& gradData) { - SkSpan 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 ExtractFromKey(const SkPaintParamsKey& key, - uint32_t headerOffset) { - CodeSnippetID id = read_code_snippet_id(key, headerOffset); +std::pair 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 make_image_uniform_data(SkShaderCodeDictionary* dict, const ImageData& imgData) { SkDEBUGCODE(static constexpr size_t kExpectedNumUniforms = 0;) - SkSpan uniforms = dict->getUniforms(CodeSnippetID::kImageShader); + SkSpan 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(imgData.fTileModes[0]) << kXTileModeShift) | (static_cast(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); diff --git a/src/core/SkPaintParamsKey.cpp b/src/core/SkPaintParamsKey.cpp index 34a0d274de..e2b4dd8cc5 100644 --- a/src/core/SkPaintParamsKey.cpp +++ b/src/core/SkPaintParamsKey.cpp @@ -5,11 +5,11 @@ * found in the LICENSE file. */ -#include "include/private/SkPaintParamsKey.h" +#include "src/core/SkPaintParamsKey.h" #include -#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(); } } diff --git a/include/private/SkPaintParamsKey.h b/src/core/SkPaintParamsKey.h similarity index 74% rename from include/private/SkPaintParamsKey.h rename to src/core/SkPaintParamsKey.h index 0d5aa8c69f..5fd9bf6719 100644 --- a/include/private/SkPaintParamsKey.h +++ b/src/core/SkPaintParamsKey.h @@ -11,6 +11,7 @@ #include #include #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(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 readCodeSnippetID(int headerOffset) const { + std::pair readCodeSnippetID(int headerOffset) const { SkASSERT(headerOffset < kMaxKeySize - kBlockHeaderSizeInBytes); - CodeSnippetID id = static_cast(fData[headerOffset]); + SkBuiltInCodeSnippetID id = static_cast(fData[headerOffset]); uint8_t blockSize = fData[headerOffset+1]; SkASSERT(headerOffset + blockSize <= this->sizeInBytes()); diff --git a/src/core/SkPaintPriv.cpp b/src/core/SkPaintPriv.cpp index 54334727ff..04b33f257e 100644 --- a/src/core/SkPaintPriv.cpp +++ b/src/core/SkPaintPriv.cpp @@ -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" diff --git a/src/core/SkShaderCodeDictionary.cpp b/src/core/SkShaderCodeDictionary.cpp index 42cff43d1a..b94090f7fb 100644 --- a/src/core/SkShaderCodeDictionary.cpp +++ b/src/core/SkShaderCodeDictionary.cpp @@ -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 SkShaderCodeDictionary::getUniforms(CodeSnippetID id) const { +SkSpan 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 }; } diff --git a/include/private/SkShaderCodeDictionary.h b/src/core/SkShaderCodeDictionary.h similarity index 90% rename from include/private/SkShaderCodeDictionary.h rename to src/core/SkShaderCodeDictionary.h index 002f6510f3..da211c4121 100644 --- a/include/private/SkShaderCodeDictionary.h +++ b/src/core/SkShaderCodeDictionary.h @@ -12,10 +12,10 @@ #include #include #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 getUniforms(CodeSnippetID) const; - const SkShaderInfo::SnippetEntry* getEntry(CodeSnippetID) const; + SkSpan 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 fCodeSnippets; + std::array fCodeSnippets; // TODO: can we do something better given this should have write-seldom/read-often behavior? mutable SkSpinlock fSpinLock; diff --git a/tests/graphite/ComboTest.cpp b/tests/graphite/ComboTest.cpp index 1af5829ebf..3315161e77 100644 --- a/tests/graphite/ComboTest.cpp +++ b/tests/graphite/ComboTest.cpp @@ -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 { diff --git a/tests/graphite/CommandBufferTest.cpp b/tests/graphite/CommandBufferTest.cpp index 4b5a1f9e07..f4595fb8ae 100644 --- a/tests/graphite/CommandBufferTest.cpp +++ b/tests/graphite/CommandBufferTest.cpp @@ -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 diff --git a/tests/graphite/UniformTest.cpp b/tests/graphite/UniformTest.cpp index 6dfbb200ce..73463b3eed 100644 --- a/tests/graphite/UniformTest.cpp +++ b/tests/graphite/UniformTest.cpp @@ -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 {