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     return verticesImplPtr_->Serialize();
51 }
52 
Deserialize(std::shared_ptr<Data> data)53 bool Vertices::Deserialize(std::shared_ptr<Data> data)
54 {
55     return verticesImplPtr_->Deserialize(data);
56 }
57 
Builder(VertexMode mode,int vertexCount,int indexCount,uint32_t flags)58 Vertices::Builder::Builder(VertexMode mode, int vertexCount, int indexCount, uint32_t flags)
59     : builderImplPtr_(ImplFactory::CreateVerticesBuilderImpl())
60 {
61     builderImplPtr_->Init(mode, vertexCount, indexCount, flags);
62 }
63 
IsValid()64 bool Vertices::Builder::IsValid()
65 {
66     return builderImplPtr_->IsValid();
67 }
68 
Positions()69 Point* Vertices::Builder::Positions()
70 {
71     return builderImplPtr_->Positions();
72 }
73 
Indices()74 uint16_t* Vertices::Builder::Indices()
75 {
76     return builderImplPtr_->Indices();
77 }
78 
TexCoords()79 Point* Vertices::Builder::TexCoords()
80 {
81     return builderImplPtr_->TexCoords();
82 }
83 
Colors()84 ColorQuad* Vertices::Builder::Colors()
85 {
86     return builderImplPtr_->Colors();
87 }
88 
Detach()89 std::shared_ptr<Vertices> Vertices::Builder::Detach()
90 {
91     return std::make_shared<Vertices>(builderImplPtr_->Detach());
92 }
93 
94 } // namespace Drawing
95 } // namespace Rosen
96 } // namespace OHOS