Skip to content

Commit

Permalink
Mandoline: Merge Surfaces and Views apps
Browse files Browse the repository at this point in the history
Currently, the scroll position of the embedder can fall out
of sync with the position of an OOPIF's content on screen.

This CL moves towards resolving this issue.

See https://docs.google.com/document/d/13ElYs_X_UvZYXOltafyExRs7N3WwtQMBVc1eDLY2dTU/edit

The eventual goal is make a mojo::View a cc::Surface or at
least a SurfaceClient of some sort such that when the
compositor thread moves around some surfaces,
they also shift over the position of the views.

This CL merges surfaces, views and GL into one thread.
TopLevelDisplayClient has a DirectOutputSurface that uses
the SurfacesContextProvider as its ContextProvider. This
means it talks to the GL driver directly rather than going
through shared memory to hop to another thread first.

BUG=492389

Review URL: https://codereview.chromium.org/1245683004

Cr-Commit-Position: refs/heads/master@{#344296}
  • Loading branch information
fsamuel authored and Commit bot committed Aug 19, 2015
1 parent fcba45d commit b8840ea
Show file tree
Hide file tree
Showing 51 changed files with 810 additions and 741 deletions.
2 changes: 0 additions & 2 deletions components/gpu/public/interfaces/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import("//third_party/mojo/src/mojo/public/tools/bindings/mojom.gni")
mojom("interfaces") {
sources = [
"command_buffer.mojom",
"context_provider.mojom",
"gpu.mojom",
"gpu_capabilities.mojom",
"viewport_parameter_listener.mojom",
]

deps = [
Expand Down
2 changes: 1 addition & 1 deletion components/html_viewer/html_document.cc
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ void HTMLDocument::initializeLayerTreeView() {
}

mojo::URLRequestPtr request(mojo::URLRequest::New());
request->url = mojo::String::From("mojo:surfaces_service");
request->url = mojo::String::From("mojo:view_manager");
mojo::SurfacePtr surface;
html_document_app_->ConnectToService(request.Pass(), &surface);

Expand Down
2 changes: 1 addition & 1 deletion components/html_viewer/html_frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ void HTMLFrame::didChangeContents() {

void HTMLFrame::initializeLayerTreeView() {
mojo::URLRequestPtr request(mojo::URLRequest::New());
request->url = mojo::String::From("mojo:surfaces_service");
request->url = mojo::String::From("mojo:view_manager");
mojo::SurfacePtr surface;
GetLocalRootApp()->ConnectToService(request.Pass(), &surface);

Expand Down
2 changes: 1 addition & 1 deletion components/pdf_viewer/pdf_viewer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class BitmapUploader : public mojo::ResourceReturner {
void Init(mojo::Shell* shell) {
mojo::ServiceProviderPtr surfaces_service_provider;
mojo::URLRequestPtr request(mojo::URLRequest::New());
request->url = mojo::String::From("mojo:surfaces_service");
request->url = mojo::String::From("mojo:view_manager");
shell->ConnectToApplication(request.Pass(),
mojo::GetProxy(&surfaces_service_provider),
nullptr, nullptr);
Expand Down
7 changes: 2 additions & 5 deletions components/view_manager/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ if (is_android) {
deps = [
":lib",
":loader",
"native_viewport",
]
}

Expand All @@ -39,7 +38,7 @@ if (is_android) {
":lib",
"//base",
"//components/view_manager/public/interfaces",
"//components/view_manager/native_viewport",
"//components/view_manager/surfaces",
"//mojo/application/public/cpp",
"//mojo/converters/geometry",
"//mojo/environment:chromium",
Expand All @@ -49,8 +48,6 @@ if (is_android) {
"//ui/events/platform",
"//ui/gl",
]

data_deps = [ "//components/view_manager/surfaces" ]
}
}

Expand Down Expand Up @@ -116,7 +113,7 @@ source_set("lib") {
"//cc/surfaces:surface_id",
"//components/view_manager/public/cpp:common",
"//components/view_manager/public/interfaces",
"//components/view_manager/native_viewport",
"//components/view_manager/surfaces",
"//mojo/application/public/cpp",
"//mojo/common:tracing_impl",
"//mojo/converters/geometry",
Expand Down
55 changes: 21 additions & 34 deletions components/view_manager/display_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
#include "base/numerics/safe_conversions.h"
#include "components/view_manager/display_manager_factory.h"
#include "components/view_manager/gles2/gpu_state.h"
#include "components/view_manager/native_viewport/onscreen_context_provider.h"
#include "components/view_manager/public/interfaces/gpu.mojom.h"
#include "components/view_manager/public/interfaces/quads.mojom.h"
#include "components/view_manager/public/interfaces/surfaces.mojom.h"
#include "components/view_manager/server_view.h"
#include "components/view_manager/surfaces/surfaces_state.h"
#include "components/view_manager/view_coordinate_conversions.h"
#include "mojo/application/public/cpp/application_connection.h"
#include "mojo/application/public/cpp/application_impl.h"
Expand Down Expand Up @@ -105,25 +105,28 @@ DisplayManagerFactory* DisplayManager::factory_ = nullptr;
DisplayManager* DisplayManager::Create(
bool is_headless,
mojo::ApplicationImpl* app_impl,
const scoped_refptr<gles2::GpuState>& gpu_state) {
if (factory_)
return factory_->CreateDisplayManager(is_headless, app_impl, gpu_state);
return new DefaultDisplayManager(is_headless, app_impl, gpu_state);
const scoped_refptr<gles2::GpuState>& gpu_state,
const scoped_refptr<surfaces::SurfacesState>& surfaces_state) {
if (factory_) {
return factory_->CreateDisplayManager(is_headless, app_impl, gpu_state,
surfaces_state);
}
return new DefaultDisplayManager(is_headless, app_impl, gpu_state,
surfaces_state);
}

DefaultDisplayManager::DefaultDisplayManager(
bool is_headless,
mojo::ApplicationImpl* app_impl,
const scoped_refptr<gles2::GpuState>& gpu_state)
const scoped_refptr<gles2::GpuState>& gpu_state,
const scoped_refptr<surfaces::SurfacesState>& surfaces_state)
: is_headless_(is_headless),
app_impl_(app_impl),
gpu_state_(gpu_state),
surfaces_state_(surfaces_state),
delegate_(nullptr),
draw_timer_(false, false),
frame_pending_(false),
context_provider_(
new native_viewport::OnscreenContextProvider(gpu_state)),
weak_factory_(this) {
frame_pending_(false) {
metrics_.size_in_pixels = mojo::Size::New();
metrics_.size_in_pixels->width = 800;
metrics_.size_in_pixels->height = 600;
Expand All @@ -148,28 +151,9 @@ void DefaultDisplayManager::Init(DisplayManagerDelegate* delegate) {
}
platform_window_->SetBounds(bounds);
platform_window_->Show();

mojo::ContextProviderPtr context_provider;
context_provider_->Bind(GetProxy(&context_provider).Pass());
mojo::DisplayFactoryPtr display_factory;
mojo::URLRequestPtr request(mojo::URLRequest::New());
request->url = mojo::String::From("mojo:surfaces_service");
app_impl_->ConnectToService(request.Pass(), &display_factory);
// TODO(fsamuel): We should indicate to the delegate that this object failed
// to initialize.
if (!display_factory)
return;
display_factory->Create(context_provider.Pass(),
nullptr, // returner - we never submit resources.
GetProxy(&display_));
}

DefaultDisplayManager::~DefaultDisplayManager() {
// Destroy before |platform_window_| because this will destroy
// CommandBufferDriver objects that contain child windows. Otherwise if this
// class destroys its window first, X errors will occur.
context_provider_.reset();

// Destroy the PlatformWindow early on as it may call us back during
// destruction and we want to be in a known state.
platform_window_.reset();
Expand Down Expand Up @@ -222,10 +206,10 @@ void DefaultDisplayManager::Draw() {
frame->passes.push_back(pass.Pass());
frame->resources.resize(0u);
frame_pending_ = true;
if (display_) {
display_->SubmitFrame(frame.Pass(),
base::Bind(&DefaultDisplayManager::DidDraw,
weak_factory_.GetWeakPtr()));
if (top_level_display_client_) {
top_level_display_client_->SubmitFrame(
frame.Pass(),
base::Bind(&DefaultDisplayManager::DidDraw, base::Unretained(this)));
}
dirty_rect_ = gfx::Rect();
}
Expand Down Expand Up @@ -347,7 +331,10 @@ void DefaultDisplayManager::OnLostCapture() {
void DefaultDisplayManager::OnAcceleratedWidgetAvailable(
gfx::AcceleratedWidget widget,
float device_pixel_ratio) {
context_provider_->SetAcceleratedWidget(widget);
if (widget != gfx::kNullAcceleratedWidget) {
top_level_display_client_.reset(new surfaces::TopLevelDisplayClient(
widget, gpu_state_, surfaces_state_));
}
UpdateMetrics(metrics_.size_in_pixels.To<gfx::Size>(), device_pixel_ratio);
}

Expand Down
31 changes: 17 additions & 14 deletions components/view_manager/display_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,34 @@
#include "base/memory/weak_ptr.h"
#include "base/timer/timer.h"
#include "components/view_manager/display_manager_delegate.h"
#include "components/view_manager/public/interfaces/display.mojom.h"
#include "components/view_manager/public/interfaces/view_manager.mojom.h"
#include "components/view_manager/surfaces/top_level_display_client.h"
#include "third_party/mojo/src/mojo/public/cpp/bindings/callback.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/platform_window/platform_window_delegate.h"

namespace cc {
class SurfaceIdAllocator;
class SurfaceManager;
} // namespace cc

namespace gles2 {
class GpuState;
} // namespace gles2

namespace native_viewport {
class OnscreenContextProvider;
} // namespace native_viewport

namespace mojo {
class ApplicationImpl;
} // namespace mojo

namespace surfaces {
class SurfacesScheduler;
class SurfacesState;
} // namespace surfaces

namespace ui {
class PlatformWindow;
struct TextInputState;
}
} // namespace ui

namespace view_manager {

Expand All @@ -53,7 +55,8 @@ class DisplayManager {
static DisplayManager* Create(
bool is_headless,
mojo::ApplicationImpl* app_impl,
const scoped_refptr<gles2::GpuState>& gpu_state);
const scoped_refptr<gles2::GpuState>& gpu_state,
const scoped_refptr<surfaces::SurfacesState>& surfaces_state);

virtual void Init(DisplayManagerDelegate* delegate) = 0;

Expand Down Expand Up @@ -85,9 +88,11 @@ class DefaultDisplayManager :
public DisplayManager,
public ui::PlatformWindowDelegate {
public:
DefaultDisplayManager(bool is_headless,
mojo::ApplicationImpl* app_impl,
const scoped_refptr<gles2::GpuState>& gpu_state);
DefaultDisplayManager(
bool is_headless,
mojo::ApplicationImpl* app_impl,
const scoped_refptr<gles2::GpuState>& gpu_state,
const scoped_refptr<surfaces::SurfacesState>& surfaces_state);
~DefaultDisplayManager() override;

// DisplayManager:
Expand Down Expand Up @@ -119,19 +124,17 @@ class DefaultDisplayManager :
bool is_headless_;
mojo::ApplicationImpl* app_impl_;
scoped_refptr<gles2::GpuState> gpu_state_;
scoped_refptr<surfaces::SurfacesState> surfaces_state_;
DisplayManagerDelegate* delegate_;

mojo::ViewportMetrics metrics_;
gfx::Rect dirty_rect_;
base::Timer draw_timer_;
bool frame_pending_;

mojo::DisplayPtr display_;
scoped_ptr<native_viewport::OnscreenContextProvider> context_provider_;
scoped_ptr<surfaces::TopLevelDisplayClient> top_level_display_client_;
scoped_ptr<ui::PlatformWindow> platform_window_;

base::WeakPtrFactory<DefaultDisplayManager> weak_factory_;

DISALLOW_COPY_AND_ASSIGN(DefaultDisplayManager);
};

Expand Down
3 changes: 2 additions & 1 deletion components/view_manager/display_manager_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ class DisplayManagerFactory {
virtual DisplayManager* CreateDisplayManager(
bool is_headless,
mojo::ApplicationImpl* app_impl,
const scoped_refptr<gles2::GpuState>& gpu_state) = 0;
const scoped_refptr<gles2::GpuState>& gpu_state,
const scoped_refptr<surfaces::SurfacesState>& surfaces_state) = 0;
};

} // namespace view_manager
Expand Down
5 changes: 4 additions & 1 deletion components/view_manager/gles2/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

source_set("gles2") {
visibility = [
"//components/view_manager/native_viewport:*",
"//components/view_manager/surfaces:*",
"//mojo/runner:lib", # For android
]

Expand All @@ -14,6 +14,9 @@ source_set("gles2") {
"command_buffer_impl.cc",
"command_buffer_impl.h",
"command_buffer_impl_observer.h",
"command_buffer_local.cc",
"command_buffer_local.h",
"command_buffer_local_client.h",
"gpu_impl.cc",
"gpu_impl.h",
"gpu_memory_tracker.cc",
Expand Down
36 changes: 1 addition & 35 deletions components/view_manager/gles2/command_buffer_driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,13 @@ CommandBufferDriver::Client::~Client() {
}

CommandBufferDriver::CommandBufferDriver(scoped_refptr<GpuState> gpu_state)
: CommandBufferDriver(gfx::kNullAcceleratedWidget,
gpu_state,
base::Callback<void(CommandBufferDriver*)>()) {}

CommandBufferDriver::CommandBufferDriver(
gfx::AcceleratedWidget widget,
scoped_refptr<GpuState> gpu_state,
const base::Callback<void(CommandBufferDriver*)>& destruct_callback)
: client_(nullptr),
widget_(widget),
gpu_state_(gpu_state),
destruct_callback_(destruct_callback),
weak_factory_(this) {
}

CommandBufferDriver::~CommandBufferDriver() {
DestroyDecoder();
if (!destruct_callback_.is_null())
destruct_callback_.Run(this);
}

void CommandBufferDriver::Initialize(
Expand Down Expand Up @@ -88,16 +76,7 @@ bool CommandBufferDriver::MakeCurrent() {

bool CommandBufferDriver::DoInitialize(
mojo::ScopedSharedBufferHandle shared_state) {
if (widget_ == gfx::kNullAcceleratedWidget)
surface_ = gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1));
else {
surface_ = gfx::GLSurface::CreateViewGLSurface(widget_);
if (auto vsync_provider = surface_->GetVSyncProvider()) {
vsync_provider->GetVSyncParameters(
base::Bind(&CommandBufferDriver::OnUpdateVSyncParameters,
weak_factory_.GetWeakPtr()));
}
}
surface_ = gfx::GLSurface::CreateOffscreenGLSurface(gfx::Size(1, 1));

if (!surface_.get())
return false;
Expand Down Expand Up @@ -177,13 +156,6 @@ void CommandBufferDriver::Flush(int32_t put_offset) {
command_buffer_->Flush(put_offset);
}

void CommandBufferDriver::DestroyWindow() {
DestroyDecoder();
surface_ = nullptr;
context_ = nullptr;
destruct_callback_.Reset();
}

void CommandBufferDriver::MakeProgress(int32_t last_get_offset) {
// TODO(piman): handle out-of-order.
sync_client_->DidMakeProgress(
Expand Down Expand Up @@ -325,12 +297,6 @@ void CommandBufferDriver::OnContextLost(uint32_t reason) {
client_->DidLoseContext();
}

void CommandBufferDriver::OnUpdateVSyncParameters(
const base::TimeTicks timebase,
const base::TimeDelta interval) {
client_->UpdateVSyncParameters(timebase, interval);
}

void CommandBufferDriver::DestroyDecoder() {
if (decoder_) {
bool have_context = decoder_->MakeCurrent();
Expand Down
Loading

0 comments on commit b8840ea

Please sign in to comment.