• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <3d/implementation_uids.h>
17 #include <core/intf_engine.h>
18 #include <core/implementation_uids.h>
19 #include <core/io/intf_file_manager.h>
20 #include <core/plugin/intf_plugin.h>
21 #include <core/plugin/intf_plugin_decl.h>
22 #include <core/log.h>
23 #include <render/device/intf_device.h>
24 #include <render/device/intf_shader_manager.h>
25 #include <render/implementation_uids.h>
26 #include <render/intf_plugin.h>
27 #include <render/intf_render_context.h>
28 
29 extern "C" const void *const CAM_PREVIEW_BIN[];
30 extern "C" const uint64_t CAM_PREVIEW_BIN_SIZE;
31 
32 #include "cam_preview/namespace.h"
33 #include "cam_preview/implementation_uids.h"
34 
CORE_BEGIN_NAMESPACE()35 CORE_BEGIN_NAMESPACE()
36 #if defined(CORE_PLUGIN) && (CORE_PLUGIN == 1)
37 IPluginRegister *gPluginRegistry{nullptr};
GetPluginRegister()38 IPluginRegister &GetPluginRegister()
39 {
40     return *gPluginRegistry;
41 }
42 #endif
43 CORE_END_NAMESPACE()
44 
45 namespace {
46 static constexpr RENDER_NS::IShaderManager::ShaderFilePathDesc SHADER_FILE_PATHS{
47     "campreviewshaders://",
48     "campreviewshaderstates://",
49     "campreviewpipelinelayouts://",
50     "campreviewvertexinputdeclarations://",
51 };
52 }
53 
54 namespace CamPreview {
55 using CORE_NS::GetName;
56 using namespace BASE_NS;
57 using namespace CORE_NS;
58 using namespace RENDER_NS;
59 using namespace CORE3D_NS;
60 
61 IComponentManager *IMotphysVfxEffectComponentManagerInstance(IEcs &);
62 void IMotphysVfxEffectComponentManagerDestroy(IComponentManager *);
63 
64 ISystem *IMotphysVfxSystemInstance(IEcs &);
65 void IMotphysVfxSystemDestroy(ISystem *);
66 
67 IComponentManager *IMotphysVfxStateComponentManagerInstance(IEcs &);
68 void IMotphysVfxStateComponentManagerDestroy(IComponentManager *);
69 
GetVersionInfo()70 const char *GetVersionInfo()
71 {
72     return "GIT_TAG: 2024.12.24 GIT_REVISION: 34eac7a GIT_BRANCH: release";
73 }
74 
75 namespace {
76 
77 constexpr string_view ROFS = "campreviewrofs";
78 constexpr string_view SHADERS = "campreviewshaders";
79 constexpr string_view VIDS = "campreviewvertexinputdeclarations";
80 constexpr string_view PIDS = "campreviewpipelinelayouts";
81 constexpr string_view SSTATES = "campreviewshaderstates";
82 
83 constexpr string_view SHADER_PATH = "campreviewrofs://shaders/";
84 constexpr string_view VID_PATH = "campreviewrofs://vertexinputdeclarations/";
85 constexpr string_view PID_PATH = "campreviewrofs://pipelinelayouts/";
86 constexpr string_view SHADER_STATE_PATH = "campreviewrofs://shaderstates/";
87 
88 constexpr BASE_NS::Uid PLUGIN_DEPENDENCIES[] = {RENDER_NS::UID_RENDER_PLUGIN, CORE3D_NS::UID_3D_PLUGIN};
89 
Initialize(IRenderContext & context)90 PluginToken Initialize(IRenderContext &context)
91 {
92     auto &fm = context.GetEngine().GetFileManager();
93     // Create campreviewrofs:// filesystem that points to embedded asset files.
94     auto rofs = fm.CreateROFilesystem(CAM_PREVIEW_BIN, CAM_PREVIEW_BIN_SIZE);
95 
96     fm.RegisterFilesystem(ROFS, move(rofs));
97     // And register it under the needed proxy protocols.
98     fm.RegisterPath(SHADERS, SHADER_PATH, false);
99     fm.RegisterPath(VIDS, VID_PATH, false);
100     fm.RegisterPath(PIDS, PID_PATH, false);
101     fm.RegisterPath(SSTATES, SHADER_STATE_PATH, false);
102 
103     context.GetDevice().GetShaderManager().LoadShaderFiles(SHADER_FILE_PATHS);
104     return &context;
105 }
106 
Uninitialize(PluginToken token)107 void Uninitialize(PluginToken token)
108 {
109     auto context = static_cast<IRenderContext *>(token);
110     context->GetDevice().GetShaderManager().UnloadShaderFiles(SHADER_FILE_PATHS);
111     auto &fm = context->GetEngine().GetFileManager();
112     fm.UnregisterPath(SHADERS, SHADER_PATH);
113     fm.UnregisterPath(VIDS, VID_PATH);
114     fm.UnregisterPath(PIDS, PID_PATH);
115     fm.UnregisterPath(SSTATES, SHADER_STATE_PATH);
116     fm.UnregisterFilesystem(ROFS);
117 }
118 
InitializeEcs(IEcs & ecs)119 PluginToken InitializeEcs(IEcs &ecs)
120 {
121     return {};
122 }
123 
UninitializeEcs(PluginToken token)124 void UninitializeEcs(PluginToken token)
125 {}
126 
127 static constexpr IRenderPlugin RENDER_PLUGIN(Initialize, Uninitialize);
128 
129 static constexpr IEcsPlugin ECS_PLUGIN(InitializeEcs, UninitializeEcs);
130 }  // namespace
131 
RegisterInterfaces(IPluginRegister & pluginRegistry)132 PluginToken RegisterInterfaces(IPluginRegister &pluginRegistry)
133 {
134 #if defined(CORE_PLUGIN) && (CORE_PLUGIN == 1)
135     gPluginRegistry = &pluginRegistry;
136 #endif
137 
138     pluginRegistry.RegisterTypeInfo(RENDER_PLUGIN);
139     pluginRegistry.RegisterTypeInfo(ECS_PLUGIN);
140     return &pluginRegistry;
141 }
142 
UnregisterInterfaces(PluginToken token)143 void UnregisterInterfaces(PluginToken token)
144 {
145     if (!token) {
146         CORE_LOG_D("An null pointer was passed to UnregisterInterfaces function.");
147         return;
148     }
149     auto &pluginRegistry = *static_cast<IPluginRegister *>(token);
150 
151     pluginRegistry.UnregisterTypeInfo(ECS_PLUGIN);
152     pluginRegistry.UnregisterTypeInfo(RENDER_PLUGIN);
153 }
154 }  // namespace CamPreview
155 
156 extern "C" {
PLUGIN_DATA(CamPreviewPlugin)157 PLUGIN_DATA(CamPreviewPlugin) {
158     {CORE_NS::IPlugin::UID},
159     "CamPreviewPlugin",
160     {CamPreview::UID_CAMERA_PREVIEW_PLUGIN, CamPreview::GetVersionInfo},
161     CamPreview::RegisterInterfaces,
162     CamPreview::UnregisterInterfaces,
163     {CamPreview::PLUGIN_DEPENDENCIES},
164 };
165 }
166