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 SKIAVERTICES_H 17 #define SKIAVERTICES_H 18 19 #include "include/core/SkVertices.h" 20 #include "impl_interface/vertices_impl.h" 21 22 namespace OHOS { 23 namespace Rosen { 24 namespace Drawing { 25 class SkiaVertices : public VerticesImpl { 26 public: 27 static inline constexpr AdapterType TYPE = AdapterType::SKIA_ADAPTER; 28 29 SkiaVertices() noexcept; 30 explicit SkiaVertices(sk_sp<SkVertices> vertices) noexcept; ~SkiaVertices()31 ~SkiaVertices() override {} 32 GetType()33 AdapterType GetType() const override 34 { 35 return AdapterType::SKIA_ADAPTER; 36 } 37 38 bool MakeCopy(VertexMode mode, int vertexCount, 39 const Point positions[], const Point texs[], const ColorQuad colors[], 40 int indexCount, const uint16_t indices[]) override; 41 42 bool MakeCopy(VertexMode mode, int vertexCount, 43 const Point positions[], const Point texs[], const ColorQuad colors[]) override; 44 45 const sk_sp<SkVertices> GetVertices() const; 46 47 std::shared_ptr<Data> Serialize() const override; 48 bool Deserialize(std::shared_ptr<Data> data) override; 49 50 class SkiaBuilder : public VerticesImpl::BuilderImpl { 51 public: 52 static inline constexpr AdapterType TYPE = AdapterType::SKIA_ADAPTER; 53 SkiaBuilder()54 SkiaBuilder() noexcept {} ~SkiaBuilder()55 ~SkiaBuilder() override {} 56 GetType()57 AdapterType GetType() const override 58 { 59 return AdapterType::SKIA_ADAPTER; 60 } 61 62 void Init(VertexMode mode, int vertexCount, int indexCount, uint32_t flags) override; 63 bool IsValid() override; 64 65 Point* Positions() override; 66 uint16_t* Indices() override; 67 Point* TexCoords() override; 68 ColorQuad* Colors() override; 69 70 std::shared_ptr<VerticesImpl> Detach() override; 71 72 private: 73 std::shared_ptr<SkVertices::Builder> skiaVerticesBuilder_; 74 }; 75 76 private: 77 sk_sp<SkVertices> skiaVertices_; 78 }; 79 } // namespace Drawing 80 } // namespace Rosen 81 } // namespace OHOS 82 #endif 83