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 SKIA_DATA_H
17 #define SKIA_DATA_H
18 
19 #include "include/core/SkData.h"
20 #include "impl_interface/data_impl.h"
21 
22 namespace OHOS {
23 namespace Rosen {
24 namespace Drawing {
25 class DRAWING_API SkiaData : public DataImpl {
26 public:
27     static inline constexpr AdapterType TYPE = AdapterType::SKIA_ADAPTER;
28 
29     SkiaData() noexcept;
~SkiaData()30     ~SkiaData() override {}
31 
GetType()32     AdapterType GetType() const override
33     {
34         return AdapterType::SKIA_ADAPTER;
35     }
36 
37     bool BuildFromMalloc(const void* data, size_t length) override;
38     bool BuildFromOHNativeBuffer(OH_NativeBuffer* nativeBuffer, size_t length) override;
39     bool BuildWithCopy(const void* data, size_t length) override;
40     bool BuildWithProc(const void* ptr, size_t length, DataReleaseProc proc, void* ctx) override;
41     bool BuildWithoutCopy(const void* data, size_t length) override;
42     bool BuildUninitialized(size_t length) override;
43     bool BuildEmpty() override;
44 
45     void* WritableData() override;
46     size_t GetSize() const override;
47     const void* GetData() const override;
48 
49     static std::shared_ptr<Data> MakeFromFileName(const char path[]);
50 
51     /*
52      * @brief  Export Skia member variables for use by the adaptation layer.
53      */
54     sk_sp<SkData> GetSkData() const;
55 
56     /*
57      * @brief  Update the member variable to filter, adaptation layer calls.
58      */
59     void SetSkData(const sk_sp<SkData>& data);
60 
61     std::shared_ptr<Data> Serialize() const override;
62 private:
63     sk_sp<SkData> skData_;
64 };
65 } // Drawing
66 } // Rosen
67 } // OHOS
68 
69 #endif
70