• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
20 #include <fuchsia/ui/policy/cpp/fidl.h>
21 #include <fuchsia/ui/scenic/cpp/fidl.h>
22 #include <fuchsia_egl.h>
23 #include <lib/async-loop/cpp/loop.h>
24 #include <lib/ui/scenic/cpp/commands.h>
25 #include <lib/ui/scenic/cpp/resources.h>
26 #include <lib/ui/scenic/cpp/session.h>
27 #include <zircon/types.h>
28 #include <string>
29 
30 ANGLE_REENABLE_DESTRUCTOR_OVERRIDE_WARNING
31 
32 struct FuchsiaEGLWindowDeleter
33 {
operatorFuchsiaEGLWindowDeleter34     void operator()(fuchsia_egl_window *eglWindow) { fuchsia_egl_window_destroy(eglWindow); }
35 };
36 
37 class ANGLE_UTIL_EXPORT ScenicWindow : public OSWindow
38 {
39   public:
40     ScenicWindow();
41     ~ScenicWindow() override;
42 
43     // OSWindow:
44     bool initialize(const std::string &name, int width, int height) override;
45     void destroy() override;
46     void resetNativeWindow() override;
47     EGLNativeWindowType getNativeWindow() const override;
48     EGLNativeDisplayType getNativeDisplay() const override;
49     void messageLoop() override;
50     void setMousePosition(int x, int y) override;
51     bool setPosition(int x, int y) override;
52     bool resize(int width, int height) override;
53     void setVisible(bool isVisible) override;
54     void signalTestEvent() override;
55 
56     // Presents the window to Scenic.
57     //
58     // We need to do this once per EGL window surface after adding the
59     // surface's image pipe as a child of our window.
60     void present();
61 
62     // FIDL callbacks:
63     void onScenicEvents(std::vector<fuchsia::ui::scenic::Event> events);
64     void onScenicError(zx_status_t status);
65     void onFramePresented(fuchsia::scenic::scheduling::FramePresentedInfo info);
66     void onViewMetrics(const fuchsia::ui::gfx::Metrics &metrics);
67     void onViewProperties(const fuchsia::ui::gfx::ViewProperties &properties);
68 
69   private:
70     void updateViewSize();
71 
72     // ScenicWindow async loop.
73     async::Loop *const mLoop;
74 
75     // System services.
76     zx::channel mServiceRoot;
77     fuchsia::ui::scenic::ScenicPtr mScenic;
78     fuchsia::ui::policy::PresenterPtr mPresenter;
79 
80     // Scenic session & resources.
81     scenic::Session mScenicSession;
82     scenic::ShapeNode mShape;
83     scenic::Material mMaterial;
84 
85     // Whether our scenic session has disconnected.
86     bool mLostSession = false;
87 
88     // Present limiting.
89     static constexpr int kMaxInFlightPresents = 2;
90     int mInFlightPresents                     = 0;
91 
92     // Scenic view.
93     std::unique_ptr<scenic::View> mView;
94 
95     // View geometry.
96     float mDisplayHeightDips = 0.f;
97     float mDisplayWidthDips  = 0.f;
98     float mDisplayScaleX     = 0.f;
99     float mDisplayScaleY     = 0.f;
100     bool mHasViewProperties  = false;
101     bool mHasViewMetrics     = false;
102     bool mViewSizeDirty      = false;
103 
104     // EGL native window.
105     std::unique_ptr<fuchsia_egl_window, FuchsiaEGLWindowDeleter> mFuchsiaEGLWindow;
106 };
107 
108 #endif  // UTIL_FUCHSIA_SCENIC_WINDOW_H
109