1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "utils/vertices.h"
17 #include "impl_factory.h"
18 #include "utils/log.h"
19
20 namespace OHOS {
21 namespace Rosen {
22 namespace Drawing {
Vertices()23 Vertices::Vertices() noexcept : verticesImplPtr_(ImplFactory::CreateVerticesImpl()) {}
24
Vertices(std::shared_ptr<VerticesImpl> vertices)25 Vertices::Vertices(std::shared_ptr<VerticesImpl> vertices) noexcept
26 : verticesImplPtr_(vertices) {}
27
MakeCopy(VertexMode mode,int vertexCount,const Point positions[],const Point texs[],const ColorQuad colors[],int indexCount,const uint16_t indices[])28 bool Vertices::MakeCopy(VertexMode mode,
29 int vertexCount, const Point positions[], const Point texs[], const ColorQuad colors[],
30 int indexCount, const uint16_t indices[])
31 {
32 if (verticesImplPtr_ == nullptr) {
33 return false;
34 }
35 return verticesImplPtr_->MakeCopy(mode, vertexCount, positions, texs, colors,
36 indexCount, indices);
37 }
38
MakeCopy(VertexMode mode,int vertexCount,const Point positions[],const Point texs[],const ColorQuad colors[])39 bool Vertices::MakeCopy(VertexMode mode,
40 int vertexCount, const Point positions[], const Point texs[], const ColorQuad colors[])
41 {
42 if (verticesImplPtr_ == nullptr) {
43 return false;
44 }
45 return verticesImplPtr_->MakeCopy(mode, vertexCount, positions, texs, colors);
46 }
47
Serialize() const48 std::shared_ptr<Data> Vertices::Serialize() const
49 {
50 if (verticesImplPtr_ == nullptr) {
51 return nullptr;
52 }
53 return verticesImplPtr_->Serialize();
54 }
55
Deserialize(std::shared_ptr<Data> data)56 bool Vertices::Deserialize(std::shared_ptr<Data> data)
57 {
58 if (verticesImplPtr_ == nullptr) {
59 return false;
60 }
61 return verticesImplPtr_->Deserialize(data);
62 }
63
Builder(VertexMode mode,int vertexCount,int indexCount,uint32_t flags)64 Vertices::Builder::Builder(VertexMode mode, int vertexCount, int indexCount, uint32_t flags)
65 : builderImplPtr_(ImplFactory::CreateVerticesBuilderImpl())
66 {
67 builderImplPtr_->Init(mode, vertexCount, indexCount, flags);
68 }
69
IsValid()70 bool Vertices::Builder::IsValid()
71 {
72 return builderImplPtr_->IsValid();
73 }
74
Positions()75 Point* Vertices::Builder::Positions()
76 {
77 return builderImplPtr_->Positions();
78 }
79
Indices()80 uint16_t* Vertices::Builder::Indices()
81 {
82 return builderImplPtr_->Indices();
83 }
84
TexCoords()85 Point* Vertices::Builder::TexCoords()
86 {
87 return builderImplPtr_->TexCoords();
88 }
89
Colors()90 ColorQuad* Vertices::Builder::Colors()
91 {
92 return builderImplPtr_->Colors();
93 }
94
Detach()95 std::shared_ptr<Vertices> Vertices::Builder::Detach()
96 {
97 return std::make_shared<Vertices>(builderImplPtr_->Detach());
98 }
99
100 } // namespace Drawing
101 } // namespace Rosen
102 } // namespace OHOS