Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(847)

Unified Diff: mojo/services/native_viewport/native_viewport_impl.cc

Issue 93793009: Implement ServiceManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/services/native_viewport/native_viewport_impl.cc
diff --git a/mojo/services/native_viewport/native_viewport_impl.cc b/mojo/services/native_viewport/native_viewport_impl.cc
index 5b980c82d443a321a558163a4733b2af375303ea..c5d3af9df29a53be611849e84937656ecfd2dda1 100644
--- a/mojo/services/native_viewport/native_viewport_impl.cc
+++ b/mojo/services/native_viewport/native_viewport_impl.cc
@@ -2,97 +2,152 @@
// 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/native_viewport_impl.h"
-
+#include "base/memory/scoped_vector.h"
#include "base/message_loop/message_loop.h"
+#include "mojo/common/bindings_support_impl.h"
#include "mojo/services/gles2/gles2_impl.h"
#include "mojo/services/native_viewport/native_viewport.h"
+#include "mojom/native_viewport.h"
+#include "mojom/shell.h"
#include "ui/events/event.h"
+#if defined(WIN32)
+#if !defined(CDECL)
+#define CDECL __cdecl
+#endif
+#define NATIVE_VIEWPORT_EXPORT __declspec(dllexport)
+#else
+#define CDECL
+#define NATIVE_VIEWPORT_EXPORT __attribute__((visibility("default")))
+#endif
+
namespace mojo {
namespace services {
-NativeViewportImpl::NativeViewportImpl(shell::Context* context,
- ScopedMessagePipeHandle pipe)
- : context_(context),
- widget_(gfx::kNullAcceleratedWidget),
- client_(pipe.Pass()) {
- client_.SetPeer(this);
-}
-
-NativeViewportImpl::~NativeViewportImpl() {
-}
-
-void NativeViewportImpl::Open() {
- native_viewport_ = services::NativeViewport::Create(context_, this);
- native_viewport_->Init();
- client_->OnCreated();
-}
-
-void NativeViewportImpl::Close() {
- DCHECK(native_viewport_);
- native_viewport_->Close();
-}
-
-void NativeViewportImpl::CreateGLES2Context(
- ScopedMessagePipeHandle gles2_client) {
- gles2_.reset(new GLES2Impl(gles2_client.Pass()));
- CreateGLES2ContextIfNeeded();
-}
-
-void NativeViewportImpl::CreateGLES2ContextIfNeeded() {
- if (widget_ == gfx::kNullAcceleratedWidget || !gles2_)
- return;
- gles2_->CreateContext(widget_, native_viewport_->GetSize());
-}
-
-bool NativeViewportImpl::OnEvent(ui::Event* ui_event) {
- AllocationScope scope;
+class NativeViewportService : public ::shell::ShellClientStub {
+ public:
+ NativeViewportService(ScopedMessagePipeHandle shell_pipe)
+ : shell_(shell_pipe.Pass()) {
+ shell_.SetPeer(this);
+ }
- Event::Builder event;
- event.set_action(ui_event->type());
- event.set_time_stamp(ui_event->time_stamp().ToInternalValue());
+ virtual ~NativeViewportService() {}
- if (ui_event->IsMouseEvent() || ui_event->IsTouchEvent()) {
- ui::LocatedEvent* located_event = static_cast<ui::LocatedEvent*>(ui_event);
- Point::Builder location;
- location.set_x(located_event->location().x());
- location.set_y(located_event->location().y());
- event.set_location(location.Finish());
+ virtual void Connect(ScopedMessagePipeHandle client_pipe) MOJO_OVERRIDE {
+ viewports_.push_back(new NativeViewportImpl(client_pipe.Pass()));
}
- if (ui_event->IsTouchEvent()) {
- ui::TouchEvent* touch_event = static_cast<ui::TouchEvent*>(ui_event);
- TouchData::Builder touch_data;
- touch_data.set_pointer_id(touch_event->touch_id());
- event.set_touch_data(touch_data.Finish());
- }
+ private:
+ class NativeViewportImpl : public NativeViewportStub,
+ public NativeViewportDelegate {
+ public:
+ NativeViewportImpl(ScopedMessagePipeHandle client_pipe)
+ : widget_(gfx::kNullAcceleratedWidget),
+ client_(client_pipe.Pass()) {
+ client_.SetPeer(this);
+ }
+ virtual ~NativeViewportImpl() {}
+
+ virtual void Open() MOJO_OVERRIDE {
+ native_viewport_ = services::NativeViewport::Create(this);
abarth-chromium 2013/12/10 01:06:03 "services::" <-- not necessary. We're already in
DaveMoore 2013/12/10 03:00:45 Without that I get this error: ../../mojo/services
+ native_viewport_->Init();
+ client_->OnCreated();
+ }
+
+ virtual void Close() MOJO_OVERRIDE {
+ gles2_.reset();
+ DCHECK(native_viewport_);
+ native_viewport_->Close();
+ }
+
+ virtual void CreateGLES2Context(ScopedMessagePipeHandle gles2_client)
+ MOJO_OVERRIDE {
+ gles2_.reset(new GLES2Impl(gles2_client.Pass()));
+ CreateGLES2ContextIfNeeded();
+ }
+
+ void CreateGLES2ContextIfNeeded() {
+ if (widget_ == gfx::kNullAcceleratedWidget || !gles2_)
+ return;
+ gles2_->CreateContext(widget_, native_viewport_->GetSize());
+ }
+
+ virtual bool OnEvent(ui::Event* ui_event) MOJO_OVERRIDE {
+ AllocationScope scope;
+
+ Event::Builder event;
+ event.set_action(ui_event->type());
+ event.set_time_stamp(ui_event->time_stamp().ToInternalValue());
+
+ if (ui_event->IsMouseEvent() || ui_event->IsTouchEvent()) {
+ ui::LocatedEvent* located_event =
+ static_cast<ui::LocatedEvent*>(ui_event);
+ Point::Builder location;
+ location.set_x(located_event->location().x());
+ location.set_y(located_event->location().y());
+ event.set_location(location.Finish());
+ }
+
+ if (ui_event->IsTouchEvent()) {
+ ui::TouchEvent* touch_event = static_cast<ui::TouchEvent*>(ui_event);
+ TouchData::Builder touch_data;
+ touch_data.set_pointer_id(touch_event->touch_id());
+ event.set_touch_data(touch_data.Finish());
+ }
+
+ client_->OnEvent(event.Finish());
+ return false;
+ }
+
+ virtual void OnAcceleratedWidgetAvailable(
+ gfx::AcceleratedWidget widget) MOJO_OVERRIDE {
+ widget_ = widget;
+ CreateGLES2ContextIfNeeded();
+ }
+
+ virtual void OnResized(const gfx::Size& size) MOJO_OVERRIDE {
+ }
+
+ virtual void OnDestroyed() MOJO_OVERRIDE {
+ // Destroying |gles2_| on the shell thread here hits thread checker
+ // asserts. All code must stop touching the AcceleratedWidget at this
+ // point as it is dead after this call stack. jamesr said we probably
+ // should make our own GLSurface and simply tell it to stop touching the
+ // AcceleratedWidget via Destroy() but we have no good way of doing that
+ // right now given our current threading model so james' recommendation
+ // was just to wait until after we move the gl service out of process.
+ // gles2_.reset();
+ client_->OnDestroyed();
+ base::MessageLoop::current()->Quit();
+ }
+
+ private:
+ gfx::AcceleratedWidget widget_;
+ scoped_ptr<services::NativeViewport> native_viewport_;
abarth-chromium 2013/12/10 01:06:03 "services::" <-- not needed
DaveMoore 2013/12/10 03:00:45 Same as above. On 2013/12/10 01:06:03, abarth wrot
+ scoped_ptr<GLES2Impl> gles2_;
+
+ RemotePtr<NativeViewportClient> client_;
+ };
+ mojo::RemotePtr<::shell::Shell> shell_;
+ ScopedVector<NativeViewportImpl> viewports_;
+};
- client_->OnEvent(event.Finish());
- return false;
-}
+} // namespace services
+} // namespace mojo
-void NativeViewportImpl::OnAcceleratedWidgetAvailable(
- gfx::AcceleratedWidget widget) {
- widget_ = widget;
- CreateGLES2ContextIfNeeded();
-}
+extern "C" NATIVE_VIEWPORT_EXPORT MojoResult CDECL MojoMain(
+ const MojoHandle shell_handle) {
+ mojo::common::BindingsSupportImpl bindings_support_impl;
+ mojo::BindingsSupport::Set(&bindings_support_impl);
-void NativeViewportImpl::OnResized(const gfx::Size& size) {
-}
+ mojo::ScopedMessagePipeHandle shell_pipe;
+ shell_pipe.reset(mojo::MessagePipeHandle(shell_handle));
-void NativeViewportImpl::OnDestroyed() {
- // TODO(beng):
- // Destroying |gles2_| on the shell thread here hits thread checker asserts.
- // All code must stop touching the AcceleratedWidget at this point as it is
- // dead after this call stack. jamesr said we probably should make our own
- // GLSurface and simply tell it to stop touching the AcceleratedWidget
- // via Destroy() but we have no good way of doing that right now given our
- // current threading model so james' recommendation was just to wait until
- // after we move the gl service out of process.
- // gles2_.reset();
- client_->OnDestroyed();
-}
+ base::MessageLoop loop(base::MessageLoop::TYPE_UI);
+ mojo::services::NativeViewportService app(
+ mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle)).Pass());
+ base::MessageLoop::current()->Run();
-} // namespace services
-} // namespace mojo
+ mojo::BindingsSupport::Set(NULL);
+ return MOJO_RESULT_OK;
+}

Powered by Google App Engine
This is Rietveld 408576698