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