xref: /aosp_15_r20/external/skia/include/gpu/ganesh/SkMeshGanesh.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 
8 #ifndef SkMeshGanesh_DEFINED
9 #define SkMeshGanesh_DEFINED
10 
11 #include "include/core/SkMesh.h"
12 #include "include/core/SkRefCnt.h"
13 #include "include/private/base/SkAPI.h"
14 
15 #include <cstddef>
16 
17 class GrDirectContext;
18 
19 namespace SkMeshes {
20 /**
21  * Makes a GPU-backed index buffer to be used with SkMeshes.
22  *
23  * @param  GrDirectContext*  If non-null, the data will be uploaded to the corresponding GPU and the
24  *                           returned buffer will only be compatible with surfaces using the same
25  *                           context. If null, the data will be uploaded to a CPU buffer.
26  * @param  data              The data used to populate the buffer, or nullptr to create a zero-
27  *                           initialized buffer.
28  * @param  size              Both the size of the data in 'data' and the size of the resulting
29  *                           buffer.
30  */
31 SK_API sk_sp<SkMesh::IndexBuffer> MakeIndexBuffer(GrDirectContext*, const void* data, size_t size);
32 
33 /**
34  * Makes a copy of an index buffer. The copy will be GPU backed if the context is non-null.
35  */
36 SK_API sk_sp<SkMesh::IndexBuffer> CopyIndexBuffer(GrDirectContext*, sk_sp<SkMesh::IndexBuffer>);
37 
38 /**
39  * Makes a GPU-backed vertex buffer to be used with SkMeshes.
40  *
41  * @param  GrDirectContext*  If non-null, the data will be uploaded to the corresponding GPU and the
42  *                           returned buffer will only be compatible with surfaces using the same
43  *                           context. If null, the data will be uploaded to a CPU buffer.
44  * @param  data              The data used to populate the buffer, or nullptr to create a zero-
45  *                           initialized buffer.
46  * @param  size              Both the size of the data in 'data' and the size of the resulting
47  *                           buffer.
48  */
49 SK_API sk_sp<SkMesh::VertexBuffer> MakeVertexBuffer(GrDirectContext*, const void*, size_t size);
50 
51 /**
52  * Makes a copy of a vertex buffer. The copy will be GPU backed if the context is non-null.
53  */
54 SK_API sk_sp<SkMesh::VertexBuffer> CopyVertexBuffer(GrDirectContext*, sk_sp<SkMesh::VertexBuffer>);
55 }  // namespace SkMeshes
56 
57 #endif
58