Flutter Engine
The Flutter Engine
SkCoordClampShader.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 The Android Open Source Project
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
20
21#include <optional>
22
23sk_sp<SkFlattenable> SkCoordClampShader::CreateProc(SkReadBuffer& buffer) {
24 sk_sp<SkShader> shader(buffer.readShader());
25 SkRect subset = buffer.readRect();
26 if (!buffer.validate(SkToBool(shader))) {
27 return nullptr;
28 }
29 return SkShaders::CoordClamp(std::move(shader), subset);
30}
31
33 buffer.writeFlattenable(fShader.get());
34 buffer.writeRect(fSubset);
35}
36
38 const SkShaders::MatrixRec& mRec) const {
39 std::optional<SkShaders::MatrixRec> childMRec = mRec.apply(rec);
40 if (!childMRec.has_value()) {
41 return false;
42 }
43 // Strictly speaking, childMRec's total matrix is not valid. It is only valid inside the subset
44 // rectangle. However, we don't mark it as such because we want the "total matrix is valid"
45 // behavior in SkImageShader for filtering.
46 auto clampCtx = rec.fAlloc->make<SkRasterPipeline_CoordClampCtx>();
47 *clampCtx = {fSubset.fLeft, fSubset.fTop, fSubset.fRight, fSubset.fBottom};
48 rec.fPipeline->append(SkRasterPipelineOp::clamp_x_and_y, clampCtx);
49 return as_SB(fShader)->appendStages(rec, *childMRec);
50}
51
54
55 // Previous name
56 SkFlattenable::Register("SkShader_CoordClamp", SkCoordClampShader::CreateProc);
57}
58
60 if (!shader) {
61 return nullptr;
62 }
63 if (!subset.isSorted()) {
64 return nullptr;
65 }
66 return sk_make_sp<SkCoordClampShader>(std::move(shader), subset);
67}
void SkRegisterCoordClampShaderFlattenable()
#define SK_REGISTER_FLATTENABLE(type)
SkShaderBase * as_SB(SkShader *shader)
Definition: SkShaderBase.h:412
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
auto make(Ctor &&ctor) -> decltype(ctor(nullptr))
Definition: SkArenaAlloc.h:120
SkRect subset() const
bool appendStages(const SkStageRec &, const SkShaders::MatrixRec &) const override
sk_sp< SkShader > shader() const
void flatten(SkWriteBuffer &) const override
static void Register(const char name[], Factory)
void append(SkRasterPipelineOp, void *=nullptr)
virtual bool appendStages(const SkStageRec &, const SkShaders::MatrixRec &) const =0
std::optional< MatrixRec > apply(const SkStageRec &rec, const SkMatrix &postInv={}) const
T * get() const
Definition: SkRefCnt.h:303
SK_API sk_sp< SkShader > CoordClamp(sk_sp< SkShader >, const SkRect &subset)
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
SkScalar fBottom
larger y-axis bounds
Definition: extension.cpp:17
SkScalar fLeft
smaller x-axis bounds
Definition: extension.cpp:14
SkScalar fRight
larger x-axis bounds
Definition: extension.cpp:16
bool isSorted() const
Definition: SkRect.h:705
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15
SkRasterPipeline * fPipeline
Definition: SkEffectPriv.h:21
SkArenaAlloc * fAlloc
Definition: SkEffectPriv.h:22