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/application_connection.h" | 11 #include "mojo/public/cpp/application/application_connection.h" |
12 #include "mojo/public/cpp/application/connect.h" | 12 #include "mojo/public/cpp/application/connect.h" |
13 #include "mojo/public/cpp/application/service_provider_impl.h" | 13 #include "mojo/public/cpp/application/service_provider_impl.h" |
14 #include "mojo/public/interfaces/application/service_provider.mojom.h" | 14 #include "mojo/public/interfaces/application/service_provider.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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 return true; | 120 return true; |
118 } | 121 } |
119 | 122 |
120 ViewManagerClientImpl::ViewManagerClientImpl( | 123 ViewManagerClientImpl::ViewManagerClientImpl( |
121 ViewManagerDelegate* delegate, | 124 ViewManagerDelegate* delegate, |
122 ApplicationConnection* app_connection) | 125 ApplicationConnection* app_connection) |
123 : connected_(false), | 126 : connected_(false), |
124 connection_id_(0), | 127 connection_id_(0), |
125 next_id_(1), | 128 next_id_(1), |
126 delegate_(delegate), | 129 delegate_(delegate), |
127 window_manager_delegate_(NULL) { | 130 window_manager_delegate_(NULL), |
| 131 app_connection_(app_connection) { |
128 // TODO(beng): Come up with a better way of establishing a configuration for | 132 // TODO(beng): Come up with a better way of establishing a configuration for |
129 // what the active window manager is. | 133 // what the active window manager is. |
130 std::string window_manager_url = "mojo:mojo_window_manager"; | 134 std::string window_manager_url = "mojo:mojo_window_manager"; |
131 if (base::CommandLine::ForCurrentProcess()->HasSwitch("window-manager")) { | 135 if (base::CommandLine::ForCurrentProcess()->HasSwitch("window-manager")) { |
132 window_manager_url = | 136 window_manager_url = |
133 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 137 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
134 "window-manager"); | 138 "window-manager"); |
135 } | 139 } |
136 app_connection->ConnectToService(window_manager_url, &window_manager_); | 140 app_connection->ConnectToService(window_manager_url, &window_manager_); |
137 window_manager_.set_client(this); | 141 window_manager_.set_client(this); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 bool ViewManagerClientImpl::OwnsView(Id id) const { | 195 bool ViewManagerClientImpl::OwnsView(Id id) const { |
192 return HiWord(id) == connection_id_; | 196 return HiWord(id) == connection_id_; |
193 } | 197 } |
194 | 198 |
195 void ViewManagerClientImpl::SetBounds(Id view_id, const gfx::Rect& bounds) { | 199 void ViewManagerClientImpl::SetBounds(Id view_id, const gfx::Rect& bounds) { |
196 DCHECK(connected_); | 200 DCHECK(connected_); |
197 service_->SetViewBounds(view_id, Rect::From(bounds), | 201 service_->SetViewBounds(view_id, Rect::From(bounds), |
198 ActionCompletedCallback()); | 202 ActionCompletedCallback()); |
199 } | 203 } |
200 | 204 |
| 205 void ViewManagerClientImpl::SetSurfaceId(Id view_id, SurfaceIdPtr surface_id) { |
| 206 DCHECK(connected_); |
| 207 if (surface_id.is_null()) |
| 208 return; |
| 209 service_->SetViewSurfaceId( |
| 210 view_id, surface_id.Pass(), ActionCompletedCallback()); |
| 211 } |
| 212 |
201 void ViewManagerClientImpl::SetViewContents(Id view_id, | 213 void ViewManagerClientImpl::SetViewContents(Id view_id, |
202 const SkBitmap& contents) { | 214 const SkBitmap& contents) { |
203 DCHECK(connected_); | 215 DCHECK(connected_); |
204 std::vector<unsigned char> data; | 216 if (!bitmap_uploader_) { |
205 gfx::PNGCodec::EncodeBGRASkBitmap(contents, false, &data); | 217 SurfacesServicePtr surfaces_service; |
206 | 218 app_connection_->ConnectToService("mojo:mojo_surfaces_service", |
207 void* memory = NULL; | 219 &surfaces_service); |
208 ScopedSharedBufferHandle duped, shared_state_handle; | 220 GpuPtr gpu_service; |
209 bool result = CreateMapAndDupSharedBuffer(data.size(), | 221 app_connection_->ConnectToService("mojo:mojo_native_viewport_service", |
210 &memory, | 222 &gpu_service); |
211 &shared_state_handle, | 223 bitmap_uploader_.reset( |
212 &duped); | 224 new BitmapUploader(surfaces_service.Pass(), gpu_service.Pass())); |
213 if (!result) | 225 } |
214 return; | 226 bitmap_uploader_->Upload( |
215 | 227 contents, |
216 memcpy(memory, &data[0], data.size()); | 228 base::Bind(&ViewManagerClientImpl::SetSurfaceId, |
217 | 229 // We'll destroy the bitmap_uploader before we are destroyed, |
218 service_->SetViewContents(view_id, duped.Pass(), | 230 // so we can use an unretained pointer here. |
219 static_cast<uint32_t>(data.size()), | 231 base::Unretained(this), |
220 ActionCompletedCallback()); | 232 view_id)); |
221 } | 233 } |
222 | 234 |
223 void ViewManagerClientImpl::SetFocus(Id view_id) { | 235 void ViewManagerClientImpl::SetFocus(Id view_id) { |
224 window_manager_->FocusWindow(view_id, ActionCompletedCallback()); | 236 window_manager_->FocusWindow(view_id, ActionCompletedCallback()); |
225 } | 237 } |
226 | 238 |
227 void ViewManagerClientImpl::SetVisible(Id view_id, bool visible) { | 239 void ViewManagerClientImpl::SetVisible(Id view_id, bool visible) { |
228 DCHECK(connected_); | 240 DCHECK(connected_); |
229 service_->SetViewVisibility(view_id, visible, ActionCompletedCallback()); | 241 service_->SetViewVisibility(view_id, visible, ActionCompletedCallback()); |
230 } | 242 } |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 base::Unretained(this)); | 451 base::Unretained(this)); |
440 } | 452 } |
441 | 453 |
442 base::Callback<void(ErrorCode)> | 454 base::Callback<void(ErrorCode)> |
443 ViewManagerClientImpl::ActionCompletedCallbackWithErrorCode() { | 455 ViewManagerClientImpl::ActionCompletedCallbackWithErrorCode() { |
444 return base::Bind(&ViewManagerClientImpl::OnActionCompletedWithErrorCode, | 456 return base::Bind(&ViewManagerClientImpl::OnActionCompletedWithErrorCode, |
445 base::Unretained(this)); | 457 base::Unretained(this)); |
446 } | 458 } |
447 | 459 |
448 } // namespace mojo | 460 } // namespace mojo |
OLD | NEW |