Commit 3a4eab3f authored by fsamuel's avatar fsamuel Committed by Commit bot

Mandoline: Remove native_viewport.mojom

native_viewport mojom + app add a lot of unnecessary complexity. For now, this should be a part of the view_manager. A future patch will get rid of native_viewport completely and will teach display_manager to dispense platform_windows.

BUG=487881
Test=internal change only.

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

Cr-Commit-Position: refs/heads/master@{#333183}
parent 12084c09
...@@ -16,6 +16,7 @@ include_rules = [ ...@@ -16,6 +16,7 @@ include_rules = [
"+mojo/application", "+mojo/application",
"+mojo/cc", "+mojo/cc",
"+mojo/common", "+mojo/common",
"+mojo/converters/geometry",
"+mojo/converters/surfaces", "+mojo/converters/surfaces",
"+mojo/platform_handle", "+mojo/platform_handle",
"+mojo/public", "+mojo/public",
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "mojo/application/public/cpp/application_impl.h" #include "mojo/application/public/cpp/application_impl.h"
#include "mojo/application/public/cpp/connect.h" #include "mojo/application/public/cpp/connect.h"
#include "mojo/application/public/interfaces/shell.mojom.h" #include "mojo/application/public/interfaces/shell.mojom.h"
#include "mojo/converters/geometry/geometry_type_converters.h"
#include "skia/ext/refptr.h" #include "skia/ext/refptr.h"
#include "third_party/WebKit/public/platform/Platform.h" #include "third_party/WebKit/public/platform/Platform.h"
#include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h"
...@@ -247,9 +248,9 @@ void HTMLDocument::InitSetupAndLoadIfNecessary() { ...@@ -247,9 +248,9 @@ void HTMLDocument::InitSetupAndLoadIfNecessary() {
return; return;
if (!web_view_) { if (!web_view_) {
setup_->InitIfNecessary(gfx::Size(root_->viewport_metrics().size->width, setup_->InitIfNecessary(
root_->viewport_metrics().size->height), root_->viewport_metrics().size_in_pixels.To<gfx::Size>(),
root_->viewport_metrics().device_pixel_ratio); root_->viewport_metrics().device_pixel_ratio);
Load(response_.Pass()); Load(response_.Pass());
} }
......
...@@ -115,20 +115,17 @@ ConnectionManager::ConnectionManager(ConnectionManagerDelegate* delegate, ...@@ -115,20 +115,17 @@ ConnectionManager::ConnectionManager(ConnectionManagerDelegate* delegate,
: delegate_(delegate), : delegate_(delegate),
window_manager_client_connection_(nullptr), window_manager_client_connection_(nullptr),
next_connection_id_(1), next_connection_id_(1),
event_dispatcher_(this),
display_manager_(display_manager.Pass()), display_manager_(display_manager.Pass()),
root_(CreateServerView(RootViewId())), root_(CreateServerView(RootViewId())),
current_change_(nullptr), current_change_(nullptr),
in_destructor_(false), in_destructor_(false),
animation_runner_(base::TimeTicks::Now()), animation_runner_(base::TimeTicks::Now()),
event_dispatcher_(this),
event_dispatcher_binding_(&event_dispatcher_),
focus_controller_(new FocusController(this, root_.get())) { focus_controller_(new FocusController(this, root_.get())) {
root_->SetBounds(gfx::Rect(800, 600)); root_->SetBounds(gfx::Rect(800, 600));
root_->SetVisible(true); root_->SetVisible(true);
mojo::NativeViewportEventDispatcherPtr event_dispatcher_ptr; display_manager_->Init(this, &event_dispatcher_);
event_dispatcher_binding_.Bind(GetProxy(&event_dispatcher_ptr));
display_manager_->Init(this, event_dispatcher_ptr.Pass());
} }
ConnectionManager::~ConnectionManager() { ConnectionManager::~ConnectionManager() {
...@@ -312,7 +309,7 @@ bool ConnectionManager::CloneAndAnimate(const ViewId& view_id) { ...@@ -312,7 +309,7 @@ bool ConnectionManager::CloneAndAnimate(const ViewId& view_id) {
} }
void ConnectionManager::ProcessEvent(mojo::EventPtr event) { void ConnectionManager::ProcessEvent(mojo::EventPtr event) {
event_dispatcher_.OnEvent(event.Pass(), EventDispatcher::OnEventCallback()); event_dispatcher_.OnEvent(event.Pass());
} }
void ConnectionManager::DispatchInputEventToView(const ServerView* view, void ConnectionManager::DispatchInputEventToView(const ServerView* view,
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "components/view_manager/event_dispatcher.h" #include "components/view_manager/event_dispatcher.h"
#include "components/view_manager/focus_controller_delegate.h" #include "components/view_manager/focus_controller_delegate.h"
#include "components/view_manager/ids.h" #include "components/view_manager/ids.h"
#include "components/view_manager/public/interfaces/native_viewport.mojom.h"
#include "components/view_manager/public/interfaces/view_manager.mojom.h" #include "components/view_manager/public/interfaces/view_manager.mojom.h"
#include "components/view_manager/public/interfaces/view_manager_root.mojom.h" #include "components/view_manager/public/interfaces/view_manager_root.mojom.h"
#include "components/view_manager/server_view_delegate.h" #include "components/view_manager/server_view_delegate.h"
...@@ -253,6 +252,10 @@ class ConnectionManager : public ServerViewDelegate, ...@@ -253,6 +252,10 @@ class ConnectionManager : public ServerViewDelegate,
// Set of ViewManagerServiceImpls. // Set of ViewManagerServiceImpls.
ConnectionMap connection_map_; ConnectionMap connection_map_;
// DisplayManager holds a raw pointer to EventDispatcher and so it must be
// destroyed after DisplayManager (and thus created before).
EventDispatcher event_dispatcher_;
scoped_ptr<DisplayManager> display_manager_; scoped_ptr<DisplayManager> display_manager_;
scoped_ptr<ServerView> root_; scoped_ptr<ServerView> root_;
...@@ -268,10 +271,6 @@ class ConnectionManager : public ServerViewDelegate, ...@@ -268,10 +271,6 @@ class ConnectionManager : public ServerViewDelegate,
AnimationRunner animation_runner_; AnimationRunner animation_runner_;
EventDispatcher event_dispatcher_;
mojo::Binding<mojo::NativeViewportEventDispatcher> event_dispatcher_binding_;
scoped_ptr<FocusController> focus_controller_; scoped_ptr<FocusController> focus_controller_;
mojo::ViewManagerRootClientPtr view_manager_root_client_; mojo::ViewManagerRootClientPtr view_manager_root_client_;
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "base/numerics/safe_conversions.h" #include "base/numerics/safe_conversions.h"
#include "components/view_manager/connection_manager.h" #include "components/view_manager/connection_manager.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/gpu.mojom.h"
#include "components/view_manager/public/interfaces/quads.mojom.h" #include "components/view_manager/public/interfaces/quads.mojom.h"
#include "components/view_manager/public/interfaces/surfaces.mojom.h" #include "components/view_manager/public/interfaces/surfaces.mojom.h"
...@@ -73,49 +75,57 @@ void DrawViewTree(mojo::Pass* pass, ...@@ -73,49 +75,57 @@ void DrawViewTree(mojo::Pass* pass,
} // namespace } // namespace
DefaultDisplayManager::DefaultDisplayManager( DefaultDisplayManager::DefaultDisplayManager(
bool is_headless,
mojo::ApplicationImpl* app_impl, mojo::ApplicationImpl* app_impl,
const mojo::Callback<void()>& native_viewport_closed_callback) const scoped_refptr<gles2::GpuState>& gpu_state,
: app_impl_(app_impl), const mojo::Callback<void()>& platform_viewport_closed_callback)
: is_headless_(is_headless),
app_impl_(app_impl),
gpu_state_(gpu_state),
connection_manager_(nullptr), connection_manager_(nullptr),
event_dispatcher_(nullptr),
draw_timer_(false, false), draw_timer_(false, false),
frame_pending_(false), frame_pending_(false),
native_viewport_closed_callback_(native_viewport_closed_callback), context_provider_(
new native_viewport::OnscreenContextProvider(gpu_state)),
platform_viewport_closed_callback_(platform_viewport_closed_callback),
weak_factory_(this) { weak_factory_(this) {
metrics_.size = mojo::Size::New(); metrics_.size_in_pixels = mojo::Size::New();
metrics_.size->width = 800; metrics_.size_in_pixels->width = 800;
metrics_.size->height = 600; metrics_.size_in_pixels->height = 600;
} }
void DefaultDisplayManager::Init( void DefaultDisplayManager::Init(
ConnectionManager* connection_manager, ConnectionManager* connection_manager,
mojo::NativeViewportEventDispatcherPtr event_dispatcher) { EventDispatcher* event_dispatcher) {
connection_manager_ = connection_manager; connection_manager_ = connection_manager;
mojo::URLRequestPtr request(mojo::URLRequest::New()); event_dispatcher_ = event_dispatcher;
// TODO(beng): should not need to connect to ourselves, should just
// create the appropriate platform window directly. platform_viewport_ =
request->url = mojo::String::From("mojo:view_manager"); native_viewport::PlatformViewport::Create(this, is_headless_).Pass();
app_impl_->ConnectToService(request.Pass(), platform_viewport_->Init(gfx::Rect(metrics_.size_in_pixels.To<gfx::Size>()));
&native_viewport_); platform_viewport_->Show();
native_viewport_.set_error_handler(this);
native_viewport_->Create(metrics_.size->Clone(),
base::Bind(&DefaultDisplayManager::OnMetricsChanged,
weak_factory_.GetWeakPtr()));
native_viewport_->Show();
mojo::ContextProviderPtr context_provider; mojo::ContextProviderPtr context_provider;
native_viewport_->GetContextProvider(GetProxy(&context_provider)); context_provider_->Bind(GetProxy(&context_provider).Pass());
mojo::DisplayFactoryPtr display_factory; mojo::DisplayFactoryPtr display_factory;
mojo::URLRequestPtr request2(mojo::URLRequest::New()); mojo::URLRequestPtr request(mojo::URLRequest::New());
request2->url = mojo::String::From("mojo:surfaces_service"); request->url = mojo::String::From("mojo:surfaces_service");
app_impl_->ConnectToService(request2.Pass(), &display_factory); app_impl_->ConnectToService(request.Pass(), &display_factory);
display_factory->Create(context_provider.Pass(), display_factory->Create(context_provider.Pass(),
nullptr, // returner - we never submit resources. nullptr, // returner - we never submit resources.
GetProxy(&display_)); GetProxy(&display_));
native_viewport_->SetEventDispatcher(event_dispatcher.Pass());
} }
DefaultDisplayManager::~DefaultDisplayManager() { DefaultDisplayManager::~DefaultDisplayManager() {
// Destroy before |platform_viewport_| 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 NativeViewport early on as it may call us back during
// destruction and we want to be in a known state.
platform_viewport_.reset();
} }
void DefaultDisplayManager::SchedulePaint(const ServerView* view, void DefaultDisplayManager::SchedulePaint(const ServerView* view,
...@@ -131,7 +141,7 @@ void DefaultDisplayManager::SchedulePaint(const ServerView* view, ...@@ -131,7 +141,7 @@ void DefaultDisplayManager::SchedulePaint(const ServerView* view,
} }
void DefaultDisplayManager::SetViewportSize(const gfx::Size& size) { void DefaultDisplayManager::SetViewportSize(const gfx::Size& size) {
native_viewport_->SetSize(Size::From(size)); platform_viewport_->SetBounds(gfx::Rect(size));
} }
const mojo::ViewportMetrics& DefaultDisplayManager::GetViewportMetrics() { const mojo::ViewportMetrics& DefaultDisplayManager::GetViewportMetrics() {
...@@ -139,7 +149,7 @@ const mojo::ViewportMetrics& DefaultDisplayManager::GetViewportMetrics() { ...@@ -139,7 +149,7 @@ const mojo::ViewportMetrics& DefaultDisplayManager::GetViewportMetrics() {
} }
void DefaultDisplayManager::Draw() { void DefaultDisplayManager::Draw() {
gfx::Rect rect(metrics_.size->width, metrics_.size->height); gfx::Rect rect(metrics_.size_in_pixels.To<gfx::Size>());
auto pass = mojo::CreateDefaultPass(1, rect); auto pass = mojo::CreateDefaultPass(1, rect);
pass->damage_rect = Rect::From(dirty_rect_); pass->damage_rect = Rect::From(dirty_rect_);
...@@ -170,20 +180,41 @@ void DefaultDisplayManager::WantToDraw() { ...@@ -170,20 +180,41 @@ void DefaultDisplayManager::WantToDraw() {
base::Bind(&DefaultDisplayManager::Draw, base::Unretained(this))); base::Bind(&DefaultDisplayManager::Draw, base::Unretained(this)));
} }
void DefaultDisplayManager::OnMetricsChanged(mojo::ViewportMetricsPtr metrics) { void DefaultDisplayManager::OnAcceleratedWidgetAvailable(
metrics_.size = metrics->size.Clone(); gfx::AcceleratedWidget widget,
metrics_.device_pixel_ratio = metrics->device_pixel_ratio; float device_pixel_ratio) {
gfx::Rect bounds(metrics_.size.To<gfx::Size>()); context_provider_->SetAcceleratedWidget(widget);
connection_manager_->root()->SetBounds(bounds); }
connection_manager_->ProcessViewportMetricsChanged(metrics_, *metrics);
native_viewport_->RequestMetrics(base::Bind( void DefaultDisplayManager::OnAcceleratedWidgetDestroyed() {
&DefaultDisplayManager::OnMetricsChanged, weak_factory_.GetWeakPtr())); context_provider_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
}
void DefaultDisplayManager::OnEvent(mojo::EventPtr event) {
event_dispatcher_->OnEvent(event.Pass());
}
void DefaultDisplayManager::OnMetricsChanged(const gfx::Size& size,
float device_scale_factor) {
if ((metrics_.size_in_pixels.To<gfx::Size>() == size) &&
(metrics_.device_pixel_ratio == device_scale_factor)) {
return;
}
mojo::ViewportMetrics metrics;
metrics.size_in_pixels = mojo::Size::From(size);
metrics.device_pixel_ratio = device_scale_factor;
connection_manager_->root()->SetBounds(gfx::Rect(size));
connection_manager_->ProcessViewportMetricsChanged(metrics_, metrics);
metrics_.size_in_pixels = metrics.size_in_pixels.Clone();
metrics_.device_pixel_ratio = metrics.device_pixel_ratio;
} }
void DefaultDisplayManager::OnConnectionError() { void DefaultDisplayManager::OnDestroyed() {
// This is called when the native_viewport is torn down before if (!platform_viewport_closed_callback_.is_null())
// ~DefaultDisplayManager may be called. platform_viewport_closed_callback_.Run();
native_viewport_closed_callback_.Run();
} }
} // namespace view_manager } // namespace view_manager
...@@ -11,22 +11,31 @@ ...@@ -11,22 +11,31 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/timer/timer.h" #include "base/timer/timer.h"
#include "components/view_manager/native_viewport/platform_viewport.h"
#include "components/view_manager/public/interfaces/display.mojom.h" #include "components/view_manager/public/interfaces/display.mojom.h"
#include "components/view_manager/public/interfaces/native_viewport.mojom.h"
#include "components/view_manager/public/interfaces/view_manager.mojom.h" #include "components/view_manager/public/interfaces/view_manager.mojom.h"
#include "third_party/mojo/src/mojo/public/cpp/bindings/callback.h" #include "third_party/mojo/src/mojo/public/cpp/bindings/callback.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
namespace cc { namespace cc {
class SurfaceIdAllocator; class SurfaceIdAllocator;
} } // namespace cc
namespace gles2 {
class GpuState;
} // namespace gles2
namespace native_viewport {
class OnscreenContextProvider;
} // namespace native_viewport
namespace mojo { namespace mojo {
class ApplicationImpl; class ApplicationImpl;
} } // namespace mojo
namespace view_manager { namespace view_manager {
class EventDispatcher;
class ConnectionManager; class ConnectionManager;
class ServerView; class ServerView;
...@@ -37,7 +46,7 @@ class DisplayManager { ...@@ -37,7 +46,7 @@ class DisplayManager {
virtual void Init( virtual void Init(
ConnectionManager* connection_manager, ConnectionManager* connection_manager,
mojo::NativeViewportEventDispatcherPtr event_dispatcher) = 0; EventDispatcher* event_dispatcher) = 0;
// Schedules a paint for the specified region in the coordinates of |view|. // Schedules a paint for the specified region in the coordinates of |view|.
virtual void SchedulePaint(const ServerView* view, virtual void SchedulePaint(const ServerView* view,
...@@ -50,17 +59,20 @@ class DisplayManager { ...@@ -50,17 +59,20 @@ class DisplayManager {
// DisplayManager implementation that connects to the services necessary to // DisplayManager implementation that connects to the services necessary to
// actually display. // actually display.
class DefaultDisplayManager : public DisplayManager, class DefaultDisplayManager :
public mojo::ErrorHandler { public DisplayManager,
public native_viewport::PlatformViewport::Delegate {
public: public:
DefaultDisplayManager( DefaultDisplayManager(
bool is_headless,
mojo::ApplicationImpl* app_impl, mojo::ApplicationImpl* app_impl,
const mojo::Callback<void()>& native_viewport_closed_callback); const scoped_refptr<gles2::GpuState>& gpu_state,
const mojo::Callback<void()>& platform_viewport_closed_callback);
~DefaultDisplayManager() override; ~DefaultDisplayManager() override;
// DisplayManager: // DisplayManager:
void Init(ConnectionManager* connection_manager, void Init(ConnectionManager* connection_manager,
mojo::NativeViewportEventDispatcherPtr event_dispatcher) override; EventDispatcher* event_dispatcher) override;
void SchedulePaint(const ServerView* view, const gfx::Rect& bounds) override; void SchedulePaint(const ServerView* view, const gfx::Rect& bounds) override;
void SetViewportSize(const gfx::Size& size) override; void SetViewportSize(const gfx::Size& size) override;
const mojo::ViewportMetrics& GetViewportMetrics() override; const mojo::ViewportMetrics& GetViewportMetrics() override;
...@@ -70,13 +82,20 @@ class DefaultDisplayManager : public DisplayManager, ...@@ -70,13 +82,20 @@ class DefaultDisplayManager : public DisplayManager,
void Draw(); void Draw();
void DidDraw(); void DidDraw();
void OnMetricsChanged(mojo::ViewportMetricsPtr metrics); // PlatformViewport::Delegate implementation:
void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget,
// ErrorHandler: float device_pixel_ratio) override;
void OnConnectionError() override; void OnAcceleratedWidgetDestroyed() override;
void OnEvent(mojo::EventPtr event) override;
void OnMetricsChanged(const gfx::Size& size,
float device_scale_factor) override;
void OnDestroyed() override;
bool is_headless_;
mojo::ApplicationImpl* app_impl_; mojo::ApplicationImpl* app_impl_;
scoped_refptr<gles2::GpuState> gpu_state_;
ConnectionManager* connection_manager_; ConnectionManager* connection_manager_;
EventDispatcher* event_dispatcher_;
mojo::ViewportMetrics metrics_; mojo::ViewportMetrics metrics_;
gfx::Rect dirty_rect_; gfx::Rect dirty_rect_;
...@@ -84,8 +103,10 @@ class DefaultDisplayManager : public DisplayManager, ...@@ -84,8 +103,10 @@ class DefaultDisplayManager : public DisplayManager,
bool frame_pending_; bool frame_pending_;
mojo::DisplayPtr display_; mojo::DisplayPtr display_;
mojo::NativeViewportPtr native_viewport_; scoped_ptr<native_viewport::OnscreenContextProvider> context_provider_;
mojo::Callback<void()> native_viewport_closed_callback_; scoped_ptr<native_viewport::PlatformViewport> platform_viewport_;
mojo::Callback<void()> platform_viewport_closed_callback_;
base::WeakPtrFactory<DefaultDisplayManager> weak_factory_; base::WeakPtrFactory<DefaultDisplayManager> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(DefaultDisplayManager); DISALLOW_COPY_AND_ASSIGN(DefaultDisplayManager);
......
...@@ -30,15 +30,11 @@ void EventDispatcher::RemoveAccelerator(mojo::KeyboardCode keyboard_code, ...@@ -30,15 +30,11 @@ void EventDispatcher::RemoveAccelerator(mojo::KeyboardCode keyboard_code,
accelerators_.erase(Accelerator(keyboard_code, flags)); accelerators_.erase(Accelerator(keyboard_code, flags));
} }
void EventDispatcher::OnEvent(mojo::EventPtr event, void EventDispatcher::OnEvent(mojo::EventPtr event) {
const OnEventCallback& callback) {
callback.Run();
if (event->pointer_data) { if (event->pointer_data) {
const gfx::Point root_point(static_cast<int>(event->pointer_data->x), const gfx::Point root_point(static_cast<int>(event->pointer_data->x),
static_cast<int>(event->pointer_data->y)); static_cast<int>(event->pointer_data->y));
ServerView* target = connection_manager_->GetFocusedView(); ServerView* target = connection_manager_->GetFocusedView();
;
if (event->action == mojo::EVENT_TYPE_POINTER_DOWN || !target) { if (event->action == mojo::EVENT_TYPE_POINTER_DOWN || !target) {
target = FindDeepestVisibleView(connection_manager_->root(), root_point); target = FindDeepestVisibleView(connection_manager_->root(), root_point);
CHECK(target); CHECK(target);
......
...@@ -8,24 +8,25 @@ ...@@ -8,24 +8,25 @@
#include <set> #include <set>
#include "base/basictypes.h" #include "base/basictypes.h"
#include "components/view_manager/public/interfaces/native_viewport.mojom.h" #include "ui/mojo/events/input_event_constants.mojom.h"
#include "ui/mojo/events/input_events.mojom.h"
#include "ui/mojo/events/input_key_codes.mojom.h"
namespace view_manager { namespace view_manager {
class ConnectionManager; class ConnectionManager;
// Handles dispatching events to the right location as well as updating focus. // Handles dispatching events to the right location as well as updating focus.
class EventDispatcher : public mojo::NativeViewportEventDispatcher { class EventDispatcher {
public: public:
explicit EventDispatcher(ConnectionManager* connection_manager); explicit EventDispatcher(ConnectionManager* connection_manager);
~EventDispatcher() override; ~EventDispatcher();
void AddAccelerator(mojo::KeyboardCode keyboard_code, mojo::EventFlags flags); void AddAccelerator(mojo::KeyboardCode keyboard_code, mojo::EventFlags flags);
void RemoveAccelerator(mojo::KeyboardCode keyboard_code, void RemoveAccelerator(mojo::KeyboardCode keyboard_code,
mojo::EventFlags flags); mojo::EventFlags flags);
// NativeViewportEventDispatcher: void OnEvent(mojo::EventPtr event);
void OnEvent(mojo::EventPtr event, const OnEventCallback& callback) override;
private: private:
struct Accelerator { struct Accelerator {
......
...@@ -7,8 +7,6 @@ import("//third_party/mojo/src/mojo/public/mojo_application.gni") ...@@ -7,8 +7,6 @@ import("//third_party/mojo/src/mojo/public/mojo_application.gni")
source_set("native_viewport") { source_set("native_viewport") {
sources = [ sources = [
"native_viewport_impl.cc",
"native_viewport_impl.h",
"onscreen_context_provider.cc", "onscreen_context_provider.cc",
"onscreen_context_provider.h", "onscreen_context_provider.h",
"platform_viewport.h", "platform_viewport.h",
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/view_manager/native_viewport/native_viewport_impl.h"
#include "base/auto_reset.h"
#include "base/bind.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/time/time.h"
#include "components/view_manager/gles2/gpu_state.h"
#include "components/view_manager/native_viewport/platform_viewport_headless.h"
#include "mojo/application/public/cpp/interface_factory.h"
#include "mojo/converters/geometry/geometry_type_converters.h"
#include "ui/events/event.h"
namespace native_viewport {
NativeViewportImpl::NativeViewportImpl(
bool is_headless,
const scoped_refptr<gles2::GpuState>& gpu_state,
mojo::InterfaceRequest<mojo::NativeViewport> request,
scoped_ptr<mojo::AppRefCount> app_refcount)
: is_headless_(is_headless),
app_refcount_(app_refcount.Pass()),
context_provider_(new OnscreenContextProvider(gpu_state)),
sent_metrics_(false),
metrics_(mojo::ViewportMetrics::New()),
binding_(this, request.Pass()),
weak_factory_(this) {
}
NativeViewportImpl::~NativeViewportImpl() {
// Destroy before |platform_viewport_| 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 NativeViewport early on as it may call us back during
// destruction and we want to be in a known state.
platform_viewport_.reset();
}
void NativeViewportImpl::Create(mojo::SizePtr size,
const CreateCallback& callback) {
create_callback_ = callback;
metrics_->size = size.Clone();
if (is_headless_)
platform_viewport_ = PlatformViewportHeadless::Create(this);
else
platform_viewport_ = PlatformViewport::Create(this);
platform_viewport_->Init(gfx::Rect(size.To<gfx::Size>()));
}
void NativeViewportImpl::RequestMetrics(
const RequestMetricsCallback& callback) {
if (!sent_metrics_) {
callback.Run(metrics_.Clone());
sent_metrics_ = true;
return;
}
metrics_callback_ = callback;
}
void NativeViewportImpl::Show() {
platform_viewport_->Show();
}
void NativeViewportImpl::Hide() {
platform_viewport_->Hide();
}
void NativeViewportImpl::Close() {
DCHECK(platform_viewport_);
platform_viewport_->Close();
}
void NativeViewportImpl::SetSize(mojo::SizePtr size) {
platform_viewport_->SetBounds(gfx::Rect(size.To<gfx::Size>()));
}
void NativeViewportImpl::GetContextProvider(
mojo::InterfaceRequest<mojo::ContextProvider> request) {
context_provider_->Bind(request.Pass());
}
void NativeViewportImpl::SetEventDispatcher(
mojo::NativeViewportEventDispatcherPtr dispatcher) {
event_dispatcher_ = dispatcher.Pass();
}
void NativeViewportImpl::OnMetricsChanged(mojo::ViewportMetricsPtr metrics) {
if (metrics_->Equals(*metrics))
return;
metrics_ = metrics.Pass();
sent_metrics_ = false;
if (!metrics_callback_.is_null()) {
metrics_callback_.Run(metrics_.Clone());
metrics_callback_.reset();
sent_metrics_ = true;
}
}
void NativeViewportImpl::OnAcceleratedWidgetAvailable(
gfx::AcceleratedWidget widget,
float device_pixel_ratio) {
metrics_->device_pixel_ratio = device_pixel_ratio;
context_provider_->SetAcceleratedWidget(widget);
// TODO: The metrics here might not match the actual window size on android
// where we don't know the actual size until the first OnMetricsChanged call.
create_callback_.Run(metrics_.Clone());
sent_metrics_ = true;
create_callback_.reset();
}
void NativeViewportImpl::OnAcceleratedWidgetDestroyed() {
context_provider_->SetAcceleratedWidget(gfx::kNullAcceleratedWidget);
}
bool NativeViewportImpl::OnEvent(mojo::EventPtr event) {
if (event.is_null() || !event_dispatcher_.get())
return false;
mojo::NativeViewportEventDispatcher::OnEventCallback callback;
switch (event->action) {
case mojo::EVENT_TYPE_POINTER_MOVE: {
// TODO(sky): add logic to remember last event location and not send if
// the same.
if (pointers_waiting_on_ack_.count(event->pointer_data->pointer_id))
return false;
pointers_waiting_on_ack_.insert(event->pointer_data->pointer_id);
callback =
base::Bind(&NativeViewportImpl::AckEvent, weak_factory_.GetWeakPtr(),
event->pointer_data->pointer_id);
break;
}
case mojo::EVENT_TYPE_POINTER_CANCEL:
pointers_waiting_on_ack_.clear();
break;
case mojo::EVENT_TYPE_POINTER_UP:
pointers_waiting_on_ack_.erase(event->pointer_data->pointer_id);
break;
default:
break;
}
event_dispatcher_->OnEvent(event.Pass(), callback);
return false;
}
void NativeViewportImpl::OnDestroyed() {
delete this;
}
void NativeViewportImpl::AckEvent(int32 pointer_id) {
pointers_waiting_on_ack_.erase(pointer_id);
}
} // namespace native_viewport
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_VIEW_MANAGER_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_
#define COMPONENTS_VIEW_MANAGER_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_
#include <set>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "components/view_manager/native_viewport/onscreen_context_provider.h"
#include "components/view_manager/native_viewport/platform_viewport.h"
#include "components/view_manager/public/interfaces/gpu.mojom.h"
#include "components/view_manager/public/interfaces/native_viewport.mojom.h"
#include "mojo/application/public/cpp/app_lifetime_helper.h"
#include "third_party/mojo/src/mojo/public/cpp/bindings/strong_binding.h"
#include "ui/gfx/geometry/rect.h"
namespace gles2 {
class GpuState;
}
namespace ui {
class Event;
}
namespace native_viewport {
// A NativeViewportImpl is bound to a message pipe and to a PlatformViewport.
// The NativeViewportImpl's lifetime ends when either the message pipe is closed
// or the PlatformViewport informs the NativeViewportImpl that it has been
// destroyed.
class NativeViewportImpl : public mojo::NativeViewport,
public PlatformViewport::Delegate {
public:
NativeViewportImpl(bool is_headless,
const scoped_refptr<gles2::GpuState>& gpu_state,
mojo::InterfaceRequest<mojo::NativeViewport> request,
scoped_ptr<mojo::AppRefCount> app_refcount);
~NativeViewportImpl() override;
// NativeViewport implementation.
void Create(mojo::SizePtr size, const CreateCallback& callback) override;
void RequestMetrics(const RequestMetricsCallback& callback) override;
void Show() override;
void Hide() override;
void Close() override;
void SetSize(mojo::SizePtr size) override;
void GetContextProvider(
mojo::InterfaceRequest<mojo::ContextProvider> request) override;
void SetEventDispatcher(
mojo::NativeViewportEventDispatcherPtr dispatcher) override;
// PlatformViewport::Delegate implementation.
void OnMetricsChanged(mojo::ViewportMetricsPtr metrics) override;
void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget,
float device_pixel_ratio) override;
void OnAcceleratedWidgetDestroyed() override;
bool OnEvent(mojo::EventPtr event) override;
void OnDestroyed() override;
private:
// Callback when the dispatcher has processed a message we're waiting on
// an ack from. |pointer_id| identifies the pointer the message was associated
// with.
void AckEvent(int32 pointer_id);
bool is_headless_;
scoped_ptr<mojo::AppRefCount> app_refcount_;
scoped_ptr<PlatformViewport> platform_viewport_;
scoped_ptr<OnscreenContextProvider> context_provider_;
bool sent_metrics_;
mojo::ViewportMetricsPtr metrics_;
CreateCallback create_callback_;
RequestMetricsCallback metrics_callback_;
mojo::NativeViewportEventDispatcherPtr event_dispatcher_;
mojo::StrongBinding<mojo::NativeViewport> binding_;
// Set of pointer_ids we've sent a move to and are waiting on an ack.
std::set<int32> pointers_waiting_on_ack_;
base::WeakPtrFactory<NativeViewportImpl> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(NativeViewportImpl);
};
} // namespace native_viewport
#endif // COMPONENTS_VIEW_MANAGER_NATIVE_VIEWPORT_NATIVE_VIEWPORT_IMPL_H_
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define COMPONENTS_VIEW_MANAGER_NATIVE_VIEWPORT_PLATFORM_VIEWPORT_H_ #define COMPONENTS_VIEW_MANAGER_NATIVE_VIEWPORT_PLATFORM_VIEWPORT_H_
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "components/view_manager/public/interfaces/native_viewport.mojom.h"
#include "ui/gfx/geometry/size.h" #include "ui/gfx/geometry/size.h"
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "ui/mojo/events/input_events.mojom.h" #include "ui/mojo/events/input_events.mojom.h"
...@@ -24,12 +23,13 @@ class PlatformViewport { ...@@ -24,12 +23,13 @@ class PlatformViewport {
public: public:
virtual ~Delegate() {} virtual ~Delegate() {}
virtual void OnMetricsChanged(mojo::ViewportMetricsPtr metrics) = 0;
virtual void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget, virtual void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget,
float device_pixel_ratio) = 0; float device_pixel_ratio) = 0;
virtual void OnAcceleratedWidgetDestroyed() = 0; virtual void OnAcceleratedWidgetDestroyed() = 0;
virtual bool OnEvent(mojo::EventPtr event) = 0;
virtual void OnDestroyed() = 0; virtual void OnDestroyed() = 0;
virtual void OnEvent(mojo::EventPtr event) = 0;
virtual void OnMetricsChanged(const gfx::Size& size,
float device_scale_factor) = 0;
}; };
virtual ~PlatformViewport() {} virtual ~PlatformViewport() {}
...@@ -41,7 +41,7 @@ class PlatformViewport { ...@@ -41,7 +41,7 @@ class PlatformViewport {
virtual gfx::Size GetSize() = 0; virtual gfx::Size GetSize() = 0;
virtual void SetBounds(const gfx::Rect& bounds) = 0; virtual void SetBounds(const gfx::Rect& bounds) = 0;
static scoped_ptr<PlatformViewport> Create(Delegate* delegate); static scoped_ptr<PlatformViewport> Create(Delegate* delegate, bool headless);
}; };
} // namespace native_viewport } // namespace native_viewport
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <android/native_window_jni.h> #include <android/native_window_jni.h>
#include "base/android/jni_android.h" #include "base/android/jni_android.h"
#include "components/view_manager/native_viewport/platform_viewport_headless.h"
#include "jni/PlatformViewportAndroid_jni.h" #include "jni/PlatformViewportAndroid_jni.h"
#include "mojo/converters/geometry/geometry_type_converters.h" #include "mojo/converters/geometry/geometry_type_converters.h"
#include "mojo/converters/input_events/input_events_type_converters.h" #include "mojo/converters/input_events/input_events_type_converters.h"
...@@ -98,12 +99,8 @@ void PlatformViewportAndroid::SurfaceSetSize(JNIEnv* env, ...@@ -98,12 +99,8 @@ void PlatformViewportAndroid::SurfaceSetSize(JNIEnv* env,
jint width, jint width,
jint height, jint height,
jfloat density) { jfloat density) {
metrics_ = mojo::ViewportMetrics::New(); size_ = gfx::Size(static_cast<int>(width), static_cast<int>(height));
metrics_->size = mojo::Size::New(); delegate_->OnMetricsChanged(size_, density);
metrics_->size->width = static_cast<int>(width);
metrics_->size->height = static_cast<int>(height);
metrics_->device_pixel_ratio = density;
delegate_->OnMetricsChanged(metrics_.Clone());
} }
bool PlatformViewportAndroid::TouchEvent(JNIEnv* env, bool PlatformViewportAndroid::TouchEvent(JNIEnv* env,
...@@ -189,7 +186,7 @@ void PlatformViewportAndroid::Close() { ...@@ -189,7 +186,7 @@ void PlatformViewportAndroid::Close() {
} }
gfx::Size PlatformViewportAndroid::GetSize() { gfx::Size PlatformViewportAndroid::GetSize() {
return metrics_->size.To<gfx::Size>(); return size_;
} }
void PlatformViewportAndroid::SetBounds(const gfx::Rect& bounds) { void PlatformViewportAndroid::SetBounds(const gfx::Rect& bounds) {
...@@ -208,7 +205,11 @@ void PlatformViewportAndroid::ReleaseWindow() { ...@@ -208,7 +205,11 @@ void PlatformViewportAndroid::ReleaseWindow() {
// PlatformViewport, public: // PlatformViewport, public:
// static // static
scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate,
bool headless) {
if (headless)
return PlatformViewportHeadless::Create(delegate);
return scoped_ptr<PlatformViewport>( return scoped_ptr<PlatformViewport>(
new PlatformViewportAndroid(delegate)).Pass(); new PlatformViewportAndroid(delegate)).Pass();
} }
......
...@@ -73,9 +73,10 @@ class PlatformViewportAndroid : public PlatformViewport { ...@@ -73,9 +73,10 @@ class PlatformViewportAndroid : public PlatformViewport {
Delegate* const delegate_; Delegate* const delegate_;
JavaObjectWeakGlobalRef java_platform_viewport_android_; JavaObjectWeakGlobalRef java_platform_viewport_android_;
ANativeWindow* window_; ANativeWindow* window_;
mojo::ViewportMetricsPtr metrics_;
ui::SequentialIDGenerator id_generator_; ui::SequentialIDGenerator id_generator_;
gfx::Size size_;
base::WeakPtrFactory<PlatformViewportAndroid> weak_factory_; base::WeakPtrFactory<PlatformViewportAndroid> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(PlatformViewportAndroid); DISALLOW_COPY_AND_ASSIGN(PlatformViewportAndroid);
......
...@@ -18,7 +18,7 @@ PlatformViewportHeadless::~PlatformViewportHeadless() { ...@@ -18,7 +18,7 @@ PlatformViewportHeadless::~PlatformViewportHeadless() {
void PlatformViewportHeadless::Init(const gfx::Rect& bounds) { void PlatformViewportHeadless::Init(const gfx::Rect& bounds) {
metrics_ = mojo::ViewportMetrics::New(); metrics_ = mojo::ViewportMetrics::New();
metrics_->device_pixel_ratio = 1.f; metrics_->device_pixel_ratio = 1.f;
metrics_->size = mojo::Size::From(bounds.size()); metrics_->size_in_pixels = mojo::Size::From(bounds.size());
} }
void PlatformViewportHeadless::Show() { void PlatformViewportHeadless::Show() {
...@@ -32,12 +32,11 @@ void PlatformViewportHeadless::Close() { ...@@ -32,12 +32,11 @@ void PlatformViewportHeadless::Close() {
} }
gfx::Size PlatformViewportHeadless::GetSize() { gfx::Size PlatformViewportHeadless::GetSize() {
return metrics_->size.To<gfx::Size>(); return metrics_->size_in_pixels.To<gfx::Size>();
} }
void PlatformViewportHeadless::SetBounds(const gfx::Rect& bounds) { void PlatformViewportHeadless::SetBounds(const gfx::Rect& bounds) {
metrics_->size = mojo::Size::From(bounds.size()); delegate_->OnMetricsChanged(bounds.size(), 1.f /* device_scale_factor */);
delegate_->OnMetricsChanged(metrics_->Clone());
} }
// static // static
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "components/view_manager/native_viewport/platform_viewport.h" #include "components/view_manager/native_viewport/platform_viewport.h"
#include "components/view_manager/public/interfaces/view_manager.mojom.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
namespace native_viewport { namespace native_viewport {
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "components/view_manager/native_viewport/platform_viewport_headless.h"
#include "components/view_manager/public/interfaces/view_manager.mojom.h"
#include "mojo/converters/geometry/geometry_type_converters.h" #include "mojo/converters/geometry/geometry_type_converters.h"
#include "mojo/converters/input_events/input_events_type_converters.h" #include "mojo/converters/input_events/input_events_type_converters.h"
#include "mojo/converters/input_events/mojo_extended_key_event_data.h" #include "mojo/converters/input_events/mojo_extended_key_event_data.h"
...@@ -49,7 +51,7 @@ class PlatformViewportX11 : public PlatformViewport, ...@@ -49,7 +51,7 @@ class PlatformViewportX11 : public PlatformViewport,
metrics_ = mojo::ViewportMetrics::New(); metrics_ = mojo::ViewportMetrics::New();
// TODO(sky): make density real. // TODO(sky): make density real.
metrics_->device_pixel_ratio = 1.f; metrics_->device_pixel_ratio = 1.f;
metrics_->size = mojo::Size::From(bounds.size()); metrics_->size_in_pixels = mojo::Size::From(bounds.size());
platform_window_.reset(new ui::X11Window(this)); platform_window_.reset(new ui::X11Window(this));
platform_window_->SetBounds(bounds); platform_window_->SetBounds(bounds);
...@@ -61,7 +63,9 @@ class PlatformViewportX11 : public PlatformViewport, ...@@ -61,7 +63,9 @@ class PlatformViewportX11 : public PlatformViewport,
void Close() override { platform_window_->Close(); } void Close() override { platform_window_->Close(); }
gfx::Size GetSize() override { return metrics_->size.To<gfx::Size>(); } gfx::Size GetSize() override {
return metrics_->size_in_pixels.To<gfx::Size>();
}
void SetBounds(const gfx::Rect& bounds) override { void SetBounds(const gfx::Rect& bounds) override {
platform_window_->SetBounds(bounds); platform_window_->SetBounds(bounds);
...@@ -69,8 +73,9 @@ class PlatformViewportX11 : public PlatformViewport, ...@@ -69,8 +73,9 @@ class PlatformViewportX11 : public PlatformViewport,
// ui::PlatformWindowDelegate: // ui::PlatformWindowDelegate:
void OnBoundsChanged(const gfx::Rect& new_bounds) override { void OnBoundsChanged(const gfx::Rect& new_bounds) override {
metrics_->size = mojo::Size::From(new_bounds.size()); // TODO(fsamuel): Use the real device_scale_factor.
delegate_->OnMetricsChanged(metrics_.Clone()); delegate_->OnMetricsChanged(new_bounds.size(),
1.f /* device_scale_factor */);
} }
void OnDamageRect(const gfx::Rect& damaged_region) override {} void OnDamageRect(const gfx::Rect& damaged_region) override {}
...@@ -158,7 +163,10 @@ class PlatformViewportX11 : public PlatformViewport, ...@@ -158,7 +163,10 @@ class PlatformViewportX11 : public PlatformViewport,
}; };
// static // static
scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate,
bool headless) {
if (headless)
return PlatformViewportHeadless::Create(delegate);
return make_scoped_ptr(new PlatformViewportX11(delegate)); return make_scoped_ptr(new PlatformViewportX11(delegate));
} }
......
...@@ -399,7 +399,7 @@ namespace { ...@@ -399,7 +399,7 @@ namespace {
ViewportMetricsPtr CreateEmptyViewportMetrics() { ViewportMetricsPtr CreateEmptyViewportMetrics() {
ViewportMetricsPtr metrics = ViewportMetrics::New(); ViewportMetricsPtr metrics = ViewportMetrics::New();
metrics->size = Size::New(); metrics->size_in_pixels = Size::New();
// TODO(vtl): The |.Pass()| below is only needed due to an MSVS bug; remove it // TODO(vtl): The |.Pass()| below is only needed due to an MSVS bug; remove it
// once that's fixed. // once that's fixed.
return metrics.Pass(); return metrics.Pass();
......
...@@ -13,7 +13,6 @@ mojom("interfaces") { ...@@ -13,7 +13,6 @@ mojom("interfaces") {
"display.mojom", "display.mojom",
"gpu.mojom", "gpu.mojom",
"gpu_capabilities.mojom", "gpu_capabilities.mojom",
"native_viewport.mojom",
"quads.mojom", "quads.mojom",
"surface_id.mojom", "surface_id.mojom",
"surfaces.mojom", "surfaces.mojom",
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module mojo;
import "components/view_manager/public/interfaces/context_provider.mojom";
import "ui/mojo/geometry/geometry.mojom";
import "ui/mojo/events/input_events.mojom";
struct ViewportMetrics {
Size size;
// A value of 0 indicates the real value is not yet available.
float device_pixel_ratio = 0.0;
};
interface NativeViewport {
// TODO(sky): having a create function is awkward. Should there be a factory
// to create the NativeViewport that takes the size?
Create(Size size) => (ViewportMetrics metrics);
Show();
Hide();
Close();
SetSize(Size size);
SetEventDispatcher(NativeViewportEventDispatcher dispatcher);
// Requests a ContextProvider capable of producing contexts that draw to
// this native viewport.
GetContextProvider(ContextProvider& provider);
// The initial viewport metrics will be sent in the reply to the Create
// method. Call RequestMetrics() to receive updates when the viewport metrics
// change. The reply will be sent when the viewport metrics are different from
// the values last sent, so to receive continuous updates call this method
// again after receiving the callback.
RequestMetrics() => (ViewportMetrics metrics);
};
interface NativeViewportEventDispatcher {
OnEvent(Event event) => ();
};
...@@ -5,13 +5,18 @@ ...@@ -5,13 +5,18 @@
module mojo; module mojo;
import "components/view_manager/public/interfaces/surface_id.mojom"; import "components/view_manager/public/interfaces/surface_id.mojom";
import "components/view_manager/public/interfaces/native_viewport.mojom";
import "components/view_manager/public/interfaces/view_manager_constants.mojom"; import "components/view_manager/public/interfaces/view_manager_constants.mojom";
import "mojo/application/public/interfaces/service_provider.mojom"; import "mojo/application/public/interfaces/service_provider.mojom";
import "network/public/interfaces/url_loader.mojom"; import "network/public/interfaces/url_loader.mojom";
import "ui/mojo/events/input_events.mojom"; import "ui/mojo/events/input_events.mojom";
import "ui/mojo/geometry/geometry.mojom"; import "ui/mojo/geometry/geometry.mojom";
struct ViewportMetrics {
Size size_in_pixels;
// A value of 0 indicates the real value is not yet available.
float device_pixel_ratio = 0.0;
};
struct ViewData { struct ViewData {
uint32 parent_id; uint32 parent_id;
uint32 view_id; uint32 view_id;
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "components/view_manager/client_connection.h" #include "components/view_manager/client_connection.h"
#include "components/view_manager/connection_manager.h" #include "components/view_manager/connection_manager.h"
#include "components/view_manager/display_manager.h" #include "components/view_manager/display_manager.h"
#include "components/view_manager/native_viewport/native_viewport_impl.h"
#include "components/view_manager/public/cpp/args.h" #include "components/view_manager/public/cpp/args.h"
#include "components/view_manager/view_manager_service_impl.h" #include "components/view_manager/view_manager_service_impl.h"
#include "mojo/application/public/cpp/application_connection.h" #include "mojo/application/public/cpp/application_connection.h"
...@@ -24,7 +23,6 @@ using mojo::ApplicationConnection; ...@@ -24,7 +23,6 @@ using mojo::ApplicationConnection;
using mojo::ApplicationImpl; using mojo::ApplicationImpl;
using mojo::Gpu; using mojo::Gpu;
using mojo::InterfaceRequest; using mojo::InterfaceRequest;
using mojo::NativeViewport;
using mojo::ViewManagerRoot; using mojo::ViewManagerRoot;
using mojo::ViewManagerService; using mojo::ViewManagerService;
...@@ -39,12 +37,6 @@ void ViewManagerApp::Initialize(ApplicationImpl* app) { ...@@ -39,12 +37,6 @@ void ViewManagerApp::Initialize(ApplicationImpl* app) {
app_impl_ = app; app_impl_ = app;
tracing_.Initialize(app); tracing_.Initialize(app);
scoped_ptr<DefaultDisplayManager> display_manager(new DefaultDisplayManager(
app_impl_, base::Bind(&ViewManagerApp::OnLostConnectionToWindowManager,
base::Unretained(this))));
connection_manager_.reset(
new ConnectionManager(this, display_manager.Pass()));
#if !defined(OS_ANDROID) #if !defined(OS_ANDROID)
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
is_headless_ = command_line->HasSwitch(mojo::kUseHeadlessConfig); is_headless_ = command_line->HasSwitch(mojo::kUseHeadlessConfig);
...@@ -56,6 +48,17 @@ void ViewManagerApp::Initialize(ApplicationImpl* app) { ...@@ -56,6 +48,17 @@ void ViewManagerApp::Initialize(ApplicationImpl* app) {
gfx::GLSurface::InitializeOneOff(); gfx::GLSurface::InitializeOneOff();
} }
#endif #endif
if (!gpu_state_.get())
gpu_state_ = new gles2::GpuState;
scoped_ptr<DefaultDisplayManager> display_manager(new DefaultDisplayManager(
is_headless_,
app_impl_,
gpu_state_,
base::Bind(&ViewManagerApp::OnLostConnectionToWindowManager,
base::Unretained(this))));
connection_manager_.reset(
new ConnectionManager(this, display_manager.Pass()));
} }
bool ViewManagerApp::ConfigureIncomingConnection( bool ViewManagerApp::ConfigureIncomingConnection(
...@@ -65,7 +68,6 @@ bool ViewManagerApp::ConfigureIncomingConnection( ...@@ -65,7 +68,6 @@ bool ViewManagerApp::ConfigureIncomingConnection(
// to the ViewManager. // to the ViewManager.
connection->AddService<ViewManagerService>(this); connection->AddService<ViewManagerService>(this);
connection->AddService<ViewManagerRoot>(this); connection->AddService<ViewManagerRoot>(this);
connection->AddService<NativeViewport>(this);
connection->AddService<Gpu>(this); connection->AddService<Gpu>(this);
return true; return true;
...@@ -139,18 +141,6 @@ void ViewManagerApp::Create(ApplicationConnection* connection, ...@@ -139,18 +141,6 @@ void ViewManagerApp::Create(ApplicationConnection* connection,
view_manager_root_binding_->set_error_handler(this); view_manager_root_binding_->set_error_handler(this);
} }
void ViewManagerApp::Create(
mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<NativeViewport> request) {
if (!gpu_state_.get())
gpu_state_ = new gles2::GpuState;
new native_viewport::NativeViewportImpl(
is_headless_,
gpu_state_,
request.Pass(),
app_impl_->app_lifetime_helper()->CreateAppRefCount());
}
void ViewManagerApp::Create( void ViewManagerApp::Create(
mojo::ApplicationConnection* connection, mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<Gpu> request) { mojo::InterfaceRequest<Gpu> request) {
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "components/view_manager/connection_manager_delegate.h" #include "components/view_manager/connection_manager_delegate.h"
#include "components/view_manager/gles2/gpu_impl.h" #include "components/view_manager/gles2/gpu_impl.h"
#include "components/view_manager/public/interfaces/native_viewport.mojom.h"
#include "components/view_manager/public/interfaces/view_manager.mojom.h" #include "components/view_manager/public/interfaces/view_manager.mojom.h"
#include "components/view_manager/public/interfaces/view_manager_root.mojom.h" #include "components/view_manager/public/interfaces/view_manager_root.mojom.h"
#include "mojo/application/public/cpp/app_lifetime_helper.h" #include "mojo/application/public/cpp/app_lifetime_helper.h"
...@@ -33,7 +32,6 @@ class ViewManagerApp : public mojo::ApplicationDelegate, ...@@ -33,7 +32,6 @@ class ViewManagerApp : public mojo::ApplicationDelegate,
public mojo::ErrorHandler, public mojo::ErrorHandler,
public mojo::InterfaceFactory<mojo::ViewManagerRoot>, public mojo::InterfaceFactory<mojo::ViewManagerRoot>,
public mojo::InterfaceFactory<mojo::ViewManagerService>, public mojo::InterfaceFactory<mojo::ViewManagerService>,
public mojo::InterfaceFactory<mojo::NativeViewport>,
public mojo::InterfaceFactory<mojo::Gpu> { public mojo::InterfaceFactory<mojo::Gpu> {
public: public:
ViewManagerApp(); ViewManagerApp();
...@@ -71,10 +69,6 @@ class ViewManagerApp : public mojo::ApplicationDelegate, ...@@ -71,10 +69,6 @@ class ViewManagerApp : public mojo::ApplicationDelegate,
void Create(mojo::ApplicationConnection* connection, void Create(mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<mojo::ViewManagerRoot> request) override; mojo::InterfaceRequest<mojo::ViewManagerRoot> request) override;
// mojo::InterfaceFactory<mojo::NativeViewport> implementation.
void Create(mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<mojo::NativeViewport> request) override;
// mojo::InterfaceFactory<mojo::Gpu> implementation. // mojo::InterfaceFactory<mojo::Gpu> implementation.
void Create(mojo::ApplicationConnection* connection, void Create(mojo::ApplicationConnection* connection,
mojo::InterfaceRequest<mojo::Gpu> request) override; mojo::InterfaceRequest<mojo::Gpu> request) override;
......
...@@ -184,7 +184,7 @@ class TestDisplayManager : public DisplayManager { ...@@ -184,7 +184,7 @@ class TestDisplayManager : public DisplayManager {
// DisplayManager: // DisplayManager:
void Init(ConnectionManager* connection_manager, void Init(ConnectionManager* connection_manager,
mojo::NativeViewportEventDispatcherPtr event_dispatcher) override {} EventDispatcher* event_dispatcher) override {}
void SchedulePaint(const ServerView* view, const gfx::Rect& bounds) override { void SchedulePaint(const ServerView* view, const gfx::Rect& bounds) override {
} }
void SetViewportSize(const gfx::Size& size) override {} void SetViewportSize(const gfx::Size& size) override {}
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mojo/runner/android/native_viewport_application_loader.h"
#include "components/view_manager/gles2/gpu_state.h"
#include "components/view_manager/native_viewport/native_viewport_impl.h"
#include "mojo/application/public/cpp/application_impl.h"
namespace mojo {
namespace runner {
NativeViewportApplicationLoader::NativeViewportApplicationLoader() {
}
NativeViewportApplicationLoader::~NativeViewportApplicationLoader() {
}
void NativeViewportApplicationLoader::Load(
const GURL& url,
InterfaceRequest<Application> application_request) {
DCHECK(application_request.is_pending());
app_.reset(new ApplicationImpl(this, application_request.Pass()));
}
bool NativeViewportApplicationLoader::ConfigureIncomingConnection(
ApplicationConnection* connection) {
connection->AddService<NativeViewport>(this);
connection->AddService<Gpu>(this);
return true;
}
void NativeViewportApplicationLoader::Create(
ApplicationConnection* connection,
InterfaceRequest<NativeViewport> request) {
if (!gpu_state_)
gpu_state_ = new gles2::GpuState;
// Pass a null AppRefCount because on Android the NativeViewPort app must
// live on the main thread and we don't want to exit that when all the native
// viewports are gone.
new native_viewport::NativeViewportImpl(
false, gpu_state_, request.Pass(),
make_scoped_ptr<mojo::AppRefCount>(nullptr));
}
void NativeViewportApplicationLoader::Create(ApplicationConnection* connection,
InterfaceRequest<Gpu> request) {
if (!gpu_state_)
gpu_state_ = new gles2::GpuState;
new gles2::GpuImpl(request.Pass(), gpu_state_);
}
} // namespace runner
} // namespace mojo
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MOJO_RUNNER_ANDROID_NATIVE_VIEWPORT_APPLICATION_LOADER_H_
#define MOJO_RUNNER_ANDROID_NATIVE_VIEWPORT_APPLICATION_LOADER_H_
#include "components/view_manager/gles2/gpu_impl.h"
#include "components/view_manager/public/interfaces/gpu.mojom.h"
#include "components/view_manager/public/interfaces/native_viewport.mojom.h"
#include "mojo/application/public/cpp/application_delegate.h"
#include "mojo/application/public/cpp/interface_factory.h"
#include "mojo/shell/application_loader.h"
namespace gles2 {
class GpuState;
}
namespace mojo {
class ApplicationImpl;
namespace runner {
class NativeViewportApplicationLoader : public shell::ApplicationLoader,
public ApplicationDelegate,
public InterfaceFactory<NativeViewport>,
public InterfaceFactory<Gpu> {
public:
NativeViewportApplicationLoader();
~NativeViewportApplicationLoader();
private:
// ApplicationLoader implementation.
void Load(const GURL& url,
InterfaceRequest<Application> application_request) override;
// ApplicationDelegate implementation.
bool ConfigureIncomingConnection(ApplicationConnection* connection) override;
// InterfaceFactory<NativeViewport> implementation.
void Create(ApplicationConnection* connection,
InterfaceRequest<NativeViewport> request) override;
// InterfaceFactory<Gpu> implementation.
void Create(ApplicationConnection* connection,
InterfaceRequest<Gpu> request) override;
scoped_refptr<gles2::GpuState> gpu_state_;
scoped_ptr<ApplicationImpl> app_;
DISALLOW_COPY_AND_ASSIGN(NativeViewportApplicationLoader);
};
} // namespace runner
} // namespace mojo
#endif // MOJO_RUNNER_ANDROID_NATIVE_VIEWPORT_APPLICATION_LOADER_H_
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