Commit be6b0633 authored by Wez's avatar Wez Committed by Commit Bot

[Fuchsia] Migrate Ozone Scenic platform off gfx::ExportTokens.

Content is typically rendered into a surface by the GPU process, and
displayed into a window owned by the Browser process.

In the Scenic Ozone platform this was implemented using import/export
Nodes connecting the GPU & Browser.  Content rendered to a ScenicSurface
by the GPU process is now exported for display by a ScenicWindow via a
nested View.

Bug: WEB-50
Test: Manually verified that web content still renders. :D
Change-Id: I3ba58c8fe509a2595ce0dd10e496701b0ebc2b71
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1649181
Commit-Queue: Wez <wez@chromium.org>
Commit-Queue: Will Harris <wfh@chromium.org>
Reviewed-by: default avatarWill Harris <wfh@chromium.org>
Auto-Submit: Wez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#667338}
parent 6ab3849a
......@@ -55,17 +55,18 @@ mojom::ScenicGpuHostPtr ScenicGpuHost::CreateHostProcessSelfBinding() {
return gpu_host;
}
void ScenicGpuHost::ExportParent(int32_t surface_handle,
mojo::ScopedHandle export_token_mojo) {
void ScenicGpuHost::AttachSurfaceToWindow(
int32_t window_id,
mojo::ScopedHandle surface_view_holder_token_mojo) {
DCHECK_CALLED_ON_VALID_THREAD(ui_thread_checker_);
ScenicWindow* scenic_window =
scenic_window_manager_->GetWindow(surface_handle);
ScenicWindow* scenic_window = scenic_window_manager_->GetWindow(window_id);
if (!scenic_window)
return;
fuchsia::ui::gfx::ExportToken export_token;
export_token.value = zx::eventpair(
mojo::UnwrapPlatformHandle(std::move(export_token_mojo)).TakeHandle());
scenic_window->ExportRenderingEntity(std::move(export_token));
fuchsia::ui::views::ViewHolderToken surface_view_holder_token;
surface_view_holder_token.value = zx::eventpair(
mojo::UnwrapPlatformHandle(std::move(surface_view_holder_token_mojo))
.TakeHandle());
scenic_window->AttachSurfaceView(std::move(surface_view_holder_token));
}
void ScenicGpuHost::OnGpuProcessLaunched(
......
......@@ -37,8 +37,9 @@ class ScenicGpuHost : public mojom::ScenicGpuHost,
mojom::ScenicGpuHostPtr CreateHostProcessSelfBinding();
// mojom::ScenicGpuHost:
void ExportParent(int32_t surface_handle,
mojo::ScopedHandle export_token_mojo) override;
void AttachSurfaceToWindow(
int32_t window_id,
mojo::ScopedHandle surface_view_holder_token_mojo) override;
// GpuPlatformSupportHost:
void OnGpuProcessLaunched(
......
......@@ -5,6 +5,7 @@
#include "ui/ozone/platform/scenic/scenic_surface.h"
#include <lib/ui/scenic/cpp/commands.h>
#include <lib/ui/scenic/cpp/view_token_pair.h>
#include <lib/zx/eventpair.h>
#include "mojo/public/cpp/system/platform_handle.h"
......@@ -18,7 +19,6 @@ ScenicSurface::ScenicSurface(
gfx::AcceleratedWidget window,
scenic::SessionPtrAndListenerRequest sesion_and_listener_request)
: scenic_session_(std::move(sesion_and_listener_request)),
parent_(&scenic_session_),
shape_(&scenic_session_),
material_(&scenic_session_),
scenic_surface_factory_(scenic_surface_factory),
......@@ -50,17 +50,21 @@ void ScenicSurface::SetTextureToImage(const scenic::Image& image) {
material_.SetTexture(image);
}
mojo::ScopedHandle ScenicSurface::CreateParentExportToken() {
// Scenic does not care about order here; it's totally fine for imports to
// cause exports, and that's what's done here.
mojo::ScopedHandle ScenicSurface::CreateView() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
zx::eventpair export_token;
parent_.BindAsRequest(&export_token);
parent_.AddChild(shape_);
// Scenic will associate the View and ViewHolder regardless of which it
// learns about first, so we don't need to synchronize View creation with
// attachment into the scene graph by the caller.
auto tokens = scenic::ViewTokenPair::New();
parent_ = std::make_unique<scenic::View>(
&scenic_session_, std::move(tokens.view_token), "chromium surface");
parent_->AddChild(shape_);
scenic_session_.Present(
/*presentation_time=*/0, [](fuchsia::images::PresentationInfo info) {});
return mojo::WrapPlatformHandle(
mojo::PlatformHandle(std::move(export_token)));
mojo::PlatformHandle(std::move(tokens.view_holder_token.value)));
}
} // namespace ui
......@@ -41,8 +41,9 @@ class ScenicSurface : public ui::PlatformWindowSurface {
// Sets the texture of the surface to an image resource.
void SetTextureToImage(const scenic::Image& image);
// Creates token to links the surface to the window in the browser process.
mojo::ScopedHandle CreateParentExportToken();
// Creates a View for this surface, and returns a ViewHolderToken handle
// that can be used to attach it into a scene graph.
mojo::ScopedHandle CreateView();
void AssertBelongsToCurrentThread() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
......@@ -55,7 +56,7 @@ class ScenicSurface : public ui::PlatformWindowSurface {
private:
scenic::Session scenic_session_;
scenic::ImportNode parent_;
std::unique_ptr<scenic::View> parent_;
scenic::ShapeNode shape_;
scenic::Material material_;
......
......@@ -100,14 +100,14 @@ GLOzone* ScenicSurfaceFactory::GetGLOzone(gl::GLImplementation implementation) {
std::unique_ptr<PlatformWindowSurface>
ScenicSurfaceFactory::CreatePlatformWindowSurface(
gfx::AcceleratedWidget widget) {
gfx::AcceleratedWidget window) {
DCHECK(gpu_host_);
auto surface =
std::make_unique<ScenicSurface>(this, widget, CreateScenicSession());
std::make_unique<ScenicSurface>(this, window, CreateScenicSession());
main_thread_task_runner_->PostTask(
FROM_HERE, base::BindOnce(&ScenicSurfaceFactory::LinkSurfaceToParent,
weak_ptr_factory_.GetWeakPtr(), widget,
surface->CreateParentExportToken()));
FROM_HERE, base::BindOnce(&ScenicSurfaceFactory::AttachSurfaceToWindow,
weak_ptr_factory_.GetWeakPtr(), window,
surface->CreateView()));
return surface;
}
......@@ -205,11 +205,12 @@ void ScenicSurfaceFactory::CreateScenicSessionOnMainThread(
scenic_->CreateSession(std::move(session_request), std::move(listener));
}
void ScenicSurfaceFactory::LinkSurfaceToParent(
gfx::AcceleratedWidget widget,
mojo::ScopedHandle export_token_mojo) {
void ScenicSurfaceFactory::AttachSurfaceToWindow(
gfx::AcceleratedWidget window,
mojo::ScopedHandle surface_view_holder_token_mojo) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
gpu_host_->ExportParent(widget, std::move(export_token_mojo));
gpu_host_->AttachSurfaceToWindow(window,
std::move(surface_view_holder_token_mojo));
}
} // namespace ui
......@@ -76,9 +76,9 @@ class ScenicSurfaceFactory : public SurfaceFactoryOzone {
fidl::InterfaceRequest<fuchsia::ui::scenic::Session> session_request,
fidl::InterfaceHandle<fuchsia::ui::scenic::SessionListener> listener);
// Links a surface to its parent in the host process.
void LinkSurfaceToParent(gfx::AcceleratedWidget widget,
mojo::ScopedHandle export_token_mojo);
// Links a surface to its parent window in the host process.
void AttachSurfaceToWindow(gfx::AcceleratedWidget window,
mojo::ScopedHandle surface_view_holder_token_mojo);
base::flat_map<gfx::AcceleratedWidget, ScenicSurface*> surface_map_
GUARDED_BY(surface_lock_);
......
......@@ -58,14 +58,14 @@ ScenicWindow::~ScenicWindow() {
manager_->RemoveWindow(window_id_, this);
}
void ScenicWindow::ExportRenderingEntity(
fuchsia::ui::gfx::ExportToken export_token) {
scenic::EntityNode export_node(&scenic_session_);
void ScenicWindow::AttachSurfaceView(
fuchsia::ui::views::ViewHolderToken token) {
scenic::ViewHolder surface_view_holder(&scenic_session_, std::move(token),
"chromium window surface");
render_node_.DetachChildren();
render_node_.AddChild(export_node);
render_node_.Attach(surface_view_holder);
export_node.Export(std::move(export_token.value));
scenic_session_.Present(
/*presentation_time=*/0, [](fuchsia::images::PresentationInfo info) {});
}
......
......@@ -39,7 +39,9 @@ class OZONE_EXPORT ScenicWindow : public PlatformWindow,
scenic::Session* scenic_session() { return &scenic_session_; }
void ExportRenderingEntity(fuchsia::ui::gfx::ExportToken export_token);
// Embeds the View identified by |token| into the render node,
// causing its contents to be displayed in this window.
void AttachSurfaceView(fuchsia::ui::views::ViewHolderToken token);
// PlatformWindow implementation.
gfx::Rect GetBounds() override;
......
......@@ -6,6 +6,7 @@ module ui.mojom;
// Browser process interface that enables the GPU process to present to Scenic.
interface ScenicGpuHost {
// Exports the surface's parent node in the scene graph using |export_token|.
ExportParent(int32 surface_handle, handle export_token);
// Attaches the surface View identified by |view_holder_token| to the scene
// graph for |window_id|.
AttachSurfaceToWindow(int32 window_id, handle view_holder_token);
};
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