diff options
author | henrika <henrika@chromium.org> | 2015-06-07 23:57:23 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-08 06:57:55 +0000 |
commit | 57d15367b02b9123792a5c2193185983476a3762 (patch) | |
tree | 935ba47451c70d69a69ffaf39bad1eb4c378f377 | |
parent | 15fb740a49ab3660b8f8d496cfab2e4d37c7e6ca (diff) | |
download | chromium_src-57d15367b02b9123792a5c2193185983476a3762.zip chromium_src-57d15367b02b9123792a5c2193185983476a3762.tar.gz chromium_src-57d15367b02b9123792a5c2193185983476a3762.tar.bz2 |
Revert of Mandoline: Remove native_viewport.mojom (patchset #14 id:250001 of https://codereview.chromium.org/1149083010/)
Reason for revert:
This patch seems to break GN bots on Windows. See e.g. http://build.chromium.org/p/chromium.win/builders/Win8%20GN/builds/8167
Original issue's description:
> 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.
>
> Committed: https://crrev.com/3a4eab3f2f4fd8f7c7eb4d195c0e86a47e085d98
> Cr-Commit-Position: refs/heads/master@{#333183}
TBR=sky@chromium.org,fsamuel@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=487881
Review URL: https://codereview.chromium.org/1164553004
Cr-Commit-Position: refs/heads/master@{#333245}
26 files changed, 542 insertions, 174 deletions
diff --git a/components/html_viewer/DEPS b/components/html_viewer/DEPS index 8867472..baf64b8 100644 --- a/components/html_viewer/DEPS +++ b/components/html_viewer/DEPS @@ -16,7 +16,6 @@ include_rules = [ "+mojo/application", "+mojo/cc", "+mojo/common", - "+mojo/converters/geometry", "+mojo/converters/surfaces", "+mojo/platform_handle", "+mojo/public", diff --git a/components/html_viewer/html_document.cc b/components/html_viewer/html_document.cc index 441de84..80f2130 100644 --- a/components/html_viewer/html_document.cc +++ b/components/html_viewer/html_document.cc @@ -26,7 +26,6 @@ #include "mojo/application/public/cpp/application_impl.h" #include "mojo/application/public/cpp/connect.h" #include "mojo/application/public/interfaces/shell.mojom.h" -#include "mojo/converters/geometry/geometry_type_converters.h" #include "skia/ext/refptr.h" #include "third_party/WebKit/public/platform/Platform.h" #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" @@ -248,9 +247,9 @@ void HTMLDocument::InitSetupAndLoadIfNecessary() { return; if (!web_view_) { - setup_->InitIfNecessary( - root_->viewport_metrics().size_in_pixels.To<gfx::Size>(), - root_->viewport_metrics().device_pixel_ratio); + setup_->InitIfNecessary(gfx::Size(root_->viewport_metrics().size->width, + root_->viewport_metrics().size->height), + root_->viewport_metrics().device_pixel_ratio); Load(response_.Pass()); } diff --git a/components/view_manager/connection_manager.cc b/components/view_manager/connection_manager.cc index 1022048..8555200 100644 --- a/components/view_manager/connection_manager.cc +++ b/components/view_manager/connection_manager.cc @@ -115,17 +115,20 @@ ConnectionManager::ConnectionManager(ConnectionManagerDelegate* delegate, : delegate_(delegate), window_manager_client_connection_(nullptr), next_connection_id_(1), - event_dispatcher_(this), display_manager_(display_manager.Pass()), root_(CreateServerView(RootViewId())), current_change_(nullptr), in_destructor_(false), animation_runner_(base::TimeTicks::Now()), + event_dispatcher_(this), + event_dispatcher_binding_(&event_dispatcher_), focus_controller_(new FocusController(this, root_.get())) { root_->SetBounds(gfx::Rect(800, 600)); root_->SetVisible(true); - display_manager_->Init(this, &event_dispatcher_); + mojo::NativeViewportEventDispatcherPtr event_dispatcher_ptr; + event_dispatcher_binding_.Bind(GetProxy(&event_dispatcher_ptr)); + display_manager_->Init(this, event_dispatcher_ptr.Pass()); } ConnectionManager::~ConnectionManager() { @@ -309,7 +312,7 @@ bool ConnectionManager::CloneAndAnimate(const ViewId& view_id) { } void ConnectionManager::ProcessEvent(mojo::EventPtr event) { - event_dispatcher_.OnEvent(event.Pass()); + event_dispatcher_.OnEvent(event.Pass(), EventDispatcher::OnEventCallback()); } void ConnectionManager::DispatchInputEventToView(const ServerView* view, diff --git a/components/view_manager/connection_manager.h b/components/view_manager/connection_manager.h index d683428..ee3cac1 100644 --- a/components/view_manager/connection_manager.h +++ b/components/view_manager/connection_manager.h @@ -15,6 +15,7 @@ #include "components/view_manager/event_dispatcher.h" #include "components/view_manager/focus_controller_delegate.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_root.mojom.h" #include "components/view_manager/server_view_delegate.h" @@ -252,10 +253,6 @@ class ConnectionManager : public ServerViewDelegate, // Set of ViewManagerServiceImpls. 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<ServerView> root_; @@ -271,6 +268,10 @@ class ConnectionManager : public ServerViewDelegate, AnimationRunner animation_runner_; + EventDispatcher event_dispatcher_; + + mojo::Binding<mojo::NativeViewportEventDispatcher> event_dispatcher_binding_; + scoped_ptr<FocusController> focus_controller_; mojo::ViewManagerRootClientPtr view_manager_root_client_; diff --git a/components/view_manager/display_manager.cc b/components/view_manager/display_manager.cc index 8e51e33..55e881a 100644 --- a/components/view_manager/display_manager.cc +++ b/components/view_manager/display_manager.cc @@ -6,8 +6,6 @@ #include "base/numerics/safe_conversions.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/quads.mojom.h" #include "components/view_manager/public/interfaces/surfaces.mojom.h" @@ -75,57 +73,49 @@ void DrawViewTree(mojo::Pass* pass, } // namespace DefaultDisplayManager::DefaultDisplayManager( - bool is_headless, mojo::ApplicationImpl* app_impl, - const scoped_refptr<gles2::GpuState>& gpu_state, - const mojo::Callback<void()>& platform_viewport_closed_callback) - : is_headless_(is_headless), - app_impl_(app_impl), - gpu_state_(gpu_state), + const mojo::Callback<void()>& native_viewport_closed_callback) + : app_impl_(app_impl), connection_manager_(nullptr), - event_dispatcher_(nullptr), draw_timer_(false, false), frame_pending_(false), - context_provider_( - new native_viewport::OnscreenContextProvider(gpu_state)), - platform_viewport_closed_callback_(platform_viewport_closed_callback), + native_viewport_closed_callback_(native_viewport_closed_callback), weak_factory_(this) { - metrics_.size_in_pixels = mojo::Size::New(); - metrics_.size_in_pixels->width = 800; - metrics_.size_in_pixels->height = 600; + metrics_.size = mojo::Size::New(); + metrics_.size->width = 800; + metrics_.size->height = 600; } void DefaultDisplayManager::Init( ConnectionManager* connection_manager, - EventDispatcher* event_dispatcher) { + mojo::NativeViewportEventDispatcherPtr event_dispatcher) { connection_manager_ = connection_manager; - event_dispatcher_ = event_dispatcher; - - platform_viewport_ = - native_viewport::PlatformViewport::Create(this, is_headless_).Pass(); - platform_viewport_->Init(gfx::Rect(metrics_.size_in_pixels.To<gfx::Size>())); - platform_viewport_->Show(); + mojo::URLRequestPtr request(mojo::URLRequest::New()); + // TODO(beng): should not need to connect to ourselves, should just + // create the appropriate platform window directly. + request->url = mojo::String::From("mojo:view_manager"); + app_impl_->ConnectToService(request.Pass(), + &native_viewport_); + 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; - context_provider_->Bind(GetProxy(&context_provider).Pass()); + native_viewport_->GetContextProvider(GetProxy(&context_provider)); 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); + mojo::URLRequestPtr request2(mojo::URLRequest::New()); + request2->url = mojo::String::From("mojo:surfaces_service"); + app_impl_->ConnectToService(request2.Pass(), &display_factory); display_factory->Create(context_provider.Pass(), nullptr, // returner - we never submit resources. GetProxy(&display_)); + + native_viewport_->SetEventDispatcher(event_dispatcher.Pass()); } 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, @@ -141,7 +131,7 @@ void DefaultDisplayManager::SchedulePaint(const ServerView* view, } void DefaultDisplayManager::SetViewportSize(const gfx::Size& size) { - platform_viewport_->SetBounds(gfx::Rect(size)); + native_viewport_->SetSize(Size::From(size)); } const mojo::ViewportMetrics& DefaultDisplayManager::GetViewportMetrics() { @@ -149,7 +139,7 @@ const mojo::ViewportMetrics& DefaultDisplayManager::GetViewportMetrics() { } void DefaultDisplayManager::Draw() { - gfx::Rect rect(metrics_.size_in_pixels.To<gfx::Size>()); + gfx::Rect rect(metrics_.size->width, metrics_.size->height); auto pass = mojo::CreateDefaultPass(1, rect); pass->damage_rect = Rect::From(dirty_rect_); @@ -180,41 +170,20 @@ void DefaultDisplayManager::WantToDraw() { base::Bind(&DefaultDisplayManager::Draw, base::Unretained(this))); } -void DefaultDisplayManager::OnAcceleratedWidgetAvailable( - gfx::AcceleratedWidget widget, - float device_pixel_ratio) { - context_provider_->SetAcceleratedWidget(widget); -} - -void DefaultDisplayManager::OnAcceleratedWidgetDestroyed() { - 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::OnMetricsChanged(mojo::ViewportMetricsPtr metrics) { + metrics_.size = metrics->size.Clone(); + metrics_.device_pixel_ratio = metrics->device_pixel_ratio; + gfx::Rect bounds(metrics_.size.To<gfx::Size>()); + connection_manager_->root()->SetBounds(bounds); + connection_manager_->ProcessViewportMetricsChanged(metrics_, *metrics); + native_viewport_->RequestMetrics(base::Bind( + &DefaultDisplayManager::OnMetricsChanged, weak_factory_.GetWeakPtr())); } -void DefaultDisplayManager::OnDestroyed() { - if (!platform_viewport_closed_callback_.is_null()) - platform_viewport_closed_callback_.Run(); +void DefaultDisplayManager::OnConnectionError() { + // This is called when the native_viewport is torn down before + // ~DefaultDisplayManager may be called. + native_viewport_closed_callback_.Run(); } } // namespace view_manager diff --git a/components/view_manager/display_manager.h b/components/view_manager/display_manager.h index 6ba94d7..9bbeeca 100644 --- a/components/view_manager/display_manager.h +++ b/components/view_manager/display_manager.h @@ -11,31 +11,22 @@ #include "base/memory/scoped_ptr.h" #include "base/memory/weak_ptr.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/native_viewport.mojom.h" #include "components/view_manager/public/interfaces/view_manager.mojom.h" #include "third_party/mojo/src/mojo/public/cpp/bindings/callback.h" #include "ui/gfx/geometry/rect.h" namespace cc { class SurfaceIdAllocator; -} // namespace cc - -namespace gles2 { -class GpuState; -} // namespace gles2 - -namespace native_viewport { -class OnscreenContextProvider; -} // namespace native_viewport +} namespace mojo { class ApplicationImpl; -} // namespace mojo +} namespace view_manager { -class EventDispatcher; class ConnectionManager; class ServerView; @@ -46,7 +37,7 @@ class DisplayManager { virtual void Init( ConnectionManager* connection_manager, - EventDispatcher* event_dispatcher) = 0; + mojo::NativeViewportEventDispatcherPtr event_dispatcher) = 0; // Schedules a paint for the specified region in the coordinates of |view|. virtual void SchedulePaint(const ServerView* view, @@ -59,20 +50,17 @@ class DisplayManager { // DisplayManager implementation that connects to the services necessary to // actually display. -class DefaultDisplayManager : - public DisplayManager, - public native_viewport::PlatformViewport::Delegate { +class DefaultDisplayManager : public DisplayManager, + public mojo::ErrorHandler { public: DefaultDisplayManager( - bool is_headless, mojo::ApplicationImpl* app_impl, - const scoped_refptr<gles2::GpuState>& gpu_state, - const mojo::Callback<void()>& platform_viewport_closed_callback); + const mojo::Callback<void()>& native_viewport_closed_callback); ~DefaultDisplayManager() override; // DisplayManager: void Init(ConnectionManager* connection_manager, - EventDispatcher* event_dispatcher) override; + mojo::NativeViewportEventDispatcherPtr event_dispatcher) override; void SchedulePaint(const ServerView* view, const gfx::Rect& bounds) override; void SetViewportSize(const gfx::Size& size) override; const mojo::ViewportMetrics& GetViewportMetrics() override; @@ -82,20 +70,13 @@ class DefaultDisplayManager : void Draw(); void DidDraw(); - // PlatformViewport::Delegate implementation: - void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget, - float device_pixel_ratio) override; - void OnAcceleratedWidgetDestroyed() override; - void OnEvent(mojo::EventPtr event) override; - void OnMetricsChanged(const gfx::Size& size, - float device_scale_factor) override; - void OnDestroyed() override; + void OnMetricsChanged(mojo::ViewportMetricsPtr metrics); + + // ErrorHandler: + void OnConnectionError() override; - bool is_headless_; mojo::ApplicationImpl* app_impl_; - scoped_refptr<gles2::GpuState> gpu_state_; ConnectionManager* connection_manager_; - EventDispatcher* event_dispatcher_; mojo::ViewportMetrics metrics_; gfx::Rect dirty_rect_; @@ -103,10 +84,8 @@ class DefaultDisplayManager : bool frame_pending_; mojo::DisplayPtr display_; - scoped_ptr<native_viewport::OnscreenContextProvider> context_provider_; - scoped_ptr<native_viewport::PlatformViewport> platform_viewport_; - mojo::Callback<void()> platform_viewport_closed_callback_; - + mojo::NativeViewportPtr native_viewport_; + mojo::Callback<void()> native_viewport_closed_callback_; base::WeakPtrFactory<DefaultDisplayManager> weak_factory_; DISALLOW_COPY_AND_ASSIGN(DefaultDisplayManager); diff --git a/components/view_manager/event_dispatcher.cc b/components/view_manager/event_dispatcher.cc index edc2bc5..a06e7c2 100644 --- a/components/view_manager/event_dispatcher.cc +++ b/components/view_manager/event_dispatcher.cc @@ -30,11 +30,15 @@ void EventDispatcher::RemoveAccelerator(mojo::KeyboardCode keyboard_code, 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) { const gfx::Point root_point(static_cast<int>(event->pointer_data->x), static_cast<int>(event->pointer_data->y)); ServerView* target = connection_manager_->GetFocusedView(); + ; if (event->action == mojo::EVENT_TYPE_POINTER_DOWN || !target) { target = FindDeepestVisibleView(connection_manager_->root(), root_point); CHECK(target); diff --git a/components/view_manager/event_dispatcher.h b/components/view_manager/event_dispatcher.h index a2d4514..9716f06 100644 --- a/components/view_manager/event_dispatcher.h +++ b/components/view_manager/event_dispatcher.h @@ -8,25 +8,24 @@ #include <set> #include "base/basictypes.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" +#include "components/view_manager/public/interfaces/native_viewport.mojom.h" namespace view_manager { class ConnectionManager; // Handles dispatching events to the right location as well as updating focus. -class EventDispatcher { +class EventDispatcher : public mojo::NativeViewportEventDispatcher { public: explicit EventDispatcher(ConnectionManager* connection_manager); - ~EventDispatcher(); + ~EventDispatcher() override; void AddAccelerator(mojo::KeyboardCode keyboard_code, mojo::EventFlags flags); void RemoveAccelerator(mojo::KeyboardCode keyboard_code, mojo::EventFlags flags); - void OnEvent(mojo::EventPtr event); + // NativeViewportEventDispatcher: + void OnEvent(mojo::EventPtr event, const OnEventCallback& callback) override; private: struct Accelerator { diff --git a/components/view_manager/native_viewport/BUILD.gn b/components/view_manager/native_viewport/BUILD.gn index 123e40e..1201bd4 100644 --- a/components/view_manager/native_viewport/BUILD.gn +++ b/components/view_manager/native_viewport/BUILD.gn @@ -7,6 +7,8 @@ import("//third_party/mojo/src/mojo/public/mojo_application.gni") source_set("native_viewport") { sources = [ + "native_viewport_impl.cc", + "native_viewport_impl.h", "onscreen_context_provider.cc", "onscreen_context_provider.h", "platform_viewport.h", diff --git a/components/view_manager/native_viewport/native_viewport_impl.cc b/components/view_manager/native_viewport/native_viewport_impl.cc new file mode 100644 index 0000000..e990cbd --- /dev/null +++ b/components/view_manager/native_viewport/native_viewport_impl.cc @@ -0,0 +1,166 @@ +// 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 diff --git a/components/view_manager/native_viewport/native_viewport_impl.h b/components/view_manager/native_viewport/native_viewport_impl.h new file mode 100644 index 0000000..2c21b14 --- /dev/null +++ b/components/view_manager/native_viewport/native_viewport_impl.h @@ -0,0 +1,90 @@ +// 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_ diff --git a/components/view_manager/native_viewport/platform_viewport.h b/components/view_manager/native_viewport/platform_viewport.h index f57adb9..6bc62ca 100644 --- a/components/view_manager/native_viewport/platform_viewport.h +++ b/components/view_manager/native_viewport/platform_viewport.h @@ -6,6 +6,7 @@ #define COMPONENTS_VIEW_MANAGER_NATIVE_VIEWPORT_PLATFORM_VIEWPORT_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/native_widget_types.h" #include "ui/mojo/events/input_events.mojom.h" @@ -23,13 +24,12 @@ class PlatformViewport { public: virtual ~Delegate() {} + virtual void OnMetricsChanged(mojo::ViewportMetricsPtr metrics) = 0; virtual void OnAcceleratedWidgetAvailable(gfx::AcceleratedWidget widget, float device_pixel_ratio) = 0; virtual void OnAcceleratedWidgetDestroyed() = 0; + virtual bool OnEvent(mojo::EventPtr event) = 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() {} @@ -41,7 +41,7 @@ class PlatformViewport { virtual gfx::Size GetSize() = 0; virtual void SetBounds(const gfx::Rect& bounds) = 0; - static scoped_ptr<PlatformViewport> Create(Delegate* delegate, bool headless); + static scoped_ptr<PlatformViewport> Create(Delegate* delegate); }; } // namespace native_viewport diff --git a/components/view_manager/native_viewport/platform_viewport_android.cc b/components/view_manager/native_viewport/platform_viewport_android.cc index f5d47be..ccca113 100644 --- a/components/view_manager/native_viewport/platform_viewport_android.cc +++ b/components/view_manager/native_viewport/platform_viewport_android.cc @@ -8,7 +8,6 @@ #include <android/native_window_jni.h> #include "base/android/jni_android.h" -#include "components/view_manager/native_viewport/platform_viewport_headless.h" #include "jni/PlatformViewportAndroid_jni.h" #include "mojo/converters/geometry/geometry_type_converters.h" #include "mojo/converters/input_events/input_events_type_converters.h" @@ -99,8 +98,12 @@ void PlatformViewportAndroid::SurfaceSetSize(JNIEnv* env, jint width, jint height, jfloat density) { - size_ = gfx::Size(static_cast<int>(width), static_cast<int>(height)); - delegate_->OnMetricsChanged(size_, density); + metrics_ = mojo::ViewportMetrics::New(); + metrics_->size = mojo::Size::New(); + 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, @@ -186,7 +189,7 @@ void PlatformViewportAndroid::Close() { } gfx::Size PlatformViewportAndroid::GetSize() { - return size_; + return metrics_->size.To<gfx::Size>(); } void PlatformViewportAndroid::SetBounds(const gfx::Rect& bounds) { @@ -205,11 +208,7 @@ void PlatformViewportAndroid::ReleaseWindow() { // PlatformViewport, public: // static -scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate, - bool headless) { - if (headless) - return PlatformViewportHeadless::Create(delegate); - +scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { return scoped_ptr<PlatformViewport>( new PlatformViewportAndroid(delegate)).Pass(); } diff --git a/components/view_manager/native_viewport/platform_viewport_android.h b/components/view_manager/native_viewport/platform_viewport_android.h index 3eba7cc..467614b 100644 --- a/components/view_manager/native_viewport/platform_viewport_android.h +++ b/components/view_manager/native_viewport/platform_viewport_android.h @@ -73,10 +73,9 @@ class PlatformViewportAndroid : public PlatformViewport { Delegate* const delegate_; JavaObjectWeakGlobalRef java_platform_viewport_android_; ANativeWindow* window_; + mojo::ViewportMetricsPtr metrics_; ui::SequentialIDGenerator id_generator_; - gfx::Size size_; - base::WeakPtrFactory<PlatformViewportAndroid> weak_factory_; DISALLOW_COPY_AND_ASSIGN(PlatformViewportAndroid); diff --git a/components/view_manager/native_viewport/platform_viewport_headless.cc b/components/view_manager/native_viewport/platform_viewport_headless.cc index a758a50..3918b18 100644 --- a/components/view_manager/native_viewport/platform_viewport_headless.cc +++ b/components/view_manager/native_viewport/platform_viewport_headless.cc @@ -18,7 +18,7 @@ PlatformViewportHeadless::~PlatformViewportHeadless() { void PlatformViewportHeadless::Init(const gfx::Rect& bounds) { metrics_ = mojo::ViewportMetrics::New(); metrics_->device_pixel_ratio = 1.f; - metrics_->size_in_pixels = mojo::Size::From(bounds.size()); + metrics_->size = mojo::Size::From(bounds.size()); } void PlatformViewportHeadless::Show() { @@ -32,11 +32,12 @@ void PlatformViewportHeadless::Close() { } gfx::Size PlatformViewportHeadless::GetSize() { - return metrics_->size_in_pixels.To<gfx::Size>(); + return metrics_->size.To<gfx::Size>(); } void PlatformViewportHeadless::SetBounds(const gfx::Rect& bounds) { - delegate_->OnMetricsChanged(bounds.size(), 1.f /* device_scale_factor */); + metrics_->size = mojo::Size::From(bounds.size()); + delegate_->OnMetricsChanged(metrics_->Clone()); } // static diff --git a/components/view_manager/native_viewport/platform_viewport_headless.h b/components/view_manager/native_viewport/platform_viewport_headless.h index 924f3a5..949bc31 100644 --- a/components/view_manager/native_viewport/platform_viewport_headless.h +++ b/components/view_manager/native_viewport/platform_viewport_headless.h @@ -7,7 +7,6 @@ #include "base/macros.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" namespace native_viewport { diff --git a/components/view_manager/native_viewport/platform_viewport_x11.cc b/components/view_manager/native_viewport/platform_viewport_x11.cc index c661fb5..d0f6976 100644 --- a/components/view_manager/native_viewport/platform_viewport_x11.cc +++ b/components/view_manager/native_viewport/platform_viewport_x11.cc @@ -6,8 +6,6 @@ #include "base/command_line.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/input_events/input_events_type_converters.h" #include "mojo/converters/input_events/mojo_extended_key_event_data.h" @@ -51,7 +49,7 @@ class PlatformViewportX11 : public PlatformViewport, metrics_ = mojo::ViewportMetrics::New(); // TODO(sky): make density real. metrics_->device_pixel_ratio = 1.f; - metrics_->size_in_pixels = mojo::Size::From(bounds.size()); + metrics_->size = mojo::Size::From(bounds.size()); platform_window_.reset(new ui::X11Window(this)); platform_window_->SetBounds(bounds); @@ -63,9 +61,7 @@ class PlatformViewportX11 : public PlatformViewport, void Close() override { platform_window_->Close(); } - gfx::Size GetSize() override { - return metrics_->size_in_pixels.To<gfx::Size>(); - } + gfx::Size GetSize() override { return metrics_->size.To<gfx::Size>(); } void SetBounds(const gfx::Rect& bounds) override { platform_window_->SetBounds(bounds); @@ -73,9 +69,8 @@ class PlatformViewportX11 : public PlatformViewport, // ui::PlatformWindowDelegate: void OnBoundsChanged(const gfx::Rect& new_bounds) override { - // TODO(fsamuel): Use the real device_scale_factor. - delegate_->OnMetricsChanged(new_bounds.size(), - 1.f /* device_scale_factor */); + metrics_->size = mojo::Size::From(new_bounds.size()); + delegate_->OnMetricsChanged(metrics_.Clone()); } void OnDamageRect(const gfx::Rect& damaged_region) override {} @@ -163,10 +158,7 @@ class PlatformViewportX11 : public PlatformViewport, }; // static -scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate, - bool headless) { - if (headless) - return PlatformViewportHeadless::Create(delegate); +scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { return make_scoped_ptr(new PlatformViewportX11(delegate)); } diff --git a/components/view_manager/public/cpp/lib/view.cc b/components/view_manager/public/cpp/lib/view.cc index 3497dfa..cc78b6c 100644 --- a/components/view_manager/public/cpp/lib/view.cc +++ b/components/view_manager/public/cpp/lib/view.cc @@ -399,7 +399,7 @@ namespace { ViewportMetricsPtr CreateEmptyViewportMetrics() { ViewportMetricsPtr metrics = ViewportMetrics::New(); - metrics->size_in_pixels = Size::New(); + metrics->size = Size::New(); // TODO(vtl): The |.Pass()| below is only needed due to an MSVS bug; remove it // once that's fixed. return metrics.Pass(); diff --git a/components/view_manager/public/interfaces/BUILD.gn b/components/view_manager/public/interfaces/BUILD.gn index 09afdb9..88330c4 100644 --- a/components/view_manager/public/interfaces/BUILD.gn +++ b/components/view_manager/public/interfaces/BUILD.gn @@ -13,6 +13,7 @@ mojom("interfaces") { "display.mojom", "gpu.mojom", "gpu_capabilities.mojom", + "native_viewport.mojom", "quads.mojom", "surface_id.mojom", "surfaces.mojom", diff --git a/components/view_manager/public/interfaces/native_viewport.mojom b/components/view_manager/public/interfaces/native_viewport.mojom new file mode 100644 index 0000000..220fc53 --- /dev/null +++ b/components/view_manager/public/interfaces/native_viewport.mojom @@ -0,0 +1,42 @@ +// 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) => (); +}; diff --git a/components/view_manager/public/interfaces/view_manager.mojom b/components/view_manager/public/interfaces/view_manager.mojom index 70afc08..a20533f 100644 --- a/components/view_manager/public/interfaces/view_manager.mojom +++ b/components/view_manager/public/interfaces/view_manager.mojom @@ -5,18 +5,13 @@ module mojo; 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 "mojo/application/public/interfaces/service_provider.mojom"; import "network/public/interfaces/url_loader.mojom"; import "ui/mojo/events/input_events.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 { uint32 parent_id; uint32 view_id; diff --git a/components/view_manager/view_manager_app.cc b/components/view_manager/view_manager_app.cc index 0dac932..75ffcde 100644 --- a/components/view_manager/view_manager_app.cc +++ b/components/view_manager/view_manager_app.cc @@ -8,6 +8,7 @@ #include "components/view_manager/client_connection.h" #include "components/view_manager/connection_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/view_manager_service_impl.h" #include "mojo/application/public/cpp/application_connection.h" @@ -23,6 +24,7 @@ using mojo::ApplicationConnection; using mojo::ApplicationImpl; using mojo::Gpu; using mojo::InterfaceRequest; +using mojo::NativeViewport; using mojo::ViewManagerRoot; using mojo::ViewManagerService; @@ -37,6 +39,12 @@ void ViewManagerApp::Initialize(ApplicationImpl* app) { app_impl_ = 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) base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); is_headless_ = command_line->HasSwitch(mojo::kUseHeadlessConfig); @@ -48,17 +56,6 @@ void ViewManagerApp::Initialize(ApplicationImpl* app) { gfx::GLSurface::InitializeOneOff(); } #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( @@ -68,6 +65,7 @@ bool ViewManagerApp::ConfigureIncomingConnection( // to the ViewManager. connection->AddService<ViewManagerService>(this); connection->AddService<ViewManagerRoot>(this); + connection->AddService<NativeViewport>(this); connection->AddService<Gpu>(this); return true; @@ -143,6 +141,18 @@ void ViewManagerApp::Create(ApplicationConnection* connection, 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( + mojo::ApplicationConnection* connection, mojo::InterfaceRequest<Gpu> request) { if (!gpu_state_.get()) gpu_state_ = new gles2::GpuState; diff --git a/components/view_manager/view_manager_app.h b/components/view_manager/view_manager_app.h index a2fa9dd..1a39c28 100644 --- a/components/view_manager/view_manager_app.h +++ b/components/view_manager/view_manager_app.h @@ -8,6 +8,7 @@ #include "base/memory/scoped_ptr.h" #include "components/view_manager/connection_manager_delegate.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_root.mojom.h" #include "mojo/application/public/cpp/app_lifetime_helper.h" @@ -32,6 +33,7 @@ class ViewManagerApp : public mojo::ApplicationDelegate, public mojo::ErrorHandler, public mojo::InterfaceFactory<mojo::ViewManagerRoot>, public mojo::InterfaceFactory<mojo::ViewManagerService>, + public mojo::InterfaceFactory<mojo::NativeViewport>, public mojo::InterfaceFactory<mojo::Gpu> { public: ViewManagerApp(); @@ -69,6 +71,10 @@ class ViewManagerApp : public mojo::ApplicationDelegate, void Create(mojo::ApplicationConnection* connection, 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. void Create(mojo::ApplicationConnection* connection, mojo::InterfaceRequest<mojo::Gpu> request) override; diff --git a/components/view_manager/view_manager_service_unittest.cc b/components/view_manager/view_manager_service_unittest.cc index 6166449..970b47e 100644 --- a/components/view_manager/view_manager_service_unittest.cc +++ b/components/view_manager/view_manager_service_unittest.cc @@ -184,7 +184,7 @@ class TestDisplayManager : public DisplayManager { // DisplayManager: void Init(ConnectionManager* connection_manager, - EventDispatcher* event_dispatcher) override {} + mojo::NativeViewportEventDispatcherPtr event_dispatcher) override {} void SchedulePaint(const ServerView* view, const gfx::Rect& bounds) override { } void SetViewportSize(const gfx::Size& size) override {} diff --git a/mojo/runner/android/native_viewport_application_loader.cc b/mojo/runner/android/native_viewport_application_loader.cc new file mode 100644 index 0000000..55979c7 --- /dev/null +++ b/mojo/runner/android/native_viewport_application_loader.cc @@ -0,0 +1,55 @@ +// 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 diff --git a/mojo/runner/android/native_viewport_application_loader.h b/mojo/runner/android/native_viewport_application_loader.h new file mode 100644 index 0000000..25b02fd --- /dev/null +++ b/mojo/runner/android/native_viewport_application_loader.h @@ -0,0 +1,58 @@ +// 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_ |