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/service_provider/service_provider.mojom.h" | 10 #include "mojo/public/interfaces/service_provider/service_provider.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/native_viewport.h" | 12 #include "mojo/services/native_viewport/native_viewport.h" |
14 #include "mojo/services/native_viewport/native_viewport.mojom.h" | 13 #include "mojo/services/native_viewport/native_viewport.mojom.h" |
15 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 14 #include "mojo/services/public/cpp/geometry/geometry_type_converters.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 13 matching lines...) Expand all Loading... |
34 NativeViewportImpl(shell::Context* context) | 33 NativeViewportImpl(shell::Context* context) |
35 : context_(context), | 34 : context_(context), |
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 Create(const Rect& bounds) OVERRIDE { | 43 virtual void Create(RectPtr bounds) OVERRIDE { |
45 native_viewport_ = | 44 native_viewport_ = |
46 services::NativeViewport::Create(context_, this); | 45 services::NativeViewport::Create(context_, this); |
47 native_viewport_->Init(bounds); | 46 native_viewport_->Init(bounds.To<gfx::Rect>()); |
48 client()->OnCreated(); | 47 client()->OnCreated(); |
49 OnBoundsChanged(bounds); | 48 OnBoundsChanged(bounds.To<gfx::Rect>()); |
50 } | 49 } |
51 | 50 |
52 virtual void Show() OVERRIDE { | 51 virtual void Show() OVERRIDE { |
53 native_viewport_->Show(); | 52 native_viewport_->Show(); |
54 } | 53 } |
55 | 54 |
56 virtual void Hide() OVERRIDE { | 55 virtual void Hide() OVERRIDE { |
57 native_viewport_->Hide(); | 56 native_viewport_->Hide(); |
58 } | 57 } |
59 | 58 |
60 virtual void Close() OVERRIDE { | 59 virtual void Close() OVERRIDE { |
61 command_buffer_.reset(); | 60 command_buffer_.reset(); |
62 DCHECK(native_viewport_); | 61 DCHECK(native_viewport_); |
63 native_viewport_->Close(); | 62 native_viewport_->Close(); |
64 } | 63 } |
65 | 64 |
66 virtual void SetBounds(const Rect& bounds) OVERRIDE { | 65 virtual void SetBounds(RectPtr bounds) OVERRIDE { |
67 AllocationScope scope; | 66 native_viewport_->SetBounds(bounds.To<gfx::Rect>()); |
68 native_viewport_->SetBounds(bounds); | |
69 } | 67 } |
70 | 68 |
71 virtual void CreateGLES2Context(ScopedMessagePipeHandle client_handle) | 69 virtual void CreateGLES2Context(ScopedMessagePipeHandle client_handle) |
72 OVERRIDE { | 70 OVERRIDE { |
73 if (command_buffer_.get() || command_buffer_handle_.is_valid()) { | 71 if (command_buffer_.get() || command_buffer_handle_.is_valid()) { |
74 LOG(ERROR) << "Can't create multiple contexts on a NativeViewport"; | 72 LOG(ERROR) << "Can't create multiple contexts on a NativeViewport"; |
75 return; | 73 return; |
76 } | 74 } |
77 | 75 |
78 // TODO(darin): CreateGLES2Context should accept a |CommandBufferPtr*|. | 76 // TODO(darin): CreateGLES2Context should accept a |CommandBufferPtr*|. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 case ui::ET_TOUCH_RELEASED: | 108 case ui::ET_TOUCH_RELEASED: |
111 native_viewport_->ReleaseCapture(); | 109 native_viewport_->ReleaseCapture(); |
112 break; | 110 break; |
113 default: | 111 default: |
114 break; | 112 break; |
115 } | 113 } |
116 | 114 |
117 if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event)) | 115 if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event)) |
118 return false; | 116 return false; |
119 | 117 |
120 AllocationScope scope; | 118 EventPtr event(Event::New()); |
121 | 119 event->action = ui_event->type(); |
122 Event::Builder event; | 120 event->flags = ui_event->flags(); |
123 event.set_action(ui_event->type()); | 121 event->time_stamp = ui_event->time_stamp().ToInternalValue(); |
124 event.set_flags(ui_event->flags()); | |
125 event.set_time_stamp(ui_event->time_stamp().ToInternalValue()); | |
126 | 122 |
127 if (ui_event->IsMouseEvent() || ui_event->IsTouchEvent()) { | 123 if (ui_event->IsMouseEvent() || ui_event->IsTouchEvent()) { |
128 ui::LocatedEvent* located_event = | 124 ui::LocatedEvent* located_event = |
129 static_cast<ui::LocatedEvent*>(ui_event); | 125 static_cast<ui::LocatedEvent*>(ui_event); |
130 Point::Builder location; | 126 event->location = Point::New(); |
131 location.set_x(located_event->location().x()); | 127 event->location->x = located_event->location().x(); |
132 location.set_y(located_event->location().y()); | 128 event->location->y = located_event->location().y(); |
133 event.set_location(location.Finish()); | |
134 } | 129 } |
135 | 130 |
136 if (ui_event->IsTouchEvent()) { | 131 if (ui_event->IsTouchEvent()) { |
137 ui::TouchEvent* touch_event = static_cast<ui::TouchEvent*>(ui_event); | 132 ui::TouchEvent* touch_event = static_cast<ui::TouchEvent*>(ui_event); |
138 TouchData::Builder touch_data; | 133 event->touch_data = TouchData::New(); |
139 touch_data.set_pointer_id(touch_event->touch_id()); | 134 event->touch_data->pointer_id = touch_event->touch_id(); |
140 event.set_touch_data(touch_data.Finish()); | |
141 } else if (ui_event->IsKeyEvent()) { | 135 } else if (ui_event->IsKeyEvent()) { |
142 ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(ui_event); | 136 ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(ui_event); |
143 KeyData::Builder key_data; | 137 event->key_data = KeyData::New(); |
144 key_data.set_key_code(key_event->key_code()); | 138 event->key_data->key_code = key_event->key_code(); |
145 key_data.set_is_char(key_event->is_char()); | 139 event->key_data->is_char = key_event->is_char(); |
146 event.set_key_data(key_data.Finish()); | |
147 } | 140 } |
148 | 141 |
149 client()->OnEvent(event.Finish(), | 142 client()->OnEvent(event.Pass(), |
150 base::Bind(&NativeViewportImpl::AckEvent, | 143 base::Bind(&NativeViewportImpl::AckEvent, |
151 base::Unretained(this))); | 144 base::Unretained(this))); |
152 waiting_for_event_ack_ = true; | 145 waiting_for_event_ack_ = true; |
153 return false; | 146 return false; |
154 } | 147 } |
155 | 148 |
156 virtual void OnAcceleratedWidgetAvailable( | 149 virtual void OnAcceleratedWidgetAvailable( |
157 gfx::AcceleratedWidget widget) OVERRIDE { | 150 gfx::AcceleratedWidget widget) OVERRIDE { |
158 widget_ = widget; | 151 widget_ = widget; |
159 CreateCommandBufferIfNeeded(); | 152 CreateCommandBufferIfNeeded(); |
160 } | 153 } |
161 | 154 |
162 virtual void OnBoundsChanged(const gfx::Rect& bounds) OVERRIDE { | 155 virtual void OnBoundsChanged(const gfx::Rect& bounds) OVERRIDE { |
163 CreateCommandBufferIfNeeded(); | 156 CreateCommandBufferIfNeeded(); |
164 AllocationScope scope; | 157 client()->OnBoundsChanged(Rect::From(bounds)); |
165 client()->OnBoundsChanged(bounds); | |
166 } | 158 } |
167 | 159 |
168 virtual void OnDestroyed() OVERRIDE { | 160 virtual void OnDestroyed() OVERRIDE { |
169 command_buffer_.reset(); | 161 command_buffer_.reset(); |
170 client()->OnDestroyed(); | 162 client()->OnDestroyed(); |
171 base::MessageLoop::current()->Quit(); | 163 base::MessageLoop::current()->Quit(); |
172 } | 164 } |
173 | 165 |
174 private: | 166 private: |
175 shell::Context* context_; | 167 shell::Context* context_; |
(...skipping 10 matching lines...) Expand all Loading... |
186 | 178 |
187 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* | 179 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* |
188 CreateNativeViewportService( | 180 CreateNativeViewportService( |
189 mojo::shell::Context* context, | 181 mojo::shell::Context* context, |
190 mojo::ScopedMessagePipeHandle service_provider_handle) { | 182 mojo::ScopedMessagePipeHandle service_provider_handle) { |
191 mojo::Application* app = new mojo::Application( | 183 mojo::Application* app = new mojo::Application( |
192 service_provider_handle.Pass()); | 184 service_provider_handle.Pass()); |
193 app->AddService<mojo::services::NativeViewportImpl>(context); | 185 app->AddService<mojo::services::NativeViewportImpl>(context); |
194 return app; | 186 return app; |
195 } | 187 } |
OLD | NEW |