skia2/include/core/SkCombinationBuilder.h
Robert Phillips dfabbfc0e3 [graphite] Add SkCombinationBuilder.h
This is cleanup left over from a prior CL's review. We will want to
use the combination builder outside of graphite.

This CL is mainly just moving stuff around except for the addition
of the SkCombinationBuilder.buildCombinations method and CreateKey
more accessible outside of Graphite.

Bug: skia:12701
Change-Id: If2cae6fcff5670e488bc14473b7b1d2f9b1fecd7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/543196
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
2022-05-23 20:26:17 +00:00

117 lines
2.8 KiB
C++

/*
* 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 SkCombinationBuilder_DEFINED
#define SkCombinationBuilder_DEFINED
#include <functional>
#include <memory>
#include <vector>
#include "include/core/SkBlendMode.h"
#include "include/core/SkTileMode.h"
class SkArenaAllocWithReset;
class SkPaintCombinations;
class SkPaintParamsKeyBuilder;
class SkShaderCodeDictionary;
class SkUniquePaintParamsID;
namespace skgpu::graphite {
class Context;
}
enum class SkShaderType : uint32_t {
kSolidColor,
kLinearGradient,
kRadialGradient,
kSweepGradient,
kConicalGradient,
kLocalMatrix,
kImage,
kBlendShader
};
// TODO: remove this class
struct SkShaderCombo {
SkShaderCombo() {}
SkShaderCombo(std::vector<SkShaderType> types,
std::vector<SkTileMode> tileModes)
: fTypes(std::move(types))
, fTileModes(std::move(tileModes)) {
}
std::vector<SkShaderType> fTypes;
std::vector<SkTileMode> fTileModes;
};
// TODO: add SkShaderID and SkColorFilterID too
class SkBlenderID {
public:
SkBlenderID() : fID(0) {} // 0 is an invalid blender ID
SkBlenderID(const SkBlenderID& src) : fID(src.fID) {}
bool isValid() const { return fID > 0; }
bool operator==(const SkBlenderID& other) const { return fID == other.fID; }
SkBlenderID& operator=(const SkBlenderID& src) {
fID = src.fID;
return *this;
}
private:
friend class SkShaderCodeDictionary; // for ctor and asUInt access
friend class SkCombinationBuilder; // for asUInt access
friend class SkPaintCombinations; // for asUInt access
SkBlenderID(uint32_t id) : fID(id) {}
uint32_t asUInt() const { return fID; }
uint32_t fID;
};
class SkCombinationBuilder {
public:
enum class BlendModeGroup {
kPorterDuff, // [ kClear .. kScreen ]
kAdvanced, // [ kOverlay .. kMultiply ]
kColorAware, // [ kHue .. kLuminosity ]
kAll
};
#ifdef SK_GRAPHITE_ENABLED
SkCombinationBuilder(skgpu::graphite::Context*);
#else
SkCombinationBuilder(SkShaderCodeDictionary*);
#endif
// Blend Modes
void add(SkBlendMode);
void add(SkBlendMode rangeStart, SkBlendMode rangeEnd); // inclusive
void add(BlendModeGroup);
void add(SkBlenderID);
// Shaders
void add(SkShaderCombo);
void reset();
private:
friend class skgpu::graphite::Context; // for access to buildCombinations
void buildCombinations(SkShaderCodeDictionary*,
const std::function<void(SkUniquePaintParamsID)>&) const;
SkShaderCodeDictionary* fDictionary;
std::unique_ptr<SkArenaAllocWithReset> fArena;
SkPaintCombinations* fCombinations;
};
#endif // SkCombinationBuilder_DEFINED