recipes-demo/homescreen/homescreen_git.bb: Bump SRCREV
[AGL/meta-agl-demo.git] / recipes-wam / cef / files / chromium / 0006-Add-webos-agl-waylandwindow-window-tree-host-essenti.patch
1 From a99977eb329ca0e114ad13ce31acc6ed38bb6a7b Mon Sep 17 00:00:00 2001
2 From: Roger Zanoni <rzanoni@igalia.com>
3 Date: Wed, 17 May 2023 21:25:53 +0200
4 Subject: [PATCH 6/9] Add webos/agl waylandwindow/window tree host essential
5  parts
6
7 ---
8  ui/aura/BUILD.gn                              |  7 ++
9  ui/aura/agl/window_tree_host_agl.h            | 42 +++++++++
10  ui/aura/agl/window_tree_host_platform_agl.cc  | 50 +++++++++++
11  ui/aura/agl/window_tree_host_platform_agl.h   | 51 +++++++++++
12  ui/aura/window_tree_host.h                    |  5 +-
13  ui/aura/window_tree_host_platform.cc          |  4 +-
14  ui/aura/window_tree_host_platform.h           |  4 +-
15  ui/ozone/platform/wayland/BUILD.gn            |  1 -
16  .../platform/wayland/extensions/agl/BUILD.gn  |  2 +
17  .../agl/host/wayland_extensions_agl.h         | 10 ++-
18  .../agl/host/wayland_extensions_agl_impl.cc   | 11 ++-
19  .../agl/host/wayland_extensions_agl_impl.h    |  9 ++
20  .../extensions/agl/host/wayland_window_agl.cc | 86 +++++++++++++++++++
21  .../extensions/agl/host/wayland_window_agl.h  | 49 +++++++++++
22  .../wayland/gpu/gl_surface_wayland.cc         | 10 ++-
23  .../host/gtk_primary_selection_device.cc      |  2 +-
24  .../gtk_primary_selection_device_manager.cc   |  4 +-
25  .../wayland/host/proxy/wayland_proxy_impl.cc  |  2 +-
26  .../wayland/host/wayland_connection.cc        | 23 ++++-
27  .../wayland/host/wayland_connection.h         |  9 +-
28  .../platform/wayland/host/wayland_cursor.cc   |  4 +-
29  .../wayland/host/wayland_data_device.cc       | 10 +--
30  .../wayland/host/wayland_data_device_base.cc  |  2 +-
31  .../host/wayland_data_drag_controller.cc      |  2 +-
32  .../wayland/host/wayland_data_source.cc       |  6 +-
33  ui/ozone/platform/wayland/host/wayland_drm.cc |  6 +-
34  .../wayland/host/wayland_extensions.h         |  6 ++
35  .../platform/wayland/host/wayland_keyboard.cc |  4 +-
36  .../platform/wayland/host/wayland_popup.cc    |  4 +-
37  ui/ozone/platform/wayland/host/wayland_shm.cc |  2 +-
38  .../platform/wayland/host/wayland_surface.cc  |  2 +-
39  .../wayland/host/wayland_toplevel_window.cc   | 14 +--
40  .../platform/wayland/host/wayland_window.cc   | 14 +--
41  .../platform/wayland/host/wayland_window.h    |  2 +
42  .../host/wayland_window_drag_controller.cc    |  2 +-
43  .../wayland/host/wayland_window_factory.cc    | 15 ++++
44  .../wayland/host/wayland_zwp_linux_dmabuf.cc  |  4 +-
45  .../wayland/host/xdg_foreign_wrapper.cc       |  4 +-
46  .../wayland/host/xdg_popup_wrapper_impl.cc    |  2 +-
47  .../wayland/host/xdg_surface_wrapper_impl.cc  |  2 +-
48  .../host/zwp_primary_selection_device.cc      |  2 +-
49  .../zwp_primary_selection_device_manager.cc   |  4 +-
50  .../host/zxdg_surface_v6_wrapper_impl.cc      |  2 +-
51  ui/platform_window/agl/platform_window_agl.h  | 36 ++++++++
52  ui/platform_window/platform_window.h          |  4 +-
53  45 files changed, 471 insertions(+), 65 deletions(-)
54  create mode 100644 ui/aura/agl/window_tree_host_agl.h
55  create mode 100644 ui/aura/agl/window_tree_host_platform_agl.cc
56  create mode 100644 ui/aura/agl/window_tree_host_platform_agl.h
57  create mode 100644 ui/ozone/platform/wayland/extensions/agl/host/wayland_window_agl.cc
58  create mode 100644 ui/ozone/platform/wayland/extensions/agl/host/wayland_window_agl.h
59  create mode 100644 ui/platform_window/agl/platform_window_agl.h
60
61 diff --git a/ui/aura/BUILD.gn b/ui/aura/BUILD.gn
62 index 1beb9003b2fad..f3d3e359a9704 100644
63 --- a/ui/aura/BUILD.gn
64 +++ b/ui/aura/BUILD.gn
65 @@ -99,6 +99,13 @@ component("aura") {
66      "window_tree_host_platform.cc",
67    ]
68  
69 +  public += [
70 +    "agl/window_tree_host_agl.h",
71 +    "agl/window_tree_host_platform_agl.h"
72 +  ]
73 +
74 +  sources += [ "agl/window_tree_host_platform_agl.cc" ]
75 +
76    friend = [ ":*" ]
77  
78    defines = [ "AURA_IMPLEMENTATION" ]
79 diff --git a/ui/aura/agl/window_tree_host_agl.h b/ui/aura/agl/window_tree_host_agl.h
80 new file mode 100644
81 index 0000000000000..858a078d939d0
82 --- /dev/null
83 +++ b/ui/aura/agl/window_tree_host_agl.h
84 @@ -0,0 +1,42 @@
85 +// Copyright 2021 LG Electronics, Inc.
86 +//
87 +// Licensed under the Apache License, Version 2.0 (the "License");
88 +// you may not use this file except in compliance with the License.
89 +// You may obtain a copy of the License at
90 +//
91 +// http://www.apache.org/licenses/LICENSE-2.0
92 +//
93 +// Unless required by applicable law or agreed to in writing, software
94 +// distributed under the License is distributed on an "AS IS" BASIS,
95 +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
96 +// See the License for the specific language governing permissions and
97 +// limitations under the License.
98 +//
99 +// SPDX-License-Identifier: Apache-2.0
100 +
101 +#ifndef UI_AURA_AGL_WINDOW_TREE_HOST_AGL_H_
102 +#define UI_AURA_AGL_WINDOW_TREE_HOST_AGL_H_
103 +
104 +#include <string>
105 +
106 +#include "ui/aura/aura_export.h"
107 +
108 +namespace aura {
109 +
110 +class AURA_EXPORT WindowTreeHostAgl {
111 + public:
112 +  WindowTreeHostAgl() = default;
113 +  WindowTreeHostAgl(const WindowTreeHostAgl&) = delete;
114 +  WindowTreeHostAgl& operator=(const WindowTreeHostAgl&) = delete;
115 +  ~WindowTreeHostAgl() = default;
116 +
117 +  virtual void SetAglActivateApp(const std::string& app) {}
118 +  virtual void SetAglAppId(const std::string& title) {}
119 +  virtual void SetAglReady() {}
120 +  virtual void SetAglBackground() {}
121 +  virtual void SetAglPanel(uint32_t edge) {}
122 +};
123 +
124 +}  // namespace aura
125 +
126 +#endif  // UI_AURA_AGL_WINDOW_TREE_HOST_AGL_H_
127 diff --git a/ui/aura/agl/window_tree_host_platform_agl.cc b/ui/aura/agl/window_tree_host_platform_agl.cc
128 new file mode 100644
129 index 0000000000000..e34595fe0ed9c
130 --- /dev/null
131 +++ b/ui/aura/agl/window_tree_host_platform_agl.cc
132 @@ -0,0 +1,50 @@
133 +// Copyright 2021 LG Electronics, Inc.
134 +//
135 +// Licensed under the Apache License, Version 2.0 (the "License");
136 +// you may not use this file except in compliance with the License.
137 +// You may obtain a copy of the License at
138 +//
139 +// http://www.apache.org/licenses/LICENSE-2.0
140 +//
141 +// Unless required by applicable law or agreed to in writing, software
142 +// distributed under the License is distributed on an "AS IS" BASIS,
143 +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
144 +// See the License for the specific language governing permissions and
145 +// limitations under the License.
146 +//
147 +// SPDX-License-Identifier: Apache-2.0
148 +
149 +#include "ui/aura/agl/window_tree_host_platform_agl.h"
150 +
151 +#include "ui/aura/window_tree_host_platform.h"
152 +#include "ui/platform_window/platform_window.h"
153 +
154 +namespace aura {
155 +
156 +WindowTreeHostPlatformAgl::WindowTreeHostPlatformAgl(
157 +    std::unique_ptr<Window> window,
158 +    aura::WindowTreeHostPlatform* window_tree_host_platform)
159 +    : aura::WindowTreeHost(std::move(window)),
160 +      window_tree_host_platform_(window_tree_host_platform) {}
161 +
162 +void WindowTreeHostPlatformAgl::SetAglActivateApp(const std::string& app) {
163 +  window_tree_host_platform_->platform_window()->SetAglActivateApp(app);
164 +}
165 +
166 +void WindowTreeHostPlatformAgl::SetAglAppId(const std::string& title) {
167 +  window_tree_host_platform_->platform_window()->SetAglAppId(title);
168 +}
169 +
170 +void WindowTreeHostPlatformAgl::SetAglReady() {
171 +  window_tree_host_platform_->platform_window()->SetAglReady();
172 +}
173 +
174 +void WindowTreeHostPlatformAgl::SetAglBackground() {
175 +  window_tree_host_platform_->platform_window()->SetAglBackground();
176 +}
177 +
178 +void WindowTreeHostPlatformAgl::SetAglPanel(uint32_t edge) {
179 +  window_tree_host_platform_->platform_window()->SetAglPanel(edge);
180 +}
181 +
182 +}  // namespace aura
183 diff --git a/ui/aura/agl/window_tree_host_platform_agl.h b/ui/aura/agl/window_tree_host_platform_agl.h
184 new file mode 100644
185 index 0000000000000..181eefae346f7
186 --- /dev/null
187 +++ b/ui/aura/agl/window_tree_host_platform_agl.h
188 @@ -0,0 +1,51 @@
189 +// Copyright 2021 LG Electronics, Inc.
190 +//
191 +// Licensed under the Apache License, Version 2.0 (the "License");
192 +// you may not use this file except in compliance with the License.
193 +// You may obtain a copy of the License at
194 +//
195 +// http://www.apache.org/licenses/LICENSE-2.0
196 +//
197 +// Unless required by applicable law or agreed to in writing, software
198 +// distributed under the License is distributed on an "AS IS" BASIS,
199 +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 +// See the License for the specific language governing permissions and
201 +// limitations under the License.
202 +//
203 +// SPDX-License-Identifier: Apache-2.0
204 +
205 +#ifndef UI_AURA_AGL_WINDOW_TREE_HOST_PLATFORM_AGL_H_
206 +#define UI_AURA_AGL_WINDOW_TREE_HOST_PLATFORM_AGL_H_
207 +
208 +#include <memory>
209 +
210 +#include "ui/aura/aura_export.h"
211 +#include "ui/aura/window_tree_host.h"
212 +
213 +namespace aura {
214 +
215 +class Window;
216 +class WindowTreeHostPlatform;
217 +
218 +class AURA_EXPORT WindowTreeHostPlatformAgl : public aura::WindowTreeHost {
219 + public:
220 +  explicit WindowTreeHostPlatformAgl(
221 +      std::unique_ptr<Window> window,
222 +      aura::WindowTreeHostPlatform* window_tree_host_platform);
223 +  WindowTreeHostPlatformAgl(const WindowTreeHostPlatformAgl&) = delete;
224 +  WindowTreeHostPlatformAgl& operator=(const WindowTreeHostPlatformAgl&) = delete;
225 +  ~WindowTreeHostPlatformAgl() override = default;
226 +
227 +  void SetAglActivateApp(const std::string& app) override;
228 +  void SetAglAppId(const std::string& title) override;
229 +  void SetAglReady() override;
230 +  void SetAglBackground() override;
231 +  void SetAglPanel(uint32_t edge) override;
232 +
233 + private:
234 +  aura::WindowTreeHostPlatform* window_tree_host_platform_;
235 +};
236 +
237 +}  // namespace aura
238 +
239 +#endif  // UI_AURA_AGL_WINDOW_TREE_HOST_PLATFORM_AGL_H_
240 diff --git a/ui/aura/window_tree_host.h b/ui/aura/window_tree_host.h
241 index 0bdb86be66ba3..b7696e6373284 100644
242 --- a/ui/aura/window_tree_host.h
243 +++ b/ui/aura/window_tree_host.h
244 @@ -30,6 +30,8 @@
245  #include "ui/gfx/native_widget_types.h"
246  #include "ui/gfx/overlay_transform.h"
247  
248 +#include "ui/aura/agl/window_tree_host_agl.h"
249 +
250  namespace gfx {
251  class Point;
252  class Rect;
253 @@ -66,7 +68,8 @@ class WindowTreeHostObserver;
254  class AURA_EXPORT WindowTreeHost : public ui::ImeKeyEventDispatcher,
255                                     public ui::EventSource,
256                                     public display::DisplayObserver,
257 -                                   public ui::CompositorObserver {
258 +                                   public ui::CompositorObserver,
259 +                                   public WindowTreeHostAgl {
260   public:
261    // VideoCaptureLock ensures state necessary for capturing video remains in
262    // effect. For example, this may force keeping the compositor visible when
263 diff --git a/ui/aura/window_tree_host_platform.cc b/ui/aura/window_tree_host_platform.cc
264 index 4c31e785d7692..cecd1f4fc03fd 100644
265 --- a/ui/aura/window_tree_host_platform.cc
266 +++ b/ui/aura/window_tree_host_platform.cc
267 @@ -51,7 +51,7 @@ std::unique_ptr<WindowTreeHost> WindowTreeHost::Create(
268  WindowTreeHostPlatform::WindowTreeHostPlatform(
269      ui::PlatformWindowInitProperties properties,
270      std::unique_ptr<Window> window)
271 -    : WindowTreeHost(std::move(window)) {
272 +    : WindowTreeHostPlatformAgl(std::move(window), this) {
273    size_in_pixels_ = properties.bounds.size();
274    CreateCompositor(false, false, properties.enable_compositing_based_throttling,
275                     properties.compositor_memory_limit_mb);
276 @@ -59,7 +59,7 @@ WindowTreeHostPlatform::WindowTreeHostPlatform(
277  }
278  
279  WindowTreeHostPlatform::WindowTreeHostPlatform(std::unique_ptr<Window> window)
280 -    : WindowTreeHost(std::move(window)),
281 +    : WindowTreeHostPlatformAgl(std::move(window), this),
282        widget_(gfx::kNullAcceleratedWidget),
283        current_cursor_(ui::mojom::CursorType::kNull) {}
284  
285 diff --git a/ui/aura/window_tree_host_platform.h b/ui/aura/window_tree_host_platform.h
286 index 3a9232743bda3..6c1e3a424afd4 100644
287 --- a/ui/aura/window_tree_host_platform.h
288 +++ b/ui/aura/window_tree_host_platform.h
289 @@ -15,6 +15,8 @@
290  #include "ui/gfx/native_widget_types.h"
291  #include "ui/platform_window/platform_window_delegate.h"
292  
293 +#include "ui/aura/agl/window_tree_host_platform_agl.h"
294 +
295  namespace ui {
296  enum class DomCode;
297  class PlatformWindow;
298 @@ -26,7 +28,7 @@ namespace aura {
299  
300  // The unified WindowTreeHost implementation for platforms
301  // that implement PlatformWindow.
302 -class AURA_EXPORT WindowTreeHostPlatform : public WindowTreeHost,
303 +class AURA_EXPORT WindowTreeHostPlatform : public WindowTreeHostPlatformAgl,
304                                             public ui::PlatformWindowDelegate {
305   public:
306    explicit WindowTreeHostPlatform(ui::PlatformWindowInitProperties properties,
307 diff --git a/ui/ozone/platform/wayland/BUILD.gn b/ui/ozone/platform/wayland/BUILD.gn
308 index 1a2f889dc8947..86ff8269af9e0 100644
309 --- a/ui/ozone/platform/wayland/BUILD.gn
310 +++ b/ui/ozone/platform/wayland/BUILD.gn
311 @@ -409,7 +409,6 @@ source_set("wayland") {
312  
313    sources += [
314     "host/wayland_extensions.h",
315 -   "host/wayland_extensions_stub.cc",
316    ]
317  
318    deps += [ "extensions/agl" ]
319 diff --git a/ui/ozone/platform/wayland/extensions/agl/BUILD.gn b/ui/ozone/platform/wayland/extensions/agl/BUILD.gn
320 index ce289bc5dbbca..01c590e53df58 100644
321 --- a/ui/ozone/platform/wayland/extensions/agl/BUILD.gn
322 +++ b/ui/ozone/platform/wayland/extensions/agl/BUILD.gn
323 @@ -31,6 +31,8 @@ source_set("agl") {
324      "host/wayland_extensions_agl.h",
325      "host/wayland_extensions_agl_impl.cc",
326      "host/wayland_extensions_agl_impl.h",
327 +    "host/wayland_window_agl.cc",
328 +    "host/wayland_window_agl.h",
329    ]
330  
331    deps = [
332 diff --git a/ui/ozone/platform/wayland/extensions/agl/host/wayland_extensions_agl.h b/ui/ozone/platform/wayland/extensions/agl/host/wayland_extensions_agl.h
333 index df42fc00c84da..295154dfb437d 100644
334 --- a/ui/ozone/platform/wayland/extensions/agl/host/wayland_extensions_agl.h
335 +++ b/ui/ozone/platform/wayland/extensions/agl/host/wayland_extensions_agl.h
336 @@ -20,6 +20,9 @@
337  namespace ui {
338  
339  class AglShellWrapper;
340 +class PlatformWindowDelegate;
341 +class WaylandConnection;
342 +class WaylandWindow;
343  
344  // AGL extensions implementation for webOS/Lite
345  class WaylandExtensionsAgl {
346 @@ -29,9 +32,14 @@ class WaylandExtensionsAgl {
347    WaylandExtensionsAgl& operator=(const WaylandExtensionsAgl&) = delete;
348    virtual ~WaylandExtensionsAgl() = default;
349  
350 +  virtual std::unique_ptr<WaylandWindow> CreateWaylandWindow(
351 +      PlatformWindowDelegate* delegate,
352 +      WaylandConnection* connection) = 0;
353 +
354 +
355    virtual AglShellWrapper* GetAglShell() = 0;
356  };
357  
358  }  // namespace ui
359  
360 -#endif  // UI_OZONE_PLATFORM_WAYLAND_EXTENSIONS_AGL_HOST_WAYLAND_EXTENSIONS_AGL_H_
361 \ No newline at end of file
362 +#endif  // UI_OZONE_PLATFORM_WAYLAND_EXTENSIONS_AGL_HOST_WAYLAND_EXTENSIONS_AGL_H_
363 diff --git a/ui/ozone/platform/wayland/extensions/agl/host/wayland_extensions_agl_impl.cc b/ui/ozone/platform/wayland/extensions/agl/host/wayland_extensions_agl_impl.cc
364 index 26a5f0550c302..87376cbb8a9d3 100644
365 --- a/ui/ozone/platform/wayland/extensions/agl/host/wayland_extensions_agl_impl.cc
366 +++ b/ui/ozone/platform/wayland/extensions/agl/host/wayland_extensions_agl_impl.cc
367 @@ -22,6 +22,7 @@
368  #include "base/logging.h"
369  #include "ui/base/ui_base_switches.h"
370  #include "ui/ozone/platform/wayland/extensions/agl/host/agl_shell_wrapper.h"
371 +#include "ui/ozone/platform/wayland/extensions/agl/host/wayland_window_agl.h"
372  #include "ui/ozone/platform/wayland/extensions/agl/common/wayland_object_agl.h"
373  #include "ui/ozone/platform/wayland/host/wayland_connection.h"
374  
375 @@ -68,8 +69,8 @@ bool WaylandExtensionsAglImpl::Bind(wl_registry* registry,
376      agl_shell_ =
377          std::make_unique<AglShellWrapper>(aglshell.release(), connection_);
378  
379 -    LOG(INFO) << "Waiting until bound...";
380 -    return agl_shell_->WaitUntilBoundOk();
381 +    //LOG(INFO) << "Waiting until bound...";
382 +    //return agl_shell_->WaitUntilBoundOk();
383    } else {
384      LOG(INFO) << "Cant bind.";
385    }
386 @@ -85,6 +86,12 @@ AglShellWrapper* WaylandExtensionsAglImpl::GetAglShell() {
387    return agl_shell_.get();
388  }
389  
390 +std::unique_ptr<WaylandWindow> WaylandExtensionsAglImpl::CreateWaylandWindow(
391 +    PlatformWindowDelegate* delegate,
392 +    WaylandConnection* connection) {
393 +  return std::make_unique<WaylandWindowAgl>(delegate, connection, this);
394 +}
395 +
396  std::unique_ptr<WaylandExtensions> CreateWaylandExtensions(
397      WaylandConnection* connection) {
398    return std::make_unique<WaylandExtensionsAglImpl>(connection);
399 diff --git a/ui/ozone/platform/wayland/extensions/agl/host/wayland_extensions_agl_impl.h b/ui/ozone/platform/wayland/extensions/agl/host/wayland_extensions_agl_impl.h
400 index f6cbabe99ed0b..3218589f1a09a 100644
401 --- a/ui/ozone/platform/wayland/extensions/agl/host/wayland_extensions_agl_impl.h
402 +++ b/ui/ozone/platform/wayland/extensions/agl/host/wayland_extensions_agl_impl.h
403 @@ -17,12 +17,17 @@
404  #ifndef UI_OZONE_PLATFORM_WAYLAND_EXTENSIONS_AGL_HOST_WAYLAND_EXTENSIONS_AGL_IMPL_H_
405  #define UI_OZONE_PLATFORM_WAYLAND_EXTENSIONS_AGL_HOST_WAYLAND_EXTENSIONS_AGL_IMPL_H_
406  
407 +#include <memory>
408 +
409  #include "ui/ozone/platform/wayland/extensions/agl/host/wayland_extensions_agl.h"
410  #include "ui/ozone/platform/wayland/host/wayland_extensions.h"
411  
412  namespace ui {
413  
414  class AglShellWrapper;
415 +class PlatformWindowDelegate;
416 +class WaylandConnection;
417 +class WaylandWindow;
418  
419  // AGL extension implementation for webOS/Lite
420  class WaylandExtensionsAglImpl : public WaylandExtensions,
421 @@ -44,6 +49,10 @@ class WaylandExtensionsAglImpl : public WaylandExtensions,
422    // WaylandExtensionsAgl overrides
423    AglShellWrapper* GetAglShell() override;
424  
425 +  std::unique_ptr<WaylandWindow> CreateWaylandWindow(
426 +      PlatformWindowDelegate* delegate,
427 +      WaylandConnection* connection) override;
428 +
429   private:
430    std::unique_ptr<AglShellWrapper> agl_shell_;
431    WaylandConnection* connection_;
432 diff --git a/ui/ozone/platform/wayland/extensions/agl/host/wayland_window_agl.cc b/ui/ozone/platform/wayland/extensions/agl/host/wayland_window_agl.cc
433 new file mode 100644
434 index 0000000000000..97b21ae537658
435 --- /dev/null
436 +++ b/ui/ozone/platform/wayland/extensions/agl/host/wayland_window_agl.cc
437 @@ -0,0 +1,86 @@
438 +// Copyright 2021 LG Electronics, Inc.
439 +//
440 +// Licensed under the Apache License, Version 2.0 (the "License");
441 +// you may not use this file except in compliance with the License.
442 +// You may obtain a copy of the License at
443 +//
444 +// http://www.apache.org/licenses/LICENSE-2.0
445 +//
446 +// Unless required by applicable law or agreed to in writing, software
447 +// distributed under the License is distributed on an "AS IS" BASIS,
448 +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
449 +// See the License for the specific language governing permissions and
450 +// limitations under the License.
451 +//
452 +// SPDX-License-Identifier: Apache-2.0
453 +
454 +#include "ui/ozone/platform/wayland/extensions/agl/host/wayland_window_agl.h"
455 +
456 +#include "base/logging.h"
457 +#include "ui/ozone/platform/wayland/extensions/agl/host/agl_shell_wrapper.h"
458 +#include "ui/ozone/platform/wayland/extensions/agl/host/wayland_extensions_agl.h"
459 +#include "ui/ozone/platform/wayland/host/shell_surface_wrapper.h"
460 +#include "ui/ozone/platform/wayland/host/shell_toplevel_wrapper.h"
461 +#include "ui/ozone/platform/wayland/host/wayland_connection.h"
462 +
463 +namespace ui {
464 +
465 +WaylandWindowAgl::WaylandWindowAgl(PlatformWindowDelegate* delegate,
466 +                                   WaylandConnection* connection,
467 +                                   WaylandExtensionsAgl* agl_extensions)
468 +    : WaylandToplevelWindow(delegate, connection),
469 +      agl_extensions_(agl_extensions) {}
470 +
471 +WaylandWindowAgl::~WaylandWindowAgl() = default;
472 +
473 +void WaylandWindowAgl::SetAglActivateApp(const std::string& app) {
474 +  if (!agl_extensions_->GetAglShell()) {
475 +    LOG(ERROR) << "Agl shell wrapper is not created";
476 +    return;
477 +  }
478 +
479 +  agl_extensions_->GetAglShell()->SetAglActivateApp(app);
480 +  connection()->ScheduleFlush();
481 +}
482 +
483 +void WaylandWindowAgl::SetAglAppId(const std::string& title) {
484 +  if (!shell_toplevel()) {
485 +    LOG(ERROR) << "Shell toplevel is not created";
486 +    return;
487 +  }
488 +
489 +  shell_toplevel()->SetAppId(title);
490 +  connection()->ScheduleFlush();
491 +}
492 +
493 +void WaylandWindowAgl::SetAglReady() {
494 +  if (!agl_extensions_->GetAglShell()) {
495 +    LOG(ERROR) << "Agl shell wrapper is not created";
496 +    return;
497 +  }
498 +
499 +  agl_extensions_->GetAglShell()->SetAglReady();
500 +  connection()->ScheduleFlush();
501 +}
502 +
503 +void WaylandWindowAgl::SetAglBackground() {
504 +  if (!agl_extensions_->GetAglShell()) {
505 +    LOG(ERROR) << "Agl shell wrapper is not created";
506 +    return;
507 +  }
508 +
509 +  agl_extensions_->GetAglShell()->SetAglBackground(this);
510 +  connection()->ScheduleFlush();
511 +}
512 +
513 +void WaylandWindowAgl::SetAglPanel(uint32_t edge) {
514 +  if (!agl_extensions_->GetAglShell()) {
515 +    LOG(ERROR) << "Agl shell wrapper is not created";
516 +    return;
517 +  }
518 +
519 +  agl_extensions_->GetAglShell()->SetAglPanel(this, edge);
520 +  connection()->ScheduleFlush();
521 +}
522 +
523 +}  // namespace ui
524 diff --git a/ui/ozone/platform/wayland/extensions/agl/host/wayland_window_agl.h b/ui/ozone/platform/wayland/extensions/agl/host/wayland_window_agl.h
525 new file mode 100644
526 index 0000000000000..b2a922604c001
527 --- /dev/null
528 +++ b/ui/ozone/platform/wayland/extensions/agl/host/wayland_window_agl.h
529 @@ -0,0 +1,49 @@
530 +// Copyright 2021 LG Electronics, Inc.
531 +//
532 +// Licensed under the Apache License, Version 2.0 (the "License");
533 +// you may not use this file except in compliance with the License.
534 +// You may obtain a copy of the License at
535 +//
536 +// http://www.apache.org/licenses/LICENSE-2.0
537 +//
538 +// Unless required by applicable law or agreed to in writing, software
539 +// distributed under the License is distributed on an "AS IS" BASIS,
540 +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
541 +// See the License for the specific language governing permissions and
542 +// limitations under the License.
543 +//
544 +// SPDX-License-Identifier: Apache-2.0
545 +//
546 +
547 +#ifndef UI_OZONE_PLATFORM_WAYLAND_EXTENSIONS_AGL_HOST_WAYLAND_WINDOW_AGL_H_
548 +#define UI_OZONE_PLATFORM_WAYLAND_EXTENSIONS_AGL_HOST_WAYLAND_WINDOW_AGL_H_
549 +
550 +#include "ui/ozone/platform/wayland/host/wayland_toplevel_window.h"
551 +
552 +namespace ui {
553 +
554 +class WaylandExtensionsAgl;
555 +
556 +class WaylandWindowAgl : public WaylandToplevelWindow {
557 + public:
558 +  explicit WaylandWindowAgl(PlatformWindowDelegate* delegate,
559 +                            WaylandConnection* connection,
560 +                            WaylandExtensionsAgl* agl_extensions);
561 +  WaylandWindowAgl(const WaylandWindowAgl&) = delete;
562 +  WaylandWindowAgl& operator=(const WaylandWindowAgl&) = delete;
563 +  ~WaylandWindowAgl() override;
564 +
565 +  // Overrides PlatformWindowAgl
566 +  void SetAglActivateApp(const std::string& app) override;
567 +  void SetAglAppId(const std::string& title) override;
568 +  void SetAglReady() override;
569 +  void SetAglBackground() override;
570 +  void SetAglPanel(uint32_t edge) override;
571 +
572 + private:
573 +  WaylandExtensionsAgl* agl_extensions_;
574 +};
575 +
576 +}  // namespace ui
577 +
578 +#endif  // UI_OZONE_PLATFORM_WAYLAND_EXTENSIONS_AGL_HOST_WAYLAND_WINDOW_AGL_H_
579 diff --git a/ui/ozone/platform/wayland/gpu/gl_surface_wayland.cc b/ui/ozone/platform/wayland/gpu/gl_surface_wayland.cc
580 index 1cef91bb39912..26ad374718005 100644
581 --- a/ui/ozone/platform/wayland/gpu/gl_surface_wayland.cc
582 +++ b/ui/ozone/platform/wayland/gpu/gl_surface_wayland.cc
583 @@ -89,8 +89,14 @@ gfx::SwapResult GLSurfaceWayland::SwapBuffers(PresentationCallback callback,
584      return scoped_swap_buffers.result();
585    }
586    window_->root_surface()->set_surface_buffer_scale(scale_factor_);
587 -  return gl::NativeViewGLSurfaceEGL::SwapBuffers(std::move(callback),
588 -                                                 std::move(data));
589 +  gfx::SwapResult result = gl::NativeViewGLSurfaceEGL::SwapBuffers(std::move(callback),
590 +                                                                   std::move(data));
591 +
592 +  if (window_) {
593 +    window_->OnSurfaceContentChanged();
594 +  }
595 +
596 +  return result;
597  }
598  
599  gfx::SwapResult GLSurfaceWayland::PostSubBuffer(int x,
600 diff --git a/ui/ozone/platform/wayland/host/gtk_primary_selection_device.cc b/ui/ozone/platform/wayland/host/gtk_primary_selection_device.cc
601 index 43445ea2442b4..94f0739599142 100644
602 --- a/ui/ozone/platform/wayland/host/gtk_primary_selection_device.cc
603 +++ b/ui/ozone/platform/wayland/host/gtk_primary_selection_device.cc
604 @@ -31,7 +31,7 @@ void GtkPrimarySelectionDevice::SetSelectionSource(
605    auto* data_source = source ? source->data_source() : nullptr;
606    gtk_primary_selection_device_set_selection(data_device_.get(), data_source,
607                                               serial);
608 -  connection()->Flush();
609 +  connection()->ScheduleFlush();
610  }
611  
612  // static
613 diff --git a/ui/ozone/platform/wayland/host/gtk_primary_selection_device_manager.cc b/ui/ozone/platform/wayland/host/gtk_primary_selection_device_manager.cc
614 index 2c39409808128..1e07ae6009776 100644
615 --- a/ui/ozone/platform/wayland/host/gtk_primary_selection_device_manager.cc
616 +++ b/ui/ozone/platform/wayland/host/gtk_primary_selection_device_manager.cc
617 @@ -66,7 +66,7 @@ GtkPrimarySelectionDevice* GtkPrimarySelectionDeviceManager::GetDevice() {
618          connection_,
619          gtk_primary_selection_device_manager_get_device(
620              device_manager_.get(), connection_->seat()->wl_object()));
621 -    connection_->Flush();
622 +    connection_->ScheduleFlush();
623    }
624    DCHECK(device_);
625    return device_.get();
626 @@ -77,7 +77,7 @@ GtkPrimarySelectionDeviceManager::CreateSource(
627      GtkPrimarySelectionSource::Delegate* delegate) {
628    auto* data_source =
629        gtk_primary_selection_device_manager_create_source(device_manager_.get());
630 -  connection_->Flush();
631 +  connection_->ScheduleFlush();
632    return std::make_unique<GtkPrimarySelectionSource>(data_source, connection_,
633                                                       delegate);
634  }
635 diff --git a/ui/ozone/platform/wayland/host/proxy/wayland_proxy_impl.cc b/ui/ozone/platform/wayland/host/proxy/wayland_proxy_impl.cc
636 index dee90b1aaaf72..caad70e0ab1cb 100644
637 --- a/ui/ozone/platform/wayland/host/proxy/wayland_proxy_impl.cc
638 +++ b/ui/ozone/platform/wayland/host/proxy/wayland_proxy_impl.cc
639 @@ -75,7 +75,7 @@ void WaylandProxyImpl::DestroyShmForWlBuffer(wl_buffer* buffer) {
640  }
641  
642  void WaylandProxyImpl::FlushForTesting() {
643 -  connection_->Flush();
644 +  connection_->ScheduleFlush();
645  }
646  
647  ui::PlatformWindowType WaylandProxyImpl::GetWindowType(
648 diff --git a/ui/ozone/platform/wayland/host/wayland_connection.cc b/ui/ozone/platform/wayland/host/wayland_connection.cc
649 index 93427c52e1284..e2d45a6f5dc67 100644
650 --- a/ui/ozone/platform/wayland/host/wayland_connection.cc
651 +++ b/ui/ozone/platform/wayland/host/wayland_connection.cc
652 @@ -285,6 +285,20 @@ bool WaylandConnection::Initialize() {
653    return true;
654  }
655  
656 +void WaylandConnection::ScheduleFlush() {
657 +  // When we are in tests, the message loop is set later when the
658 +  // initialization of the OzonePlatform complete. Thus, just
659 +  // flush directly. This doesn't happen in normal run.
660 +  if (!base::CurrentUIThread::IsSet()) {
661 +    Flush();
662 +  } else if (!scheduled_flush_) {
663 +    base::ThreadTaskRunnerHandle::Get()->PostTask(
664 +        FROM_HERE,
665 +        base::BindOnce(&WaylandConnection::Flush, base::Unretained(this)));
666 +    scheduled_flush_ = true;
667 +  }
668 +}
669 +
670  void WaylandConnection::RoundTripQueue() {
671    if (roundtrip_closure_for_testing_) {
672      roundtrip_closure_for_testing_.Run();
673 @@ -354,6 +368,7 @@ void WaylandConnection::RegisterGlobalObjectFactory(
674  
675  void WaylandConnection::Flush() {
676    wl_display_flush(display_.get());
677 +  scheduled_flush_ = false;
678  }
679  
680  void WaylandConnection::UpdateInputDevices() {
681 @@ -441,7 +456,7 @@ void WaylandConnection::Global(void* data,
682  
683    auto factory_it = connection->global_object_factories_.find(interface);
684    if (connection->extensions_->Bind(registry, name, interface, version)) {
685 -    DVLOG(1) << "Successfully bound to " << interface;
686 +    LOG(INFO) << "Successfully bound to " << interface;
687    } else if (factory_it != connection->global_object_factories_.end()) {
688      (*factory_it->second)(connection, registry, name, interface, version);
689    } else if (!connection->compositor_ &&
690 @@ -609,7 +624,7 @@ void WaylandConnection::Global(void* data,
691  
692    connection->available_globals_.emplace_back(interface, version);
693  
694 -  connection->Flush();
695 +  connection->ScheduleFlush();
696  }
697  
698  base::TimeTicks WaylandConnection::ConvertPresentationTime(uint32_t tv_sec_hi,
699 @@ -674,14 +689,14 @@ void WaylandConnection::PingV6(void* data,
700                                 uint32_t serial) {
701    WaylandConnection* connection = static_cast<WaylandConnection*>(data);
702    zxdg_shell_v6_pong(shell_v6, serial);
703 -  connection->Flush();
704 +  connection->ScheduleFlush();
705  }
706  
707  // static
708  void WaylandConnection::Ping(void* data, xdg_wm_base* shell, uint32_t serial) {
709    WaylandConnection* connection = static_cast<WaylandConnection*>(data);
710    xdg_wm_base_pong(shell, serial);
711 -  connection->Flush();
712 +  connection->ScheduleFlush();
713  }
714  
715  // static
716 diff --git a/ui/ozone/platform/wayland/host/wayland_connection.h b/ui/ozone/platform/wayland/host/wayland_connection.h
717 index dfd1d060c73f2..d2d7a866d3af8 100644
718 --- a/ui/ozone/platform/wayland/host/wayland_connection.h
719 +++ b/ui/ozone/platform/wayland/host/wayland_connection.h
720 @@ -94,8 +94,8 @@ class WaylandConnection {
721  
722    bool Initialize();
723  
724 -  // Immediately flushes the Wayland display.
725 -  void Flush();
726 +  // Schedules a flush of the Wayland connection.
727 +  void ScheduleFlush();
728  
729    // Calls wl_display_roundtrip_queue. Might be required during initialization
730    // of some objects that should block until they are initialized.
731 @@ -340,6 +340,9 @@ class WaylandConnection {
732    friend class ZwpIdleInhibitManager;
733    friend class ZwpPrimarySelectionDeviceManager;
734  
735 +  // Immediately flushes the Wayland display.
736 +  void Flush();
737 +
738    void RegisterGlobalObjectFactory(const char* interface_name,
739                                     wl::GlobalObjectFactory factory);
740  
741 @@ -467,6 +470,8 @@ class WaylandConnection {
742    // sizes.
743    bool surface_submission_in_pixel_coordinates_ = false;
744  
745 +  bool scheduled_flush_ = false;
746 +
747    wl::SerialTracker serial_tracker_;
748  
749    // Global Wayland interfaces available in the current session, with their
750 diff --git a/ui/ozone/platform/wayland/host/wayland_cursor.cc b/ui/ozone/platform/wayland/host/wayland_cursor.cc
751 index 891ca2e5e1f3c..48ac8b8925ddd 100644
752 --- a/ui/ozone/platform/wayland/host/wayland_cursor.cc
753 +++ b/ui/ozone/platform/wayland/host/wayland_cursor.cc
754 @@ -109,7 +109,7 @@ void WaylandCursor::HideCursor() {
755    wl_surface_attach(pointer_surface_.get(), nullptr, 0, 0);
756    wl_surface_commit(pointer_surface_.get());
757  
758 -  connection_->Flush();
759 +  connection_->ScheduleFlush();
760  
761    if (listener_)
762      listener_->OnCursorBufferAttached(nullptr);
763 @@ -160,7 +160,7 @@ void WaylandCursor::AttachAndCommit(wl_buffer* buffer,
764    wl_surface_attach(pointer_surface_.get(), buffer, 0, 0);
765    wl_surface_commit(pointer_surface_.get());
766  
767 -  connection_->Flush();
768 +  connection_->ScheduleFlush();
769  }
770  
771  }  // namespace ui
772 diff --git a/ui/ozone/platform/wayland/host/wayland_data_device.cc b/ui/ozone/platform/wayland/host/wayland_data_device.cc
773 index a1d691b6315ac..ccc7bfb0305a8 100644
774 --- a/ui/ozone/platform/wayland/host/wayland_data_device.cc
775 +++ b/ui/ozone/platform/wayland/host/wayland_data_device.cc
776 @@ -46,7 +46,7 @@ void WaylandDataDevice::StartDrag(const WaylandDataSource& data_source,
777                              origin_window.root_surface()->surface(),
778                              icon_surface, serial);
779    drag_delegate_->DrawIcon();
780 -  connection()->Flush();
781 +  connection()->ScheduleFlush();
782  }
783  
784  void WaylandDataDevice::ResetDragDelegate() {
785 @@ -78,7 +78,7 @@ void WaylandDataDevice::SetSelectionSource(WaylandDataSource* source,
786                                             uint32_t serial) {
787    auto* data_source = source ? source->data_source() : nullptr;
788    wl_data_device_set_selection(data_device_.get(), data_source, serial);
789 -  connection()->Flush();
790 +  connection()->ScheduleFlush();
791  }
792  
793  void WaylandDataDevice::ReadDragDataFromFD(base::ScopedFD fd,
794 @@ -140,7 +140,7 @@ void WaylandDataDevice::OnEnter(void* data,
795        gfx::PointF(wl_fixed_to_double(x), wl_fixed_to_double(y)), window);
796    self->drag_delegate_->OnDragEnter(window, point, serial);
797  
798 -  self->connection()->Flush();
799 +  self->connection()->ScheduleFlush();
800  }
801  
802  void WaylandDataDevice::OnMotion(void* data,
803 @@ -161,7 +161,7 @@ void WaylandDataDevice::OnDrop(void* data, wl_data_device* data_device) {
804    auto* self = static_cast<WaylandDataDevice*>(data);
805    if (self->drag_delegate_) {
806      self->drag_delegate_->OnDragDrop();
807 -    self->connection()->Flush();
808 +    self->connection()->ScheduleFlush();
809    }
810  
811    // There are buggy Exo versions, which send 'drop' event (even for
812 @@ -178,7 +178,7 @@ void WaylandDataDevice::OnLeave(void* data, wl_data_device* data_device) {
813    auto* self = static_cast<WaylandDataDevice*>(data);
814    if (self->drag_delegate_) {
815      self->drag_delegate_->OnDragLeave();
816 -    self->connection()->Flush();
817 +    self->connection()->ScheduleFlush();
818    }
819    self->ResetDragDelegateIfNeeded();
820  }
821 diff --git a/ui/ozone/platform/wayland/host/wayland_data_device_base.cc b/ui/ozone/platform/wayland/host/wayland_data_device_base.cc
822 index 4287f72617708..d0c077c2e69ea 100644
823 --- a/ui/ozone/platform/wayland/host/wayland_data_device_base.cc
824 +++ b/ui/ozone/platform/wayland/host/wayland_data_device_base.cc
825 @@ -72,7 +72,7 @@ void WaylandDataDeviceBase::RegisterDeferredReadCallback() {
826  
827    wl_callback_add_listener(deferred_read_callback_.get(), &kListener, this);
828  
829 -  connection_->Flush();
830 +  connection_->ScheduleFlush();
831  }
832  
833  void WaylandDataDeviceBase::RegisterDeferredReadClosure(
834 diff --git a/ui/ozone/platform/wayland/host/wayland_data_drag_controller.cc b/ui/ozone/platform/wayland/host/wayland_data_drag_controller.cc
835 index f2123ec8bac3f..11750a3f55da2 100644
836 --- a/ui/ozone/platform/wayland/host/wayland_data_drag_controller.cc
837 +++ b/ui/ozone/platform/wayland/host/wayland_data_drag_controller.cc
838 @@ -217,7 +217,7 @@ void WaylandDataDragController::OnDragSurfaceFrame(void* data,
839    DCHECK(self);
840    self->DrawIconInternal();
841    self->icon_frame_callback_.reset();
842 -  self->connection_->Flush();
843 +  self->connection_->ScheduleFlush();
844  }
845  
846  void WaylandDataDragController::DrawIconInternal() {
847 diff --git a/ui/ozone/platform/wayland/host/wayland_data_source.cc b/ui/ozone/platform/wayland/host/wayland_data_source.cc
848 index de1e110f73b11..e24f31b1a8f52 100644
849 --- a/ui/ozone/platform/wayland/host/wayland_data_source.cc
850 +++ b/ui/ozone/platform/wayland/host/wayland_data_source.cc
851 @@ -119,7 +119,7 @@ void DataSource<wl_data_source>::Offer(
852      const std::vector<std::string>& mime_types) {
853    for (auto& mime_type : mime_types)
854      wl_data_source_offer(data_source_.get(), mime_type.c_str());
855 -  connection_->Flush();
856 +  connection_->ScheduleFlush();
857  }
858  
859  template <typename T>
860 @@ -154,7 +154,7 @@ void DataSource<gtk_primary_selection_source>::Offer(
861      const std::vector<std::string>& mime_types) {
862    for (const auto& mime_type : mime_types)
863      gtk_primary_selection_source_offer(data_source_.get(), mime_type.c_str());
864 -  connection_->Flush();
865 +  connection_->ScheduleFlush();
866  }
867  
868  template <>
869 @@ -173,7 +173,7 @@ void DataSource<zwp_primary_selection_source_v1>::Offer(
870    for (const auto& mime_type : mime_types)
871      zwp_primary_selection_source_v1_offer(data_source_.get(),
872                                            mime_type.c_str());
873 -  connection_->Flush();
874 +  connection_->ScheduleFlush();
875  }
876  
877  template class DataSource<gtk_primary_selection_source>;
878 diff --git a/ui/ozone/platform/wayland/host/wayland_drm.cc b/ui/ozone/platform/wayland/host/wayland_drm.cc
879 index 7edc0da798b9b..280350d9286c0 100644
880 --- a/ui/ozone/platform/wayland/host/wayland_drm.cc
881 +++ b/ui/ozone/platform/wayland/host/wayland_drm.cc
882 @@ -57,7 +57,7 @@ WaylandDrm::WaylandDrm(wl_drm* drm, WaylandConnection* connection)
883        &Capabilities,
884    };
885    wl_drm_add_listener(wl_drm_.get(), &kDrmListener, this);
886 -  connection_->Flush();
887 +  connection_->ScheduleFlush();
888  
889    // A roundtrip after binding guarantees that the client has received all
890    // supported formats and capabilities of the device.
891 @@ -91,7 +91,7 @@ void WaylandDrm::CreateBuffer(const base::ScopedFD& fd,
892    wl::Object<wl_buffer> buffer(wl_drm_create_prime_buffer(
893        wl_drm_.get(), fd.get(), size.width(), size.height(), format, offset[0],
894        stride[0], offset[1], stride[1], offset[2], stride[2]));
895 -  connection_->Flush();
896 +  connection_->ScheduleFlush();
897  
898    std::move(callback).Run(std::move(buffer));
899  }
900 @@ -145,7 +145,7 @@ void WaylandDrm::Authenticate(const char* drm_device_path) {
901    }
902  
903    wl_drm_authenticate(wl_drm_.get(), magic);
904 -  connection_->Flush();
905 +  connection_->ScheduleFlush();
906  
907    // Do the roundtrip to make sure the server processes this request and
908    // authenticates us.
909 diff --git a/ui/ozone/platform/wayland/host/wayland_extensions.h b/ui/ozone/platform/wayland/host/wayland_extensions.h
910 index 3bd2fd7a211ae..f6ed47507d217 100644
911 --- a/ui/ozone/platform/wayland/host/wayland_extensions.h
912 +++ b/ui/ozone/platform/wayland/host/wayland_extensions.h
913 @@ -25,7 +25,9 @@ namespace ui {
914  
915  class ShellToplevelWrapper;
916  class ShellPopupWrapper;
917 +class PlatformWindowDelegate;
918  class WaylandConnection;
919 +class WaylandWindow;
920  
921  // Wayland extensions abstract interface to support extending of the Wayland
922  // protocol. Inherit it to provide your own Wayland extensions implementation.
923 @@ -45,6 +47,10 @@ class WaylandExtensions {
924  
925    // Checks whether the extensions have bound shell object(s).
926    virtual bool HasShellObject() const = 0;
927 +
928 +  virtual std::unique_ptr<WaylandWindow> CreateWaylandWindow(
929 +      PlatformWindowDelegate* delegate,
930 +      WaylandConnection* connection) = 0;
931  };
932  
933  // Creates Wayland extensions.
934 diff --git a/ui/ozone/platform/wayland/host/wayland_keyboard.cc b/ui/ozone/platform/wayland/host/wayland_keyboard.cc
935 index c6e64f1e55da3..473a702bf8987 100644
936 --- a/ui/ozone/platform/wayland/host/wayland_keyboard.cc
937 +++ b/ui/ozone/platform/wayland/host/wayland_keyboard.cc
938 @@ -54,7 +54,7 @@ class WaylandKeyboard::ZCRExtendedKeyboard {
939  
940    void AckKey(uint32_t serial, bool handled) {
941      zcr_extended_keyboard_v1_ack_key(obj_.get(), serial, handled);
942 -    keyboard_->connection_->Flush();
943 +    keyboard_->connection_->ScheduleFlush();
944    }
945  
946    // Returns true if connected object will send zcr_extended_keyboard::peek_key.
947 @@ -247,7 +247,7 @@ void WaylandKeyboard::FlushInput(base::OnceClosure closure) {
948    // get spurious repeats.
949    sync_callback_.reset(wl_display_sync(connection_->display_wrapper()));
950    wl_callback_add_listener(sync_callback_.get(), &callback_listener_, this);
951 -  connection_->Flush();
952 +  connection_->ScheduleFlush();
953  }
954  
955  void WaylandKeyboard::DispatchKey(unsigned int key,
956 diff --git a/ui/ozone/platform/wayland/host/wayland_popup.cc b/ui/ozone/platform/wayland/host/wayland_popup.cc
957 index 84e429457462e..cb13557093dc2 100644
958 --- a/ui/ozone/platform/wayland/host/wayland_popup.cc
959 +++ b/ui/ozone/platform/wayland/host/wayland_popup.cc
960 @@ -124,7 +124,7 @@ void WaylandPopup::Show(bool inactive) {
961      return;
962    }
963  
964 -  connection()->Flush();
965 +  connection()->ScheduleFlush();
966    WaylandWindow::Show(inactive);
967  }
968  
969 @@ -147,7 +147,7 @@ void WaylandPopup::Hide() {
970      decorated_via_aura_popup_ = false;
971    }
972  
973 -  connection()->Flush();
974 +  connection()->ScheduleFlush();
975  }
976  
977  bool WaylandPopup::IsVisible() const {
978 diff --git a/ui/ozone/platform/wayland/host/wayland_shm.cc b/ui/ozone/platform/wayland/host/wayland_shm.cc
979 index 80d27227b9ab3..2b6c4f31ca0d8 100644
980 --- a/ui/ozone/platform/wayland/host/wayland_shm.cc
981 +++ b/ui/ozone/platform/wayland/host/wayland_shm.cc
982 @@ -62,7 +62,7 @@ wl::Object<wl_buffer> WaylandShm::CreateBuffer(const base::ScopedFD& fd,
983        with_alpha_channel ? WL_SHM_FORMAT_ARGB8888 : WL_SHM_FORMAT_XRGB8888;
984    wl::Object<wl_buffer> shm_buffer(wl_shm_pool_create_buffer(
985        pool.get(), 0, size.width(), size.height(), size.width() * 4, format));
986 -  connection_->Flush();
987 +  connection_->ScheduleFlush();
988    return shm_buffer;
989  }
990  
991 diff --git a/ui/ozone/platform/wayland/host/wayland_surface.cc b/ui/ozone/platform/wayland/host/wayland_surface.cc
992 index cd178f9aaee00..ffe5062402b33 100644
993 --- a/ui/ozone/platform/wayland/host/wayland_surface.cc
994 +++ b/ui/ozone/platform/wayland/host/wayland_surface.cc
995 @@ -267,7 +267,7 @@ void WaylandSurface::UpdateBufferDamageRegion(const gfx::Rect& damage_px) {
996  void WaylandSurface::Commit(bool flush) {
997    wl_surface_commit(surface_.get());
998    if (flush)
999 -    connection_->Flush();
1000 +    connection_->ScheduleFlush();
1001  }
1002  
1003  void WaylandSurface::set_surface_buffer_scale(float scale) {
1004 diff --git a/ui/ozone/platform/wayland/host/wayland_toplevel_window.cc b/ui/ozone/platform/wayland/host/wayland_toplevel_window.cc
1005 index e39daa898c9a5..68aebd357fdc2 100644
1006 --- a/ui/ozone/platform/wayland/host/wayland_toplevel_window.cc
1007 +++ b/ui/ozone/platform/wayland/host/wayland_toplevel_window.cc
1008 @@ -131,7 +131,7 @@ void WaylandToplevelWindow::DispatchHostWindowDragMovement(
1009    else
1010      shell_toplevel_->SurfaceResize(connection(), hittest);
1011  
1012 -  connection()->Flush();
1013 +  connection()->ScheduleFlush();
1014  }
1015  
1016  void WaylandToplevelWindow::Show(bool inactive) {
1017 @@ -166,7 +166,7 @@ void WaylandToplevelWindow::Hide() {
1018      aura_surface_.reset();
1019    }
1020    shell_toplevel_.reset();
1021 -  connection()->Flush();
1022 +  connection()->ScheduleFlush();
1023  }
1024  
1025  bool WaylandToplevelWindow::IsVisible() const {
1026 @@ -183,7 +183,7 @@ void WaylandToplevelWindow::SetTitle(const std::u16string& title) {
1027  
1028    if (shell_toplevel_) {
1029      shell_toplevel_->SetTitle(title);
1030 -    connection()->Flush();
1031 +    connection()->ScheduleFlush();
1032    }
1033  }
1034  
1035 @@ -262,13 +262,13 @@ void WaylandToplevelWindow::Activate() {
1036    // but nothing more happens (until the user moves the mouse over a Lacros
1037    // window in which case events will start and the activation will come
1038    // through).
1039 -  connection()->Flush();
1040 +  connection()->ScheduleFlush();
1041  }
1042  
1043  void WaylandToplevelWindow::Deactivate() {
1044    if (shell_toplevel_ && shell_toplevel_->SupportsActivation()) {
1045      shell_toplevel_->Deactivate();
1046 -    connection()->Flush();
1047 +    connection()->ScheduleFlush();
1048    }
1049  }
1050  
1051 @@ -877,7 +877,7 @@ void WaylandToplevelWindow::TriggerStateChanges() {
1052  
1053    delegate()->OnWindowStateChanged(previous_state_, state_);
1054  
1055 -  connection()->Flush();
1056 +  connection()->ScheduleFlush();
1057  }
1058  
1059  void WaylandToplevelWindow::SetWindowState(PlatformWindowState state) {
1060 @@ -908,7 +908,7 @@ void WaylandToplevelWindow::SetSizeConstraints() {
1061    if (max_size_dip.has_value())
1062      shell_toplevel_->SetMaxSize(max_size_dip->width(), max_size_dip->height());
1063  
1064 -  connection()->Flush();
1065 +  connection()->ScheduleFlush();
1066  }
1067  
1068  void WaylandToplevelWindow::SetOrResetRestoredBounds() {
1069 diff --git a/ui/ozone/platform/wayland/host/wayland_window.cc b/ui/ozone/platform/wayland/host/wayland_window.cc
1070 index f8b8c36a745e5..e415efde8ccd8 100644
1071 --- a/ui/ozone/platform/wayland/host/wayland_window.cc
1072 +++ b/ui/ozone/platform/wayland/host/wayland_window.cc
1073 @@ -430,7 +430,7 @@ void WaylandWindow::SetDecorationInsets(const gfx::Insets* insets_px) {
1074    else
1075      frame_insets_px_ = absl::nullopt;
1076    UpdateDecorations();
1077 -  connection_->Flush();
1078 +  connection_->ScheduleFlush();
1079  }
1080  
1081  void WaylandWindow::SetWindowIcons(const gfx::ImageSkia& window_icon,
1082 @@ -522,6 +522,10 @@ void WaylandWindow::HandleSurfaceConfigure(uint32_t serial) {
1083        << "Only shell surfaces must receive HandleSurfaceConfigure calls.";
1084  }
1085  
1086 +void WaylandWindow::OnSurfaceContentChanged() {
1087 +  connection_->ScheduleFlush();
1088 +}
1089 +
1090  void WaylandWindow::HandleToplevelConfigure(int32_t widht,
1091                                              int32_t height,
1092                                              const WindowStates& window_states) {
1093 @@ -551,7 +555,7 @@ void WaylandWindow::UpdateVisualSize(const gfx::Size& size_px) {
1094  
1095    if (apply_pending_state_on_update_visual_size_for_testing_) {
1096      root_surface_->ApplyPendingState();
1097 -    connection_->Flush();
1098 +    connection_->ScheduleFlush();
1099    }
1100  }
1101  
1102 @@ -661,7 +665,7 @@ bool WaylandWindow::Initialize(PlatformWindowInitProperties properties) {
1103    std::vector<gfx::Rect> region{gfx::Rect{size_px_}};
1104    root_surface_->set_opaque_region(&region);
1105    root_surface_->ApplyPendingState();
1106 -  connection_->Flush();
1107 +  connection_->ScheduleFlush();
1108  
1109    return true;
1110  }
1111 @@ -957,7 +961,7 @@ void WaylandWindow::ProcessPendingBoundsDip(uint32_t serial) {
1112      // window has been applied.
1113      SetWindowGeometry(pending_bounds_dip_);
1114      AckConfigure(serial);
1115 -    connection()->Flush();
1116 +    connection()->ScheduleFlush();
1117    } else if (!pending_configures_.empty() &&
1118               pending_bounds_dip_.size() ==
1119                   pending_configures_.back().bounds_dip.size()) {
1120 @@ -1051,7 +1055,7 @@ bool WaylandWindow::ProcessVisualSizeUpdate(const gfx::Size& size_px) {
1121      auto serial = result->serial;
1122      SetWindowGeometry(result->bounds_dip);
1123      AckConfigure(serial);
1124 -    connection()->Flush();
1125 +    connection()->ScheduleFlush();
1126      pending_configures_.erase(pending_configures_.begin(), ++result);
1127      return true;
1128    }
1129 diff --git a/ui/ozone/platform/wayland/host/wayland_window.h b/ui/ozone/platform/wayland/host/wayland_window.h
1130 index f0f75d4481cd2..dae1ddcd2933f 100644
1131 --- a/ui/ozone/platform/wayland/host/wayland_window.h
1132 +++ b/ui/ozone/platform/wayland/host/wayland_window.h
1133 @@ -218,6 +218,8 @@ class WaylandWindow : public PlatformWindow,
1134    // currently bound to.
1135    virtual void HandleSurfaceConfigure(uint32_t serial);
1136  
1137 +  void OnSurfaceContentChanged();
1138 +
1139    struct WindowStates {
1140      bool is_maximized = false;
1141      bool is_fullscreen = false;
1142 diff --git a/ui/ozone/platform/wayland/host/wayland_window_drag_controller.cc b/ui/ozone/platform/wayland/host/wayland_window_drag_controller.cc
1143 index 6f45f47a71c25..a269ec9b368a4 100644
1144 --- a/ui/ozone/platform/wayland/host/wayland_window_drag_controller.cc
1145 +++ b/ui/ozone/platform/wayland/host/wayland_window_drag_controller.cc
1146 @@ -84,7 +84,7 @@ class WaylandWindowDragController::ExtendedDragSource {
1147      auto* surface = window ? window->root_surface()->surface() : nullptr;
1148      zcr_extended_drag_source_v1_drag(source_.get(), surface, offset.x(),
1149                                       offset.y());
1150 -    connection_.Flush();
1151 +    connection_.ScheduleFlush();
1152    }
1153  
1154   private:
1155 diff --git a/ui/ozone/platform/wayland/host/wayland_window_factory.cc b/ui/ozone/platform/wayland/host/wayland_window_factory.cc
1156 index 4857125bb5f34..b2f73218681b9 100644
1157 --- a/ui/ozone/platform/wayland/host/wayland_window_factory.cc
1158 +++ b/ui/ozone/platform/wayland/host/wayland_window_factory.cc
1159 @@ -13,6 +13,8 @@
1160  #include "ui/ozone/platform/wayland/host/wayland_window.h"
1161  #include "ui/platform_window/platform_window_init_properties.h"
1162  
1163 +#include "ui/ozone/platform/wayland/host/wayland_extensions.h"
1164 +
1165  namespace ui {
1166  
1167  namespace {
1168 @@ -41,6 +43,13 @@ std::unique_ptr<WaylandWindow> WaylandWindow::Create(
1169        // toplevel window instead.
1170        if (auto* parent =
1171                GetParentWindow(connection, properties.parent_widget)) {
1172 +
1173 +        if (connection->extensions()) {
1174 +          window = connection->extensions()->CreateWaylandWindow(delegate,
1175 +                                                                 connection);
1176 +          if (window)
1177 +            break;
1178 +        }
1179          window = std::make_unique<WaylandPopup>(delegate, connection, parent);
1180        } else {
1181          DLOG(WARNING) << "Failed to determine for menu/popup window.";
1182 @@ -52,6 +61,12 @@ std::unique_ptr<WaylandWindow> WaylandWindow::Create(
1183      case PlatformWindowType::kDrag:
1184        // TODO(msisov): Figure out what kind of surface we need to create for
1185        // bubble and drag windows.
1186 +      if (connection->extensions()) {
1187 +        window =
1188 +            connection->extensions()->CreateWaylandWindow(delegate, connection);
1189 +        if (window)
1190 +          break;
1191 +      }
1192        window = std::make_unique<WaylandToplevelWindow>(delegate, connection);
1193        break;
1194      default:
1195 diff --git a/ui/ozone/platform/wayland/host/wayland_zwp_linux_dmabuf.cc b/ui/ozone/platform/wayland/host/wayland_zwp_linux_dmabuf.cc
1196 index 3db8cb5e5dba9..5d6293e016842 100644
1197 --- a/ui/ozone/platform/wayland/host/wayland_zwp_linux_dmabuf.cc
1198 +++ b/ui/ozone/platform/wayland/host/wayland_zwp_linux_dmabuf.cc
1199 @@ -104,7 +104,7 @@ void WaylandZwpLinuxDmabuf::CreateBuffer(const base::ScopedFD& fd,
1200      // created buffer and notify the client about it via the |callback|.
1201      pending_params_.emplace(std::move(params), std::move(callback));
1202    }
1203 -  connection_->Flush();
1204 +  connection_->ScheduleFlush();
1205  }
1206  
1207  bool WaylandZwpLinuxDmabuf::CanCreateBufferImmed() const {
1208 @@ -150,7 +150,7 @@ void WaylandZwpLinuxDmabuf::NotifyRequestCreateBufferDone(
1209  
1210    pending_params_.erase(it);
1211  
1212 -  connection_->Flush();
1213 +  connection_->ScheduleFlush();
1214  }
1215  
1216  // static
1217 diff --git a/ui/ozone/platform/wayland/host/xdg_foreign_wrapper.cc b/ui/ozone/platform/wayland/host/xdg_foreign_wrapper.cc
1218 index 8b8591fabe015..9b3c6e5136d5d 100644
1219 --- a/ui/ozone/platform/wayland/host/xdg_foreign_wrapper.cc
1220 +++ b/ui/ozone/platform/wayland/host/xdg_foreign_wrapper.cc
1221 @@ -162,7 +162,7 @@ void XdgForeignWrapperImpl<zxdg_exporter_v1, zxdg_exported_v1>::
1222    zxdg_exported_v1_add_listener(exported_surface.exported.get(),
1223                                  &kExportedListener, this);
1224    exported_surfaces_.emplace_back(std::move(exported_surface));
1225 -  connection_->Flush();
1226 +  connection_->ScheduleFlush();
1227  }
1228  
1229  template <>
1230 @@ -176,7 +176,7 @@ void XdgForeignWrapperImpl<zxdg_exporter_v2, zxdg_exported_v2>::
1231    zxdg_exported_v2_add_listener(exported_surface.exported.get(),
1232                                  &kExportedListener, this);
1233    exported_surfaces_.emplace_back(std::move(exported_surface));
1234 -  connection_->Flush();
1235 +  connection_->ScheduleFlush();
1236  }
1237  
1238  // static
1239 diff --git a/ui/ozone/platform/wayland/host/xdg_popup_wrapper_impl.cc b/ui/ozone/platform/wayland/host/xdg_popup_wrapper_impl.cc
1240 index 23b7ad8fbf3cc..2e1f8fc129bf7 100644
1241 --- a/ui/ozone/platform/wayland/host/xdg_popup_wrapper_impl.cc
1242 +++ b/ui/ozone/platform/wayland/host/xdg_popup_wrapper_impl.cc
1243 @@ -230,7 +230,7 @@ bool XDGPopupWrapperImpl::SetBounds(const gfx::Rect& new_bounds) {
1244    xdg_popup_reposition(xdg_popup_.get(), positioner.get(),
1245                         ++next_reposition_token_);
1246  
1247 -  connection_->Flush();
1248 +  connection_->ScheduleFlush();
1249    return true;
1250  }
1251  
1252 diff --git a/ui/ozone/platform/wayland/host/xdg_surface_wrapper_impl.cc b/ui/ozone/platform/wayland/host/xdg_surface_wrapper_impl.cc
1253 index 048071b4b7b76..692f562e203f0 100644
1254 --- a/ui/ozone/platform/wayland/host/xdg_surface_wrapper_impl.cc
1255 +++ b/ui/ozone/platform/wayland/host/xdg_surface_wrapper_impl.cc
1256 @@ -40,7 +40,7 @@ bool XDGSurfaceWrapperImpl::Initialize() {
1257    }
1258  
1259    xdg_surface_add_listener(xdg_surface_.get(), &xdg_surface_listener, this);
1260 -  connection_->Flush();
1261 +  connection_->ScheduleFlush();
1262    return true;
1263  }
1264  
1265 diff --git a/ui/ozone/platform/wayland/host/zwp_primary_selection_device.cc b/ui/ozone/platform/wayland/host/zwp_primary_selection_device.cc
1266 index d02c76db80aa2..9e7e0a916d66d 100644
1267 --- a/ui/ozone/platform/wayland/host/zwp_primary_selection_device.cc
1268 +++ b/ui/ozone/platform/wayland/host/zwp_primary_selection_device.cc
1269 @@ -31,7 +31,7 @@ void ZwpPrimarySelectionDevice::SetSelectionSource(
1270    auto* data_source = source ? source->data_source() : nullptr;
1271    zwp_primary_selection_device_v1_set_selection(data_device_.get(), data_source,
1272                                                  serial);
1273 -  connection()->Flush();
1274 +  connection()->ScheduleFlush();
1275  }
1276  
1277  // static
1278 diff --git a/ui/ozone/platform/wayland/host/zwp_primary_selection_device_manager.cc b/ui/ozone/platform/wayland/host/zwp_primary_selection_device_manager.cc
1279 index 9d5d79635b66d..2ca82ce6031ba 100644
1280 --- a/ui/ozone/platform/wayland/host/zwp_primary_selection_device_manager.cc
1281 +++ b/ui/ozone/platform/wayland/host/zwp_primary_selection_device_manager.cc
1282 @@ -66,7 +66,7 @@ ZwpPrimarySelectionDevice* ZwpPrimarySelectionDeviceManager::GetDevice() {
1283          connection_,
1284          zwp_primary_selection_device_manager_v1_get_device(
1285              device_manager_.get(), connection_->seat()->wl_object()));
1286 -    connection_->Flush();
1287 +    connection_->ScheduleFlush();
1288    }
1289    DCHECK(device_);
1290    return device_.get();
1291 @@ -77,7 +77,7 @@ ZwpPrimarySelectionDeviceManager::CreateSource(
1292      ZwpPrimarySelectionSource::Delegate* delegate) {
1293    auto* data_source = zwp_primary_selection_device_manager_v1_create_source(
1294        device_manager_.get());
1295 -  connection_->Flush();
1296 +  connection_->ScheduleFlush();
1297    return std::make_unique<ZwpPrimarySelectionSource>(data_source, connection_,
1298                                                       delegate);
1299  }
1300 diff --git a/ui/ozone/platform/wayland/host/zxdg_surface_v6_wrapper_impl.cc b/ui/ozone/platform/wayland/host/zxdg_surface_v6_wrapper_impl.cc
1301 index e900f9d37e8ad..5c4c538800f65 100644
1302 --- a/ui/ozone/platform/wayland/host/zxdg_surface_v6_wrapper_impl.cc
1303 +++ b/ui/ozone/platform/wayland/host/zxdg_surface_v6_wrapper_impl.cc
1304 @@ -43,7 +43,7 @@ bool ZXDGSurfaceV6WrapperImpl::Initialize() {
1305  
1306    zxdg_surface_v6_add_listener(zxdg_surface_v6_.get(),
1307                                 &zxdg_surface_v6_listener, this);
1308 -  connection_->Flush();
1309 +  connection_->ScheduleFlush();
1310    return true;
1311  }
1312  
1313 diff --git a/ui/platform_window/agl/platform_window_agl.h b/ui/platform_window/agl/platform_window_agl.h
1314 new file mode 100644
1315 index 0000000000000..4bc915d663e72
1316 --- /dev/null
1317 +++ b/ui/platform_window/agl/platform_window_agl.h
1318 @@ -0,0 +1,36 @@
1319 +// Copyright 2021 LG Electronics, Inc.
1320 +//
1321 +// Licensed under the Apache License, Version 2.0 (the "License");
1322 +// you may not use this file except in compliance with the License.
1323 +// You may obtain a copy of the License at
1324 +//
1325 +// http://www.apache.org/licenses/LICENSE-2.0
1326 +//
1327 +// Unless required by applicable law or agreed to in writing, software
1328 +// distributed under the License is distributed on an "AS IS" BASIS,
1329 +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1330 +// See the License for the specific language governing permissions and
1331 +// limitations under the License.
1332 +//
1333 +// SPDX-License-Identifier: Apache-2.0
1334 +
1335 +#ifndef UI_PLATFORM_WINDOW_AGL_PLATFORM_WINDOW_AGL_H_
1336 +#define UI_PLATFORM_WINDOW_AGL_PLATFORM_WINDOW_AGL_H_
1337 +
1338 +#include <string>
1339 +
1340 +namespace ui {
1341 +
1342 +// AGL additions for platform window.
1343 +class PlatformWindowAgl {
1344 + public:
1345 +  virtual void SetAglActivateApp(const std::string& app) {}
1346 +  virtual void SetAglAppId(const std::string& title) {}
1347 +  virtual void SetAglReady() {}
1348 +  virtual void SetAglBackground() {}
1349 +  virtual void SetAglPanel(uint32_t edge) {}
1350 +};
1351 +
1352 +}  // namespace ui
1353 +
1354 +#endif  // UI_PLATFORM_WINDOW_AGL_PLATFORM_WINDOW_AGL_H_
1355 diff --git a/ui/platform_window/platform_window.h b/ui/platform_window/platform_window.h
1356 index a7bd3ef17a728..80f67671b88cf 100644
1357 --- a/ui/platform_window/platform_window.h
1358 +++ b/ui/platform_window/platform_window.h
1359 @@ -9,6 +9,7 @@
1360  #include <string>
1361  #include <vector>
1362  
1363 +#include "agl/platform_window_agl.h"
1364  #include "base/component_export.h"
1365  #include "ui/base/class_property.h"
1366  #include "ui/base/ui_base_types.h"
1367 @@ -32,7 +33,8 @@ class PlatformCursor;
1368  
1369  // Generic PlatformWindow interface.
1370  class COMPONENT_EXPORT(PLATFORM_WINDOW) PlatformWindow
1371 -    : public PropertyHandler {
1372 +    : public PropertyHandler,
1373 +      public PlatformWindowAgl {
1374   public:
1375    PlatformWindow();
1376    ~PlatformWindow() override;
1377 -- 
1378 2.39.2
1379