Flutter Engine
The Flutter Engine
SkMeshPriv.h
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
8#ifndef SkMeshPriv_DEFINED
9#define SkMeshPriv_DEFINED
10
11#include "include/core/SkData.h"
12#include "include/core/SkMesh.h"
14
18 using ColorType = SkMeshSpecification::ColorType;
19
21 return SkSpan(spec.fVaryings);
22 }
23
24 static const SkSL::Program* VS(const SkMeshSpecification& spec) { return spec.fVS.get(); }
25 static const SkSL::Program* FS(const SkMeshSpecification& spec) { return spec.fFS.get(); }
26
27 static int Hash(const SkMeshSpecification& spec) { return spec.fHash; }
28
29 static ColorType GetColorType(const SkMeshSpecification& spec) { return spec.fColorType; }
30 static bool HasColors(const SkMeshSpecification& spec) {
31 return GetColorType(spec) != ColorType::kNone;
32 }
33
35 return spec.fColorSpace.get();
36 }
37
38 static SkAlphaType AlphaType(const SkMeshSpecification& spec) { return spec.fAlphaType; }
39
41 switch (type) {
50 }
52 }
53
55 switch (type) {
61 }
63 }
64
66 return spec.fPassthroughLocalCoordsVaryingIndex;
67 }
68
69 /**
70 * A varying is dead if it is never referenced OR it is only referenced as a passthrough for
71 * local coordinates. In the latter case, its index will returned as
72 * PassthroughLocalCoordsVaryingIndex. Our analysis is not very sophisticated so this is
73 * determined conservatively.
74 */
75 static bool VaryingIsDead(const SkMeshSpecification& spec, int v) {
76 SkASSERT(v >= 0 && SkToSizeT(v) < spec.fVaryings.size());
77 return (1 << v) & spec.fDeadVaryingMask;
78 }
79};
80
81namespace SkMeshPriv {
82class Buffer {
83public:
84 virtual ~Buffer() = 0;
85
86 Buffer() = default;
87 Buffer(const Buffer&) = delete;
88
89 Buffer& operator=(const Buffer&) = delete;
90
91 virtual const void* peek() const { return nullptr; }
92
93 virtual bool isGaneshBacked() const { return false; }
94};
95
96class IB : public Buffer, public SkMesh::IndexBuffer {};
97class VB : public Buffer, public SkMesh::VertexBuffer {};
98
99template <typename Base> class CpuBuffer final : public Base {
100public:
101 ~CpuBuffer() override = default;
102
103 static sk_sp<Base> Make(const void* data, size_t size);
104
105 const void* peek() const override { return fData->data(); }
106
107 size_t size() const override { return fData->size(); }
108
109private:
110 CpuBuffer(sk_sp<SkData> data) : fData(std::move(data)) {}
111
112 bool onUpdate(GrDirectContext*, const void* data, size_t offset, size_t size) override;
113
114 sk_sp<SkData> fData;
115};
116
119} // namespace SkMeshPriv
120
121inline SkMeshPriv::Buffer::~Buffer() = default;
122
123template <typename Base> sk_sp<Base> SkMeshPriv::CpuBuffer<Base>::Make(const void* data,
124 size_t size) {
125 SkASSERT(size);
126 sk_sp<SkData> storage;
127 if (data) {
128 storage = SkData::MakeWithCopy(data, size);
129 } else {
131 }
132 return sk_sp<Base>(new CpuBuffer<Base>(std::move(storage)));
133}
134
135template <typename Base> bool SkMeshPriv::CpuBuffer<Base>::onUpdate(GrDirectContext* dc,
136 const void* data,
137 size_t offset,
138 size_t size) {
139 if (dc) {
140 return false;
141 }
142 std::memcpy(SkTAddOffset<void>(fData->writable_data(), offset), data, size);
143 return true;
144}
145
146#endif
SkAlphaType
Definition: SkAlphaType.h:26
#define SkUNREACHABLE
Definition: SkAssert.h:135
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkMeshSpecification::Attribute Attribute
Definition: SkMesh.cpp:54
SkMeshSpecification::Varying Varying
Definition: SkMesh.cpp:55
SkSLType
SkSpan(Container &&) -> SkSpan< std::remove_pointer_t< decltype(std::data(std::declval< Container >()))> >
constexpr size_t SkToSizeT(S x)
Definition: SkTo.h:31
GLenum type
const void * data() const
Definition: SkData.h:37
static sk_sp< SkData > MakeWithCopy(const void *data, size_t length)
Definition: SkData.cpp:111
static sk_sp< SkData > MakeZeroInitialized(size_t length)
Definition: SkData.cpp:120
size_t size() const
Definition: SkData.h:30
Buffer(const Buffer &)=delete
virtual bool isGaneshBacked() const
Definition: SkMeshPriv.h:93
Buffer & operator=(const Buffer &)=delete
virtual ~Buffer()=0
virtual const void * peek() const
Definition: SkMeshPriv.h:91
~CpuBuffer() override=default
const void * peek() const override
Definition: SkMeshPriv.h:105
size_t size() const override
Definition: SkMeshPriv.h:107
static sk_sp< Base > Make(const void *data, size_t size)
Definition: SkMeshPriv.h:123
T * get() const
Definition: SkRefCnt.h:303
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 keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
Definition: ref_ptr.h:256
SeparatedVector2 offset
static int PassthroughLocalCoordsVaryingIndex(const SkMeshSpecification &spec)
Definition: SkMeshPriv.h:65
static bool HasColors(const SkMeshSpecification &spec)
Definition: SkMeshPriv.h:30
static SkSpan< const Varying > Varyings(const SkMeshSpecification &spec)
Definition: SkMeshPriv.h:20
static const SkSL::Program * FS(const SkMeshSpecification &spec)
Definition: SkMeshPriv.h:25
static bool VaryingIsDead(const SkMeshSpecification &spec, int v)
Definition: SkMeshPriv.h:75
static int Hash(const SkMeshSpecification &spec)
Definition: SkMeshPriv.h:27
static const SkSL::Program * VS(const SkMeshSpecification &spec)
Definition: SkMeshPriv.h:24
static ColorType GetColorType(const SkMeshSpecification &spec)
Definition: SkMeshPriv.h:29
static SkSLType VaryingTypeAsSLType(Varying::Type type)
Definition: SkMeshPriv.h:40
static SkAlphaType AlphaType(const SkMeshSpecification &spec)
Definition: SkMeshPriv.h:38
static SkColorSpace * ColorSpace(const SkMeshSpecification &spec)
Definition: SkMeshPriv.h:34
static SkSLType AttrTypeAsSLType(Attribute::Type type)
Definition: SkMeshPriv.h:54
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63