1 /*
2  * Copyright (c) 2024 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_shadow_layer.h"
17 #include "drawing_helper.h"
18 
19 #include "drawing_canvas_utils.h"
20 
21 #include "effect/blur_draw_looper.h"
22 
23 using namespace OHOS;
24 using namespace Rosen;
25 using namespace Drawing;
26 
OH_Drawing_ShadowLayerCreate(float blurRadius,float x,float y,uint32_t color)27 OH_Drawing_ShadowLayer* OH_Drawing_ShadowLayerCreate(float blurRadius, float x, float y, uint32_t color)
28 {
29     if (blurRadius <= 0.f) {
30         g_drawingErrorCode = OH_DRAWING_ERROR_PARAMETER_OUT_OF_RANGE;
31         return nullptr;
32     }
33     NativeHandle<BlurDrawLooper>* blurDrawLooperHandle = new NativeHandle<BlurDrawLooper>;
34     blurDrawLooperHandle->value = BlurDrawLooper::CreateBlurDrawLooper(blurRadius, x, y, color);
35     if (blurDrawLooperHandle->value == nullptr) {
36         delete blurDrawLooperHandle;
37         return nullptr;
38     }
39     return Helper::CastTo<NativeHandle<BlurDrawLooper>*, OH_Drawing_ShadowLayer*>(blurDrawLooperHandle);
40 }
41 
OH_Drawing_ShadowLayerDestroy(OH_Drawing_ShadowLayer * cShadowLayer)42 void OH_Drawing_ShadowLayerDestroy(OH_Drawing_ShadowLayer* cShadowLayer)
43 {
44     if (!cShadowLayer) {
45         return;
46     }
47     delete Helper::CastTo<OH_Drawing_ShadowLayer*, NativeHandle<BlurDrawLooper>*>(cShadowLayer);
48 }
49