summaryrefslogtreecommitdiffstats
path: root/meta-agl-flutter/recipes-graphics/toyota/files/0001-Add-optional-agl_shell-plugin.patch
blob: 79fac9e314a146ce7a6bb80cbc17b34e726ba15a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
From 164756be1d20b555f43e2eb3160da3efa7d38865 Mon Sep 17 00:00:00 2001
From: Scott Murray <scott.murray@konsulko.com>
Date: Thu, 1 Jun 2023 14:34:03 -0400
Subject: [PATCH] Add optional agl_shell plugin

Add an optional agl_shell static plugin to expose the activate_app
call from the agl-shell Wayland protocol that is used when running
against the AGL compositor.  This provides a way for a homescreen
application to activate other application surfaces to switch between
multiple applications as is needed for the AGL demo.

Upstream-Status: Pending

Signed-off-by: Scott Murray <scott.murray@konsulko.com>
[Updated to work with upstream OSS 0223 release]
Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
---
 cmake/plugins.cmake                         |  5 ++
 shell/engine.cc                             |  6 ++
 shell/engine.h                              | 10 +++
 shell/platform_channel.cc                   |  6 ++
 shell/static_plugins/agl_shell/agl_shell.cc | 77 +++++++++++++++++++++
 shell/static_plugins/agl_shell/agl_shell.h  | 31 +++++++++
 shell/wayland/display.cc                    |  7 ++
 shell/wayland/display.h                     |  8 +++
 shell/wayland/window.h                      |  2 +
 9 files changed, 152 insertions(+)
 create mode 100644 shell/static_plugins/agl_shell/agl_shell.cc
 create mode 100644 shell/static_plugins/agl_shell/agl_shell.h

diff --git a/cmake/plugins.cmake b/cmake/plugins.cmake
index b720dca..20a55d7 100644
--- a/cmake/plugins.cmake
+++ b/cmake/plugins.cmake
@@ -123,4 +123,9 @@ if (BUILD_PLUGIN_SECURE_STORAGE)
 endif ()
 
 
+option(BUILD_PLUGIN_AGL_SHELL "Includes AGL Shell Wayland Protocol Plugin" OFF)
+if (BUILD_PLUGIN_AGL_SHELL)
+    ENABLE_PLUGIN(agl_shell)
+endif ()
+
 message(STATUS "Plugin Config .......... ${PLUGINS}")
diff --git a/shell/engine.cc b/shell/engine.cc
index d20b6ba..a0e38e9 100644
--- a/shell/engine.cc
+++ b/shell/engine.cc
@@ -614,3 +614,9 @@ MAYBE_UNUSED TextInput* Engine::GetTextInput() const {
   return m_key_event;
 }
 #endif
+
+#if ENABLE_PLUGIN_AGL_SHELL
+std::shared_ptr<Display> Engine::GetDisplay() const {
+  return m_egl_window->GetDisplay();
+}
+#endif
diff --git a/shell/engine.h b/shell/engine.h
index 94808dc..3a06f51 100644
--- a/shell/engine.h
+++ b/shell/engine.h
@@ -60,6 +60,12 @@ class KeyEvent;
 
 #endif
 
