Debian Codegraph @

xbmc/windowing/wayland/WinSystemWaylandWebOS.cpp

raw
1 /*
2 * Copyright (C) 2023 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
4 *
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
8
9 #include "WinSystemWaylandWebOS.h"
10
11 #include "Connection.h"
12 #include "OSScreenSaverWebOS.h"
13 #include "Registry.h"
14 #include "ShellSurfaceWebOSShell.h"
15 #include "application/ApplicationComponents.h"
16 #include "application/ApplicationPlayer.h"
17 #include "cores/AudioEngine/Sinks/AESinkStarfish.h"
18 #include "cores/VideoPlayer/DVDCodecs/Video/DVDVideoCodecStarfish.h"
19 #include "cores/VideoPlayer/VideoRenderers/HwDecRender/RendererStarfish.h"
20 #include "input/actions/Action.h"
21 #include "input/actions/ActionIDs.h"
22 #include "messaging/ApplicationMessenger.h"
23 #include "utils/JSONVariantParser.h"
24 #include "utils/log.h"
25
26 #include <CompileInfo.h>
27
28 namespace
29 {
30 constexpr const char* LUNA_REGISTER_APP = "luna://com.webos.service.applicationmanager/registerApp";
31 } // namespace
32
33 namespace KODI::WINDOWING::WAYLAND
34 {
35
36 bool CWinSystemWaylandWebOS::InitWindowSystem()
37 {
38 if (!CWinSystemWayland::InitWindowSystem())
39 return false;
40
41 CDVDVideoCodecStarfish::Register();
42 CRendererStarfish::Register();
43 CAESinkStarfish::Register();
44
45 m_webosRegistry = std::make_unique<CRegistry>(*GetConnection());
46 m_webosRegistry->RequestSingleton(m_compositor, 1, 4);
47 // available since webOS 5.0
48 m_webosRegistry->RequestSingleton(m_webosForeign, 1, 2, false);
49 m_webosRegistry->Bind();
50
51 m_requestContext->pub = true;
52 m_requestContext->multiple = true;
53 m_requestContext->callback = &OnAppLifecycleEventWrapper;
54 m_requestContext->userdata = this;
55 if (HLunaServiceCall(LUNA_REGISTER_APP, "{}", m_requestContext.get()))
56 {
57 CLog::LogF(LOGWARNING, "Luna request call failed");
58 m_requestContext = nullptr;
59 }
60
61 return true;
62 }
63
64 bool CWinSystemWaylandWebOS::CreateNewWindow(const std::string& name,
65 bool fullScreen,
66 RESOLUTION_INFO& res)
67 {
68 if (!CWinSystemWayland::CreateNewWindow(name, fullScreen, res))
69 return false;
70
71 if (m_webosForeign)
72 {
73 m_exportedSurface = m_webosForeign.export_element(
74 GetMainSurface(),
75 static_cast<uint32_t>(wayland::webos_foreign_webos_exported_type::video_object));
76 m_exportedSurface.on_window_id_assigned() = [this](std::string window_id,
77 uint32_t exported_type) {
78 CLog::Log(LOGDEBUG,
79 "CreateNewWindow:CDVDVideoCodecStarfish: Foreign video surface exported {}",
80 window_id);
81 this->m_exportedWindowName = window_id;
82 };
83 }
84
85 return true;
86 }
87
88 CWinSystemWaylandWebOS::~CWinSystemWaylandWebOS() noexcept
89 {
90 m_exportedSurface = wayland::webos_exported_t{};
91 m_webosForeign = wayland::webos_foreign_t{};
92
93 if (m_webosRegistry)
94 {
95 m_webosRegistry->UnbindSingletons();
96 }
97 m_webosRegistry.reset();
98 }
99
100 bool CWinSystemWaylandWebOS::HasCursor()
101 {
102 return false;
103 }
104
105 std::string CWinSystemWaylandWebOS::GetExportedWindowName()
106 {
107 return m_exportedWindowName;
108 }
109
110 bool CWinSystemWaylandWebOS::SetExportedWindow(CRect orig, CRect src, CRect dest)
111 {
112 if (m_webosForeign)
113 {
114 CLog::LogF(LOGINFO,
115 "CWinSystemWaylandWebOS: orig {} {} {} {} src {} {} {} {} -> dest {} {} {} {}",
116 orig.x1, orig.y1, orig.x2, orig.y2, src.x1, src.y1, src.x2, src.y2, dest.x1, dest.y1,
117 dest.x2, dest.y2);
118 wayland::region_t origRegion = m_compositor.create_region();
119 wayland::region_t srcRegion = m_compositor.create_region();
120 wayland::region_t dstRegion = m_compositor.create_region();
121 origRegion.add(static_cast<int>(orig.x1), static_cast<int>(orig.y1),
122 static_cast<int>(orig.Width()), static_cast<int>(orig.Height()));
123 srcRegion.add(static_cast<int>(src.x1), static_cast<int>(src.y1), static_cast<int>(src.Width()),
124 static_cast<int>(src.Height()));
125 dstRegion.add(static_cast<int>(dest.x1), static_cast<int>(dest.y1),
126 static_cast<int>(dest.Width()), static_cast<int>(dest.Height()));
127 m_exportedSurface.set_crop_region(origRegion, srcRegion, dstRegion);
128
129 return true;
130 }
131
132 return false;
133 }
134
135 bool CWinSystemWaylandWebOS::SupportsExportedWindow()
136 {
137 return m_webosForeign;
138 }
139
140 IShellSurface* CWinSystemWaylandWebOS::CreateShellSurface(const std::string& name)
141 {
142 return new CShellSurfaceWebOSShell(*this, *GetConnection(), GetMainSurface(), name,
143 std::string(CCompileInfo::GetAppName()));
144 }
145
146 std::unique_ptr<KODI::WINDOWING::IOSScreenSaver> CWinSystemWaylandWebOS::GetOSScreenSaverImpl()
147 {
148 return std::make_unique<COSScreenSaverWebOS>();
149 }
150
151 bool CWinSystemWaylandWebOS::OnAppLifecycleEventWrapper(LSHandle* sh, LSMessage* reply, void* ctx)
152 {
153 HContext* context = static_cast<HContext*>(ctx);
154 return static_cast<CWinSystemWaylandWebOS*>(context->userdata)->OnAppLifecycleEvent(sh, reply);
155 }
156
157 void CWinSystemWaylandWebOS::OnConfigure(std::uint32_t serial,
158 CSizeInt size,
159 IShellSurface::StateBitset state)
160 {
161 const auto& components = CServiceBroker::GetAppComponents();
162 const auto player = components.GetComponent<CApplicationPlayer>();
163
164 // intercept minimized event, passing the minimized event causes a weird animation
165 if (state.none())
166 {
167 m_resumePlayback = false;
168
169 if (player->IsPlaying() && player->HasVideo() && !player->IsPaused())
170 {
171 CServiceBroker::GetAppMessenger()->SendMsg(TMSG_GUI_ACTION, WINDOW_INVALID, -1,
172 static_cast<void*>(new CAction(ACTION_PAUSE)));
173 m_resumePlayback = true;
174 }
175 }
176 else
177 {
178 if (m_resumePlayback && player->IsPlaying() && player->HasVideo() && player->IsPaused())
179 {
180 CServiceBroker::GetAppMessenger()->SendMsg(
181 TMSG_GUI_ACTION, WINDOW_INVALID, -1, static_cast<void*>(new CAction(ACTION_PLAYER_PLAY)));
182 m_resumePlayback = false;
183 }
184 CWinSystemWayland::OnConfigure(serial, size, state);
185 }
186 }
187
188 bool CWinSystemWaylandWebOS::OnAppLifecycleEvent(LSHandle* sh, LSMessage* reply)
189 {
190 const char* msg = HLunaServiceMessage(reply);
191 CLog::Log(LOGDEBUG, "Got lifecycle event: {}", msg);
192
193 CVariant event;
194 CJSONVariantParser::Parse(msg, event);
195
196 IShellSurface* shellSurface = GetShellSurface();
197 if (event["event"] == "relaunch" && shellSurface)
198 shellSurface->SetFullScreen(nullptr, 60.0f);
199
200 return true;
201 }
202
203 } // namespace KODI::WINDOWING::WAYLAND