Commit 9b949563 authored by erg's avatar erg Committed by Commit bot

core_services: add native_viewport_service on non-android.

This moves native_viewport_service into core_services on desktop
mandoline builds, colocating the service with the surfaces service. We
can't do this on android yet because android does some tricks with the
ApplicationLoader to make the native_viewport_service run in the shell's
main thread.

BUG=484234

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

Cr-Commit-Position: refs/heads/master@{#330201}
parent a9beeba8
......@@ -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",
......
......@@ -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);
}
// 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
// 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_
......@@ -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)
......
......@@ -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",
]
}
}
include_rules = [
"+components/clipboard",
"+components/kiosk_wm",
"+components/native_viewport",
"+components/resource_provider",
"+components/surfaces",
"+components/view_manager",
......
......@@ -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 =
......
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