• 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 #ifndef OHOS_ROSEN_UI_EFFECT_CONTROLLER_COMMON_H
17 #define OHOS_ROSEN_UI_EFFECT_CONTROLLER_COMMON_H
18 #include <message_parcel.h>
19 #include <parcel.h>
20 
21 #include "ui_effect/effect/include/visual_effect.h"
22 #include "ui_effect/filter/include/filter.h"
23 #include "js_runtime_utils.h"
24 #include "window_manager_hilog.h"
25 
26 namespace OHOS::Rosen {
27 #define NAPI_CHECK(func, msg)                                                                           \
28     do {                                                                                                \
29         napi_status status = func;                                                                      \
30         if (status != napi_status::napi_ok) {                                                           \
31             TLOGE(WmsLogTag::DEFAULT, "Failed with reason %{public}s, code:%{public}d", msg, status);   \
32             return status;                                                                              \
33         }                                                                                               \
34     } while (0)
35 
36 template<typename T>
WrapObjectDestructor(napi_env env,void * nativeObject,void *)37 void WrapObjectDestructor(napi_env env, void* nativeObject, void*)
38 {
39     T* obj = static_cast<T*>(nativeObject);
40     if (obj) {
41         delete obj;
42     }
43 }
44 
45 const int32_t UIEFFECT_INVALID_ID = -1;
46 class UIEffectParams : public Parcelable {
47 public:
48     bool Marshalling(Parcel& parcel) const override;
49     static UIEffectParams* Unmarshalling(Parcel& parcel);
50 
IsEmpty()51     bool IsEmpty()
52     {
53         return backgroundFilter_ == nullptr && effect_ == nullptr;
54     }
55 
56     napi_status ConvertToJsValue(napi_env env, napi_value& val);
57     napi_status ConvertFromJsValue(napi_env env, napi_value val);
58 
59 private:
60     std::shared_ptr<Filter> backgroundFilter_ = nullptr;
61     std::shared_ptr<VisualEffect> effect_ = nullptr;
62 };
63 } // namespace OHOS::Rosen
64 #endif