| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "mojo/services/native_viewport/native_viewport_service.h" | 5 #include "mojo/services/native_viewport/native_viewport_service.h" | 
| 6 | 6 | 
| 7 #include "base/macros.h" | 7 #include "base/macros.h" | 
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" | 
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" | 
| 10 #include "mojo/public/bindings/allocation_scope.h" | 10 #include "mojo/public/bindings/allocation_scope.h" | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 26 } | 26 } | 
| 27 | 27 | 
| 28 } | 28 } | 
| 29 | 29 | 
| 30 class NativeViewportImpl | 30 class NativeViewportImpl | 
| 31     : public Service<mojo::NativeViewport, NativeViewportImpl, shell::Context>, | 31     : public Service<mojo::NativeViewport, NativeViewportImpl, shell::Context>, | 
| 32       public NativeViewportDelegate { | 32       public NativeViewportDelegate { | 
| 33  public: | 33  public: | 
| 34   NativeViewportImpl() | 34   NativeViewportImpl() | 
| 35       : widget_(gfx::kNullAcceleratedWidget), | 35       : widget_(gfx::kNullAcceleratedWidget), | 
| 36         waiting_for_event_ack_(false), | 36         waiting_for_event_ack_(false) {} | 
| 37         pending_event_timestamp_(0) {} |  | 
| 38   virtual ~NativeViewportImpl() {} | 37   virtual ~NativeViewportImpl() {} | 
| 39 | 38 | 
| 40   virtual void Create(const Rect& bounds) OVERRIDE { | 39   virtual void Create(const Rect& bounds) OVERRIDE { | 
| 41     native_viewport_ = | 40     native_viewport_ = | 
| 42         services::NativeViewport::Create(context(), this); | 41         services::NativeViewport::Create(context(), this); | 
| 43     native_viewport_->Init(bounds); | 42     native_viewport_->Init(bounds); | 
| 44     client()->OnCreated(); | 43     client()->OnCreated(); | 
| 45     OnBoundsChanged(bounds); | 44     OnBoundsChanged(bounds); | 
| 46   } | 45   } | 
| 47 | 46 | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
| 75     // TODO(darin): | 74     // TODO(darin): | 
| 76     // CreateGLES2Context should accept a ScopedCommandBufferClientHandle once | 75     // CreateGLES2Context should accept a ScopedCommandBufferClientHandle once | 
| 77     // it is possible to import interface definitions from another module.  For | 76     // it is possible to import interface definitions from another module.  For | 
| 78     // now, we just kludge it. | 77     // now, we just kludge it. | 
| 79     command_buffer_handle_.reset( | 78     command_buffer_handle_.reset( | 
| 80         InterfaceHandle<CommandBufferClient>(client_handle.release().value())); | 79         InterfaceHandle<CommandBufferClient>(client_handle.release().value())); | 
| 81 | 80 | 
| 82     CreateCommandBufferIfNeeded(); | 81     CreateCommandBufferIfNeeded(); | 
| 83   } | 82   } | 
| 84 | 83 | 
| 85   virtual void AckEvent(const Event& event) OVERRIDE { | 84   void AckEvent() { | 
| 86     DCHECK_EQ(event.time_stamp(), pending_event_timestamp_); |  | 
| 87     waiting_for_event_ack_ = false; | 85     waiting_for_event_ack_ = false; | 
| 88   } | 86   } | 
| 89 | 87 | 
| 90   void CreateCommandBufferIfNeeded() { | 88   void CreateCommandBufferIfNeeded() { | 
| 91     if (!command_buffer_handle_.is_valid()) | 89     if (!command_buffer_handle_.is_valid()) | 
| 92       return; | 90       return; | 
| 93     DCHECK(!command_buffer_.get()); | 91     DCHECK(!command_buffer_.get()); | 
| 94     if (widget_ == gfx::kNullAcceleratedWidget) | 92     if (widget_ == gfx::kNullAcceleratedWidget) | 
| 95       return; | 93       return; | 
| 96     gfx::Size size = native_viewport_->GetSize(); | 94     gfx::Size size = native_viewport_->GetSize(); | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 111     case ui::ET_TOUCH_RELEASED: | 109     case ui::ET_TOUCH_RELEASED: | 
| 112       native_viewport_->ReleaseCapture(); | 110       native_viewport_->ReleaseCapture(); | 
| 113       break; | 111       break; | 
| 114     default: | 112     default: | 
| 115       break; | 113       break; | 
| 116     } | 114     } | 
| 117 | 115 | 
| 118     if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event)) | 116     if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event)) | 
| 119       return false; | 117       return false; | 
| 120 | 118 | 
| 121     pending_event_timestamp_ = ui_event->time_stamp().ToInternalValue(); |  | 
| 122     AllocationScope scope; | 119     AllocationScope scope; | 
| 123 | 120 | 
| 124     Event::Builder event; | 121     Event::Builder event; | 
| 125     event.set_action(ui_event->type()); | 122     event.set_action(ui_event->type()); | 
| 126     event.set_flags(ui_event->flags()); | 123     event.set_flags(ui_event->flags()); | 
| 127     event.set_time_stamp(pending_event_timestamp_); | 124     event.set_time_stamp(ui_event->time_stamp().ToInternalValue()); | 
| 128 | 125 | 
| 129     if (ui_event->IsMouseEvent() || ui_event->IsTouchEvent()) { | 126     if (ui_event->IsMouseEvent() || ui_event->IsTouchEvent()) { | 
| 130       ui::LocatedEvent* located_event = | 127       ui::LocatedEvent* located_event = | 
| 131           static_cast<ui::LocatedEvent*>(ui_event); | 128           static_cast<ui::LocatedEvent*>(ui_event); | 
| 132       Point::Builder location; | 129       Point::Builder location; | 
| 133       location.set_x(located_event->location().x()); | 130       location.set_x(located_event->location().x()); | 
| 134       location.set_y(located_event->location().y()); | 131       location.set_y(located_event->location().y()); | 
| 135       event.set_location(location.Finish()); | 132       event.set_location(location.Finish()); | 
| 136     } | 133     } | 
| 137 | 134 | 
| 138     if (ui_event->IsTouchEvent()) { | 135     if (ui_event->IsTouchEvent()) { | 
| 139       ui::TouchEvent* touch_event = static_cast<ui::TouchEvent*>(ui_event); | 136       ui::TouchEvent* touch_event = static_cast<ui::TouchEvent*>(ui_event); | 
| 140       TouchData::Builder touch_data; | 137       TouchData::Builder touch_data; | 
| 141       touch_data.set_pointer_id(touch_event->touch_id()); | 138       touch_data.set_pointer_id(touch_event->touch_id()); | 
| 142       event.set_touch_data(touch_data.Finish()); | 139       event.set_touch_data(touch_data.Finish()); | 
| 143     } else if (ui_event->IsKeyEvent()) { | 140     } else if (ui_event->IsKeyEvent()) { | 
| 144       ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(ui_event); | 141       ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(ui_event); | 
| 145       KeyData::Builder key_data; | 142       KeyData::Builder key_data; | 
| 146       key_data.set_key_code(key_event->key_code()); | 143       key_data.set_key_code(key_event->key_code()); | 
| 147       key_data.set_is_char(key_event->is_char()); | 144       key_data.set_is_char(key_event->is_char()); | 
| 148       event.set_key_data(key_data.Finish()); | 145       event.set_key_data(key_data.Finish()); | 
| 149     } | 146     } | 
| 150 | 147 | 
| 151     client()->OnEvent(event.Finish()); | 148     client()->OnEvent(event.Finish(), | 
|  | 149                       base::Bind(&NativeViewportImpl::AckEvent, | 
|  | 150                                  base::Unretained(this))); | 
| 152     waiting_for_event_ack_ = true; | 151     waiting_for_event_ack_ = true; | 
| 153     return false; | 152     return false; | 
| 154   } | 153   } | 
| 155 | 154 | 
| 156   virtual void OnAcceleratedWidgetAvailable( | 155   virtual void OnAcceleratedWidgetAvailable( | 
| 157       gfx::AcceleratedWidget widget) OVERRIDE { | 156       gfx::AcceleratedWidget widget) OVERRIDE { | 
| 158     widget_ = widget; | 157     widget_ = widget; | 
| 159     CreateCommandBufferIfNeeded(); | 158     CreateCommandBufferIfNeeded(); | 
| 160   } | 159   } | 
| 161 | 160 | 
| 162   virtual void OnBoundsChanged(const gfx::Rect& bounds) OVERRIDE { | 161   virtual void OnBoundsChanged(const gfx::Rect& bounds) OVERRIDE { | 
| 163     CreateCommandBufferIfNeeded(); | 162     CreateCommandBufferIfNeeded(); | 
| 164     AllocationScope scope; | 163     AllocationScope scope; | 
| 165     client()->OnBoundsChanged(bounds); | 164     client()->OnBoundsChanged(bounds); | 
| 166   } | 165   } | 
| 167 | 166 | 
| 168   virtual void OnDestroyed() OVERRIDE { | 167   virtual void OnDestroyed() OVERRIDE { | 
| 169     command_buffer_.reset(); | 168     command_buffer_.reset(); | 
| 170     client()->OnDestroyed(); | 169     client()->OnDestroyed(); | 
| 171     base::MessageLoop::current()->Quit(); | 170     base::MessageLoop::current()->Quit(); | 
| 172   } | 171   } | 
| 173 | 172 | 
| 174  private: | 173  private: | 
| 175   gfx::AcceleratedWidget widget_; | 174   gfx::AcceleratedWidget widget_; | 
| 176   scoped_ptr<services::NativeViewport> native_viewport_; | 175   scoped_ptr<services::NativeViewport> native_viewport_; | 
| 177   ScopedCommandBufferClientHandle command_buffer_handle_; | 176   ScopedCommandBufferClientHandle command_buffer_handle_; | 
| 178   scoped_ptr<CommandBufferImpl> command_buffer_; | 177   scoped_ptr<CommandBufferImpl> command_buffer_; | 
| 179   bool waiting_for_event_ack_; | 178   bool waiting_for_event_ack_; | 
| 180   int64 pending_event_timestamp_; |  | 
| 181 }; | 179 }; | 
| 182 | 180 | 
| 183 }  // namespace services | 181 }  // namespace services | 
| 184 }  // namespace mojo | 182 }  // namespace mojo | 
| 185 | 183 | 
| 186 | 184 | 
| 187 #if defined(OS_ANDROID) | 185 #if defined(OS_ANDROID) | 
| 188 | 186 | 
| 189 // Android will call this. | 187 // Android will call this. | 
| 190 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* | 188 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 204   base::MessageLoopForUI loop; | 202   base::MessageLoopForUI loop; | 
| 205   mojo::Application app(shell_handle); | 203   mojo::Application app(shell_handle); | 
| 206   app.AddServiceFactory( | 204   app.AddServiceFactory( | 
| 207     new mojo::ServiceFactory<mojo::services::NativeViewportImpl, | 205     new mojo::ServiceFactory<mojo::services::NativeViewportImpl, | 
| 208                              mojo::shell::Context>); | 206                              mojo::shell::Context>); | 
| 209   loop.Run(); | 207   loop.Run(); | 
| 210   return MOJO_RESULT_OK; | 208   return MOJO_RESULT_OK; | 
| 211 } | 209 } | 
| 212 | 210 | 
| 213 #endif // !OS_ANDROID | 211 #endif // !OS_ANDROID | 
| OLD | NEW | 
|---|