+#if ENABLE_PLUGIN_AGL_SHELL
+
+class Display;
+
+#endif
+
 class Engine {
  public:
   /**
@@ -445,6 +451,10 @@ class Engine {
   MAYBE_UNUSED NODISCARD KeyEvent* GetKeyEvent() const;
 #endif
 
+#if ENABLE_PLUGIN_AGL_SHELL
+  std::shared_ptr<Display> GetDisplay() const;
+#endif
+
   /**
    * @brief Get backend of view
    * @return Backend*
diff --git a/shell/platform_channel.cc b/shell/platform_channel.cc
index b72156a..81d7cb5 100644
--- a/shell/platform_channel.cc
+++ b/shell/platform_channel.cc
@@ -62,6 +62,9 @@
 #ifdef ENABLE_PLUGIN_SECURE_STORAGE
 #include "static_plugins/secure_storage/secure_storage.h"
 #endif
+#ifdef ENABLE_PLUGIN_AGL_SHELL
+#include "static_plugins/agl_shell/agl_shell.h"
+#endif
 
 PlatformChannel* PlatformChannel::singleton = nullptr;
 
@@ -122,4 +125,7 @@ PlatformChannel::PlatformChannel() {
   RegisterCallback(SecureStorage::kChannelName,
                    &SecureStorage::OnPlatformMessage);
 #endif
+#ifdef ENABLE_PLUGIN_AGL_SHELL
+  RegisterCallback(AglShell::kChannelName, &AglShell::OnPlatformMessage);
+#endif
 }
diff --git a/shell/static_plugins/agl_shell/agl_shell.cc b/shell/static_plugins/agl_shell/agl_shell.cc
new file mode 100644
index 0000000..e6160a5
--- /dev/null
+++ b/shell/static_plugins/agl_shell/agl_shell.cc
@@ -0,0 +1,77 @@
+// Copyright 2020 Toyota Connected North America
+// Copyright 2022 Konsulko Group
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "agl_shell.h"
+
+#include <flutter/fml/logging.h>
+#include <flutter/standard_method_codec.h>
+
+#include "engine.h"
+#include "wayland/display.h"
+
+#include <iostream>
+
+void AglShell::OnPlatformMessage(const FlutterPlatformMessage* message,
+                                 void* userdata) {
+  std::unique_ptr<std::vector<uint8_t>> result;
+  auto engine = reinterpret_cast<Engine*>(userdata);
+  auto& codec = flutter::StandardMethodCodec::GetInstance();
+  auto obj = codec.DecodeMethodCall(message->message, message->message_size);
+
+  auto method = obj->method_name();
+  if (method == kMethodActivateApp) {
+    if (obj->arguments()->IsNull()) {
+      result = codec.EncodeErrorEnvelope("argument_error", "Invalid Arguments");
+      goto done;
+    }
+
+    auto args = std::get_if<flutter::EncodableMap>(obj->arguments());
+    if (!args) {
+      result = codec.EncodeErrorEnvelope("argument_error", "Invalid Arguments");
+      goto done;
+    }
+
+    std::string app_id;
+    auto it = args->find(flutter::EncodableValue("app_id"));
+    if (it != args->end()) {
+      app_id = std::get<std::string>(it->second);
+    }
+
+    int32_t index = 0;
+    it = args->find(flutter::EncodableValue("index"));
+    if (it != args->end()) {
+      index = std::get<int32_t>(it->second);
+    }
+
+    if (app_id.empty() || index < 0) {
+      result = codec.EncodeErrorEnvelope("argument_error", "Invalid Arguments");
+      goto done;
+    }
+
+    auto display = engine->GetDisplay();
+    if (display) {
+      display->AglShellDoActivate(app_id, index);
+    }
+    auto val = flutter::EncodableValue(true);
+    result = codec.EncodeSuccessEnvelope(&val);
+  } else {
+    FML_DLOG(INFO) << "AglShell: " << method << " is unhandled";
+    result = codec.EncodeErrorEnvelope("unhandled_method", "Unhandled Method");
+  }
+
+done:
+  engine->SendPlatformMessageResponse(message->response_handle, result->data(),
+                                      result->size());
+}
diff --git a/shell/static_plugins/agl_shell/agl_shell.h b/shell/static_plugins/agl_shell/agl_shell.h
new file mode 100644
index 0000000..698e44c
--- /dev/null
+++ b/shell/static_plugins/agl_shell/agl_shell.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2020 Toyota Connected North America
+ * Copyright 2022 Konsulko Group
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <shell/platform/embedder/embedder.h>
+
+class AglShell {
+ public:
+  static constexpr char kChannelName[] = "flutter/agl_shell";
+
+  static void OnPlatformMessage(const FlutterPlatformMessage* message,
+                                void* userdata);
+
+ private:
+  static constexpr char kMethodActivateApp[] = "activate_app";
+};
diff --git a/shell/wayland/display.cc b/shell/wayland/display.cc
index 9351fb9..583d8ba 100644
--- a/shell/wayland/display.cc
+++ b/shell/wayland/display.cc
@@ -845,6 +845,13 @@ void Display::AglShellDoReady() const {
   }
 }
 
+void Display::AglShellDoActivate(const std::string& app_id, size_t index) {
+  if (m_agl.shell) {
+    agl_shell_activate_app(m_agl.shell, app_id.c_str(),
+                           m_all_outputs[index]->output);
+  }
+}
+
 void Display::SetEngine(wl_surface* surface, Engine* engine) {
   m_active_engine = engine;
   m_active_surface = surface;
diff --git a/shell/wayland/display.h b/shell/wayland/display.h
index daeefea..3efdc9c 100644
--- a/shell/wayland/display.h
+++ b/shell/wayland/display.h
@@ -150,6 +150,14 @@ class Display {
    */
   void AglShellDoReady() const;
 
+  /**
+   * @brief AglShellDoActivate:
+   * @return void
+   * @relation
+   * wayland, agl-shell
+   */
+  void AglShellDoActivate(const std::string& app_id, size_t index);
+
   /**
    * @brief Set Engine
    * @param[in] surface Image
diff --git a/shell/wayland/window.h b/shell/wayland/window.h
index c0f2abc..da9cf45 100644
--- a/shell/wayland/window.h
+++ b/shell/wayland/window.h
@@ -127,6 +127,8 @@ class WaylandWindow {
     return std::pair<int32_t, int32_t>{m_geometry.width, m_geometry.height};
   }
 
+  std::shared_ptr<Display> GetDisplay() { return m_display; }
+
  private:
   size_t m_index;
   std::shared_ptr<Display> m_display;
-- 
2.40.1