OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/public/cpp/view_manager/lib/view_manager_client_impl.h" | 5 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
11 #include "mojo/public/cpp/application/connect.h" | 11 #include "mojo/public/cpp/application/connect.h" |
12 #include "mojo/public/cpp/application/service_provider_impl.h" | 12 #include "mojo/public/cpp/application/service_provider_impl.h" |
13 #include "mojo/public/interfaces/application/service_provider.mojom.h" | 13 #include "mojo/public/interfaces/application/service_provider.mojom.h" |
14 #include "mojo/public/interfaces/application/shell.mojom.h" | 14 #include "mojo/public/interfaces/application/shell.mojom.h" |
| 15 #include "mojo/services/public/cpp/view_manager/lib/bitmap_uploader.h" |
15 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" | 16 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" |
16 #include "mojo/services/public/cpp/view_manager/util.h" | 17 #include "mojo/services/public/cpp/view_manager/util.h" |
17 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 18 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
18 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 19 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
19 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" | 20 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" |
| 21 #include "mojo/services/public/interfaces/gpu/gpu.mojom.h" |
| 22 #include "mojo/services/public/interfaces/surfaces/surfaces_service.mojom.h" |
20 #include "third_party/skia/include/core/SkBitmap.h" | 23 #include "third_party/skia/include/core/SkBitmap.h" |
21 #include "ui/gfx/codec/png_codec.h" | 24 #include "ui/gfx/codec/png_codec.h" |
22 | 25 |
23 namespace mojo { | 26 namespace mojo { |
24 | 27 |
25 Id MakeTransportId(ConnectionSpecificId connection_id, | 28 Id MakeTransportId(ConnectionSpecificId connection_id, |
26 ConnectionSpecificId local_id) { | 29 ConnectionSpecificId local_id) { |
27 return (connection_id << 16) | local_id; | 30 return (connection_id << 16) | local_id; |
28 } | 31 } |
29 | 32 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 | 119 |
117 return true; | 120 return true; |
118 } | 121 } |
119 | 122 |
120 ViewManagerClientImpl::ViewManagerClientImpl(ViewManagerDelegate* delegate, | 123 ViewManagerClientImpl::ViewManagerClientImpl(ViewManagerDelegate* delegate, |
121 Shell* shell) | 124 Shell* shell) |
122 : connected_(false), | 125 : connected_(false), |
123 connection_id_(0), | 126 connection_id_(0), |
124 next_id_(1), | 127 next_id_(1), |
125 delegate_(delegate), | 128 delegate_(delegate), |
126 window_manager_delegate_(NULL) { | 129 window_manager_delegate_(NULL), |
| 130 shell_(shell) { |
127 // TODO(beng): Come up with a better way of establishing a configuration for | 131 // TODO(beng): Come up with a better way of establishing a configuration for |
128 // what the active window manager is. | 132 // what the active window manager is. |
129 std::string window_manager_url = "mojo:mojo_window_manager"; | 133 std::string window_manager_url = "mojo:mojo_window_manager"; |
130 if (base::CommandLine::ForCurrentProcess()->HasSwitch("window-manager")) { | 134 if (base::CommandLine::ForCurrentProcess()->HasSwitch("window-manager")) { |
131 window_manager_url = | 135 window_manager_url = |
132 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 136 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
133 "window-manager"); | 137 "window-manager"); |
134 } | 138 } |
135 InterfacePtr<ServiceProvider> sp; | 139 InterfacePtr<ServiceProvider> sp; |
136 shell->ConnectToApplication(window_manager_url, Get(&sp)); | 140 shell->ConnectToApplication(window_manager_url, Get(&sp)); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 bool ViewManagerClientImpl::OwnsView(Id id) const { | 196 bool ViewManagerClientImpl::OwnsView(Id id) const { |
193 return HiWord(id) == connection_id_; | 197 return HiWord(id) == connection_id_; |
194 } | 198 } |
195 | 199 |
196 void ViewManagerClientImpl::SetBounds(Id view_id, const gfx::Rect& bounds) { | 200 void ViewManagerClientImpl::SetBounds(Id view_id, const gfx::Rect& bounds) { |
197 DCHECK(connected_); | 201 DCHECK(connected_); |
198 service_->SetViewBounds(view_id, Rect::From(bounds), | 202 service_->SetViewBounds(view_id, Rect::From(bounds), |
199 ActionCompletedCallback()); | 203 ActionCompletedCallback()); |
200 } | 204 } |
201 | 205 |
| 206 void ViewManagerClientImpl::SetSurfaceId(Id view_id, SurfaceIdPtr surface_id) { |
| 207 DCHECK(connected_); |
| 208 if (surface_id.is_null()) |
| 209 return; |
| 210 service_->SetViewSurfaceId( |
| 211 view_id, surface_id.Pass(), ActionCompletedCallback()); |
| 212 } |
| 213 |
202 void ViewManagerClientImpl::SetViewContents(Id view_id, | 214 void ViewManagerClientImpl::SetViewContents(Id view_id, |
203 const SkBitmap& contents) { | 215 const SkBitmap& contents) { |
204 DCHECK(connected_); | 216 DCHECK(connected_); |
205 std::vector<unsigned char> data; | 217 if (!bitmap_uploader_) { |
206 gfx::PNGCodec::EncodeBGRASkBitmap(contents, false, &data); | 218 SurfacesServicePtr surfaces_service; |
207 | 219 InterfacePtr<ServiceProvider> surfaces_service_provider; |
208 void* memory = NULL; | 220 shell_->ConnectToApplication("mojo:mojo_surfaces_service", |
209 ScopedSharedBufferHandle duped, shared_state_handle; | 221 Get(&surfaces_service_provider)); |
210 bool result = CreateMapAndDupSharedBuffer(data.size(), | 222 ConnectToService(surfaces_service_provider.get(), &surfaces_service); |
211 &memory, | 223 GpuPtr gpu_service; |
212 &shared_state_handle, | 224 InterfacePtr<ServiceProvider> gpu_service_provider; |
213 &duped); | 225 shell_->ConnectToApplication("mojo:mojo_native_viewport_service", |
214 if (!result) | 226 Get(&gpu_service_provider)); |
215 return; | 227 ConnectToService(gpu_service_provider.get(), &gpu_service); |
216 | 228 bitmap_uploader_.reset( |
217 memcpy(memory, &data[0], data.size()); | 229 new BitmapUploader(surfaces_service.Pass(), gpu_service.Pass())); |
218 | 230 } |
219 service_->SetViewContents(view_id, duped.Pass(), | 231 bitmap_uploader_->Upload( |
220 static_cast<uint32_t>(data.size()), | 232 contents, |
221 ActionCompletedCallback()); | 233 base::Bind(&ViewManagerClientImpl::SetSurfaceId, |
| 234 // We'll destroy the bitmap_uploader before we are destroyed, |
| 235 // so we can use an unretained pointer here. |
| 236 base::Unretained(this), |
| 237 view_id)); |
222 } | 238 } |
223 | 239 |
224 void ViewManagerClientImpl::SetFocus(Id view_id) { | 240 void ViewManagerClientImpl::SetFocus(Id view_id) { |
225 window_manager_->FocusWindow(view_id, ActionCompletedCallback()); | 241 window_manager_->FocusWindow(view_id, ActionCompletedCallback()); |
226 } | 242 } |
227 | 243 |
228 void ViewManagerClientImpl::SetVisible(Id view_id, bool visible) { | 244 void ViewManagerClientImpl::SetVisible(Id view_id, bool visible) { |
229 DCHECK(connected_); | 245 DCHECK(connected_); |
230 service_->SetViewVisibility(view_id, visible, ActionCompletedCallback()); | 246 service_->SetViewVisibility(view_id, visible, ActionCompletedCallback()); |
231 } | 247 } |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 base::Unretained(this)); | 466 base::Unretained(this)); |
451 } | 467 } |
452 | 468 |
453 base::Callback<void(ErrorCode)> | 469 base::Callback<void(ErrorCode)> |
454 ViewManagerClientImpl::ActionCompletedCallbackWithErrorCode() { | 470 ViewManagerClientImpl::ActionCompletedCallbackWithErrorCode() { |
455 return base::Bind(&ViewManagerClientImpl::OnActionCompletedWithErrorCode, | 471 return base::Bind(&ViewManagerClientImpl::OnActionCompletedWithErrorCode, |
456 base::Unretained(this)); | 472 base::Unretained(this)); |
457 } | 473 } |
458 | 474 |
459 } // namespace mojo | 475 } // namespace mojo |
OLD | NEW |