1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
/*
* Copyright 2024 Google LLC
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef skgpu_graphite_precompile_PaintOptions_DEFINED
#define skgpu_graphite_precompile_PaintOptions_DEFINED
#include "include/core/SkBlendMode.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSpan.h"
#include "include/private/base/SkTArray.h"
#include "include/private/base/SkTDArray.h"
#include <functional>
namespace skgpu::graphite {
class PrecompileBlender;
class PrecompileColorFilter;
class PrecompileImageFilter;
class PrecompileMaskFilter;
class PrecompileShader;
enum class Coverage;
enum DrawTypeFlags : uint16_t;
enum class PrecompileImageFilterFlags : uint32_t;
class KeyContext;
class PaintOptionsPriv;
class PaintParamsKeyBuilder;
class PipelineDataGatherer;
struct RenderPassDesc;
class UniquePaintParamsID;
/** \class PaintOptions
This is the Precompilation analog to SkPaint. It encapsulates a set of options for each
field of the SkPaint (e.g., colorFilters, imageFilters, etc). Many of the specific details
of an SkPaint that are irrelevant to the final compiled Pipelines are abstracted away
(e.g., the SkPaint's color field).
How Precompilation works in practice is a PaintOptions object is created and a set of options
for each slot (e.g., shader, blender) are added. When passed to the Precompile() function,
all the combinations specified by the PaintOptions will be created and precompiled.
To be concrete, if a PaintOptions object had two shader options and two blender options,
four combinations would be precompiled.
*/
class SK_API PaintOptions {
public:
/** Constructs a PaintOptions object with default values. It is equivalent to a default
* initialized SkPaint.
@return default initialized PaintOptions
*/
PaintOptions();
PaintOptions(const PaintOptions&);
~PaintOptions();
PaintOptions& operator=(const PaintOptions&);
/** Sets the shader options used when generating precompilation combinations.
This corresponds to SkPaint's setShader() method
@param shaders The options used for shading when generating precompilation combinations.
*/
void setShaders(SkSpan<const sk_sp<PrecompileShader>> shaders);
SkSpan<const sk_sp<PrecompileShader>> getShaders() const {
return SkSpan<const sk_sp<PrecompileShader>>(fShaderOptions);
}
/** Sets the image filter options used when generating precompilation combinations.
This corresponds to SkPaint's setImageFilter() method
@param imageFilters The options used for image filtering when generating precompilation
combinations.
*/
void setImageFilters(SkSpan<const sk_sp<PrecompileImageFilter>> imageFilters);
SkSpan<const sk_sp<PrecompileImageFilter>> getImageFilters() const {
return SkSpan<const sk_sp<PrecompileImageFilter>>(fImageFilterOptions);
}
/** Sets the mask filter options used when generating precompilation combinations.
This corresponds to SkPaint's setMaskFilter() method
@param maskFilters The options used for mask filtering when generating precompilation
combinations.
*/
void setMaskFilters(SkSpan<const sk_sp<PrecompileMaskFilter>> maskFilters);
SkSpan<const sk_sp<PrecompileMaskFilter>> getMaskFilters() const {
return SkSpan<const sk_sp<PrecompileMaskFilter>>(fMaskFilterOptions);
}
/** Sets the color filter options used when generating precompilation combinations.
This corresponds to SkPaint's setColorFilter() method
@param colorFilters The options used for color filtering when generating precompilation
combinations.
*/
void setColorFilters(SkSpan<const sk_sp<PrecompileColorFilter>> colorFilters);
SkSpan<const sk_sp<PrecompileColorFilter>> getColorFilters() const {
return SkSpan<const sk_sp<PrecompileColorFilter>>(fColorFilterOptions);
}
/** Sets the blend mode options used when generating precompilation combinations.
This corresponds to SkPaint's setBlendMode() method
@param blendModes The options used for blending when generating precompilation
combinations.
*/
void setBlendModes(SkSpan<const SkBlendMode> blendModes);
SkSpan<const SkBlendMode> getBlendModes() const {
return SkSpan<const SkBlendMode>(fBlendModeOptions.data(), fBlendModeOptions.size());
}
/** Sets the blender options used when generating precompilation combinations.
This corresponds to SkPaint's setBlender() method
@param blenders The options used for blending when generating precompilation combinations.
*/
void setBlenders(SkSpan<const sk_sp<PrecompileBlender>> blenders);
SkSpan<const sk_sp<PrecompileBlender>> getBlenders() const {
return SkSpan<const sk_sp<PrecompileBlender>>(fBlenderOptions);
}
/** Sets the dither setting used when generating precompilation combinations
This corresponds to SkPaint's setDither() method
@param dither the dither setting used when generating precompilation combinations.
*/
void setDither(bool dither) { fDither = dither; }
bool isDither() const { return fDither; }
// Provides access to functions that aren't part of the public API.
PaintOptionsPriv priv();
const PaintOptionsPriv priv() const; // NOLINT(readability-const-return-type)
private:
friend class PaintOptionsPriv;
friend class PrecompileImageFilter; // for ProcessCombination access
friend class PrecompileMaskFilter; // for ProcessCombination access
void addColorFilter(sk_sp<PrecompileColorFilter> cf);
void addBlendMode(SkBlendMode bm) {
fBlendModeOptions.push_back(bm);
}
void setClipShaders(SkSpan<const sk_sp<PrecompileShader>> clipShaders);
int numShaderCombinations() const;
int numColorFilterCombinations() const;
int numBlendCombinations() const;
int numClipShaderCombinations() const;
int numCombinations() const;
// 'desiredCombination' must be less than the result of the numCombinations call
void createKey(const KeyContext&,
PaintParamsKeyBuilder*,
PipelineDataGatherer*,
int desiredCombination,
bool addPrimitiveBlender,
Coverage coverage) const;
typedef std::function<void(UniquePaintParamsID id,
DrawTypeFlags,
bool withPrimitiveBlender,
Coverage,
const RenderPassDesc&)> ProcessCombination;
void buildCombinations(const KeyContext&,
PipelineDataGatherer*,
DrawTypeFlags,
bool addPrimitiveBlender,
Coverage,
const RenderPassDesc&,
const ProcessCombination&) const;
skia_private::TArray<sk_sp<PrecompileShader>> fShaderOptions;
skia_private::TArray<sk_sp<PrecompileColorFilter>> fColorFilterOptions;
skia_private::TArray<SkBlendMode> fBlendModeOptions;
skia_private::TArray<sk_sp<PrecompileBlender>> fBlenderOptions;
skia_private::TArray<sk_sp<PrecompileShader>> fClipShaderOptions;
skia_private::TArray<sk_sp<PrecompileImageFilter>> fImageFilterOptions;
skia_private::TArray<sk_sp<PrecompileMaskFilter>> fMaskFilterOptions;
bool fDither = false;
};
} // namespace skgpu::graphite
#endif // skgpu_graphite_precompile_PaintOptions_DEFINED
|