Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkMatrixColorFilter.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2011 Google Inc.
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
9
22
23#include <array>
24#include <cstring>
25
26static bool is_alpha_unchanged(const float matrix[20]) {
27 const float* srcA = matrix + 15;
28
29 return SkScalarNearlyZero(srcA[0]) && SkScalarNearlyZero(srcA[1]) &&
30 SkScalarNearlyZero(srcA[2]) && SkScalarNearlyEqual(srcA[3], 1) &&
31 SkScalarNearlyZero(srcA[4]);
32}
33
35 : fAlphaIsUnchanged(is_alpha_unchanged(array)), fDomain(domain) {
36 memcpy(fMatrix, array, 20 * sizeof(float));
37}
38
40 SkASSERT(sizeof(fMatrix) / sizeof(float) == 20);
41 buffer.writeScalarArray(fMatrix, 20);
42
43 // RGBA flag
44 buffer.writeBool(fDomain == Domain::kRGBA);
45}
46
47sk_sp<SkFlattenable> SkMatrixColorFilter::CreateProc(SkReadBuffer& buffer) {
48 float matrix[20];
49 if (!buffer.readScalarArray(matrix, 20)) {
50 return nullptr;
51 }
52
53 auto is_rgba = buffer.readBool();
55}
56
57bool SkMatrixColorFilter::onAsAColorMatrix(float matrix[20]) const {
58 if (matrix) {
59 memcpy(matrix, fMatrix, 20 * sizeof(float));
60 }
61 return true;
62}
63
64bool SkMatrixColorFilter::appendStages(const SkStageRec& rec, bool shaderIsOpaque) const {
65 const bool willStayOpaque = shaderIsOpaque && fAlphaIsUnchanged,
66 hsla = fDomain == Domain::kHSLA;
67
69 if (!shaderIsOpaque) {
70 p->append(SkRasterPipelineOp::unpremul);
71 }
72 if (hsla) {
73 p->append(SkRasterPipelineOp::rgb_to_hsl);
74 }
75 if (true) {
76 p->append(SkRasterPipelineOp::matrix_4x5, fMatrix);
77 }
78 if (hsla) {
79 p->append(SkRasterPipelineOp::hsl_to_rgb);
80 }
81 if (true) {
82 p->append(SkRasterPipelineOp::clamp_01);
83 }
84 if (!willStayOpaque) {
85 p->append(SkRasterPipelineOp::premul);
86 }
87 return true;
88}
89
90///////////////////////////////////////////////////////////////////////////////
91
92static sk_sp<SkColorFilter> MakeMatrix(const float array[20], SkMatrixColorFilter::Domain domain) {
93 if (!SkIsFinite(array, 20)) {
94 return nullptr;
95 }
96 return sk_make_sp<SkMatrixColorFilter>(array, domain);
97}
98
102
106
110
114
117 // Previous name
118 SkFlattenable::Register("SkColorFilter_Matrix", SkMatrixColorFilter::CreateProc);
119}
#define SkASSERT(cond)
Definition SkAssert.h:116
static bool is_rgba(SkColorType colorType)
#define SK_REGISTER_FLATTENABLE(type)
static bool SkIsFinite(T x, Pack... values)
void SkRegisterMatrixColorFilterFlattenable()
static bool is_alpha_unchanged(const float matrix[20])
static sk_sp< SkColorFilter > MakeMatrix(const float array[20], SkMatrixColorFilter::Domain domain)
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
Definition SkScalar.h:101
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition SkScalar.h:107
static sk_sp< SkColorFilter > Matrix(const SkColorMatrix &)
static sk_sp< SkColorFilter > HSLAMatrix(const SkColorMatrix &)
static void Register(const char name[], Factory)
bool appendStages(const SkStageRec &rec, bool shaderIsOpaque) const override
SkMatrixColorFilter(const float array[20], Domain)
const float * matrix() const
bool onAsAColorMatrix(float matrix[20]) const override
void flatten(SkWriteBuffer &) const override
static const uint8_t buffer[]
SkRasterPipeline * fPipeline