Hash :
4154c1c1
Author :
Date :
2019-02-12T15:43:03
Fuchsia: Migrate ScenicWindow to ViewV2 Fuchsia is transitioning its view creation APIs. Migrate to the new one. BUG=angleproject:2475 TEST=angle_end2end_tests on Fuchsia Change-Id: I09abfda18a5e3da46909b5b967325a083586a7d0 Reviewed-on: https://chromium-review.googlesource.com/c/1474337 Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Michael Spang <spang@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
//
// Copyright 2019 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// ScenicWindow.cpp:
// Implements methods from ScenicWindow
//
#include "util/fuchsia/ScenicWindow.h"
#include <lib/async-loop/cpp/loop.h>
#include <lib/fdio/util.h>
#include <lib/fidl/cpp/interface_ptr.h>
#include <lib/fidl/cpp/interface_request.h>
#include <lib/zx/channel.h>
#include <zircon/status.h>
#include "common/debug.h"
namespace
{
async::Loop *GetDefaultLoop()
{
static async::Loop *defaultLoop = new async::Loop(&kAsyncLoopConfigAttachToThread);
return defaultLoop;
}
zx::channel ConnectToServiceRoot()
{
zx::channel clientChannel;
zx::channel serverChannel;
zx_status_t result = zx::channel::create(0, &clientChannel, &serverChannel);
ASSERT(result == ZX_OK);
result = fdio_service_connect("/svc/.", serverChannel.release());
ASSERT(result == ZX_OK);
return clientChannel;
}
template <typename Interface>
zx_status_t ConnectToService(zx_handle_t serviceRoot, fidl::InterfaceRequest<Interface> request)
{
ASSERT(request.is_valid());
return fdio_service_connect_at(serviceRoot, Interface::Name_, request.TakeChannel().release());
}
template <typename Interface>
fidl::InterfacePtr<Interface> ConnectToService(zx_handle_t serviceRoot)
{
fidl::InterfacePtr<Interface> result;
ConnectToService(serviceRoot, result.NewRequest());
return result;
}
} // namespace
ScenicWindow::ScenicWindow()
: mLoop(GetDefaultLoop()),
mServiceRoot(ConnectToServiceRoot()),
mScenic(ConnectToService<fuchsia::ui::scenic::Scenic>(mServiceRoot.get())),
mPresenter(ConnectToService<fuchsia::ui::policy::Presenter>(mServiceRoot.get())),
mScenicSession(mScenic.get()),
mShape(&mScenicSession),
mMaterial(&mScenicSession)
{}
ScenicWindow::~ScenicWindow()
{
destroy();
}
bool ScenicWindow::initialize(const std::string &name, size_t width, size_t height)
{
// Set up scenic resources.
mShape.SetShape(scenic::Rectangle(&mScenicSession, width, height));
mShape.SetMaterial(mMaterial);
// Create view.
zx::eventpair viewHolderToken;
zx::eventpair viewToken;
zx_status_t status = zx::eventpair::create(0 /* options */, &viewToken, &viewHolderToken);
ASSERT(status == ZX_OK);
mView = std::make_unique<scenic::View>(&mScenicSession, std::move(viewToken), name);
mView->AddChild(mShape);
mScenicSession.Present(0, [](fuchsia::images::PresentationInfo info) {});
// Present view.
mPresenter->Present2(std::move(viewHolderToken), nullptr);
mWidth = width;
mHeight = height;
resetNativeWindow();
return true;
}
void ScenicWindow::destroy()
{
mFuchsiaEGLWindow.reset();
}
void ScenicWindow::resetNativeWindow()
{
fuchsia::images::ImagePipePtr imagePipe;
uint32_t imagePipeId = mScenicSession.AllocResourceId();
mScenicSession.Enqueue(scenic::NewCreateImagePipeCmd(imagePipeId, imagePipe.NewRequest()));
mMaterial.SetTexture(imagePipeId);
mScenicSession.ReleaseResource(imagePipeId);
mScenicSession.Present(0, [](fuchsia::images::PresentationInfo info) {});
mFuchsiaEGLWindow.reset(
fuchsia_egl_window_create(imagePipe.Unbind().TakeChannel().release(), mWidth, mHeight));
}
EGLNativeWindowType ScenicWindow::getNativeWindow() const
{
return reinterpret_cast<EGLNativeWindowType>(mFuchsiaEGLWindow.get());
}
EGLNativeDisplayType ScenicWindow::getNativeDisplay() const
{
return EGL_DEFAULT_DISPLAY;
}
void ScenicWindow::messageLoop()
{
mLoop->Run(zx::deadline_after({}), true /* once */);
}
void ScenicWindow::setMousePosition(int x, int y)
{
UNIMPLEMENTED();
}
bool ScenicWindow::setPosition(int x, int y)
{
UNIMPLEMENTED();
return false;
}
bool ScenicWindow::resize(int width, int height)
{
mWidth = width;
mHeight = height;
fuchsia_egl_window_resize(mFuchsiaEGLWindow.get(), width, height);
return true;
}
void ScenicWindow::setVisible(bool isVisible) {}
void ScenicWindow::signalTestEvent() {}
void ScenicWindow::OnScenicEvents(std::vector<fuchsia::ui::scenic::Event> events)
{
UNIMPLEMENTED();
}
void ScenicWindow::OnScenicError(zx_status_t status)
{
WARN() << "OnScenicError: " << zx_status_get_string(status);
}
// static
OSWindow *OSWindow::New()
{
return new ScenicWindow;
}