19class PremultipliedColor;
22struct MutableSubPixmapView;
25enum class SpreadMode {
46enum class Stage : std::uint8_t {
47 MoveSourceToDestination,
48 MoveDestinationToSource,
102 EvenlySpaced2StopGradient,
105 XYTo2PtConicalFocalOnCircle,
106 XYTo2PtConicalWellBehaved,
107 XYTo2PtConicalSmaller,
108 XYTo2PtConicalGreater,
111 Mask2PtConicalDegenerates,
113 Alter2PtConicalCompensateFocal,
114 Alter2PtConicalUnswap,
116 ApplyConcentricScaleBias,
118 GammaExpandDestination2,
121 GammaExpandDestination22,
124 GammaExpandDestinationSrgb,
128 PremultiplyDestination,
130 FusedLinearGradient2Stop,
131 FusedRadialGradient2Stop,
132 FusedBilinearPattern,
136inline constexpr std::size_t kStagesCount = 1 +
static_cast<std::size_t
>(Stage::FusedBilinearPattern);
138inline constexpr std::size_t kMaxStages = 32;
142 std::array<std::uint8_t, 2> pixels = {0, 0};
143 std::uint32_t stride = 0;
144 std::size_t shift = 0;
146 [[nodiscard]] std::array<std::uint8_t, 2> copyAtXY(std::size_t dx, std::size_t dy,
147 std::size_t tail)
const {
148 const auto base =
static_cast<std::size_t
>(stride) * dy + dx;
152 const auto offset = base - shift;
153 if (offset == 0 && tail == 1) {
154 return {pixels[0], 0};
156 if (offset == 0 && tail == 2) {
157 return {pixels[0], pixels[1]};
159 if (offset == 1 && tail == 1) {
160 return {pixels[1], 0};
168 const std::uint8_t* data =
nullptr;
169 std::uint32_t realWidth = 0;
171 [[nodiscard]] std::size_t byteOffset(std::size_t dx, std::size_t dy)
const {
172 return offset(dx, dy);
176 [[nodiscard]]
constexpr std::size_t offset(std::size_t dx, std::size_t dy)
const {
177 return static_cast<std::size_t
>(realWidth) * dy + dx;
183 SpreadMode spreadMode = SpreadMode::Pad;
184 float invWidth = 0.0f;
185 float invHeight = 0.0f;
189struct UniformColorCtx {
194 std::array<std::uint16_t, 4> rgba = {0, 0, 0, 0};
198struct GradientColor {
204 constexpr bool operator==(
const GradientColor&)
const =
default;
206 [[nodiscard]]
static constexpr GradientColor newFromRGBA(
float r,
float g,
float b,
float a) {
207 return GradientColor{r, g, b, a};
212struct EvenlySpaced2StopGradientCtx {
213 GradientColor factor{};
214 GradientColor bias{};
220struct FusedLinearGradient2StopCtx {
224 GradientColor factor{};
225 GradientColor bias{};
226 bool needsPremultiply =
false;
232struct FusedRadialGradient2StopCtx {
239 GradientColor factor{};
240 GradientColor bias{};
241 bool needsPremultiply =
false;
247struct FusedBilinearPatternCtx {
254 const std::uint8_t* pixels =
nullptr;
255 std::uint32_t width = 0;
256 std::uint32_t height = 0;
257 float invWidth = 0.0f;
258 float invHeight = 0.0f;
259 SpreadMode spreadMode = SpreadMode::Pad;
260 float opacity = 1.0f;
261 bool useNearest =
false;
262 bool fuseSourceOver =
false;
263 bool fuseSourceOverCoverage =
false;
264 std::int8_t opaqueCheckResult = -1;
268struct TwoPointConicalGradientCtx {
269 std::array<std::uint32_t, 8> mask = {};
277 float invScale = 0.0f;
282 float currentCoverage = 0.0f;
284 UniformColorCtx uniformColor;
285 EvenlySpaced2StopGradientCtx evenlySpaced2StopGradient;
286 FusedLinearGradient2StopCtx fusedLinearGradient2Stop;
287 FusedRadialGradient2StopCtx fusedRadialGradient2Stop;
288 FusedBilinearPatternCtx fusedBilinearPattern;
291 std::vector<GradientColor> factors;
292 std::vector<GradientColor> biases;
293 std::vector<float> tValues;
295 void pushConstColor(GradientColor color) {
296 factors.push_back(GradientColor{0.0f, 0.0f, 0.0f, 0.0f});
297 biases.push_back(color);
301 TwoPointConicalGradientCtx twoPointConicalGradient;
308class RasterPipeline {
315 RasterPipeline() =
default;
316 RasterPipeline(Kind kind, Context context,
const std::array<Stage, kMaxStages>& stages,
317 std::size_t stageCount);
319 [[nodiscard]] Kind kind()
const {
return kind_; }
321 Context& ctx() {
return ctx_; }
322 [[nodiscard]]
const Context& ctx()
const {
return ctx_; }
324 void run(
const ScreenIntRect& rect,
const AAMaskCtx& aaMaskCtx, MaskCtx maskCtx,
325 const PixmapView& pixmapSrc, MutableSubPixmapView* pixmapDst);
327 [[nodiscard]] std::size_t stageCount()
const {
return stageCount_; }
330 using HighpStageFn = void (*)(highp::Pipeline&);
331 using LowpStageFn = void (*)(lowp::Pipeline&);
333 void initializeFunctions();
335 Kind kind_ = Kind::High;
337 std::array<Stage, kMaxStages> stages_ = {};
338 std::size_t stageCount_ = 0;
339 std::array<HighpStageFn, kMaxStages> highpFunctions_{};
340 std::array<HighpStageFn, kMaxStages> highpTailFunctions_{};
341 std::array<LowpStageFn, kMaxStages> lowpFunctions_{};
342 std::array<LowpStageFn, kMaxStages> lowpTailFunctions_{};
346class RasterPipelineBuilder {
348 RasterPipelineBuilder() =
default;
350 void setForceHqPipeline(
bool hq) { forceHqPipeline_ = hq; }
352 void push(Stage stage) {
353 if (stageCount_ >= kMaxStages) {
356 stages_[stageCount_++] = stage;
359 void pushTransform(
const Transform& ts) {
360 if (ts.isFinite() && !ts.isIdentity()) {
361 push(Stage::Transform);
366 void pushUniformColor(
const PremultipliedColor& c);
368 [[nodiscard]] RasterPipeline compile();
370 [[nodiscard]] Context& ctx() {
return ctx_; }
371 [[nodiscard]]
const Context& ctx()
const {
return ctx_; }
374 std::array<Stage, kMaxStages> stages_ = {};
375 std::size_t stageCount_ = 0;
376 bool forceHqPipeline_ =
false;
@ SoftLight
Soft version of hard light.
@ Lighten
Maximum of source and destination.
@ Exclusion
Similar to Difference but lower contrast.
@ Difference
Absolute difference.
@ Saturation
Source saturation, destination hue and luminosity.
@ Screen
Inverse multiply.
@ SourceOut
Source where destination is transparent.
@ DestinationOut
Destination where source is transparent.
@ DestinationIn
Destination where source is opaque.
@ Luminosity
Source luminosity, destination hue and saturation.
@ Overlay
Multiply or screen based on destination.
@ SourceIn
Source where destination is opaque.
@ Xor
Source XOR destination.
@ DestinationOver
Destination over source.
@ SourceAtop
Source atop destination.
@ DestinationAtop
Destination atop source.
@ ColorBurn
Darken destination toward source.
@ SourceOver
Source over destination (default).
@ Modulate
Component-wise multiply.
@ Color
Source hue and saturation, destination luminosity.
@ HardLight
Multiply or screen based on source.
@ Clear
Output is transparent.
@ Multiply
Component-wise multiply (with alpha handling).
@ ColorDodge
Brighten destination toward source.
@ Darken
Minimum of source and destination.
@ Hue
Source hue, destination saturation and luminosity.
@ Bicubic
Bicubic interpolation (highest quality).
@ Bilinear
Bilinear interpolation.