Flutter Engine
The Flutter Engine
SkColorShader.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2016 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
12#include "include/core/SkData.h"
24
25#include <utility>
26
28
30 return SkColorGetA(fColor) == 255;
31}
32
33sk_sp<SkFlattenable> SkColorShader::CreateProc(SkReadBuffer& buffer) {
34 return sk_make_sp<SkColorShader>(buffer.readColor());
35}
36
37void SkColorShader::flatten(SkWriteBuffer& buffer) const {
38 buffer.writeColor(fColor);
39}
40
42 : fColorSpace(std::move(space))
43 , fColor({color.fR, color.fG, color.fB, SkTPin(color.fA, 0.0f, 1.0f)})
44{}
45
46sk_sp<SkFlattenable> SkColor4Shader::CreateProc(SkReadBuffer& buffer) {
49 buffer.readColor4f(&color);
50 if (buffer.readBool()) {
51 sk_sp<SkData> data = buffer.readByteArrayAsData();
52 colorSpace = data ? SkColorSpace::Deserialize(data->data(), data->size()) : nullptr;
53 }
54 return SkShaders::Color(color, std::move(colorSpace));
55}
56
57void SkColor4Shader::flatten(SkWriteBuffer& buffer) const {
58 buffer.writeColor4f(fColor);
59 sk_sp<SkData> colorSpaceData = fColorSpace ? fColorSpace->serialize() : nullptr;
60 if (colorSpaceData) {
61 buffer.writeBool(true);
62 buffer.writeDataAsByteArray(colorSpaceData.get());
63 } else {
64 buffer.writeBool(false);
65 }
66}
67
68bool SkColorShader::appendStages(const SkStageRec& rec, const SkShaders::MatrixRec&) const {
69 SkColor4f color = SkColor4f::FromColor(fColor);
72 rec.fPipeline->appendConstantColor(rec.fAlloc, color.premul().vec());
73 return true;
74}
75
76bool SkColor4Shader::appendStages(const SkStageRec& rec, const SkShaders::MatrixRec&) const {
77 SkColor4f color = fColor;
80 rec.fPipeline->appendConstantColor(rec.fAlloc, color.premul().vec());
81 return true;
82}
83
84bool SkColor4Shader::onAsLuminanceColor(SkColor4f* lum) const {
85 SkColor4f color = fColor;
88 *lum = color;
89 return true;
90}
91
92/////////////////////////////////////////////////////////////////////////////////////////////////
93
96}
97
100}
101
102namespace SkShaders {
103sk_sp<SkShader> Color(SkColor color) { return sk_make_sp<SkColorShader>(color); }
104
106 if (!SkIsFinite(color.vec(), 4)) {
107 return nullptr;
108 }
109 return sk_make_sp<SkColor4Shader>(color, std::move(space));
110}
111} // namespace SkShaders
kUnpremul_SkAlphaType
void SkRegisterColor4ShaderFlattenable()
void SkRegisterColorShaderFlattenable()
SkColorSpace * sk_srgb_singleton()
uint32_t SkColor
Definition: SkColor.h:37
#define SkColorGetA(color)
Definition: SkColor.h:61
#define SK_REGISTER_FLATTENABLE(type)
static bool SkIsFinite(T x, Pack... values)
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
Definition: SkTPin.h:19
SkColor4Shader(const SkColor4f &, sk_sp< SkColorSpace >)
SkColor4f color() const
Definition: SkColorShader.h:67
sk_sp< SkColorSpace > colorSpace() const
Definition: SkColorShader.h:66
SkColor color() const
Definition: SkColorShader.h:39
SkColorShader(SkColor c)
bool isOpaque() const override
static sk_sp< SkColorSpace > Deserialize(const void *data, size_t length)
sk_sp< SkData > serialize() const
void appendConstantColor(SkArenaAlloc *, const float rgba[4])
T * get() const
Definition: SkRefCnt.h:303
DlColor color
static float lum(float r, float g, float b)
Definition: hsl.cpp:52
SK_API sk_sp< SkShader > Color(SkColor)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
Definition: ref_ptr.h:256
void apply(float rgba[4]) const
SkRasterPipeline * fPipeline
Definition: SkEffectPriv.h:21
SkColorSpace * fDstCS
Definition: SkEffectPriv.h:24
SkArenaAlloc * fAlloc
Definition: SkEffectPriv.h:22
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63