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 "drawing_memory_stream.h"
17 
18 #include <cstddef>
19 #include <unordered_map>
20 
21 #include "drawing_canvas_utils.h"
22 
23 #include "utils/memory_stream.h"
24 
25 using namespace OHOS;
26 using namespace Rosen;
27 using namespace Drawing;
28 
CastToMemoryStream(OH_Drawing_MemoryStream * cCanvas)29 static MemoryStream* CastToMemoryStream(OH_Drawing_MemoryStream* cCanvas)
30 {
31     return reinterpret_cast<MemoryStream*>(cCanvas);
32 }
33 
OH_Drawing_MemoryStreamCreate(const void * data,size_t length,bool copyData)34 OH_Drawing_MemoryStream* OH_Drawing_MemoryStreamCreate(const void* data, size_t length, bool copyData)
35 {
36     if (data == nullptr || length == 0) {
37         g_drawingErrorCode = OH_DRAWING_ERROR_INVALID_PARAMETER;
38         return nullptr;
39     }
40     return (OH_Drawing_MemoryStream*)new MemoryStream(data, length, copyData);
41 }
42 
OH_Drawing_MemoryStreamDestroy(OH_Drawing_MemoryStream * cMemoryStream)43 void OH_Drawing_MemoryStreamDestroy(OH_Drawing_MemoryStream* cMemoryStream)
44 {
45     if (cMemoryStream == nullptr) {
46         return;
47     }
48     delete CastToMemoryStream(cMemoryStream);
49 }
50