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/data.h"
17 
18 #include "impl_factory.h"
19 #include "static_factory.h"
20 
21 namespace OHOS {
22 namespace Rosen {
23 namespace Drawing {
Data()24 Data::Data() noexcept : impl_(ImplFactory::CreateDataImpl()) {}
25 
BuildFromMalloc(const void * data,size_t length)26 bool Data::BuildFromMalloc(const void* data, size_t length)
27 {
28     return impl_->BuildFromMalloc(data, length);
29 }
30 
BuildFromOHNativeBuffer(OH_NativeBuffer * nativeBuffer,size_t length)31 bool Data::BuildFromOHNativeBuffer(OH_NativeBuffer *nativeBuffer, size_t length)
32 {
33     return impl_->BuildFromOHNativeBuffer(nativeBuffer, length);
34 }
35 
BuildWithCopy(const void * data,size_t length)36 bool Data::BuildWithCopy(const void* data, size_t length)
37 {
38     return impl_->BuildWithCopy(data, length);
39 }
40 
BuildWithProc(const void * ptr,size_t length,DataReleaseProc proc,void * ctx)41 bool Data::BuildWithProc(const void* ptr, size_t length, DataReleaseProc proc, void* ctx)
42 {
43     return impl_->BuildWithProc(ptr, length, proc, ctx);
44 }
45 
BuildWithoutCopy(const void * data,size_t length)46 bool Data::BuildWithoutCopy(const void* data, size_t length)
47 {
48     return impl_->BuildWithoutCopy(data, length);
49 }
50 
BuildUninitialized(size_t length)51 bool Data::BuildUninitialized(size_t length)
52 {
53     return impl_->BuildUninitialized(length);
54 }
55 
BuildEmpty()56 bool Data::BuildEmpty()
57 {
58     return impl_->BuildEmpty();
59 }
60 
GetSize() const61 size_t Data::GetSize() const
62 {
63     return impl_->GetSize();
64 }
65 
GetData() const66 const void* Data::GetData() const
67 {
68     return impl_->GetData();
69 }
70 
MakeFromFileName(const char path[])71 std::shared_ptr<Data> Data::MakeFromFileName(const char path[])
72 {
73     return StaticFactory::MakeDataFromFileName(path);
74 }
75 
WritableData()76 void* Data::WritableData()
77 {
78     return impl_->WritableData();
79 }
80 
Serialize() const81 std::shared_ptr<Data> Data::Serialize() const
82 {
83     return impl_->Serialize();
84 }
85 } // namespace Drawing
86 } // namespace Rosen
87 } // namespace OHOS
88