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_path_effect.h"
17 
18 #include <mutex>
19 #include <unordered_map>
20 
21 #include "drawing_canvas_utils.h"
22 #include "drawing_helper.h"
23 
24 #include "effect/path_effect.h"
25 
26 using namespace OHOS;
27 using namespace Rosen;
28 using namespace Drawing;
29 
OH_Drawing_CreateDashPathEffect(float * intervals,int count,float phase)30 OH_Drawing_PathEffect* OH_Drawing_CreateDashPathEffect(float* intervals, int count, float phase)
31 {
32     if (intervals == nullptr || count <= 0) {
33         g_drawingErrorCode = OH_DRAWING_ERROR_INVALID_PARAMETER;
34         return nullptr;
35     }
36     NativeHandle<PathEffect>* pathEffectHandle = new NativeHandle<PathEffect>;
37     pathEffectHandle->value = PathEffect::CreateDashPathEffect(intervals, count, phase);
38     if (pathEffectHandle->value == nullptr) {
39         delete pathEffectHandle;
40         return nullptr;
41     }
42     return Helper::CastTo<NativeHandle<PathEffect>*, OH_Drawing_PathEffect*>(pathEffectHandle);
43 }
44 
OH_Drawing_PathEffectDestroy(OH_Drawing_PathEffect * cPathEffect)45 void OH_Drawing_PathEffectDestroy(OH_Drawing_PathEffect* cPathEffect)
46 {
47     if (!cPathEffect) {
48         return;
49     }
50     delete Helper::CastTo<OH_Drawing_PathEffect*, NativeHandle<PathEffect>*>(cPathEffect);
51 }
52