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 #ifndef VERTICES_H 17 #define VERTICES_H 18 19 #include "drawing/engine_adapter/impl_interface/vertices_impl.h" 20 21 namespace OHOS { 22 namespace Rosen { 23 namespace Drawing { 24 25 enum class VertexMode { 26 TRIANGLES_VERTEXMODE, 27 TRIANGLESSTRIP_VERTEXMODE, 28 TRIANGLEFAN_VERTEXMODE, 29 30 LAST_VERTEXMODE = TRIANGLEFAN_VERTEXMODE, 31 }; 32 33 enum class BuilderFlags { 34 HAS_TEXCOORDS_BUILDER_FLAG = 1 << 0, 35 HAS_COLORS_BUILDER_FLAG = 1 << 1, 36 }; 37 38 class Vertices { 39 public: 40 Vertices() noexcept; 41 explicit Vertices(std::shared_ptr<VerticesImpl>) noexcept; ~Vertices()42 virtual ~Vertices() {}; 43 44 /* 45 * @brief Make a copy from vertices data. 46 * @param vertexCount Vertex count. 47 * @param positions Positions data pointer. 48 * @param tex Texture coordinate data pointer. 49 * @param colors Color data pointer. 50 * @param indexCount Index count. 51 * @param indices Index data pointer. 52 * @return Returns true if MakeCopy succeed. 53 */ 54 bool MakeCopy(VertexMode mode, 55 int vertexCount, const Point positions[], const Point texs[], const ColorQuad colors[], 56 int indexCount, const uint16_t indices[]); 57 58 /* 59 * @brief Make a copy from vertices data. 60 * @param vertexCount Vertex count. 61 * @param positions Positions data pointer. 62 * @param tex Texture coordinate data pointer. 63 * @param colors Color data pointer. 64 * @return Returns true if MakeCopy succeed. 65 */ 66 bool MakeCopy(VertexMode mode, 67 int vertexCount, const Point positions[], const Point texs[], const ColorQuad colors[]); 68 69 /* 70 * @brief Get the adaptation layer instance, called in the adaptation layer. 71 * @return Adaptation Layer instance. 72 */ 73 template<typename T> GetImpl()74 T* GetImpl() const 75 { 76 if (verticesImplPtr_ == nullptr) { 77 return nullptr; 78 } 79 return verticesImplPtr_->DowncastingTo<T>(); 80 } 81 std::shared_ptr<Data> Serialize() const; 82 bool Deserialize(std::shared_ptr<Data> data); 83 class Builder { 84 public: 85 Builder(VertexMode mode, int vertexCount, int indexCount, uint32_t flags); ~Builder()86 virtual ~Builder() {}; 87 88 /* 89 * @brief Return if builder is valid. 90 */ 91 bool IsValid(); 92 93 /* 94 * @brief Return positions data pointer in the builder. 95 */ 96 Point* Positions(); 97 98 /* 99 * @brief Return indices data pointer in the builder. 100 */ 101 uint16_t* Indices(); 102 103 /* 104 * @brief Return texture coordinate data pointer in the builder. 105 */ 106 Point* TexCoords(); 107 108 /* 109 * @brief Return color data pointer in theBuilder. 110 */ 111 ColorQuad* Colors(); 112 113 /* 114 * @brief Detach the built vertices object. After yhe first call, this will always return null. 115 * @return Return a shared pointer of Vertices object or nullptr. 116 */ 117 std::shared_ptr<Vertices> Detach(); 118 119 private: 120 std::shared_ptr<VerticesImpl::BuilderImpl> builderImplPtr_; 121 }; 122 123 private: 124 std::shared_ptr<VerticesImpl> verticesImplPtr_; 125 }; 126 } // namespace Drawing 127 } // namespace Rosen 128 } // namespace OHOS 129 #endif 130