summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorabarth <abarth@chromium.org>2014-09-25 18:12:17 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-26 01:12:24 +0000
commitcff892f9c3062ddd2ac7e3c2385a5fb63be0b886 (patch)
treeb43cb6e63832dc100cf776406a546a639c2382c6
parent9c49ac15c14a1040752e310aec6826c17ac29830 (diff)
downloadchromium_src-cff892f9c3062ddd2ac7e3c2385a5fb63be0b886.zip
chromium_src-cff892f9c3062ddd2ac7e3c2385a5fb63be0b886.tar.gz
chromium_src-cff892f9c3062ddd2ac7e3c2385a5fb63be0b886.tar.bz2
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}
-rw-r--r--mojo/mojo_services.gypi2
-rw-r--r--mojo/services/native_viewport/BUILD.gn2
-rw-r--r--mojo/services/native_viewport/main.cc12
-rw-r--r--mojo/services/native_viewport/native_viewport_impl.cc13
-rw-r--r--mojo/services/native_viewport/native_viewport_impl.h3
-rw-r--r--mojo/services/native_viewport/platform_viewport.h2
-rw-r--r--mojo/services/native_viewport/platform_viewport_headless.cc52
-rw-r--r--mojo/services/native_viewport/platform_viewport_headless.h35
-rw-r--r--mojo/services/native_viewport/platform_viewport_stub.cc38
-rw-r--r--mojo/services/public/interfaces/native_viewport/native_viewport.mojom11
-rw-r--r--mojo/shell/context.cc2
11 files changed, 126 insertions, 46 deletions
diff --git a/mojo/mojo_services.gypi b/mojo/mojo_services.gypi
index 8599a62..e8efab8 100644
--- a/mojo/mojo_services.gypi
+++ b/mojo/mojo_services.gypi
@@ -364,6 +364,8 @@
'services/native_viewport/native_viewport_impl.h',
'services/native_viewport/platform_viewport.h',
'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_ozone.cc',
'services/native_viewport/platform_viewport_stub.cc',
diff --git a/mojo/services/native_viewport/BUILD.gn b/mojo/services/native_viewport/BUILD.gn
index 3e47c24..036e8e9 100644
--- a/mojo/services/native_viewport/BUILD.gn
+++ b/mojo/services/native_viewport/BUILD.gn
@@ -55,6 +55,8 @@ source_set("lib") {
"platform_viewport_android.cc",
"platform_viewport_android.h",
"platform_viewport_mac.mm",
+ "platform_viewport_headless.cc",
+ "platform_viewport_headless.h",
"platform_viewport_win.cc",
"viewport_surface.cc",
"viewport_surface.h",
diff --git a/mojo/services/native_viewport/main.cc b/mojo/services/native_viewport/main.cc
index fb150da..0a85b15 100644
--- a/mojo/services/native_viewport/main.cc
+++ b/mojo/services/native_viewport/main.cc
@@ -26,6 +26,7 @@ class NativeViewportAppDelegate
: share_group_(new gfx::GLShareGroup),
mailbox_manager_(new gpu::gles2::MailboxManager),
is_test_(false),
+ is_headless_(false),
is_initialized_(false) {}
virtual ~NativeViewportAppDelegate() {}
@@ -36,11 +37,17 @@ class NativeViewportAppDelegate
: app_delegate_(app_delegate) {}
virtual void UseTestConfig(
- const mojo::Callback<void()>& callback) OVERRIDE {
+ const Callback<void()>& callback) OVERRIDE {
app_delegate_->is_test_ = true;
callback.Run();
}
+ virtual void UseHeadlessConfig(
+ const Callback<void()>& callback) OVERRIDE {
+ app_delegate_->is_headless_ = true;
+ callback.Run();
+ }
+
private:
NativeViewportAppDelegate* app_delegate_;
};
@@ -70,7 +77,7 @@ class NativeViewportAppDelegate
is_initialized_ = true;
}
#endif
- BindToRequest(new NativeViewportImpl(app_), &request);
+ BindToRequest(new NativeViewportImpl(app_, is_headless_), &request);
}
// InterfaceFactory<Gpu> implementation.
@@ -90,6 +97,7 @@ class NativeViewportAppDelegate
scoped_refptr<gfx::GLShareGroup> share_group_;
scoped_refptr<gpu::gles2::MailboxManager> mailbox_manager_;
bool is_test_;
+ bool is_headless_;
bool is_initialized_;
DISALLOW_COPY_AND_ASSIGN(NativeViewportAppDelegate);
};
diff --git a/mojo/services/native_viewport/native_viewport_impl.cc b/mojo/services/native_viewport/native_viewport_impl.cc
index a0ab999..4fce13f 100644
--- a/mojo/services/native_viewport/native_viewport_impl.cc
+++ b/mojo/services/native_viewport/native_viewport_impl.cc
@@ -11,6 +11,7 @@
#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/application_impl.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/public/cpp/geometry/geometry_type_converters.h"
#include "mojo/services/public/cpp/input_events/input_events_type_converters.h"
@@ -28,8 +29,11 @@ bool IsRateLimitedEventType(ui::Event* event) {
} // namespace
-NativeViewportImpl::NativeViewportImpl(ApplicationImpl* app)
- : widget_id_(0u), waiting_for_event_ack_(false), weak_factory_(this) {
+NativeViewportImpl::NativeViewportImpl(ApplicationImpl* app, bool is_headless)
+ : is_headless_(is_headless),
+ widget_id_(0u),
+ waiting_for_event_ack_(false),
+ weak_factory_(this) {
app->ConnectToService("mojo:mojo_surfaces_service", &surfaces_service_);
// TODO(jamesr): Should be mojo_gpu_service
app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_);
@@ -42,7 +46,10 @@ NativeViewportImpl::~NativeViewportImpl() {
}
void NativeViewportImpl::Create(SizePtr bounds) {
- platform_viewport_ = PlatformViewport::Create(this);
+ if (is_headless_)
+ platform_viewport_ = PlatformViewportHeadless::Create(this);
+ else
+ platform_viewport_ = PlatformViewport::Create(this);
gfx::Rect rect = gfx::Rect(bounds.To<gfx::Size>());
platform_viewport_->Init(rect);
OnBoundsChanged(rect);
diff --git a/mojo/services/native_viewport/native_viewport_impl.h b/mojo/services/native_viewport/native_viewport_impl.h
index ec406d0..5043da0 100644
--- a/mojo/services/native_viewport/native_viewport_impl.h
+++ b/mojo/services/native_viewport/native_viewport_impl.h
@@ -24,7 +24,7 @@ class ViewportSurface;
class NativeViewportImpl : public InterfaceImpl<NativeViewport>,
public PlatformViewport::Delegate {
public:
- explicit NativeViewportImpl(ApplicationImpl* app);
+ NativeViewportImpl(ApplicationImpl* app, bool is_headless);
virtual ~NativeViewportImpl();
// InterfaceImpl<NativeViewport> implementation.
@@ -45,6 +45,7 @@ class NativeViewportImpl : public InterfaceImpl<NativeViewport>,
void AckEvent();
private:
+ bool is_headless_;
scoped_ptr<PlatformViewport> platform_viewport_;
scoped_ptr<ViewportSurface> viewport_surface_;
uint64_t widget_id_;
diff --git a/mojo/services/native_viewport/platform_viewport.h b/mojo/services/native_viewport/platform_viewport.h
index f42eb7d..a3ba3dc 100644
--- a/mojo/services/native_viewport/platform_viewport.h
+++ b/mojo/services/native_viewport/platform_viewport.h
@@ -26,7 +26,7 @@ class PlatformViewport {
public:
virtual ~Delegate() {}
- virtual void OnBoundsChanged(const gfx::Rect& size) = 0;
+ virtual void OnBoundsChanged(const gfx::Rect& rect) = 0;
virtual void OnAcceleratedWidgetAvailable(
gfx::AcceleratedWidget widget) = 0;
virtual bool OnEvent(ui::Event* ui_event) = 0;
diff --git a/mojo/services/native_viewport/platform_viewport_headless.cc b/mojo/services/native_viewport/platform_viewport_headless.cc
new file mode 100644
index 0000000..1c34711
--- /dev/null
+++ b/mojo/services/native_viewport/platform_viewport_headless.cc
@@ -0,0 +1,52 @@
+// 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
diff --git a/mojo/services/native_viewport/platform_viewport_headless.h b/mojo/services/native_viewport/platform_viewport_headless.h
new file mode 100644
index 0000000..ff5b18f
--- /dev/null
+++ b/mojo/services/native_viewport/platform_viewport_headless.h
@@ -0,0 +1,35 @@
+// 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
diff --git a/mojo/services/native_viewport/platform_viewport_stub.cc b/mojo/services/native_viewport/platform_viewport_stub.cc
index 9ed83fd..80a7e94 100644
--- a/mojo/services/native_viewport/platform_viewport_stub.cc
+++ b/mojo/services/native_viewport/platform_viewport_stub.cc
@@ -1,46 +1,14 @@
-// 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
// found in the LICENSE file.
-#include "mojo/services/native_viewport/platform_viewport.h"
-
-// Stub to build on platforms we don't fully support yet.
+#include "mojo/services/native_viewport/platform_viewport_headless.h"
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
scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) {
- return scoped_ptr<PlatformViewport>(
- new PlatformViewportStub(delegate)).Pass();
+ return PlatformViewportHeadless::Create(delegate);
}
} // namespace mojo
diff --git a/mojo/services/public/interfaces/native_viewport/native_viewport.mojom b/mojo/services/public/interfaces/native_viewport/native_viewport.mojom
index 6c9fd19..61afb1a 100644
--- a/mojo/services/public/interfaces/native_viewport/native_viewport.mojom
+++ b/mojo/services/public/interfaces/native_viewport/native_viewport.mojom
@@ -26,11 +26,16 @@ interface NativeViewportClient {
OnEvent(Event event) => ();
};
-// Connect to this interface before any other connections are made and call
-// UseTestConfig(), blocking on the reply. This will ensure that the correct
-// global initialization is done before subsequent connections.
+// Connect to this interface before any other connections are made to configure
+// the NativeViewport service.
interface NativeViewportConfig {
+ // Call UseTestConfig() and block on the reply. This will ensure that the
+ // correct global initialization is done before subsequent connections.
UseTestConfig() => ();
+
+ // Call UseHeadlessConfig() and block on the reply. This will ensure that
+ // the native viewport is later created in headless mode.
+ UseHeadlessConfig() => ();
};
}
diff --git a/mojo/shell/context.cc b/mojo/shell/context.cc
index 64db00b..4397271 100644
--- a/mojo/shell/context.cc
+++ b/mojo/shell/context.cc
@@ -143,7 +143,7 @@ class Context::NativeViewportApplicationLoader
// InterfaceFactory<NativeViewport> implementation.
virtual void Create(ApplicationConnection* connection,
InterfaceRequest<NativeViewport> request) OVERRIDE {
- BindToRequest(new NativeViewportImpl(app_.get()), &request);
+ BindToRequest(new NativeViewportImpl(app_.get(), false), &request);
}
// InterfaceFactory<Gpu> implementation.