Chromium Code Reviews| 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..2933b4f913c8d2a19a943898a19f8d2996d06564 100644 |
| --- a/mojo/services/native_viewport/native_viewport_impl.cc |
| +++ b/mojo/services/native_viewport/native_viewport_impl.cc |
| @@ -2,97 +2,143 @@ |
| // 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) |
|
Ben Goodger (Google)
2013/12/10 16:35:03
indentation is wacky here
DaveMoore
2013/12/11 18:56:44
Done.
|
| + : 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())); |
|
darin (slow to review)
2013/12/10 06:12:36
It looks like this vector only grows?
DaveMoore
2013/12/11 18:56:44
It does. We need to have it clean up. But we need
|
| } |
| - 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, |
|
darin (slow to review)
2013/12/10 06:12:36
It feels like in a build where NV service is stati
DaveMoore
2013/12/11 18:56:44
I think it will be a ShellClient implementation, a
|
| + 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); |
| + 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 { |
| + base::MessageLoop::current()->Quit(); |
| + } |
| + |
| + private: |
| + gfx::AcceleratedWidget widget_; |
| + scoped_ptr<services::NativeViewport> native_viewport_; |
| + 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( |
|
darin (slow to review)
2013/12/10 06:12:36
I'm confused about seeing a MojoMain for the NV se
Ben Goodger (Google)
2013/12/10 16:35:03
Also what's the plan here for Android?
DaveMoore
2013/12/11 18:56:44
I think once we add support for statically linked
DaveMoore
2013/12/11 18:56:44
We're going to create this with a messageloop and
|
| + 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; |
| +} |