meta-agl-flutter: update for meta-agl-core changes
[AGL/meta-agl-devel.git] / meta-agl-flutter / recipes-graphics / toyota / files / 0001-Add-optional-agl_shell-plugin.patch
1 From 413898c43c8f66a7d49fe8bb74a85ce67733bc86 Mon Sep 17 00:00:00 2001
2 From: Scott Murray <scott.murray@konsulko.com>
3 Date: Thu, 1 Jun 2023 14:34:03 -0400
4 Subject: [PATCH] Add optional agl_shell plugin
5
6 Add an optional agl_shell static plugin to expose the activate_app
7 call from the agl-shell Wayland protocol that is used when running
8 against the AGL compositor.  This provides a way for a homescreen
9 application to activate other application surfaces to switch between
10 multiple applications as is needed for the AGL demo.
11
12 Upstream-Status: Pending
13
14 Signed-off-by: Scott Murray <scott.murray@konsulko.com>
15 [Updated to work with upstream OSS 0223 release]
16 Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
17
18 ---
19  cmake/plugins.cmake                         |  5 ++
20  shell/engine.cc                             |  6 ++
21  shell/engine.h                              | 10 +++
22  shell/platform_channel.cc                   |  6 ++
23  shell/static_plugins/agl_shell/agl_shell.cc | 77 +++++++++++++++++++++
24  shell/static_plugins/agl_shell/agl_shell.h  | 31 +++++++++
25  shell/wayland/display.cc                    |  7 ++
26  shell/wayland/display.h                     |  8 +++
27  shell/wayland/window.h                      |  2 +
28  9 files changed, 152 insertions(+)
29  create mode 100644 shell/static_plugins/agl_shell/agl_shell.cc
30  create mode 100644 shell/static_plugins/agl_shell/agl_shell.h
31
32 diff --git a/cmake/plugins.cmake b/cmake/plugins.cmake
33 index b720dca..20a55d7 100644
34 --- a/cmake/plugins.cmake
35 +++ b/cmake/plugins.cmake
36 @@ -123,4 +123,9 @@ if (BUILD_PLUGIN_SECURE_STORAGE)
37  endif ()
38  
39  
40 +option(BUILD_PLUGIN_AGL_SHELL "Includes AGL Shell Wayland Protocol Plugin" OFF)
41 +if (BUILD_PLUGIN_AGL_SHELL)
42 +    ENABLE_PLUGIN(agl_shell)
43 +endif ()
44 +
45  message(STATUS "Plugin Config .......... ${PLUGINS}")
46 diff --git a/shell/engine.cc b/shell/engine.cc
47 index d20b6ba..a0e38e9 100644
48 --- a/shell/engine.cc
49 +++ b/shell/engine.cc
50 @@ -614,3 +614,9 @@ MAYBE_UNUSED TextInput* Engine::GetTextInput() const {
51    return m_key_event;
52  }
53  #endif
54 +
55 +#if ENABLE_PLUGIN_AGL_SHELL
56 +std::shared_ptr<Display> Engine::GetDisplay() const {
57 +  return m_egl_window->GetDisplay();
58 +}
59 +#endif
60 diff --git a/shell/engine.h b/shell/engine.h
61 index 94808dc..3a06f51 100644
62 --- a/shell/engine.h
63 +++ b/shell/engine.h
64 @@ -60,6 +60,12 @@ class KeyEvent;
65  
66  #endif
67  
68 +#if ENABLE_PLUGIN_AGL_SHELL
69 +
70 +class Display;
71 +
72 +#endif
73 +
74  class Engine {
75   public:
76    /**
77 @@ -445,6 +451,10 @@ class Engine {
78    MAYBE_UNUSED NODISCARD KeyEvent* GetKeyEvent() const;
79  #endif
80  
81 +#if ENABLE_PLUGIN_AGL_SHELL
82 +  std::shared_ptr<Display> GetDisplay() const;
83 +#endif
84 +
85    /**
86     * @brief Get backend of view
87     * @return Backend*
88 diff --git a/shell/platform_channel.cc b/shell/platform_channel.cc
89 index b72156a..81d7cb5 100644
90 --- a/shell/platform_channel.cc
91 +++ b/shell/platform_channel.cc
92 @@ -62,6 +62,9 @@
93  #ifdef ENABLE_PLUGIN_SECURE_STORAGE
94  #include "static_plugins/secure_storage/secure_storage.h"
95  #endif
96 +#ifdef ENABLE_PLUGIN_AGL_SHELL
97 +#include "static_plugins/agl_shell/agl_shell.h"
98 +#endif
99  
100  PlatformChannel* PlatformChannel::singleton = nullptr;
101  
102 @@ -122,4 +125,7 @@ PlatformChannel::PlatformChannel() {
103    RegisterCallback(SecureStorage::kChannelName,
104                     &SecureStorage::OnPlatformMessage);
105  #endif
106 +#ifdef ENABLE_PLUGIN_AGL_SHELL
107 +  RegisterCallback(AglShell::kChannelName, &AglShell::OnPlatformMessage);
108 +#endif
109  }
110 diff --git a/shell/static_plugins/agl_shell/agl_shell.cc b/shell/static_plugins/agl_shell/agl_shell.cc
111 new file mode 100644
112 index 0000000..e6160a5
113 --- /dev/null
114 +++ b/shell/static_plugins/agl_shell/agl_shell.cc
115 @@ -0,0 +1,77 @@
116 +// Copyright 2020 Toyota Connected North America
117 +// Copyright 2022 Konsulko Group
118 +//
119 +// Licensed under the Apache License, Version 2.0 (the "License");
120 +// you may not use this file except in compliance with the License.
121 +// You may obtain a copy of the License at
122 +//
123 +//      http://www.apache.org/licenses/LICENSE-2.0
124 +//
125 +// Unless required by applicable law or agreed to in writing, software
126 +// distributed under the License is distributed on an "AS IS" BASIS,
127 +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
128 +// See the License for the specific language governing permissions and
129 +// limitations under the License.
130 +
131 +#include "agl_shell.h"
132 +
133 +#include <flutter/fml/logging.h>
134 +#include <flutter/standard_method_codec.h>
135 +
136 +#include "engine.h"
137 +#include "wayland/display.h"
138 +
139 +#include <iostream>
140 +
141 +void AglShell::OnPlatformMessage(const FlutterPlatformMessage* message,
142 +                                 void* userdata) {
143 +  std::unique_ptr<std::vector<uint8_t>> result;
144 +  auto engine = reinterpret_cast<Engine*>(userdata);
145 +  auto& codec = flutter::StandardMethodCodec::GetInstance();
146 +  auto obj = codec.DecodeMethodCall(message->message, message->message_size);
147 +
148 +  auto method = obj->method_name();
149 +  if (method == kMethodActivateApp) {
150 +    if (obj->arguments()->IsNull()) {
151 +      result = codec.EncodeErrorEnvelope("argument_error", "Invalid Arguments");
152 +      goto done;
153 +    }
154 +
155 +    auto args = std::get_if<flutter::EncodableMap>(obj->arguments());
156 +    if (!args) {
157 +      result = codec.EncodeErrorEnvelope("argument_error", "Invalid Arguments");
158 +      goto done;
159 +    }
160 +
161 +    std::string app_id;
162 +    auto it = args->find(flutter::EncodableValue("app_id"));
163 +    if (it != args->end()) {
164 +      app_id = std::get<std::string>(it->second);
165 +    }
166 +
167 +    int32_t index = 0;
168 +    it = args->find(flutter::EncodableValue("index"));
169 +    if (it != args->end()) {
170 +      index = std::get<int32_t>(it->second);
171 +    }
172 +
173 +    if (app_id.empty() || index < 0) {
174 +      result = codec.EncodeErrorEnvelope("argument_error", "Invalid Arguments");
175 +      goto done;
176 +    }
177 +
178 +    auto display = engine->GetDisplay();
179 +    if (display) {
180 +      display->AglShellDoActivate(app_id, index);
181 +    }
182 +    auto val = flutter::EncodableValue(true);
183 +    result = codec.EncodeSuccessEnvelope(&val);
184 +  } else {
185 +    FML_DLOG(INFO) << "AglShell: " << method << " is unhandled";
186 +    result = codec.EncodeErrorEnvelope("unhandled_method", "Unhandled Method");
187 +  }
188 +
189 +done:
190 +  engine->SendPlatformMessageResponse(message->response_handle, result->data(),
191 +                                      result->size());
192 +}
193 diff --git a/shell/static_plugins/agl_shell/agl_shell.h b/shell/static_plugins/agl_shell/agl_shell.h
194 new file mode 100644
195 index 0000000..698e44c
196 --- /dev/null
197 +++ b/shell/static_plugins/agl_shell/agl_shell.h
198 @@ -0,0 +1,31 @@
199 +/*
200 + * Copyright 2020 Toyota Connected North America
201 + * Copyright 2022 Konsulko Group
202 + *
203 + * Licensed under the Apache License, Version 2.0 (the "License");
204 + * you may not use this file except in compliance with the License.
205 + * You may obtain a copy of the License at
206 + *
207 + *      http://www.apache.org/licenses/LICENSE-2.0
208 + *
209 + * Unless required by applicable law or agreed to in writing, software
210 + * distributed under the License is distributed on an "AS IS" BASIS,
211 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
212 + * See the License for the specific language governing permissions and
213 + * limitations under the License.
214 + */
215 +
216 +#pragma once
217 +
218 +#include <shell/platform/embedder/embedder.h>
219 +
220 +class AglShell {
221 + public:
222 +  static constexpr char kChannelName[] = "flutter/agl_shell";
223 +
224 +  static void OnPlatformMessage(const FlutterPlatformMessage* message,
225 +                                void* userdata);
226 +
227 + private:
228 +  static constexpr char kMethodActivateApp[] = "activate_app";
229 +};
230 diff --git a/shell/wayland/display.cc b/shell/wayland/display.cc
231 index 434dd05..99aa5ff 100644
232 --- a/shell/wayland/display.cc
233 +++ b/shell/wayland/display.cc
234 @@ -869,6 +869,13 @@ void Display::AglShellDoSetupActivationArea(uint32_t x,
235                                  width, height);
236  }
237  
238 +void Display::AglShellDoActivate(const std::string& app_id, size_t index) {
239 +  if (m_agl.shell) {
240 +    agl_shell_activate_app(m_agl.shell, app_id.c_str(),
241 +                           m_all_outputs[index]->output);
242 +  }
243 +}
244 +
245  void Display::SetEngine(wl_surface* surface, Engine* engine) {
246    m_active_engine = engine;
247    m_active_surface = surface;
248 diff --git a/shell/wayland/display.h b/shell/wayland/display.h
249 index 06b0f8b..ef6ea3f 100644
250 --- a/shell/wayland/display.h
251 +++ b/shell/wayland/display.h
252 @@ -150,6 +150,14 @@ class Display {
253     */
254    void AglShellDoReady() const;
255  
256 +  /**
257 +   * @brief AglShellDoActivate:
258 +   * @return void
259 +   * @relation
260 +   * wayland, agl-shell
261 +   */
262 +  void AglShellDoActivate(const std::string& app_id, size_t index);
263 +
264    /**
265     * @brief AglShell: Set up an activation area where to display the client's
266     * window
267 diff --git a/shell/wayland/window.h b/shell/wayland/window.h
268 index d5e3c77..677dbdc 100644
269 --- a/shell/wayland/window.h
270 +++ b/shell/wayland/window.h
271 @@ -129,6 +129,8 @@ class WaylandWindow {
272      return std::pair<int32_t, int32_t>{m_geometry.width, m_geometry.height};
273    }
274  
275 +  std::shared_ptr<Display> GetDisplay() { return m_display; }
276 +
277   private:
278    size_t m_index;
279    std::shared_ptr<Display> m_display;