Commit 36f2c80a by Michael Spang Committed by Commit Bot

Fuchsia: Fix size & position of test window on Scenic

Scenic places our window in with its center in the corner if we don't apply any translation. Therefore we only see 1/4 of the surface. Translate the surface so the full size is visible. Also account for display scaling as we're sizing in pixels and scenic is sizing in density independent pixels. Bug: angleproject:4382 Test: angle_end2end_tests Change-Id: I1ae0b877c0ed7cf9d810bb2c8317b9842bd322a1 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1716226 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 3a2522de
...@@ -72,6 +72,7 @@ ScenicWindow::ScenicWindow() ...@@ -72,6 +72,7 @@ ScenicWindow::ScenicWindow()
mMaterial(&mScenicSession) mMaterial(&mScenicSession)
{ {
mScenicSession.set_error_handler(fit::bind_member(this, &ScenicWindow::onScenicError)); 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( mScenicSession.set_on_frame_presented_handler(
fit::bind_member(this, &ScenicWindow::onFramePresented)); fit::bind_member(this, &ScenicWindow::onFramePresented));
} }
...@@ -84,7 +85,7 @@ ScenicWindow::~ScenicWindow() ...@@ -84,7 +85,7 @@ ScenicWindow::~ScenicWindow()
bool ScenicWindow::initialize(const std::string &name, int width, int height) bool ScenicWindow::initialize(const std::string &name, int width, int height)
{ {
// Set up scenic resources. // Set up scenic resources.
mShape.SetShape(scenic::Rectangle(&mScenicSession, width, height)); mShape.SetEventMask(fuchsia::ui::gfx::kMetricsEventMask);
mShape.SetMaterial(mMaterial); mShape.SetMaterial(mMaterial);
fuchsia::ui::views::ViewToken viewToken; fuchsia::ui::views::ViewToken viewToken;
...@@ -103,6 +104,13 @@ bool ScenicWindow::initialize(const std::string &name, int width, int height) ...@@ -103,6 +104,13 @@ bool ScenicWindow::initialize(const std::string &name, int width, int height)
resetNativeWindow(); resetNativeWindow();
// Block until initial view dimensions are known.
while (!mHasViewMetrics && !mHasViewProperties && !mLostSession)
{
mLoop->ResetQuit();
mLoop->Run(zx::time::infinite(), true /* once */);
}
return true; return true;
} }
...@@ -168,6 +176,10 @@ bool ScenicWindow::resize(int width, int height) ...@@ -168,6 +176,10 @@ bool ScenicWindow::resize(int width, int height)
fuchsia_egl_window_resize(mFuchsiaEGLWindow.get(), width, height); fuchsia_egl_window_resize(mFuchsiaEGLWindow.get(), width, height);
mViewSizeDirty = true;
updateViewSize();
return true; return true;
} }
...@@ -203,7 +215,29 @@ void ScenicWindow::onFramePresented(fuchsia::scenic::scheduling::FramePresentedI ...@@ -203,7 +215,29 @@ void ScenicWindow::onFramePresented(fuchsia::scenic::scheduling::FramePresentedI
void ScenicWindow::onScenicEvents(std::vector<fuchsia::ui::scenic::Event> events) void ScenicWindow::onScenicEvents(std::vector<fuchsia::ui::scenic::Event> events)
{ {
UNIMPLEMENTED(); 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) void ScenicWindow::onScenicError(zx_status_t status)
...@@ -213,6 +247,52 @@ void ScenicWindow::onScenicError(zx_status_t status) ...@@ -213,6 +247,52 @@ void ScenicWindow::onScenicError(zx_status_t status)
mLoop->Quit(); 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 // static
OSWindow *OSWindow::New() OSWindow *OSWindow::New()
{ {
......
...@@ -63,8 +63,12 @@ class ANGLE_UTIL_EXPORT ScenicWindow : public OSWindow ...@@ -63,8 +63,12 @@ class ANGLE_UTIL_EXPORT ScenicWindow : public OSWindow
void onScenicEvents(std::vector<fuchsia::ui::scenic::Event> events); void onScenicEvents(std::vector<fuchsia::ui::scenic::Event> events);
void onScenicError(zx_status_t status); void onScenicError(zx_status_t status);
void onFramePresented(fuchsia::scenic::scheduling::FramePresentedInfo info); void onFramePresented(fuchsia::scenic::scheduling::FramePresentedInfo info);
void onViewMetrics(const fuchsia::ui::gfx::Metrics &metrics);
void onViewProperties(const fuchsia::ui::gfx::ViewProperties &properties);
private: private:
void updateViewSize();
// ScenicWindow async loop. // ScenicWindow async loop.
async::Loop *const mLoop; async::Loop *const mLoop;
...@@ -88,6 +92,15 @@ class ANGLE_UTIL_EXPORT ScenicWindow : public OSWindow ...@@ -88,6 +92,15 @@ class ANGLE_UTIL_EXPORT ScenicWindow : public OSWindow
// Scenic view. // Scenic view.
std::unique_ptr<scenic::View> mView; std::unique_ptr<scenic::View> mView;
// View geometry.
float mDisplayHeightDips = 0.f;
float mDisplayWidthDips = 0.f;
float mDisplayScaleX = 0.f;
float mDisplayScaleY = 0.f;
bool mHasViewProperties = false;
bool mHasViewMetrics = false;
bool mViewSizeDirty = false;
// EGL native window. // EGL native window.
std::unique_ptr<fuchsia_egl_window, FuchsiaEGLWindowDeleter> mFuchsiaEGLWindow; std::unique_ptr<fuchsia_egl_window, FuchsiaEGLWindowDeleter> mFuchsiaEGLWindow;
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment