| 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/cpp/bindings/allocation_scope.h" | |
| 11 #include "mojo/public/interfaces/shell/shell.mojom.h" | 10 #include "mojo/public/interfaces/shell/shell.mojom.h" |
| 12 #include "mojo/services/gles2/command_buffer_impl.h" | 11 #include "mojo/services/gles2/command_buffer_impl.h" |
| 13 #include "mojo/services/native_viewport/geometry_conversions.h" | 12 #include "mojo/services/native_viewport/geometry_conversions.h" |
| 14 #include "mojo/services/native_viewport/native_viewport.h" | 13 #include "mojo/services/native_viewport/native_viewport.h" |
| 15 #include "mojo/services/native_viewport/native_viewport.mojom.h" | 14 #include "mojo/services/native_viewport/native_viewport.mojom.h" |
| 16 #include "ui/events/event.h" | 15 #include "ui/events/event.h" |
| 17 | 16 |
| 18 namespace mojo { | 17 namespace mojo { |
| 19 namespace services { | 18 namespace services { |
| 20 namespace { | 19 namespace { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 36 widget_(gfx::kNullAcceleratedWidget), | 35 widget_(gfx::kNullAcceleratedWidget), |
| 37 waiting_for_event_ack_(false) {} | 36 waiting_for_event_ack_(false) {} |
| 38 virtual ~NativeViewportImpl() { | 37 virtual ~NativeViewportImpl() { |
| 39 // Destroy the NativeViewport early on as it may call us back during | 38 // Destroy the NativeViewport early on as it may call us back during |
| 40 // destruction and we want to be in a known state. | 39 // destruction and we want to be in a known state. |
| 41 native_viewport_.reset(); | 40 native_viewport_.reset(); |
| 42 } | 41 } |
| 43 | 42 |
| 44 virtual void OnConnectionError() OVERRIDE {} | 43 virtual void OnConnectionError() OVERRIDE {} |
| 45 | 44 |
| 46 virtual void Create(const Rect& bounds) OVERRIDE { | 45 virtual void Create(RectPtr bounds) OVERRIDE { |
| 47 native_viewport_ = | 46 native_viewport_ = |
| 48 services::NativeViewport::Create(context_, this); | 47 services::NativeViewport::Create(context_, this); |
| 49 native_viewport_->Init(bounds); | 48 native_viewport_->Init(bounds.To<gfx::Rect>()); |
| 50 client()->OnCreated(); | 49 client()->OnCreated(); |
| 51 OnBoundsChanged(bounds); | 50 OnBoundsChanged(bounds.To<gfx::Rect>()); |
| 52 } | 51 } |
| 53 | 52 |
| 54 virtual void Show() OVERRIDE { | 53 virtual void Show() OVERRIDE { |
| 55 native_viewport_->Show(); | 54 native_viewport_->Show(); |
| 56 } | 55 } |
| 57 | 56 |
| 58 virtual void Hide() OVERRIDE { | 57 virtual void Hide() OVERRIDE { |
| 59 native_viewport_->Hide(); | 58 native_viewport_->Hide(); |
| 60 } | 59 } |
| 61 | 60 |
| 62 virtual void Close() OVERRIDE { | 61 virtual void Close() OVERRIDE { |
| 63 command_buffer_.reset(); | 62 command_buffer_.reset(); |
| 64 DCHECK(native_viewport_); | 63 DCHECK(native_viewport_); |
| 65 native_viewport_->Close(); | 64 native_viewport_->Close(); |
| 66 } | 65 } |
| 67 | 66 |
| 68 virtual void SetBounds(const Rect& bounds) OVERRIDE { | 67 virtual void SetBounds(RectPtr bounds) OVERRIDE { |
| 69 gfx::Rect gfx_bounds(bounds.position().x(), bounds.position().y(), | 68 gfx::Rect gfx_bounds(bounds->position->x, bounds->position->y, |
| 70 bounds.size().width(), bounds.size().height()); | 69 bounds->size->width, bounds->size->height); |
| 71 native_viewport_->SetBounds(gfx_bounds); | 70 native_viewport_->SetBounds(gfx_bounds); |
| 72 } | 71 } |
| 73 | 72 |
| 74 virtual void CreateGLES2Context(ScopedMessagePipeHandle client_handle) | 73 virtual void CreateGLES2Context(ScopedMessagePipeHandle client_handle) |
| 75 OVERRIDE { | 74 OVERRIDE { |
| 76 if (command_buffer_.get() || command_buffer_handle_.is_valid()) { | 75 if (command_buffer_.get() || command_buffer_handle_.is_valid()) { |
| 77 LOG(ERROR) << "Can't create multiple contexts on a NativeViewport"; | 76 LOG(ERROR) << "Can't create multiple contexts on a NativeViewport"; |
| 78 return; | 77 return; |
| 79 } | 78 } |
| 80 | 79 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 case ui::ET_TOUCH_RELEASED: | 112 case ui::ET_TOUCH_RELEASED: |
| 114 native_viewport_->ReleaseCapture(); | 113 native_viewport_->ReleaseCapture(); |
| 115 break; | 114 break; |
| 116 default: | 115 default: |
| 117 break; | 116 break; |
| 118 } | 117 } |
| 119 | 118 |
| 120 if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event)) | 119 if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event)) |
| 121 return false; | 120 return false; |
| 122 | 121 |
| 123 AllocationScope scope; | 122 EventPtr event(Event::New()); |
| 124 | 123 event->action = ui_event->type(); |
| 125 Event::Builder event; | 124 event->flags = ui_event->flags(); |
| 126 event.set_action(ui_event->type()); | 125 event->time_stamp = ui_event->time_stamp().ToInternalValue(); |
| 127 event.set_flags(ui_event->flags()); | |
| 128 event.set_time_stamp(ui_event->time_stamp().ToInternalValue()); | |
| 129 | 126 |
| 130 if (ui_event->IsMouseEvent() || ui_event->IsTouchEvent()) { | 127 if (ui_event->IsMouseEvent() || ui_event->IsTouchEvent()) { |
| 131 ui::LocatedEvent* located_event = | 128 ui::LocatedEvent* located_event = |
| 132 static_cast<ui::LocatedEvent*>(ui_event); | 129 static_cast<ui::LocatedEvent*>(ui_event); |
| 133 Point::Builder location; | 130 event->location = Point::New(); |
| 134 location.set_x(located_event->location().x()); | 131 event->location->x = located_event->location().x(); |
| 135 location.set_y(located_event->location().y()); | 132 event->location->y = located_event->location().y(); |
| 136 event.set_location(location.Finish()); | |
| 137 } | 133 } |
| 138 | 134 |
| 139 if (ui_event->IsTouchEvent()) { | 135 if (ui_event->IsTouchEvent()) { |
| 140 ui::TouchEvent* touch_event = static_cast<ui::TouchEvent*>(ui_event); | 136 ui::TouchEvent* touch_event = static_cast<ui::TouchEvent*>(ui_event); |
| 141 TouchData::Builder touch_data; | 137 event->touch_data = TouchData::New(); |
| 142 touch_data.set_pointer_id(touch_event->touch_id()); | 138 event->touch_data->pointer_id = touch_event->touch_id(); |
| 143 event.set_touch_data(touch_data.Finish()); | |
| 144 } else if (ui_event->IsKeyEvent()) { | 139 } else if (ui_event->IsKeyEvent()) { |
| 145 ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(ui_event); | 140 ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(ui_event); |
| 146 KeyData::Builder key_data; | 141 event->key_data = KeyData::New(); |
| 147 key_data.set_key_code(key_event->key_code()); | 142 event->key_data->key_code = key_event->key_code(); |
| 148 key_data.set_is_char(key_event->is_char()); | 143 event->key_data->is_char = key_event->is_char(); |
| 149 event.set_key_data(key_data.Finish()); | |
| 150 } | 144 } |
| 151 | 145 |
| 152 client()->OnEvent(event.Finish(), | 146 client()->OnEvent(event.Pass(), |
| 153 base::Bind(&NativeViewportImpl::AckEvent, | 147 base::Bind(&NativeViewportImpl::AckEvent, |
| 154 base::Unretained(this))); | 148 base::Unretained(this))); |
| 155 waiting_for_event_ack_ = true; | 149 waiting_for_event_ack_ = true; |
| 156 return false; | 150 return false; |
| 157 } | 151 } |
| 158 | 152 |
| 159 virtual void OnAcceleratedWidgetAvailable( | 153 virtual void OnAcceleratedWidgetAvailable( |
| 160 gfx::AcceleratedWidget widget) OVERRIDE { | 154 gfx::AcceleratedWidget widget) OVERRIDE { |
| 161 widget_ = widget; | 155 widget_ = widget; |
| 162 CreateCommandBufferIfNeeded(); | 156 CreateCommandBufferIfNeeded(); |
| 163 } | 157 } |
| 164 | 158 |
| 165 virtual void OnBoundsChanged(const gfx::Rect& bounds) OVERRIDE { | 159 virtual void OnBoundsChanged(const gfx::Rect& bounds) OVERRIDE { |
| 166 CreateCommandBufferIfNeeded(); | 160 CreateCommandBufferIfNeeded(); |
| 167 AllocationScope scope; | 161 client()->OnBoundsChanged(Rect::From(bounds)); |
| 168 client()->OnBoundsChanged(bounds); | |
| 169 } | 162 } |
| 170 | 163 |
| 171 virtual void OnDestroyed() OVERRIDE { | 164 virtual void OnDestroyed() OVERRIDE { |
| 172 command_buffer_.reset(); | 165 command_buffer_.reset(); |
| 173 client()->OnDestroyed(); | 166 client()->OnDestroyed(); |
| 174 base::MessageLoop::current()->Quit(); | 167 base::MessageLoop::current()->Quit(); |
| 175 } | 168 } |
| 176 | 169 |
| 177 private: | 170 private: |
| 178 shell::Context* context_; | 171 shell::Context* context_; |
| 179 gfx::AcceleratedWidget widget_; | 172 gfx::AcceleratedWidget widget_; |
| 180 scoped_ptr<services::NativeViewport> native_viewport_; | 173 scoped_ptr<services::NativeViewport> native_viewport_; |
| 181 ScopedMessagePipeHandle command_buffer_handle_; | 174 ScopedMessagePipeHandle command_buffer_handle_; |
| 182 scoped_ptr<CommandBufferImpl> command_buffer_; | 175 scoped_ptr<CommandBufferImpl> command_buffer_; |
| 183 bool waiting_for_event_ack_; | 176 bool waiting_for_event_ack_; |
| 184 }; | 177 }; |
| 185 | 178 |
| 186 } // namespace services | 179 } // namespace services |
| 187 } // namespace mojo | 180 } // namespace mojo |
| 188 | 181 |
| 189 | 182 |
| 190 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* | 183 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* |
| 191 CreateNativeViewportService(mojo::shell::Context* context, | 184 CreateNativeViewportService(mojo::shell::Context* context, |
| 192 mojo::ScopedMessagePipeHandle shell_handle) { | 185 mojo::ScopedMessagePipeHandle shell_handle) { |
| 193 mojo::Application* app = new mojo::Application(shell_handle.Pass()); | 186 mojo::Application* app = new mojo::Application(shell_handle.Pass()); |
| 194 app->AddService<mojo::services::NativeViewportImpl>(context); | 187 app->AddService<mojo::services::NativeViewportImpl>(context); |
| 195 return app; | 188 return app; |
| 196 } | 189 } |
| 197 | 190 |
| OLD | NEW |