Hash :
fdb7874d
Author :
Date :
2020-08-26T22:04:19
Gracefully fail end2end tests if no window support EGL_WINDOW_BIT is now specifically requested for tests that open a window (those that aren't WithNoFixture). This makes sure pbuffer-only configs are not selected for the window. Additionally, a few WithNoFixture tests are made more robust in the presence of no-window configs. In the context of crbug.com/1034840, this means that a subset of end2end tests would be able to run in a remote desktop environment. Tested on Linux/X11 by turning a subset of configs PBUFFER-only. Bug: chromium:1034840 Change-Id: I09fd149d43d3b865856fe6b9491c5f333f4a2efc Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2378922 Reviewed-by: Jonah Ryan-Davis <jonahr@google.com> Reviewed-by: back sept 10 - Jamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@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 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
//
// 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 <fuchsia/images/cpp/fidl.h>
#include <fuchsia/ui/views/cpp/fidl.h>
#include <lib/async-loop/cpp/loop.h>
#include <lib/async-loop/default.h>
#include <lib/fdio/directory.h>
#include <lib/fidl/cpp/interface_ptr.h>
#include <lib/fidl/cpp/interface_request.h>
#include <lib/ui/scenic/cpp/view_token_pair.h>
#include <lib/zx/channel.h>
#include <zircon/status.h>
namespace
{
async::Loop *GetDefaultLoop()
{
static async::Loop *defaultLoop = new async::Loop(&kAsyncLoopConfigNeverAttachToThread);
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,
async_dispatcher_t *dispatcher)
{
fidl::InterfacePtr<Interface> result;
ConnectToService(serviceRoot, result.NewRequest(dispatcher));
return result;
}
} // namespace
ScenicWindow::ScenicWindow()
: mLoop(GetDefaultLoop()),
mServiceRoot(ConnectToServiceRoot()),
mScenic(
ConnectToService<fuchsia::ui::scenic::Scenic>(mServiceRoot.get(), mLoop->dispatcher())),
mPresenter(ConnectToService<fuchsia::ui::policy::Presenter>(mServiceRoot.get(),
mLoop->dispatcher())),
mScenicSession(mScenic.get(), mLoop->dispatcher()),
mShape(&mScenicSession),
mMaterial(&mScenicSession)
{
mScenicSession.set_error_handler(fit::bind_member(this, &ScenicWindow::onScenicError));
mScenicSession.set_event_handler(fit::bind_member(this, &ScenicWindow::onScenicEvents));
mScenicSession.set_on_frame_presented_handler(
fit::bind_member(this, &ScenicWindow::onFramePresented));
}
ScenicWindow::~ScenicWindow()
{
destroy();
}
bool ScenicWindow::initializeImpl(const std::string &name, int width, int height)
{
// Set up scenic resources.
mShape.SetEventMask(fuchsia::ui::gfx::kMetricsEventMask);
mShape.SetMaterial(mMaterial);
fuchsia::ui::views::ViewToken viewToken;
fuchsia::ui::views::ViewHolderToken viewHolderToken;
std::tie(viewToken, viewHolderToken) = scenic::NewViewTokenPair();
// Create view.
mView = std::make_unique<scenic::View>(&mScenicSession, std::move(viewToken), name);
mView->AddChild(mShape);
// Present view.
mPresenter->PresentOrReplaceView(std::move(viewHolderToken), nullptr);
mWidth = width;
mHeight = height;
resetNativeWindow();
// Block until initial view dimensions are known.
while (!mHasViewMetrics && !mHasViewProperties && !mLostSession)
{
mLoop->ResetQuit();
mLoop->Run(zx::time::infinite(), true /* once */);
}
return true;
}
void ScenicWindow::disableErrorMessageDialog() {}
void ScenicWindow::destroy()
{
while (mInFlightPresents != 0 && !mLostSession)
{
mLoop->ResetQuit();
mLoop->Run();
}
ASSERT(mInFlightPresents == 0 || mLostSession);
mFuchsiaEGLWindow.reset();
}
void ScenicWindow::resetNativeWindow()
{
fuchsia::images::ImagePipe2Ptr imagePipe;
uint32_t imagePipeId = mScenicSession.AllocResourceId();
mScenicSession.Enqueue(
scenic::NewCreateImagePipe2Cmd(imagePipeId, imagePipe.NewRequest(mLoop->dispatcher())));
zx_handle_t imagePipeHandle = imagePipe.Unbind().TakeChannel().release();
mMaterial.SetTexture(imagePipeId);
mScenicSession.ReleaseResource(imagePipeId);
present();
mFuchsiaEGLWindow.reset(fuchsia_egl_window_create(imagePipeHandle, mWidth, mHeight));
}
EGLNativeWindowType ScenicWindow::getNativeWindow() const
{
return reinterpret_cast<EGLNativeWindowType>(mFuchsiaEGLWindow.get());
}
EGLNativeDisplayType ScenicWindow::getNativeDisplay() const
{
return EGL_DEFAULT_DISPLAY;
}
void ScenicWindow::messageLoop()
{
mLoop->ResetQuit();
mLoop->RunUntilIdle();
}
void ScenicWindow::setMousePosition(int x, int y)
{
UNIMPLEMENTED();
}
bool ScenicWindow::setOrientation(int width, int height)
{
UNIMPLEMENTED();
return false;
}
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);
mViewSizeDirty = true;
updateViewSize();
return true;
}
void ScenicWindow::setVisible(bool isVisible) {}
void ScenicWindow::signalTestEvent() {}
void ScenicWindow::present()
{
while (mInFlightPresents >= kMaxInFlightPresents && !mLostSession)
{
mLoop->ResetQuit();
mLoop->Run();
}
if (mLostSession)
{
return;
}
ASSERT(mInFlightPresents < kMaxInFlightPresents);
++mInFlightPresents;
mScenicSession.Present2(0, 0, [](fuchsia::scenic::scheduling::FuturePresentationTimes info) {});
}
void ScenicWindow::onFramePresented(fuchsia::scenic::scheduling::FramePresentedInfo info)
{
mInFlightPresents -= info.presentation_infos.size();
ASSERT(mInFlightPresents >= 0);
mLoop->Quit();
}
void ScenicWindow::onScenicEvents(std::vector<fuchsia::ui::scenic::Event> events)
{
for (const auto &event : events)
{
if (event.is_gfx())
{
if (event.gfx().is_metrics())
{
if (event.gfx().metrics().node_id != mShape.id())
continue;
onViewMetrics(event.gfx().metrics().metrics);
}
else if (event.gfx().is_view_properties_changed())
{
if (event.gfx().view_properties_changed().view_id != mView->id())
continue;
onViewProperties(event.gfx().view_properties_changed().properties);
}
}
}
if (mViewSizeDirty)
{
updateViewSize();
}
}
void ScenicWindow::onScenicError(zx_status_t status)
{
WARN() << "OnScenicError: " << zx_status_get_string(status);
mLostSession = true;
mLoop->Quit();
}
void ScenicWindow::onViewMetrics(const fuchsia::ui::gfx::Metrics &metrics)
{
mDisplayScaleX = metrics.scale_x;
mDisplayScaleY = metrics.scale_y;
mHasViewMetrics = true;
mViewSizeDirty = true;
}
void ScenicWindow::onViewProperties(const fuchsia::ui::gfx::ViewProperties &properties)
{
float width = properties.bounding_box.max.x - properties.bounding_box.min.x -
properties.inset_from_min.x - properties.inset_from_max.x;
float height = properties.bounding_box.max.y - properties.bounding_box.min.y -
properties.inset_from_min.y - properties.inset_from_max.y;
mDisplayWidthDips = width;
mDisplayHeightDips = height;
mHasViewProperties = true;
mViewSizeDirty = true;
}
void ScenicWindow::updateViewSize()
{
if (!mViewSizeDirty || !mHasViewMetrics || !mHasViewProperties)
{
return;
}
mViewSizeDirty = false;
// Surface size in pixels is
// (mWidth, mHeight)
//
// View size in pixels is
// (mDisplayWidthDips * mDisplayScaleX) x (mDisplayHeightDips * mDisplayScaleY)
float widthDips = mWidth / mDisplayScaleX;
float heightDips = mHeight / mDisplayScaleY;
mShape.SetShape(scenic::Rectangle(&mScenicSession, widthDips, heightDips));
mShape.SetTranslation(0.5f * widthDips, 0.5f * heightDips, 0.f);
present();
}
// static
OSWindow *OSWindow::New()
{
return new ScenicWindow;
}