xref: /aosp_15_r20/external/angle/util/fuchsia/ScenicWindow.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2019 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // ScenicWindow.h:
7 //    Subclasses OSWindow for Fuchsia's Scenic compositor.
8 //
9 
10 #ifndef UTIL_FUCHSIA_SCENIC_WINDOW_H
11 #define UTIL_FUCHSIA_SCENIC_WINDOW_H
12 
13 #include "common/debug.h"
14 #include "util/OSWindow.h"
15 #include "util/util_export.h"
16 
17 // Disable ANGLE-specific warnings that pop up in fuchsia headers.
18 ANGLE_DISABLE_DESTRUCTOR_OVERRIDE_WARNING
19 ANGLE_DISABLE_SUGGEST_OVERRIDE_WARNINGS
20 
21 #include <fuchsia/element/cpp/fidl.h>
22 #include <fuchsia_egl.h>
23 #include <lib/async-loop/cpp/loop.h>
24 #include <zircon/types.h>
25 #include <string>
26 
27 ANGLE_REENABLE_SUGGEST_OVERRIDE_WARNINGS
28 ANGLE_REENABLE_DESTRUCTOR_OVERRIDE_WARNING
29 
30 struct FuchsiaEGLWindowDeleter
31 {
operatorFuchsiaEGLWindowDeleter32     void operator()(fuchsia_egl_window *eglWindow) { fuchsia_egl_window_destroy(eglWindow); }
33 };
34 
35 class ANGLE_UTIL_EXPORT ScenicWindow : public OSWindow
36 {
37   public:
38     ScenicWindow();
39     ~ScenicWindow() override;
40 
41     // OSWindow:
42     void disableErrorMessageDialog() override;
43     void destroy() override;
44     void resetNativeWindow() override;
45     EGLNativeWindowType getNativeWindow() const override;
46     EGLNativeDisplayType getNativeDisplay() const override;
47     void messageLoop() override;
48     void setMousePosition(int x, int y) override;
49     bool setOrientation(int width, int height) override;
50     bool setPosition(int x, int y) override;
51     bool resize(int width, int height) override;
52     void setVisible(bool isVisible) override;
53     void signalTestEvent() override;
54 
55     // Presents the window to Scenic.
56     //
57     // We need to do this once per EGL window surface after adding the
58     // surface's image pipe as a child of our window.
59     void present();
60 
61   private:
62     bool initializeImpl(const std::string &name, int width, int height) override;
63     void updateViewSize();
64 
65     // ScenicWindow async loop.
66     async::Loop *const mLoop;
67 
68     // System services.
69     zx::channel mServiceRoot;
70     fuchsia::element::GraphicalPresenterPtr mPresenter;
71 
72     // EGL native window.
73     std::unique_ptr<fuchsia_egl_window, FuchsiaEGLWindowDeleter> mFuchsiaEGLWindow;
74 };
75 
76 #endif  // UTIL_FUCHSIA_SCENIC_WINDOW_H
77