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