| 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" | |
| 16 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" | 15 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" |
| 17 #include "mojo/services/public/cpp/view_manager/util.h" | 16 #include "mojo/services/public/cpp/view_manager/util.h" |
| 18 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" | 17 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h" |
| 19 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 18 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
| 20 #include "mojo/services/public/cpp/view_manager/window_manager_delegate.h" | 19 #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" | |
| 23 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
| 24 #include "ui/gfx/codec/png_codec.h" | 21 #include "ui/gfx/codec/png_codec.h" |
| 25 | 22 |
| 26 namespace mojo { | 23 namespace mojo { |
| 27 | 24 |
| 28 Id MakeTransportId(ConnectionSpecificId connection_id, | 25 Id MakeTransportId(ConnectionSpecificId connection_id, |
| 29 ConnectionSpecificId local_id) { | 26 ConnectionSpecificId local_id) { |
| 30 return (connection_id << 16) | local_id; | 27 return (connection_id << 16) | local_id; |
| 31 } | 28 } |
| 32 | 29 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 ViewPrivate(root_).view_manager())->RemoveRoot(root_); | 87 ViewPrivate(root_).view_manager())->RemoveRoot(root_); |
| 91 view->RemoveObserver(this); | 88 view->RemoveObserver(this); |
| 92 delete this; | 89 delete this; |
| 93 } | 90 } |
| 94 | 91 |
| 95 View* root_; | 92 View* root_; |
| 96 | 93 |
| 97 DISALLOW_COPY_AND_ASSIGN(RootObserver); | 94 DISALLOW_COPY_AND_ASSIGN(RootObserver); |
| 98 }; | 95 }; |
| 99 | 96 |
| 100 bool CreateMapAndDupSharedBuffer(size_t size, | |
| 101 void** memory, | |
| 102 ScopedSharedBufferHandle* handle, | |
| 103 ScopedSharedBufferHandle* duped) { | |
| 104 MojoResult result = CreateSharedBuffer(NULL, size, handle); | |
| 105 if (result != MOJO_RESULT_OK) | |
| 106 return false; | |
| 107 DCHECK(handle->is_valid()); | |
| 108 | |
| 109 result = DuplicateBuffer(handle->get(), NULL, duped); | |
| 110 if (result != MOJO_RESULT_OK) | |
| 111 return false; | |
| 112 DCHECK(duped->is_valid()); | |
| 113 | |
| 114 result = MapBuffer( | |
| 115 handle->get(), 0, size, memory, MOJO_MAP_BUFFER_FLAG_NONE); | |
| 116 if (result != MOJO_RESULT_OK) | |
| 117 return false; | |
| 118 DCHECK(*memory); | |
| 119 | |
| 120 return true; | |
| 121 } | |
| 122 | |
| 123 ViewManagerClientImpl::ViewManagerClientImpl(ViewManagerDelegate* delegate, | 97 ViewManagerClientImpl::ViewManagerClientImpl(ViewManagerDelegate* delegate, |
| 124 Shell* shell) | 98 Shell* shell) |
| 125 : connected_(false), | 99 : connected_(false), |
| 126 connection_id_(0), | 100 connection_id_(0), |
| 127 next_id_(1), | 101 next_id_(1), |
| 128 delegate_(delegate), | 102 delegate_(delegate), |
| 129 window_manager_delegate_(NULL), | 103 window_manager_delegate_(NULL), |
| 130 shell_(shell) { | 104 shell_(shell) { |
| 131 // TODO(beng): Come up with a better way of establishing a configuration for | 105 // TODO(beng): Come up with a better way of establishing a configuration for |
| 132 // what the active window manager is. | 106 // what the active window manager is. |
| (...skipping 19 matching lines...) Expand all Loading... |
| 152 non_owned.push_back(it->second); | 126 non_owned.push_back(it->second); |
| 153 views_.erase(it); | 127 views_.erase(it); |
| 154 } | 128 } |
| 155 } | 129 } |
| 156 // Delete the non-owned views last. In the typical case these are roots. The | 130 // Delete the non-owned views last. In the typical case these are roots. The |
| 157 // exception is the window manager, which may know aboutother random views | 131 // exception is the window manager, which may know aboutother random views |
| 158 // that it doesn't own. | 132 // that it doesn't own. |
| 159 // NOTE: we manually delete as we're a friend. | 133 // NOTE: we manually delete as we're a friend. |
| 160 for (size_t i = 0; i < non_owned.size(); ++i) | 134 for (size_t i = 0; i < non_owned.size(); ++i) |
| 161 delete non_owned[i]; | 135 delete non_owned[i]; |
| 136 |
| 162 delegate_->OnViewManagerDisconnected(this); | 137 delegate_->OnViewManagerDisconnected(this); |
| 163 } | 138 } |
| 164 | 139 |
| 165 Id ViewManagerClientImpl::CreateView() { | 140 Id ViewManagerClientImpl::CreateView() { |
| 166 DCHECK(connected_); | 141 DCHECK(connected_); |
| 167 const Id view_id = MakeTransportId(connection_id_, ++next_id_); | 142 const Id view_id = MakeTransportId(connection_id_, ++next_id_); |
| 168 service_->CreateView(view_id, ActionCompletedCallbackWithErrorCode()); | 143 service_->CreateView(view_id, ActionCompletedCallbackWithErrorCode()); |
| 169 return view_id; | 144 return view_id; |
| 170 } | 145 } |
| 171 | 146 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 } | 179 } |
| 205 | 180 |
| 206 void ViewManagerClientImpl::SetSurfaceId(Id view_id, SurfaceIdPtr surface_id) { | 181 void ViewManagerClientImpl::SetSurfaceId(Id view_id, SurfaceIdPtr surface_id) { |
| 207 DCHECK(connected_); | 182 DCHECK(connected_); |
| 208 if (surface_id.is_null()) | 183 if (surface_id.is_null()) |
| 209 return; | 184 return; |
| 210 service_->SetViewSurfaceId( | 185 service_->SetViewSurfaceId( |
| 211 view_id, surface_id.Pass(), ActionCompletedCallback()); | 186 view_id, surface_id.Pass(), ActionCompletedCallback()); |
| 212 } | 187 } |
| 213 | 188 |
| 214 void ViewManagerClientImpl::SetViewContents(Id view_id, | |
| 215 const SkBitmap& contents) { | |
| 216 DCHECK(connected_); | |
| 217 if (!bitmap_uploader_) { | |
| 218 SurfacesServicePtr surfaces_service; | |
| 219 InterfacePtr<ServiceProvider> surfaces_service_provider; | |
| 220 shell_->ConnectToApplication("mojo:mojo_surfaces_service", | |
| 221 Get(&surfaces_service_provider)); | |
| 222 ConnectToService(surfaces_service_provider.get(), &surfaces_service); | |
| 223 GpuPtr gpu_service; | |
| 224 InterfacePtr<ServiceProvider> gpu_service_provider; | |
| 225 shell_->ConnectToApplication("mojo:mojo_native_viewport_service", | |
| 226 Get(&gpu_service_provider)); | |
| 227 ConnectToService(gpu_service_provider.get(), &gpu_service); | |
| 228 bitmap_uploader_.reset( | |
| 229 new BitmapUploader(surfaces_service.Pass(), gpu_service.Pass())); | |
| 230 } | |
| 231 bitmap_uploader_->Upload( | |
| 232 contents, | |
| 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)); | |
| 238 } | |
| 239 | |
| 240 void ViewManagerClientImpl::SetFocus(Id view_id) { | 189 void ViewManagerClientImpl::SetFocus(Id view_id) { |
| 241 window_manager_->FocusWindow(view_id, ActionCompletedCallback()); | 190 window_manager_->FocusWindow(view_id, ActionCompletedCallback()); |
| 242 } | 191 } |
| 243 | 192 |
| 244 void ViewManagerClientImpl::SetVisible(Id view_id, bool visible) { | 193 void ViewManagerClientImpl::SetVisible(Id view_id, bool visible) { |
| 245 DCHECK(connected_); | 194 DCHECK(connected_); |
| 246 service_->SetViewVisibility(view_id, visible, ActionCompletedCallback()); | 195 service_->SetViewVisibility(view_id, visible, ActionCompletedCallback()); |
| 247 } | 196 } |
| 248 | 197 |
| 249 void ViewManagerClientImpl::Embed(const String& url, Id view_id) { | 198 void ViewManagerClientImpl::Embed(const String& url, Id view_id) { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 base::Unretained(this)); | 415 base::Unretained(this)); |
| 467 } | 416 } |
| 468 | 417 |
| 469 base::Callback<void(ErrorCode)> | 418 base::Callback<void(ErrorCode)> |
| 470 ViewManagerClientImpl::ActionCompletedCallbackWithErrorCode() { | 419 ViewManagerClientImpl::ActionCompletedCallbackWithErrorCode() { |
| 471 return base::Bind(&ViewManagerClientImpl::OnActionCompletedWithErrorCode, | 420 return base::Bind(&ViewManagerClientImpl::OnActionCompletedWithErrorCode, |
| 472 base::Unretained(this)); | 421 base::Unretained(this)); |
| 473 } | 422 } |
| 474 | 423 |
| 475 } // namespace mojo | 424 } // namespace mojo |
| OLD | NEW |