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.cpp:
7 // Implements methods from ScenicWindow
8 //
9
10 #include "util/fuchsia/ScenicWindow.h"
11
12 #include <fuchsia/element/cpp/fidl.h>
13 #include <lib/async-loop/cpp/loop.h>
14 #include <lib/async-loop/default.h>
15 #include <lib/fdio/directory.h>
16 #include <lib/fidl/cpp/interface_ptr.h>
17 #include <lib/fidl/cpp/interface_request.h>
18 #include <lib/zx/channel.h>
19 #include <zircon/status.h>
20
21 namespace
22 {
23
GetDefaultLoop()24 async::Loop *GetDefaultLoop()
25 {
26 static async::Loop *defaultLoop = new async::Loop(&kAsyncLoopConfigNeverAttachToThread);
27 return defaultLoop;
28 }
29
ConnectToServiceRoot()30 zx::channel ConnectToServiceRoot()
31 {
32 zx::channel clientChannel;
33 zx::channel serverChannel;
34 zx_status_t result = zx::channel::create(0, &clientChannel, &serverChannel);
35 ASSERT(result == ZX_OK);
36 result = fdio_service_connect("/svc/.", serverChannel.release());
37 ASSERT(result == ZX_OK);
38 return clientChannel;
39 }
40
41 template <typename Interface>
ConnectToService(zx_handle_t serviceRoot,fidl::InterfaceRequest<Interface> request)42 zx_status_t ConnectToService(zx_handle_t serviceRoot, fidl::InterfaceRequest<Interface> request)
43 {
44 ASSERT(request.is_valid());
45 return fdio_service_connect_at(serviceRoot, Interface::Name_, request.TakeChannel().release());
46 }
47
48 template <typename Interface>
ConnectToService(zx_handle_t serviceRoot,async_dispatcher_t * dispatcher)49 fidl::InterfacePtr<Interface> ConnectToService(zx_handle_t serviceRoot,
50 async_dispatcher_t *dispatcher)
51 {
52 fidl::InterfacePtr<Interface> result;
53 ConnectToService(serviceRoot, result.NewRequest(dispatcher));
54 return result;
55 }
56
57 } // namespace
58
59 // TODO: http://anglebug.com/42050005 - Implement using fuchsia.element.GraphicalPresenter to pass a
60 // ViewCreationToken to Fuchsia Flatland.
ScenicWindow()61 ScenicWindow::ScenicWindow()
62 : mLoop(GetDefaultLoop()),
63 mServiceRoot(ConnectToServiceRoot()),
64 mPresenter(ConnectToService<fuchsia::element::GraphicalPresenter>(mServiceRoot.get(),
65 mLoop->dispatcher()))
66 {}
67
~ScenicWindow()68 ScenicWindow::~ScenicWindow()
69 {
70 destroy();
71 }
72
initializeImpl(const std::string & name,int width,int height)73 bool ScenicWindow::initializeImpl(const std::string &name, int width, int height)
74 {
75 return true;
76 }
77
disableErrorMessageDialog()78 void ScenicWindow::disableErrorMessageDialog() {}
79
destroy()80 void ScenicWindow::destroy()
81 {
82 mFuchsiaEGLWindow.reset();
83 }
84
resetNativeWindow()85 void ScenicWindow::resetNativeWindow()
86 {
87 UNIMPLEMENTED();
88 }
89
getNativeWindow() const90 EGLNativeWindowType ScenicWindow::getNativeWindow() const
91 {
92 return reinterpret_cast<EGLNativeWindowType>(mFuchsiaEGLWindow.get());
93 }
94
getNativeDisplay() const95 EGLNativeDisplayType ScenicWindow::getNativeDisplay() const
96 {
97 return EGL_DEFAULT_DISPLAY;
98 }
99
messageLoop()100 void ScenicWindow::messageLoop()
101 {
102 mLoop->ResetQuit();
103 mLoop->RunUntilIdle();
104 }
105
setMousePosition(int x,int y)106 void ScenicWindow::setMousePosition(int x, int y)
107 {
108 UNIMPLEMENTED();
109 }
110
setOrientation(int width,int height)111 bool ScenicWindow::setOrientation(int width, int height)
112 {
113 UNIMPLEMENTED();
114 return false;
115 }
116
setPosition(int x,int y)117 bool ScenicWindow::setPosition(int x, int y)
118 {
119 UNIMPLEMENTED();
120 return false;
121 }
122
resize(int width,int height)123 bool ScenicWindow::resize(int width, int height)
124 {
125 fuchsia_egl_window_resize(mFuchsiaEGLWindow.get(), width, height);
126 return true;
127 }
128
setVisible(bool isVisible)129 void ScenicWindow::setVisible(bool isVisible) {}
130
signalTestEvent()131 void ScenicWindow::signalTestEvent() {}
132
present()133 void ScenicWindow::present()
134 {
135 UNIMPLEMENTED();
136 }
137
updateViewSize()138 void ScenicWindow::updateViewSize()
139 {
140 UNIMPLEMENTED();
141 }
142
143 // static
New()144 OSWindow *OSWindow::New()
145 {
146 return new ScenicWindow;
147 }
148