Flutter Engine
The Flutter Engine
SkBlenders.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
12
14#include "include/core/SkData.h"
19
20sk_sp<SkBlender> SkBlenders::Arithmetic(float k1, float k2, float k3, float k4,
21 bool enforcePremul) {
22 using namespace SkKnownRuntimeEffects;
23
24 if (!SkIsFinite(k1, k2, k3, k4)) {
25 return nullptr;
26 }
27
28 // Are we nearly a SkBlendMode?
29 const struct {
30 float k1, k2, k3, k4;
32 } table[] = {
33 { 0, 1, 0, 0, SkBlendMode::kSrc },
34 { 0, 0, 1, 0, SkBlendMode::kDst },
35 { 0, 0, 0, 0, SkBlendMode::kClear },
36 };
37 for (const auto& t : table) {
38 if (SkScalarNearlyEqual(k1, t.k1) &&
39 SkScalarNearlyEqual(k2, t.k2) &&
40 SkScalarNearlyEqual(k3, t.k3) &&
41 SkScalarNearlyEqual(k4, t.k4)) {
42 return SkBlender::Mode(t.mode);
43 }
44 }
45
46 // If we get here, we need the actual blender effect.
47 const SkRuntimeEffect* arithmeticEffect = GetKnownRuntimeEffect(StableKey::kArithmetic);
48
49 const float array[] = {
50 k1, k2, k3, k4,
51 enforcePremul ? 0.0f : 1.0f,
52 };
53 return arithmeticEffect->makeBlender(SkData::MakeWithCopy(array, sizeof(array)));
54}
SkBlendMode
Definition: SkBlendMode.h:38
@ kClear
r = 0
static bool SkIsFinite(T x, Pack... values)
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkScalar.h:107
SI F table(const skcms_Curve *curve, F v)
static sk_sp< SkBlender > Mode(SkBlendMode mode)
static sk_sp< SkBlender > Arithmetic(float k1, float k2, float k3, float k4, bool enforcePremul)
Definition: SkBlenders.cpp:20
static sk_sp< SkData > MakeWithCopy(const void *data, size_t length)
Definition: SkData.cpp:111
sk_sp< SkBlender > makeBlender(sk_sp< const SkData > uniforms, SkSpan< const ChildPtr > children={}) const
const SkRuntimeEffect * GetKnownRuntimeEffect(StableKey stableKey)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
Definition: switches.h:228