• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "ani_sampling_options.h"
17 
18 namespace OHOS::Rosen {
19 namespace Drawing {
20 
21 const char* ANI_CLASS_SAMPLING_OPTIONS_NAME = "L@ohos/graphics/drawing/drawing/SamplingOptions;";
22 
AniInit(ani_env * env)23 ani_status AniSamplingOptions::AniInit(ani_env *env)
24 {
25     ani_class cls = nullptr;
26     ani_status ret = env->FindClass(ANI_CLASS_SAMPLING_OPTIONS_NAME, &cls);
27     if (ret != ANI_OK) {
28         ROSEN_LOGE("[ANI] can't find class: %{public}s", ANI_CLASS_SAMPLING_OPTIONS_NAME);
29         return ANI_NOT_FOUND;
30     }
31 
32     std::array methods = {
33         ani_native_function { "constructorNative", ":V", reinterpret_cast<void*>(Constructor) },
34         ani_native_function { "constructorNative", "L@ohos/graphics/drawing/drawing/FilterMode;:V",
35             reinterpret_cast<void*>(ConstructorWithFilterMode) },
36     };
37 
38     ret = env->Class_BindNativeMethods(cls, methods.data(), methods.size());
39     if (ret != ANI_OK) {
40         ROSEN_LOGE("[ANI] bind methods fail: %{public}s", ANI_CLASS_SAMPLING_OPTIONS_NAME);
41         return ANI_NOT_FOUND;
42     }
43 
44     return ANI_OK;
45 }
46 
47 
Constructor(ani_env * env,ani_object obj)48 void AniSamplingOptions::Constructor(ani_env* env, ani_object obj)
49 {
50     std::shared_ptr<SamplingOptions> samplingOptions = std::make_shared<SamplingOptions>();
51     AniSamplingOptions* aniSamplingOptions = new AniSamplingOptions(samplingOptions);
52     if (ANI_OK != env->Object_SetFieldByName_Long(obj, NATIVE_OBJ, reinterpret_cast<ani_long>(aniSamplingOptions))) {
53         ROSEN_LOGE("AniSamplingOptions::Constructor failed create aniSamplingOptions");
54         delete aniSamplingOptions;
55         return;
56     }
57 }
58 
ConstructorWithFilterMode(ani_env * env,ani_object obj,ani_enum_item filterModeObj)59 void AniSamplingOptions::ConstructorWithFilterMode(ani_env* env, ani_object obj, ani_enum_item filterModeObj)
60 {
61     ani_int filterMode;
62     if (ANI_OK != env->EnumItem_GetValue_Int(filterModeObj, &filterMode)) {
63         AniThrowError(env, "Invalid params.");
64         return;
65     }
66 
67     std::shared_ptr<SamplingOptions> samplingOptions = std::make_shared<SamplingOptions>(FilterMode(filterMode));
68     AniSamplingOptions* aniSamplingOptions = new AniSamplingOptions(samplingOptions);
69 
70     if (ANI_OK != env->Object_SetFieldByName_Long(obj, NATIVE_OBJ, reinterpret_cast<ani_long>(aniSamplingOptions))) {
71         ROSEN_LOGE("AniSamplingOptions::Constructor failed create aniSamplingOptions");
72         delete aniSamplingOptions;
73         return;
74     }
75 }
76 
~AniSamplingOptions()77 AniSamplingOptions::~AniSamplingOptions()
78 {
79     m_samplingOptions = nullptr;
80 }
81 
GetSamplingOptions()82 std::shared_ptr<SamplingOptions> AniSamplingOptions::GetSamplingOptions()
83 {
84     return m_samplingOptions;
85 }
86 
87 } // namespace Drawing
88 } // namespace OHOS::Rosen
89