diff options
8 files changed, 136 insertions, 72 deletions
diff --git a/components/native_viewport/BUILD.gn b/components/native_viewport/BUILD.gn index 5b27f1d..a313b26 100644 --- a/components/native_viewport/BUILD.gn +++ b/components/native_viewport/BUILD.gn @@ -57,6 +57,8 @@ if (is_android) { source_set("lib") { sources = [ + "native_viewport_application_delegate.cc", + "native_viewport_application_delegate.h", "native_viewport_impl.cc", "native_viewport_impl.h", "onscreen_context_provider.cc", diff --git a/components/native_viewport/main.cc b/components/native_viewport/main.cc index 7cc3323..1a749f4 100644 --- a/components/native_viewport/main.cc +++ b/components/native_viewport/main.cc @@ -2,83 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/command_line.h" -#include "base/macros.h" #include "base/message_loop/message_loop.h" -#include "components/gles2/gpu_impl.h" -#include "components/native_viewport/native_viewport_impl.h" -#include "components/native_viewport/public/cpp/args.h" +#include "components/native_viewport/native_viewport_application_delegate.h" #include "mojo/application/application_runner_chromium.h" -#include "mojo/application/public/cpp/application_connection.h" -#include "mojo/application/public/cpp/application_delegate.h" -#include "mojo/application/public/cpp/application_impl.h" -#include "mojo/application/public/cpp/interface_factory_impl.h" -#include "mojo/common/tracing_impl.h" #include "third_party/mojo/src/mojo/public/c/system/main.h" -#include "ui/events/event_switches.h" -#include "ui/gl/gl_surface.h" - -using mojo::ApplicationConnection; -using mojo::Gpu; -using mojo::NativeViewport; - -namespace native_viewport { - -class NativeViewportAppDelegate : public mojo::ApplicationDelegate, - public mojo::InterfaceFactory<NativeViewport>, - public mojo::InterfaceFactory<Gpu> { - public: - NativeViewportAppDelegate() : is_headless_(false) {} - ~NativeViewportAppDelegate() override {} - - private: - // mojo::ApplicationDelegate implementation. - void Initialize(mojo::ApplicationImpl* application) override { - tracing_.Initialize(application); - - base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); - is_headless_ = command_line->HasSwitch(mojo::kUseHeadlessConfig); - if (!is_headless_) { - if (command_line->HasSwitch(mojo::kUseTestConfig)) - gfx::GLSurface::InitializeOneOffForTests(); - else - gfx::GLSurface::InitializeOneOff(); - } - } - - bool ConfigureIncomingConnection(ApplicationConnection* connection) override { - connection->AddService<NativeViewport>(this); - connection->AddService<Gpu>(this); - return true; - } - - // mojo::InterfaceFactory<NativeViewport> implementation. - void Create(ApplicationConnection* connection, - mojo::InterfaceRequest<NativeViewport> request) override { - if (!gpu_state_.get()) - gpu_state_ = new gles2::GpuState; - new NativeViewportImpl(is_headless_, gpu_state_, request.Pass()); - } - - // mojo::InterfaceFactory<Gpu> implementation. - void Create(ApplicationConnection* connection, - mojo::InterfaceRequest<Gpu> request) override { - if (!gpu_state_.get()) - gpu_state_ = new gles2::GpuState; - new gles2::GpuImpl(request.Pass(), gpu_state_); - } - - scoped_refptr<gles2::GpuState> gpu_state_; - bool is_headless_; - mojo::TracingImpl tracing_; - - DISALLOW_COPY_AND_ASSIGN(NativeViewportAppDelegate); -}; -} MojoResult MojoMain(MojoHandle shell_handle) { mojo::ApplicationRunnerChromium runner( - new native_viewport::NativeViewportAppDelegate); + new native_viewport::NativeViewportApplicationDelegate); runner.set_message_loop_type(base::MessageLoop::TYPE_UI); return runner.Run(shell_handle); } diff --git a/components/native_viewport/native_viewport_application_delegate.cc b/components/native_viewport/native_viewport_application_delegate.cc new file mode 100644 index 0000000..4f247c7 --- /dev/null +++ b/components/native_viewport/native_viewport_application_delegate.cc @@ -0,0 +1,61 @@ +// Copyright 2015 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/native_viewport/native_viewport_application_delegate.h" + +#include "base/command_line.h" +#include "components/native_viewport/native_viewport_impl.h" +#include "components/native_viewport/public/cpp/args.h" +#include "mojo/application/public/cpp/application_connection.h" +#include "mojo/application/public/cpp/application_impl.h" +#include "ui/events/event_switches.h" +#include "ui/gl/gl_surface.h" + +namespace native_viewport { + +NativeViewportApplicationDelegate::NativeViewportApplicationDelegate() + : is_headless_(false) { +} + +NativeViewportApplicationDelegate::~NativeViewportApplicationDelegate() { +} + +void NativeViewportApplicationDelegate::Initialize( + mojo::ApplicationImpl* application) { + tracing_.Initialize(application); + + base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); + is_headless_ = command_line->HasSwitch(mojo::kUseHeadlessConfig); + if (!is_headless_) { + if (command_line->HasSwitch(mojo::kUseTestConfig)) + gfx::GLSurface::InitializeOneOffForTests(); + else + gfx::GLSurface::InitializeOneOff(); + } +} + +bool NativeViewportApplicationDelegate::ConfigureIncomingConnection( + mojo::ApplicationConnection* connection) { + connection->AddService<mojo::NativeViewport>(this); + connection->AddService<mojo::Gpu>(this); + return true; +} + +void NativeViewportApplicationDelegate::Create( + mojo::ApplicationConnection* connection, + mojo::InterfaceRequest<mojo::NativeViewport> request) { + if (!gpu_state_.get()) + gpu_state_ = new gles2::GpuState; + new NativeViewportImpl(is_headless_, gpu_state_, request.Pass()); +} + +void NativeViewportApplicationDelegate::Create( + mojo::ApplicationConnection* connection, + mojo::InterfaceRequest<mojo::Gpu> request) { + if (!gpu_state_.get()) + gpu_state_ = new gles2::GpuState; + new gles2::GpuImpl(request.Pass(), gpu_state_); +} + +} // namespace native_viewport diff --git a/components/native_viewport/native_viewport_application_delegate.h b/components/native_viewport/native_viewport_application_delegate.h new file mode 100644 index 0000000..4584fff --- /dev/null +++ b/components/native_viewport/native_viewport_application_delegate.h @@ -0,0 +1,53 @@ +// Copyright 2015 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_NATIVE_VIEWPORT_NATIVE_VIEWPORT_APPLICATION_DELEGATE_H_ +#define COMPONENTS_NATIVE_VIEWPORT_NATIVE_VIEWPORT_APPLICATION_DELEGATE_H_ + +#include "base/macros.h" +#include "components/gles2/gpu_impl.h" +#include "components/native_viewport/public/interfaces/native_viewport.mojom.h" +#include "mojo/application/public/cpp/application_delegate.h" +#include "mojo/application/public/cpp/interface_factory_impl.h" +#include "mojo/common/tracing_impl.h" + +namespace mojo { +class ApplicationConnection; +class ApplicationImpl; +} + +namespace native_viewport { + +class NativeViewportApplicationDelegate + : public mojo::ApplicationDelegate, + public mojo::InterfaceFactory<mojo::NativeViewport>, + public mojo::InterfaceFactory<mojo::Gpu> { + public: + NativeViewportApplicationDelegate(); + ~NativeViewportApplicationDelegate() override; + + private: + // mojo::ApplicationDelegate implementation. + void Initialize(mojo::ApplicationImpl* application) override; + bool ConfigureIncomingConnection( + mojo::ApplicationConnection* connection) override; + + // mojo::InterfaceFactory<NativeViewport> implementation. + void Create(mojo::ApplicationConnection* connection, + mojo::InterfaceRequest<mojo::NativeViewport> request) override; + + // mojo::InterfaceFactory<Gpu> implementation. + void Create(mojo::ApplicationConnection* connection, + mojo::InterfaceRequest<mojo::Gpu> request) override; + + scoped_refptr<gles2::GpuState> gpu_state_; + bool is_headless_; + mojo::TracingImpl tracing_; + + DISALLOW_COPY_AND_ASSIGN(NativeViewportApplicationDelegate); +}; + +} // namespace native_viewport + +#endif // COMPONENTS_NATIVE_VIEWPORT_NATIVE_VIEWPORT_APPLICATION_DELEGATE_H_ diff --git a/mandoline/app/core_services_initialization.cc b/mandoline/app/core_services_initialization.cc index 5eeb30c..612dd2b 100644 --- a/mandoline/app/core_services_initialization.cc +++ b/mandoline/app/core_services_initialization.cc @@ -14,6 +14,11 @@ void InitCoreServicesForContext(mojo::runner::Context* context) { mojo::shell::ApplicationManager* manager = context->application_manager(); manager->RegisterApplicationPackageAlias(GURL("mojo:clipboard"), GURL("mojo:core_services"), "Core"); +#if !defined(OS_ANDROID) + manager->RegisterApplicationPackageAlias(GURL("mojo:native_viewport_service"), + GURL("mojo:core_services"), + "Surfaces"); +#endif manager->RegisterApplicationPackageAlias( GURL("mojo:network_service"), GURL("mojo:core_services"), "Network"); #if !defined(OS_ANDROID) diff --git a/mandoline/services/core_services/BUILD.gn b/mandoline/services/core_services/BUILD.gn index eecacaf..19ec9af 100644 --- a/mandoline/services/core_services/BUILD.gn +++ b/mandoline/services/core_services/BUILD.gn @@ -76,6 +76,10 @@ source_set("sources") { ] if (!is_android) { - deps += [ "//mandoline/ui/omnibox:lib" ] + deps += [ + "//components/native_viewport:lib", + "//components/native_viewport/public/cpp:args", + "//mandoline/ui/omnibox:lib", + ] } } diff --git a/mandoline/services/core_services/DEPS b/mandoline/services/core_services/DEPS index 5234781..2035162 100644 --- a/mandoline/services/core_services/DEPS +++ b/mandoline/services/core_services/DEPS @@ -1,6 +1,7 @@ include_rules = [ "+components/clipboard", "+components/kiosk_wm", + "+components/native_viewport", "+components/resource_provider", "+components/surfaces", "+components/view_manager", diff --git a/mandoline/services/core_services/core_services_application_delegate.cc b/mandoline/services/core_services/core_services_application_delegate.cc index 5104cac..5eeb52c 100644 --- a/mandoline/services/core_services/core_services_application_delegate.cc +++ b/mandoline/services/core_services/core_services_application_delegate.cc @@ -6,6 +6,7 @@ #include "base/bind.h" #include "components/clipboard/clipboard_application_delegate.h" +#include "components/native_viewport/native_viewport_application_delegate.h" #include "components/resource_provider/resource_provider_app.h" #include "components/surfaces/surfaces_service_application.h" #include "components/view_manager/view_manager_app.h" @@ -128,6 +129,10 @@ void CoreServicesApplicationDelegate::StartApplication( scoped_ptr<mojo::ApplicationDelegate> delegate; if (url == "mojo://clipboard/") delegate.reset(new clipboard::ClipboardApplicationDelegate); +#if !defined(OS_ANDROID) + else if (url == "mojo://native_viewport_service/") + delegate.reset(new native_viewport::NativeViewportApplicationDelegate); +#endif else if (url == "mojo://network_service/") delegate.reset(new NetworkServiceDelegate); #if !defined(OS_ANDROID) @@ -152,6 +157,8 @@ void CoreServicesApplicationDelegate::StartApplication( // In the case of mojo:network_service, we must use an IO message loop. if (url == "mojo://network_service/") { thread_options.message_loop_type = base::MessageLoop::TYPE_IO; + } else if (url == "mojo://native_viewport_service/") { + thread_options.message_loop_type = base::MessageLoop::TYPE_UI; } else { // We must use a MessagePumpMojo to awake on mojo messages. thread_options.message_pump_factory = |