blob: b8390c14153f4ee5a20aae37db69af1d06b30dd1 [file] [log] [blame]
* Copyright 2021 Google LLC
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
#ifndef SkBlenderBase_DEFINED
#define SkBlenderBase_DEFINED
#include "include/core/SkBlender.h"
#include "src/core/SkArenaAlloc.h"
#include "src/core/SkVM.h"
#include <optional>
struct GrFPArgs;
class GrFragmentProcessor;
class SkColorInfo;
class SkPaintParamsKeyBuilder;
class SkPipelineDataGatherer;
class SkRuntimeEffect;
class SkKeyContext;
* Encapsulates a blend function, including non-public APIs.
* Blends combine a source color (the result of our paint) and destination color (from the canvas)
* into a final color.
class SkBlenderBase : public SkBlender {
* Returns true if this SkBlender represents any SkBlendMode, and returns the blender's
* SkBlendMode in `mode`. Returns false for other types of blends.
virtual std::optional<SkBlendMode> asBlendMode() const { return {}; }
/** Creates the blend program in SkVM. */
skvm::Color program(skvm::Builder* p, skvm::Color src, skvm::Color dst,
const SkColorInfo& colorInfo, skvm::Uniforms* uniforms,
SkArenaAlloc* alloc) const {
return this->onProgram(p, src, dst, colorInfo, uniforms, alloc);
* Returns a GrFragmentProcessor that implements this blend for the GPU backend.
* The GrFragmentProcessor expects premultiplied inputs and returns a premultiplied output.
virtual std::unique_ptr<GrFragmentProcessor> asFragmentProcessor(
std::unique_ptr<GrFragmentProcessor> srcFP,
std::unique_ptr<GrFragmentProcessor> dstFP,
const GrFPArgs& fpArgs) const = 0;
virtual SkRuntimeEffect* asRuntimeEffect() const { return nullptr; }
// TODO: make pure virtual
// 'primitiveColorBlender' is true when this blender is acting to blend the primitive's color
// with the paint's color. When false, the blender is acting to blend the result of the paint
// evaluation with the back buffer.
virtual void addToKey(const SkKeyContext&,
bool primitiveColorBlender) const;
static SkFlattenable::Type GetFlattenableType() { return kSkBlender_Type; }
Type getFlattenableType() const override { return GetFlattenableType(); }
virtual skvm::Color onProgram(skvm::Builder* p, skvm::Color src, skvm::Color dst,
const SkColorInfo& colorInfo, skvm::Uniforms* uniforms,
SkArenaAlloc* alloc) const = 0;
using INHERITED = SkFlattenable;
inline SkBlenderBase* as_BB(SkBlender* blend) {
return static_cast<SkBlenderBase*>(blend);
inline const SkBlenderBase* as_BB(const SkBlender* blend) {
return static_cast<const SkBlenderBase*>(blend);
inline const SkBlenderBase* as_BB(const sk_sp<SkBlender>& blend) {
return static_cast<SkBlenderBase*>(blend.get());
#endif // SkBlenderBase_DEFINED