Flutter Engine
The Flutter Engine
SkWorkingColorSpaceShader.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 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
9
13#include "include/core/SkData.h"
21
22#include <utility>
23
24bool SkWorkingColorSpaceShader::appendStages(const SkStageRec& rec,
25 const SkShaders::MatrixRec& mRec) const {
27 if (!dstCS) {
28 dstCS = SkColorSpace::MakeSRGB();
29 }
30
32 working = {rec.fDstColorType, kPremul_SkAlphaType, fWorkingSpace};
33
34 const auto* dstToWorking = rec.fAlloc->make<SkColorSpaceXformSteps>(dst, working);
35 const auto* workingToDst = rec.fAlloc->make<SkColorSpaceXformSteps>(working, dst);
36
37 // Alpha-only image shaders reference the paint color, which is already in the destination
38 // color space. We need to transform it to the working space for consistency.
39 SkColor4f paintColorInWorkingSpace = rec.fPaintColor.makeOpaque();
40 dstToWorking->apply(paintColorInWorkingSpace.vec());
41
42 SkStageRec workingRec = {rec.fPipeline,
43 rec.fAlloc,
44 rec.fDstColorType,
45 fWorkingSpace.get(),
46 paintColorInWorkingSpace,
47 rec.fSurfaceProps};
48
49 if (!as_SB(fShader)->appendStages(workingRec, mRec)) {
50 return false;
51 }
52
53 workingToDst->apply(rec.fPipeline);
54 return true;
55}
56
57void SkWorkingColorSpaceShader::flatten(SkWriteBuffer& buffer) const {
58 buffer.writeFlattenable(fShader.get());
59 buffer.writeDataAsByteArray(fWorkingSpace->serialize().get());
60}
61
62sk_sp<SkFlattenable> SkWorkingColorSpaceShader::CreateProc(SkReadBuffer& buffer) {
63 sk_sp<SkShader> shader(buffer.readShader());
64 auto data = buffer.readByteArrayAsData();
65 if (!buffer.validate(data != nullptr)) {
66 return nullptr;
67 }
69 if (!buffer.validate(workingSpace != nullptr)) {
70 return nullptr;
71 }
72 return sk_make_sp<SkWorkingColorSpaceShader>(std::move(shader), std::move(workingSpace));
73}
74
77}
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
#define SK_REGISTER_FLATTENABLE(type)
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
SkShaderBase * as_SB(SkShader *shader)
Definition: SkShaderBase.h:412
void SkRegisterWorkingColorSpaceShaderFlattenable()
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
Definition: SkArenaAlloc.h:120
static sk_sp< SkColorSpace > MakeSRGB()
static sk_sp< SkColorSpace > Deserialize(const void *data, size_t length)
sk_sp< SkData > serialize() const
virtual bool appendStages(const SkStageRec &, const SkShaders::MatrixRec &) const =0
sk_sp< SkShader > shader() const
sk_sp< SkColorSpace > workingSpace() const
T * get() const
Definition: SkRefCnt.h:303
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
dst
Definition: cp.py:12
void apply(float rgba[4]) const
const SkSurfaceProps & fSurfaceProps
Definition: SkEffectPriv.h:26
SkColor4f fPaintColor
Definition: SkEffectPriv.h:25
SkRasterPipeline * fPipeline
Definition: SkEffectPriv.h:21
SkColorSpace * fDstCS
Definition: SkEffectPriv.h:24
SkArenaAlloc * fAlloc
Definition: SkEffectPriv.h:22
SkColorType fDstColorType
Definition: SkEffectPriv.h:23
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63