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

Side by Side Diff: mojo/services/native_viewport/native_viewport_service.cc

Issue 294833002: Mojo: more idiomatic C++ bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix windows bustage Created 6 years, 6 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/geometry/geometry_type_converters.h" 10 #include "mojo/geometry/geometry_type_converters.h"
11 #include "mojo/public/cpp/bindings/allocation_scope.h"
12 #include "mojo/public/interfaces/shell/shell.mojom.h" 11 #include "mojo/public/interfaces/shell/shell.mojom.h"
13 #include "mojo/services/gles2/command_buffer_impl.h" 12 #include "mojo/services/gles2/command_buffer_impl.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 {
21 20
(...skipping 12 matching lines...) Expand all
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 gfx::Rect gfx_bounds(bounds.position().x(), bounds.position().y(), 66 gfx::Rect gfx_bounds(bounds->position->x, bounds->position->y,
68 bounds.size().width(), bounds.size().height()); 67 bounds->size->width, bounds->size->height);
69 native_viewport_->SetBounds(gfx_bounds); 68 native_viewport_->SetBounds(gfx_bounds);
70 } 69 }
71 70
72 virtual void CreateGLES2Context(ScopedMessagePipeHandle client_handle) 71 virtual void CreateGLES2Context(ScopedMessagePipeHandle client_handle)
73 OVERRIDE { 72 OVERRIDE {
74 if (command_buffer_.get() || command_buffer_handle_.is_valid()) { 73 if (command_buffer_.get() || command_buffer_handle_.is_valid()) {
75 LOG(ERROR) << "Can't create multiple contexts on a NativeViewport"; 74 LOG(ERROR) << "Can't create multiple contexts on a NativeViewport";
76 return; 75 return;
77 } 76 }
78 77
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 case ui::ET_TOUCH_RELEASED: 110 case ui::ET_TOUCH_RELEASED:
112 native_viewport_->ReleaseCapture(); 111 native_viewport_->ReleaseCapture();
113 break; 112 break;
114 default: 113 default:
115 break; 114 break;
116 } 115 }
117 116
118 if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event)) 117 if (waiting_for_event_ack_ && IsRateLimitedEventType(ui_event))
119 return false; 118 return false;
120 119
121 AllocationScope scope; 120 EventPtr event(Event::New());
122 121 event->action = ui_event->type();
123 Event::Builder event; 122 event->flags = ui_event->flags();
124 event.set_action(ui_event->type()); 123 event->time_stamp = ui_event->time_stamp().ToInternalValue();
125 event.set_flags(ui_event->flags());
126 event.set_time_stamp(ui_event->time_stamp().ToInternalValue());
127 124
128 if (ui_event->IsMouseEvent() || ui_event->IsTouchEvent()) { 125 if (ui_event->IsMouseEvent() || ui_event->IsTouchEvent()) {
129 ui::LocatedEvent* located_event = 126 ui::LocatedEvent* located_event =
130 static_cast<ui::LocatedEvent*>(ui_event); 127 static_cast<ui::LocatedEvent*>(ui_event);
131 Point::Builder location; 128 event->location = Point::New();
132 location.set_x(located_event->location().x()); 129 event->location->x = located_event->location().x();
133 location.set_y(located_event->location().y()); 130 event->location->y = located_event->location().y();
134 event.set_location(location.Finish());
135 } 131 }
136 132
137 if (ui_event->IsTouchEvent()) { 133 if (ui_event->IsTouchEvent()) {
138 ui::TouchEvent* touch_event = static_cast<ui::TouchEvent*>(ui_event); 134 ui::TouchEvent* touch_event = static_cast<ui::TouchEvent*>(ui_event);
139 TouchData::Builder touch_data; 135 event->touch_data = TouchData::New();
140 touch_data.set_pointer_id(touch_event->touch_id()); 136 event->touch_data->pointer_id = touch_event->touch_id();
141 event.set_touch_data(touch_data.Finish());
142 } else if (ui_event->IsKeyEvent()) { 137 } else if (ui_event->IsKeyEvent()) {
143 ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(ui_event); 138 ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(ui_event);
144 KeyData::Builder key_data; 139 event->key_data = KeyData::New();
145 key_data.set_key_code(key_event->key_code()); 140 event->key_data->key_code = key_event->key_code();
146 key_data.set_is_char(key_event->is_char()); 141 event->key_data->is_char = key_event->is_char();
147 event.set_key_data(key_data.Finish());
148 } 142 }
149 143
150 client()->OnEvent(event.Finish(), 144 client()->OnEvent(event.Pass(),
151 base::Bind(&NativeViewportImpl::AckEvent, 145 base::Bind(&NativeViewportImpl::AckEvent,
152 base::Unretained(this))); 146 base::Unretained(this)));
153 waiting_for_event_ack_ = true; 147 waiting_for_event_ack_ = true;
154 return false; 148 return false;
155 } 149 }
156 150
157 virtual void OnAcceleratedWidgetAvailable( 151 virtual void OnAcceleratedWidgetAvailable(
158 gfx::AcceleratedWidget widget) OVERRIDE { 152 gfx::AcceleratedWidget widget) OVERRIDE {
159 widget_ = widget; 153 widget_ = widget;
160 CreateCommandBufferIfNeeded(); 154 CreateCommandBufferIfNeeded();
161 } 155 }
162 156
163 virtual void OnBoundsChanged(const gfx::Rect& bounds) OVERRIDE { 157 virtual void OnBoundsChanged(const gfx::Rect& bounds) OVERRIDE {
164 CreateCommandBufferIfNeeded(); 158 CreateCommandBufferIfNeeded();
165 AllocationScope scope; 159 client()->OnBoundsChanged(Rect::From(bounds));
166 client()->OnBoundsChanged(bounds);
167 } 160 }
168 161
169 virtual void OnDestroyed() OVERRIDE { 162 virtual void OnDestroyed() OVERRIDE {
170 command_buffer_.reset(); 163 command_buffer_.reset();
171 client()->OnDestroyed(); 164 client()->OnDestroyed();
172 base::MessageLoop::current()->Quit(); 165 base::MessageLoop::current()->Quit();
173 } 166 }
174 167
175 private: 168 private:
176 shell::Context* context_; 169 shell::Context* context_;
177 gfx::AcceleratedWidget widget_; 170 gfx::AcceleratedWidget widget_;
178 scoped_ptr<services::NativeViewport> native_viewport_; 171 scoped_ptr<services::NativeViewport> native_viewport_;
179 ScopedMessagePipeHandle command_buffer_handle_; 172 ScopedMessagePipeHandle command_buffer_handle_;
180 scoped_ptr<CommandBufferImpl> command_buffer_; 173 scoped_ptr<CommandBufferImpl> command_buffer_;
181 bool waiting_for_event_ack_; 174 bool waiting_for_event_ack_;
182 }; 175 };
183 176
184 } // namespace services 177 } // namespace services
185 } // namespace mojo 178 } // namespace mojo
186 179
187 180
188 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* 181 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application*
189 CreateNativeViewportService(mojo::shell::Context* context, 182 CreateNativeViewportService(mojo::shell::Context* context,
190 mojo::ScopedMessagePipeHandle shell_handle) { 183 mojo::ScopedMessagePipeHandle shell_handle) {
191 mojo::Application* app = new mojo::Application(shell_handle.Pass()); 184 mojo::Application* app = new mojo::Application(shell_handle.Pass());
192 app->AddService<mojo::services::NativeViewportImpl>(context); 185 app->AddService<mojo::services::NativeViewportImpl>(context);
193 return app; 186 return app;
194 } 187 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698