Commit cff892f9 authored by abarth's avatar abarth Committed by Commit bot

Add a headless configuration to Mojo's native viewport service

Rather than talking to X11, in headless mode, the native viewport service just
drops requests on the floor. This configuration is useful for writing
integration tests for the Mojo system that don't need to interact with X11.

R=jamesr@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#296846}
parent 9c49ac15
...@@ -364,6 +364,8 @@ ...@@ -364,6 +364,8 @@
'services/native_viewport/native_viewport_impl.h', 'services/native_viewport/native_viewport_impl.h',
'services/native_viewport/platform_viewport.h', 'services/native_viewport/platform_viewport.h',
'services/native_viewport/platform_viewport_android.cc', 'services/native_viewport/platform_viewport_android.cc',
'services/native_viewport/platform_viewport_headless.cc',
'services/native_viewport/platform_viewport_headless.h',
'services/native_viewport/platform_viewport_mac.mm', 'services/native_viewport/platform_viewport_mac.mm',
'services/native_viewport/platform_viewport_ozone.cc', 'services/native_viewport/platform_viewport_ozone.cc',
'services/native_viewport/platform_viewport_stub.cc', 'services/native_viewport/platform_viewport_stub.cc',
......
...@@ -55,6 +55,8 @@ source_set("lib") { ...@@ -55,6 +55,8 @@ source_set("lib") {
"platform_viewport_android.cc", "platform_viewport_android.cc",
"platform_viewport_android.h", "platform_viewport_android.h",
"platform_viewport_mac.mm", "platform_viewport_mac.mm",
"platform_viewport_headless.cc",
"platform_viewport_headless.h",
"platform_viewport_win.cc", "platform_viewport_win.cc",
"viewport_surface.cc", "viewport_surface.cc",
"viewport_surface.h", "viewport_surface.h",
......
...@@ -26,6 +26,7 @@ class NativeViewportAppDelegate ...@@ -26,6 +26,7 @@ class NativeViewportAppDelegate
: share_group_(new gfx::GLShareGroup), : share_group_(new gfx::GLShareGroup),
mailbox_manager_(new gpu::gles2::MailboxManager), mailbox_manager_(new gpu::gles2::MailboxManager),
is_test_(false), is_test_(false),
is_headless_(false),
is_initialized_(false) {} is_initialized_(false) {}
virtual ~NativeViewportAppDelegate() {} virtual ~NativeViewportAppDelegate() {}
...@@ -36,11 +37,17 @@ class NativeViewportAppDelegate ...@@ -36,11 +37,17 @@ class NativeViewportAppDelegate
: app_delegate_(app_delegate) {} : app_delegate_(app_delegate) {}
virtual void UseTestConfig( virtual void UseTestConfig(
const mojo::Callback<void()>& callback) OVERRIDE { const Callback<void()>& callback) OVERRIDE {
app_delegate_->is_test_ = true; app_delegate_->is_test_ = true;
callback.Run(); callback.Run();
} }
virtual void UseHeadlessConfig(
const Callback<void()>& callback) OVERRIDE {
app_delegate_->is_headless_ = true;
callback.Run();
}
private: private:
NativeViewportAppDelegate* app_delegate_; NativeViewportAppDelegate* app_delegate_;
}; };
...@@ -70,7 +77,7 @@ class NativeViewportAppDelegate ...@@ -70,7 +77,7 @@ class NativeViewportAppDelegate
is_initialized_ = true; is_initialized_ = true;
} }
#endif #endif
BindToRequest(new NativeViewportImpl(app_), &request); BindToRequest(new NativeViewportImpl(app_, is_headless_), &request);
} }
// InterfaceFactory<Gpu> implementation. // InterfaceFactory<Gpu> implementation.
...@@ -90,6 +97,7 @@ class NativeViewportAppDelegate ...@@ -90,6 +97,7 @@ class NativeViewportAppDelegate
scoped_refptr<gfx::GLShareGroup> share_group_; scoped_refptr<gfx::GLShareGroup> share_group_;
scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_; scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_;
bool is_test_; bool is_test_;
bool is_headless_;
bool is_initialized_; bool is_initialized_;
DISALLOW_COPY_AND_ASSIGN(NativeViewportAppDelegate); DISALLOW_COPY_AND_ASSIGN(NativeViewportAppDelegate);
}; };
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "mojo/public/cpp/application/application_delegate.h" #include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/application_impl.h" #include "mojo/public/cpp/application/application_impl.h"
#include "mojo/public/cpp/application/interface_factory.h" #include "mojo/public/cpp/application/interface_factory.h"
#include "mojo/services/native_viewport/platform_viewport_headless.h"
#include "mojo/services/native_viewport/viewport_surface.h" #include "mojo/services/native_viewport/viewport_surface.h"
#include "mojo/services/public/cpp/geometry/geometry_type_converters.h" #include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
#include "mojo/services/public/cpp/input_events/input_events_type_converters.h" #include "mojo/services/public/cpp/input_events/input_events_type_converters.h"
...@@ -28,8 +29,11 @@ bool IsRateLimitedEventType(ui::Event* event) { ...@@ -28,8 +29,11 @@ bool IsRateLimitedEventType(ui::Event* event) {
} // namespace } // namespace
NativeViewportImpl::NativeViewportImpl(ApplicationImpl* app) NativeViewportImpl::NativeViewportImpl(ApplicationImpl* app, bool is_headless)
: widget_id_(0u), waiting_for_event_ack_(false), weak_factory_(this) { : is_headless_(is_headless),
widget_id_(0u),
waiting_for_event_ack_(false),
weak_factory_(this) {
app->ConnectToService("mojo:mojo_surfaces_service", &surfaces_service_); app->ConnectToService("mojo:mojo_surfaces_service", &surfaces_service_);
// TODO(jamesr): Should be mojo_gpu_service // TODO(jamesr): Should be mojo_gpu_service
app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_); app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_);
...@@ -42,6 +46,9 @@ NativeViewportImpl::~NativeViewportImpl() { ...@@ -42,6 +46,9 @@ NativeViewportImpl::~NativeViewportImpl() {
} }
void NativeViewportImpl::Create(SizePtr bounds) { void NativeViewportImpl::Create(SizePtr bounds) {
if (is_headless_)
platform_viewport_ = PlatformViewportHeadless::Create(this);
else
platform_viewport_ = PlatformViewport::Create(this); platform_viewport_ = PlatformViewport::Create(this);
gfx::Rect rect = gfx::Rect(bounds.To<gfx::Size>()); gfx::Rect rect = gfx::Rect(bounds.To<gfx::Size>());
platform_viewport_->Init(rect); platform_viewport_->Init(rect);
......
...@@ -24,7 +24,7 @@ class ViewportSurface; ...@@ -24,7 +24,7 @@ class ViewportSurface;
class NativeViewportImpl : public InterfaceImpl<NativeViewport>, class NativeViewportImpl : public InterfaceImpl<NativeViewport>,
public PlatformViewport::Delegate { public PlatformViewport::Delegate {
public: public:
explicit NativeViewportImpl(ApplicationImpl* app); NativeViewportImpl(ApplicationImpl* app, bool is_headless);
virtual ~NativeViewportImpl(); virtual ~NativeViewportImpl();
// InterfaceImpl<NativeViewport> implementation. // InterfaceImpl<NativeViewport> implementation.
...@@ -45,6 +45,7 @@ class NativeViewportImpl : public InterfaceImpl<NativeViewport>, ...@@ -45,6 +45,7 @@ class NativeViewportImpl : public InterfaceImpl<NativeViewport>,
void AckEvent(); void AckEvent();
private: private:
bool is_headless_;
scoped_ptr<PlatformViewport> platform_viewport_; scoped_ptr<PlatformViewport> platform_viewport_;
scoped_ptr<ViewportSurface> viewport_surface_; scoped_ptr<ViewportSurface> viewport_surface_;
uint64_t widget_id_; uint64_t widget_id_;
......
...@@ -26,7 +26,7 @@ class PlatformViewport { ...@@ -26,7 +26,7 @@ class PlatformViewport {
public: public:
virtual ~Delegate() {} virtual ~Delegate() {}
virtual void OnBoundsChanged(const gfx::Rect& size) = 0; virtual void OnBoundsChanged(const gfx::Rect& rect) = 0;
virtual void OnAcceleratedWidgetAvailable( virtual void OnAcceleratedWidgetAvailable(
gfx::AcceleratedWidget widget) = 0; gfx::AcceleratedWidget widget) = 0;
virtual bool OnEvent(ui::Event* ui_event) = 0; virtual bool OnEvent(ui::Event* ui_event) = 0;
......
// Copyright 2013 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/services/native_viewport/platform_viewport_headless.h"
namespace mojo {
PlatformViewportHeadless::PlatformViewportHeadless(Delegate* delegate)
: delegate_(delegate) {
}
PlatformViewportHeadless::~PlatformViewportHeadless() {
}
void PlatformViewportHeadless::Init(const gfx::Rect& bounds) {
bounds_ = bounds;
}
void PlatformViewportHeadless::Show() {
}
void PlatformViewportHeadless::Hide() {
}
void PlatformViewportHeadless::Close() {
delegate_->OnDestroyed();
}
gfx::Size PlatformViewportHeadless::GetSize() {
return bounds_.size();
}
void PlatformViewportHeadless::SetBounds(const gfx::Rect& bounds) {
bounds_ = bounds;
delegate_->OnBoundsChanged(bounds_);
}
void PlatformViewportHeadless::SetCapture() {
}
void PlatformViewportHeadless::ReleaseCapture() {
}
// static
scoped_ptr<PlatformViewport> PlatformViewportHeadless::Create(
Delegate* delegate) {
return scoped_ptr<PlatformViewport>(
new PlatformViewportHeadless(delegate)).Pass();
}
} // namespace mojo
// Copyright 2013 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/services/native_viewport/platform_viewport.h"
#include "ui/gfx/rect.h"
namespace mojo {
class PlatformViewportHeadless : public PlatformViewport {
public:
virtual ~PlatformViewportHeadless();
static scoped_ptr<PlatformViewport> Create(Delegate* delegate);
private:
explicit PlatformViewportHeadless(Delegate* delegate);
// Overridden from PlatformViewport:
virtual void Init(const gfx::Rect& bounds) OVERRIDE;
virtual void Show() OVERRIDE;
virtual void Hide() OVERRIDE;
virtual void Close() OVERRIDE;
virtual gfx::Size GetSize() OVERRIDE;
virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE;
virtual void SetCapture() OVERRIDE;
virtual void ReleaseCapture() OVERRIDE;
Delegate* delegate_;
gfx::Rect bounds_;
DISALLOW_COPY_AND_ASSIGN(PlatformViewportHeadless);
};
} // namespace mojo
// Copyright 2013 The Chromium Authors. All rights reserved. // Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "mojo/services/native_viewport/platform_viewport.h" #include "mojo/services/native_viewport/platform_viewport_headless.h"
// Stub to build on platforms we don't fully support yet.
namespace mojo { namespace mojo {
class PlatformViewportStub : public PlatformViewport {
public:
PlatformViewportStub(Delegate* delegate) : delegate_(delegate) {
}
virtual ~PlatformViewportStub() {
}
private:
// Overridden from PlatformViewport:
virtual void Init() OVERRIDE {
}
virtual void Show() OVERRIDE {
}
virtual void Hide() OVERRIDE {
}
virtual void Close() OVERRIDE {
delegate_->OnDestroyed();
}
virtual gfx::Size GetSize() OVERRIDE {
return gfx::Size();
}
virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE {
}
Delegate* delegate_;
DISALLOW_COPY_AND_ASSIGN(PlatformViewportStub);
};
// static // static
scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) {
return scoped_ptr<PlatformViewport>( return PlatformViewportHeadless::Create(delegate);
new PlatformViewportStub(delegate)).Pass();
} }
} // namespace mojo } // namespace mojo
...@@ -26,11 +26,16 @@ interface NativeViewportClient { ...@@ -26,11 +26,16 @@ interface NativeViewportClient {
OnEvent(Event event) => (); OnEvent(Event event) => ();
}; };
// Connect to this interface before any other connections are made and call // Connect to this interface before any other connections are made to configure
// UseTestConfig(), blocking on the reply. This will ensure that the correct // the NativeViewport service.
// global initialization is done before subsequent connections.
interface NativeViewportConfig { interface NativeViewportConfig {
// Call UseTestConfig() and block on the reply. This will ensure that the
// correct global initialization is done before subsequent connections.
UseTestConfig() => (); UseTestConfig() => ();
// Call UseHeadlessConfig() and block on the reply. This will ensure that
// the native viewport is later created in headless mode.
UseHeadlessConfig() => ();
}; };
} }
...@@ -143,7 +143,7 @@ class Context::NativeViewportApplicationLoader ...@@ -143,7 +143,7 @@ class Context::NativeViewportApplicationLoader
// InterfaceFactory<NativeViewport> implementation. // InterfaceFactory<NativeViewport> implementation.
virtual void Create(ApplicationConnection* connection, virtual void Create(ApplicationConnection* connection,
InterfaceRequest<NativeViewport> request) OVERRIDE { InterfaceRequest<NativeViewport> request) OVERRIDE {
BindToRequest(new NativeViewportImpl(app_.get()), &request); BindToRequest(new NativeViewportImpl(app_.get(), false), &request);
} }
// InterfaceFactory<Gpu> implementation. // InterfaceFactory<Gpu> implementation.
......
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