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 <base/util/uid.h>
17 #include <core/intf_engine.h>
18 #include <core/io/intf_file_manager.h>
19 #include <core/plugin/intf_plugin.h>
20 #include <core/plugin/intf_plugin_decl.h>
21 #include <font/implementation_uids.h>
22 #include <render/implementation_uids.h>
23 #include <render/intf_plugin.h>
24 #include <render/intf_render_context.h>
25 #include <render/namespace.h>
26
27 #include "font_manager.h"
28
29 FONT_BEGIN_NAMESPACE()
30 namespace {
31 static CORE_NS::IPluginRegister* gPluginRegistry { nullptr };
32
33 static constexpr BASE_NS::Uid PLUGIN_DEPENDENCIES[] = { RENDER_NS::UID_RENDER_PLUGIN };
34
35 struct RenderPluginState final {
36 RENDER_NS::IRenderContext& context_;
37 FontManager::Ptr fontManager_;
38 CORE_NS::InterfaceTypeInfo interfaceInfo_ = CORE_NS::InterfaceTypeInfo {
39 this,
40 UID_FONT_MANAGER,
41 "IFontManager",
42 nullptr,
43 [](CORE_NS::IClassRegister&, CORE_NS::PluginToken token) -> CORE_NS::IInterface* {
44 if (token) {
45 RenderPluginState* state = static_cast<RenderPluginState*>(token);
46 if (!state->fontManager_) {
47 state->fontManager_.reset(new FontManager(state->context_));
48 }
49 return state->fontManager_.get();
50 }
51 return nullptr;
52 },
53 };
RenderPluginState__anon9631::final54 RenderPluginState(RENDER_NS::IRenderContext& context) : context_(context) {}
55 };
56
CreatePlugin(RENDER_NS::IRenderContext& context)57 CORE_NS::PluginToken CreatePlugin(RENDER_NS::IRenderContext& context)
58 {
59 RenderPluginState* state = new RenderPluginState { context };
60 auto& registry = *context.GetInterface<CORE_NS::IClassRegister>();
61 registry.RegisterInterfaceType(state->interfaceInfo_);
62 return state;
63 }
64
DestroyPlugin(CORE_NS::PluginToken token)65 void DestroyPlugin(CORE_NS::PluginToken token)
66 {
67 RenderPluginState* state = static_cast<RenderPluginState*>(token);
68 auto& registry = *state->context_.GetInterface<CORE_NS::IClassRegister>();
69 registry.UnregisterInterfaceType(state->interfaceInfo_);
70 delete state;
71 }
72
73 static constexpr RENDER_NS::IRenderPlugin RENDER_PLUGIN(CreatePlugin, DestroyPlugin);
74 } // namespace
75
76 // implementation in the generated version.cpp
77 const char* GetVersionInfo();
78
RegisterInterfaces(CORE_NS::IPluginRegister& pluginRegistry)79 CORE_NS::PluginToken RegisterInterfaces(CORE_NS::IPluginRegister& pluginRegistry)
80 {
81 gPluginRegistry = &pluginRegistry;
82
83 pluginRegistry.RegisterTypeInfo(RENDER_PLUGIN);
84 return &pluginRegistry;
85 }
86
UnregisterInterfaces(CORE_NS::PluginToken token)87 void UnregisterInterfaces(CORE_NS::PluginToken token)
88 {
89 auto* pluginRegistry = static_cast<CORE_NS::IPluginRegister*>(token);
90 pluginRegistry->UnregisterTypeInfo(RENDER_PLUGIN);
91 }
92 FONT_END_NAMESPACE()
93
94 CORE_BEGIN_NAMESPACE()
GetPluginRegister()95 IPluginRegister& GetPluginRegister()
96 {
97 return *FONT_NS::gPluginRegistry;
98 }
99 CORE_END_NAMESPACE()
100
101 extern "C" {
PLUGIN_DATA(FontPlugin)102 PLUGIN_DATA(FontPlugin) {
103 { CORE_NS::IPlugin::UID },
104 // name of plugin.
105 "Font Plugin",
106 // Version information of the plugin.
107 { FONT_NS::UID_FONT_PLUGIN, FONT_NS::GetVersionInfo },
108 FONT_NS::RegisterInterfaces,
109 FONT_NS::UnregisterInterfaces,
110 { FONT_NS::PLUGIN_DEPENDENCIES },
111 };
112 }
113