From 0fa0367c8abb98d0ad172bc21e37e61fef33a652 Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Thu, 3 Feb 2022 12:28:22 -0500 Subject: [PATCH] [graphite] Use PaintParams::toKey in ExtractPaintData Bug: skia:12701 Change-Id: I9af3c437512f2538066ddbbe576739c8873d0bc0 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/503345 Reviewed-by: Michael Ludwig Commit-Queue: Robert Phillips --- experimental/graphite/src/ContextUtils.cpp | 53 ++-------------------- src/core/SkKeyHelpers.cpp | 43 ------------------ src/core/SkKeyHelpers.h | 12 ----- 3 files changed, 4 insertions(+), 104 deletions(-) diff --git a/experimental/graphite/src/ContextUtils.cpp b/experimental/graphite/src/ContextUtils.cpp index 822364b1fa..9dde4f046a 100644 --- a/experimental/graphite/src/ContextUtils.cpp +++ b/experimental/graphite/src/ContextUtils.cpp @@ -72,58 +72,13 @@ static const char* kNoneSkSL = "outColor = half4(0.0, 0.0, 1.0, 1.0);\n"; } // anonymous namespace std::tuple> ExtractPaintData( - SkShaderCodeDictionary* dictionary, const PaintParams& p) { - SkPaintParamsKey key; + SkShaderCodeDictionary* dictionary, + const PaintParams& p) { + SkPaintParamsKey key; std::unique_ptr block = std::make_unique(); - // TODO: add UniformData generation to PaintParams::toKey and use it here - if (auto s = p.shader()) { - SkColor colors[GradientData::kMaxStops]; - float offsets[GradientData::kMaxStops]; - SkShader::GradientInfo gradInfo; - - gradInfo.fColorCount = GradientData::kMaxStops; - gradInfo.fColors = colors; - gradInfo.fColorOffsets = offsets; - - SkShader::GradientType type = s->asAGradient(&gradInfo); - if (gradInfo.fColorCount > GradientData::kMaxStops) { - type = SkShader::GradientType::kNone_GradientType; - } - - GradientData data(type, gradInfo.fPoint, gradInfo.fRadius, - gradInfo.fTileMode, gradInfo.fColorCount, - colors, offsets); - - switch (type) { - case SkShader::kLinear_GradientType: [[fallthrough]]; - case SkShader::kRadial_GradientType: [[fallthrough]]; - case SkShader::kSweep_GradientType: [[fallthrough]]; - case SkShader::kConical_GradientType: - GradientShaderBlocks::AddToKey(SkBackend::kGraphite, - &key, - block.get(), - data); - break; - case SkShader::GradientType::kColor_GradientType: [[fallthrough]]; - // TODO: The solid color gradient type should use its color, not - // the paint color - case SkShader::GradientType::kNone_GradientType: [[fallthrough]]; - default: - SolidColorShaderBlock::AddToKey(SkBackend::kGraphite, &key, block.get(), p.color()); - break; - } - } else { - // Solid colored paint - SolidColorShaderBlock::AddToKey(SkBackend::kGraphite, &key, block.get(), p.color()); - } - - if (p.blender()) { - as_BB(p.blender())->addToKey(dictionary, SkBackend::kGraphite, &key, block.get()); - } else { - BlendModeBlock::AddToKey(SkBackend::kGraphite, &key, block.get(), SkBlendMode::kSrcOver); - } + p.toKey(dictionary, SkBackend::kGraphite, &key, block.get()); auto entry = dictionary->findOrCreate(key); diff --git a/src/core/SkKeyHelpers.cpp b/src/core/SkKeyHelpers.cpp index de0ce56ad1..c93d3b37dc 100644 --- a/src/core/SkKeyHelpers.cpp +++ b/src/core/SkKeyHelpers.cpp @@ -264,49 +264,6 @@ GradientData::GradientData(SkShader::GradientType type, sk_bzero(fOffsets, sizeof(fOffsets)); } -GradientData::GradientData(SkShader::GradientType type, - SkPoint points[2], - float radii[2], - SkTileMode tm, - int numStops, - SkColor colors[kMaxStops], - float offsets[kMaxStops]) - : fType(type) - , fTM(tm) - , fNumStops(numStops) { - memcpy(fPoints, points, sizeof(fPoints)); - memcpy(fRadii, radii, sizeof(fRadii)); - this->toColor4fs(fNumStops, colors); - this->toOffsets(fNumStops, offsets); -} - -void GradientData::toColor4fs(int numColors, SkColor colors[kMaxStops]) { - if (numColors < 2 || numColors > kMaxStops) { - sk_bzero(fColor4fs, sizeof(fColor4fs)); - return; - } - - int i; - for (i = 0; i < numColors; ++i) { - fColor4fs[i] = SkColor4f::FromColor(colors[i]); - } - for ( ; i < kMaxStops; ++i) { - fColor4fs[i] = fColor4fs[numColors-1]; - } -} - -void GradientData::toOffsets(int numStops, float inputOffsets[kMaxStops]) { - if (numStops < 2 || numStops > kMaxStops) { - sk_bzero(fOffsets, sizeof(fOffsets)); - return; - } - - memcpy(fOffsets, inputOffsets, numStops * sizeof(float)); - for (int i = numStops ; i < kMaxStops; ++i) { - fOffsets[i] = fOffsets[numStops-1]; - } -} - GradientData::GradientData(SkShader::GradientType type, SkPoint point0, SkPoint point1, float radius0, float radius1, diff --git a/src/core/SkKeyHelpers.h b/src/core/SkKeyHelpers.h index 65c0c75d47..1277cf3be9 100644 --- a/src/core/SkKeyHelpers.h +++ b/src/core/SkKeyHelpers.h @@ -59,14 +59,6 @@ namespace GradientShaderBlocks { // This ctor is used when extracting information from PaintParams. It must provide // enough data to generate the uniform data the selected code snippet will require. - GradientData(SkShader::GradientType, - SkPoint points[2], - float radii[2], - SkTileMode, - int numStops, - SkColor colors[kMaxStops], - float offsets[kMaxStops]); - GradientData(SkShader::GradientType, SkPoint point0, SkPoint point1, float radius0, float radius1, @@ -95,10 +87,6 @@ namespace GradientShaderBlocks { int fNumStops; SkColor4f fColor4fs[kMaxStops]; float fOffsets[kMaxStops]; - - private: - void toColor4fs(int numColors, SkColor colors[kMaxStops]); - void toOffsets(int numStops, float inputOffsets[kMaxStops]); }; void AddToKey(SkBackend,