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

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

Issue 265793015: Mojo: Replace RemotePtr with InterfacePtr and InterfaceImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 7 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/public/cpp/bindings/allocation_scope.h" 10 #include "mojo/public/cpp/bindings/allocation_scope.h"
(...skipping 16 matching lines...) Expand all
27 27
28 } 28 }
29 29
30 class NativeViewportImpl 30 class NativeViewportImpl
31 : public ServiceConnection<mojo::NativeViewport, 31 : public ServiceConnection<mojo::NativeViewport,
32 NativeViewportImpl, 32 NativeViewportImpl,
33 shell::Context>, 33 shell::Context>,
34 public NativeViewportDelegate { 34 public NativeViewportDelegate {
35 public: 35 public:
36 NativeViewportImpl() 36 NativeViewportImpl()
37 : widget_(gfx::kNullAcceleratedWidget), 37 : client_(NULL),
38 widget_(gfx::kNullAcceleratedWidget),
38 waiting_for_event_ack_(false) {} 39 waiting_for_event_ack_(false) {}
39 virtual ~NativeViewportImpl() { 40 virtual ~NativeViewportImpl() {
40 // Destroy the NativeViewport early on as it may call us back during 41 // Destroy the NativeViewport early on as it may call us back during
41 // destruction and we want to be in a known state. 42 // destruction and we want to be in a known state.
42 native_viewport_.reset(); 43 native_viewport_.reset();
43 } 44 }
44 45
46 virtual void SetClient(NativeViewportClient* client) OVERRIDE {
47 client_ = client;
48 }
49
45 virtual void Create(const Rect& bounds) OVERRIDE { 50 virtual void Create(const Rect& bounds) OVERRIDE {
46 native_viewport_ = 51 native_viewport_ =
47 services::NativeViewport::Create(context(), this); 52 services::NativeViewport::Create(context(), this);
48 native_viewport_->Init(bounds); 53 native_viewport_->Init(bounds);
49 client()->OnCreated(); 54 client_->OnCreated();
50 OnBoundsChanged(bounds); 55 OnBoundsChanged(bounds);
51 } 56 }
52 57
53 virtual void Show() OVERRIDE { 58 virtual void Show() OVERRIDE {
54 native_viewport_->Show(); 59 native_viewport_->Show();
55 } 60 }
56 61
57 virtual void Hide() OVERRIDE { 62 virtual void Hide() OVERRIDE {
58 native_viewport_->Hide(); 63 native_viewport_->Hide();
59 } 64 }
60 65
61 virtual void Close() OVERRIDE { 66 virtual void Close() OVERRIDE {
62 command_buffer_.reset(); 67 command_buffer_.reset();
63 DCHECK(native_viewport_); 68 DCHECK(native_viewport_);
64 native_viewport_->Close(); 69 native_viewport_->Close();
65 } 70 }
66 71
67 virtual void SetBounds(const Rect& bounds) OVERRIDE { 72 virtual void SetBounds(const Rect& bounds) OVERRIDE {
68 gfx::Rect gfx_bounds(bounds.position().x(), bounds.position().y(), 73 gfx::Rect gfx_bounds(bounds.position().x(), bounds.position().y(),
69 bounds.size().width(), bounds.size().height()); 74 bounds.size().width(), bounds.size().height());
70 native_viewport_->SetBounds(gfx_bounds); 75 native_viewport_->SetBounds(gfx_bounds);
71 } 76 }
72 77
73 virtual void CreateGLES2Context(ScopedMessagePipeHandle client_handle) 78 virtual void CreateGLES2Context(ScopedMessagePipeHandle client_handle)
74 OVERRIDE { 79 OVERRIDE {
75 if (command_buffer_ || command_buffer_handle_.is_valid()) { 80 if (command_buffer_.get() || command_buffer_handle_.is_valid()) {
76 LOG(ERROR) << "Can't create multiple contexts on a NativeViewport"; 81 LOG(ERROR) << "Can't create multiple contexts on a NativeViewport";
77 return; 82 return;
78 } 83 }
79 84
80 // TODO(darin): 85 // TODO(darin): CreateGLES2Context should accept a |CommandBufferPtr*|.
81 // CreateGLES2Context should accept a ScopedCommandBufferClientHandle once 86 command_buffer_handle_ = client_handle.Pass();
82 // it is possible to import interface definitions from another module. For
83 // now, we just kludge it.
84 command_buffer_handle_.reset(
85 InterfaceHandle<CommandBufferClient>(client_handle.release().value()));
86 87
87 CreateCommandBufferIfNeeded(); 88 CreateCommandBufferIfNeeded();
88 } 89 }
89 90
90 void AckEvent() { 91 void AckEvent() {
91 waiting_for_event_ack_ = false; 92 waiting_for_event_ack_ = false;
92 } 93 }
93 94
94 void CreateCommandBufferIfNeeded() { 95 void CreateCommandBufferIfNeeded() {
95 if (!command_buffer_handle_.is_valid()) 96 if (!command_buffer_handle_.is_valid())
96 return; 97 return;
97 DCHECK(!command_buffer_.get()); 98 DCHECK(!command_buffer_.get());
98 if (widget_ == gfx::kNullAcceleratedWidget) 99 if (widget_ == gfx::kNullAcceleratedWidget)
99 return; 100 return;
100 gfx::Size size = native_viewport_->GetSize(); 101 gfx::Size size = native_viewport_->GetSize();
101 if (size.IsEmpty()) 102 if (size.IsEmpty())
102 return; 103 return;
103 command_buffer_.reset(new CommandBufferImpl( 104 command_buffer_.reset(
104 command_buffer_handle_.Pass(), widget_, native_viewport_->GetSize())); 105 BindToPipe(new CommandBufferImpl(widget_, native_viewport_->GetSize()),
106 command_buffer_handle_.Pass()));
105 } 107 }
106 108
107 virtual bool OnEvent(ui::Event* ui_event) OVERRIDE { 109 virtual bool OnEvent(ui::Event* ui_event) OVERRIDE {
108 // Must not return early before updating capture. 110 // Must not return early before updating capture.
109 switch (ui_event->type()) { 111 switch (ui_event->type()) {
110 case ui::ET_MOUSE_PRESSED: 112 case ui::ET_MOUSE_PRESSED:
111 case ui::ET_TOUCH_PRESSED: 113 case ui::ET_TOUCH_PRESSED:
112 native_viewport_->SetCapture(); 114 native_viewport_->SetCapture();
113 break; 115 break;
114 case ui::ET_MOUSE_RELEASED: 116 case ui::ET_MOUSE_RELEASED:
(...skipping 29 matching lines...) Expand all
144 touch_data.set_pointer_id(touch_event->touch_id()); 146 touch_data.set_pointer_id(touch_event->touch_id());
145 event.set_touch_data(touch_data.Finish()); 147 event.set_touch_data(touch_data.Finish());
146 } else if (ui_event->IsKeyEvent()) { 148 } else if (ui_event->IsKeyEvent()) {
147 ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(ui_event); 149 ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(ui_event);
148 KeyData::Builder key_data; 150 KeyData::Builder key_data;
149 key_data.set_key_code(key_event->key_code()); 151 key_data.set_key_code(key_event->key_code());
150 key_data.set_is_char(key_event->is_char()); 152 key_data.set_is_char(key_event->is_char());
151 event.set_key_data(key_data.Finish()); 153 event.set_key_data(key_data.Finish());
152 } 154 }
153 155
154 client()->OnEvent(event.Finish(), 156 client_->OnEvent(event.Finish(),
155 base::Bind(&NativeViewportImpl::AckEvent, 157 base::Bind(&NativeViewportImpl::AckEvent,
156 base::Unretained(this))); 158 base::Unretained(this)));
157 waiting_for_event_ack_ = true; 159 waiting_for_event_ack_ = true;
158 return false; 160 return false;
159 } 161 }
160 162
161 virtual void OnAcceleratedWidgetAvailable( 163 virtual void OnAcceleratedWidgetAvailable(
162 gfx::AcceleratedWidget widget) OVERRIDE { 164 gfx::AcceleratedWidget widget) OVERRIDE {
163 widget_ = widget; 165 widget_ = widget;
164 CreateCommandBufferIfNeeded(); 166 CreateCommandBufferIfNeeded();
165 } 167 }
166 168
167 virtual void OnBoundsChanged(const gfx::Rect& bounds) OVERRIDE { 169 virtual void OnBoundsChanged(const gfx::Rect& bounds) OVERRIDE {
168 CreateCommandBufferIfNeeded(); 170 CreateCommandBufferIfNeeded();
169 AllocationScope scope; 171 AllocationScope scope;
170 client()->OnBoundsChanged(bounds); 172 client_->OnBoundsChanged(bounds);
171 } 173 }
172 174
173 virtual void OnDestroyed() OVERRIDE { 175 virtual void OnDestroyed() OVERRIDE {
174 command_buffer_.reset(); 176 command_buffer_.reset();
175 client()->OnDestroyed(); 177 client_->OnDestroyed();
176 base::MessageLoop::current()->Quit(); 178 base::MessageLoop::current()->Quit();
177 } 179 }
178 180
179 private: 181 private:
182 NativeViewportClient* client_;
180 gfx::AcceleratedWidget widget_; 183 gfx::AcceleratedWidget widget_;
181 scoped_ptr<services::NativeViewport> native_viewport_; 184 scoped_ptr<services::NativeViewport> native_viewport_;
182 ScopedCommandBufferClientHandle command_buffer_handle_; 185 ScopedMessagePipeHandle command_buffer_handle_;
183 scoped_ptr<CommandBufferImpl> command_buffer_; 186 scoped_ptr<CommandBufferImpl> command_buffer_;
184 bool waiting_for_event_ack_; 187 bool waiting_for_event_ack_;
185 }; 188 };
186 189
187 } // namespace services 190 } // namespace services
188 } // namespace mojo 191 } // namespace mojo
189 192
190 193
191 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application* 194 MOJO_NATIVE_VIEWPORT_EXPORT mojo::Application*
192 CreateNativeViewportService(mojo::shell::Context* context, 195 CreateNativeViewportService(mojo::shell::Context* context,
193 mojo::ScopedShellHandle shell_handle) { 196 mojo::ScopedMessagePipeHandle shell_handle) {
194 mojo::Application* app = new mojo::Application(shell_handle.Pass()); 197 mojo::Application* app = new mojo::Application(shell_handle.Pass());
195 app->AddServiceConnector( 198 app->AddServiceConnector(
196 new mojo::ServiceConnector<mojo::services::NativeViewportImpl, 199 new mojo::ServiceConnector<mojo::services::NativeViewportImpl,
197 mojo::shell::Context>(context)); 200 mojo::shell::Context>(context));
198 return app; 201 return app;
199 } 202 }
200 203
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698