18bf80f4bSopenharmony_ci/* 28bf80f4bSopenharmony_ci * Copyright (C) 2024 Huawei Device Co., Ltd. 38bf80f4bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 48bf80f4bSopenharmony_ci * you may not use this file except in compliance with the License. 58bf80f4bSopenharmony_ci * You may obtain a copy of the License at 68bf80f4bSopenharmony_ci * 78bf80f4bSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 88bf80f4bSopenharmony_ci * 98bf80f4bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 108bf80f4bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 118bf80f4bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 128bf80f4bSopenharmony_ci * See the License for the specific language governing permissions and 138bf80f4bSopenharmony_ci * limitations under the License. 148bf80f4bSopenharmony_ci */ 158bf80f4bSopenharmony_ci 168bf80f4bSopenharmony_ci#ifndef OHOS_RENDER_3D_SCENE_JS_H 178bf80f4bSopenharmony_ci#define OHOS_RENDER_3D_SCENE_JS_H 188bf80f4bSopenharmony_ci#include <meta/api/threading/mutex.h> 198bf80f4bSopenharmony_ci#include <meta/interface/intf_object.h> 208bf80f4bSopenharmony_ci#include <scene_plugin/interface/intf_material.h> // for bitmap. 218bf80f4bSopenharmony_ci#include <scene_plugin/interface/intf_mesh.h> 228bf80f4bSopenharmony_ci 238bf80f4bSopenharmony_ci#include <base/containers/unordered_map.h> 248bf80f4bSopenharmony_ci#ifdef __SCENE_ADAPTER__ 258bf80f4bSopenharmony_ci#include "scene_adapter/intf_scene_adapter.h" 268bf80f4bSopenharmony_ci#endif 278bf80f4bSopenharmony_ci#include "BaseObjectJS.h" 288bf80f4bSopenharmony_ciclass SceneJS : public BaseObject<SceneJS> { 298bf80f4bSopenharmony_cipublic: 308bf80f4bSopenharmony_ci static constexpr uint32_t ID = 4; 318bf80f4bSopenharmony_ci static void Init(napi_env env, napi_value exports); 328bf80f4bSopenharmony_ci 338bf80f4bSopenharmony_ci SceneJS(napi_env, napi_callback_info); 348bf80f4bSopenharmony_ci ~SceneJS() override; 358bf80f4bSopenharmony_ci void* GetInstanceImpl(uint32_t id) override; 368bf80f4bSopenharmony_ci#ifdef __SCENE_ADAPTER__ 378bf80f4bSopenharmony_ci std::shared_ptr<OHOS::Render3D::ISceneAdapter> scene_ = nullptr; 388bf80f4bSopenharmony_ci#endif 398bf80f4bSopenharmony_ci 408bf80f4bSopenharmony_ci void StoreBitmap(BASE_NS::string_view uri, SCENE_NS::IBitmap::Ptr bitmap); 418bf80f4bSopenharmony_ci SCENE_NS::IBitmap::Ptr FetchBitmap(BASE_NS::string_view uri); 428bf80f4bSopenharmony_ci 438bf80f4bSopenharmony_ci void DisposeHook(uintptr_t token, NapiApi::Object); 448bf80f4bSopenharmony_ci void ReleaseDispose(uintptr_t token); 458bf80f4bSopenharmony_ci 468bf80f4bSopenharmony_ci void StrongDisposeHook(uintptr_t token, NapiApi::Object); 478bf80f4bSopenharmony_ci void ReleaseStrongDispose(uintptr_t token); 488bf80f4bSopenharmony_ci 498bf80f4bSopenharmony_ciprivate: 508bf80f4bSopenharmony_ci napi_value Dispose(NapiApi::FunctionContext<>& ctx); 518bf80f4bSopenharmony_ci void DisposeNative() override; 528bf80f4bSopenharmony_ci void Finalize(napi_env env) override; 538bf80f4bSopenharmony_ci // JS properties 548bf80f4bSopenharmony_ci napi_value GetRoot(NapiApi::FunctionContext<>& ctx); 558bf80f4bSopenharmony_ci 568bf80f4bSopenharmony_ci napi_value GetAnimations(NapiApi::FunctionContext<>& ctx); 578bf80f4bSopenharmony_ci 588bf80f4bSopenharmony_ci napi_value GetEnvironment(NapiApi::FunctionContext<>& ctx); 598bf80f4bSopenharmony_ci void SetEnvironment(NapiApi::FunctionContext<NapiApi::Object>& ctx); 608bf80f4bSopenharmony_ci 618bf80f4bSopenharmony_ci // JS methods 628bf80f4bSopenharmony_ci napi_value GetNode(NapiApi::FunctionContext<BASE_NS::string>& ctx); 638bf80f4bSopenharmony_ci napi_value GetResourceFactory(NapiApi::FunctionContext<>& ctx); 648bf80f4bSopenharmony_ci 658bf80f4bSopenharmony_ci napi_value CreateCamera(NapiApi::FunctionContext<NapiApi::Object>& ctx); 668bf80f4bSopenharmony_ci napi_value CreateLight(NapiApi::FunctionContext<NapiApi::Object, uint32_t>& ctx); 678bf80f4bSopenharmony_ci napi_value CreateNode(NapiApi::FunctionContext<NapiApi::Object>& ctx); 688bf80f4bSopenharmony_ci napi_value CreateEnvironment(NapiApi::FunctionContext<NapiApi::Object>& ctx); 698bf80f4bSopenharmony_ci napi_value CreateImage(NapiApi::FunctionContext<NapiApi::Object>& ctx); 708bf80f4bSopenharmony_ci napi_value CreateShader(NapiApi::FunctionContext<NapiApi::Object>& ctx); 718bf80f4bSopenharmony_ci napi_value CreateMaterial(NapiApi::FunctionContext<NapiApi::Object, uint32_t>& ctx); 728bf80f4bSopenharmony_ci 738bf80f4bSopenharmony_ci // static js method 748bf80f4bSopenharmony_ci static napi_value Load(NapiApi::FunctionContext<>& ctx); 758bf80f4bSopenharmony_ci 768bf80f4bSopenharmony_ci // make a storage of all bitmaps.. 778bf80f4bSopenharmony_ci CORE_NS::Mutex mutex_; 788bf80f4bSopenharmony_ci BASE_NS::unordered_map<BASE_NS::string, SCENE_NS::IBitmap::Ptr> bitmaps_; 798bf80f4bSopenharmony_ci NapiApi::StrongRef environmentJS_; 808bf80f4bSopenharmony_ci BASE_NS::unordered_map<uintptr_t, NapiApi::StrongRef> strongDisposables_; 818bf80f4bSopenharmony_ci BASE_NS::unordered_map<uintptr_t, NapiApi::WeakRef> disposables_; 828bf80f4bSopenharmony_ci 838bf80f4bSopenharmony_cipublic: 848bf80f4bSopenharmony_ci NapiApi::Object CreateEnvironment(NapiApi::Object, NapiApi::Object); 858bf80f4bSopenharmony_ci}; 868bf80f4bSopenharmony_ci#endif // OHOS_RENDER_3D_SCENE_JS_H