[graphite] Add initial hooks for handling SkColorFilters

This add 2 hooks for SkColorFilters:
  adds SkColorFilter ref to PaintParams
  adds addToKey virtual to SkColorFilterBase

Bug: b/238755762
Change-Id: I6ad1d4407763fe9516bdf4e4531466c570092148
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/558307
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2022-07-14 12:31:00 -04:00 committed by SkCQ
parent 7cad921a19
commit a33c1914d7
3 changed files with 39 additions and 7 deletions

View File

@ -18,6 +18,9 @@ class GrRecordingContext;
class SkArenaAlloc;
class SkBitmap;
class SkColorSpace;
class SkKeyContext;
class SkPaintParamsKeyBuilder;
class SkPipelineDataGatherer;
class SkRuntimeEffect;
struct SkStageRec;
using GrFPResult = std::tuple<bool, std::unique_ptr<GrFragmentProcessor>>;
@ -75,6 +78,20 @@ public:
virtual SkPMColor4f onFilterColor4f(const SkPMColor4f& color, SkColorSpace* dstCS) const;
#ifdef SK_ENABLE_SKSL
/**
Add implementation details, for the specified backend, of this SkColorFilter to the
provided key.
@param keyContext backend context for key creation
@param builder builder for creating the key for this SkShader
@param gatherer if non-null, storage for this colorFilter's data
*/
virtual void addToKey(const SkKeyContext& keyContext,
SkPaintParamsKeyBuilder* builder,
SkPipelineDataGatherer* gatherer) const {}
#endif
protected:
SkColorFilterBase() {}

View File

@ -9,6 +9,7 @@
#include "include/core/SkShader.h"
#include "src/core/SkBlenderBase.h"
#include "src/core/SkColorFilterBase.h"
#include "src/core/SkKeyContext.h"
#include "src/core/SkKeyHelpers.h"
#include "src/core/SkPaintParamsKey.h"
@ -20,15 +21,18 @@ namespace skgpu::graphite {
PaintParams::PaintParams(const SkColor4f& color,
sk_sp<SkBlender> blender,
sk_sp<SkShader> shader)
sk_sp<SkShader> shader,
sk_sp<SkColorFilter> colorFilter)
: fColor(color)
, fBlender(std::move(blender))
, fShader(std::move(shader)) {}
, fShader(std::move(shader))
, fColorFilter(std::move(colorFilter)) {}
PaintParams::PaintParams(const SkPaint& paint)
: fColor(paint.getColor4f())
, fBlender(paint.refBlender())
, fShader(paint.refShader()) {}
, fShader(paint.refShader())
, fColorFilter(paint.refColorFilter()) {}
PaintParams::PaintParams(const PaintParams& other) = default;
PaintParams::~PaintParams() = default;
@ -43,6 +47,8 @@ sk_sp<SkBlender> PaintParams::refBlender() const { return fBlender; }
sk_sp<SkShader> PaintParams::refShader() const { return fShader; }
sk_sp<SkColorFilter> PaintParams::refColorFilter() const { return fColorFilter; }
void PaintParams::toKey(const SkKeyContext& keyContext,
SkPaintParamsKeyBuilder* builder,
SkPipelineDataGatherer* gatherer) const {
@ -54,6 +60,10 @@ void PaintParams::toKey(const SkKeyContext& keyContext,
builder->endBlock();
}
if (fColorFilter) {
as_CFB(fColorFilter)->addToKey(keyContext, builder, gatherer);
}
if (fBlender) {
as_BB(fBlender)->addToKey(keyContext, builder, gatherer);
} else {

View File

@ -27,7 +27,7 @@ namespace skgpu::graphite {
// assumed to be anti-aliased.
class PaintParams {
public:
PaintParams(const SkColor4f& color, sk_sp<SkBlender>, sk_sp<SkShader>);
PaintParams(const SkColor4f& color, sk_sp<SkBlender>, sk_sp<SkShader>, sk_sp<SkColorFilter>);
explicit PaintParams(const SkPaint&);
PaintParams(const PaintParams&);
@ -44,14 +44,19 @@ public:
SkShader* shader() const { return fShader.get(); }
sk_sp<SkShader> refShader() const;
SkColorFilter* colorFilter() const { return fColorFilter.get(); }
sk_sp<SkColorFilter> refColorFilter() const;
void toKey(const SkKeyContext&,
SkPaintParamsKeyBuilder*,
SkPipelineDataGatherer*) const;
private:
SkColor4f fColor;
sk_sp<SkBlender> fBlender; // A nullptr here means SrcOver blending
sk_sp<SkShader> fShader; // For now only use SkShader::asAGradient() when converting to GPU
SkColor4f fColor;
sk_sp<SkBlender> fBlender; // A nullptr here means SrcOver blending
sk_sp<SkShader> fShader;
sk_sp<SkColorFilter> fColorFilter;
// TODO: Will also store ColorFilter, dither, and any extra shader from an
// active clipShader().
};