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" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
90 ViewPrivate(root_).view_manager())->RemoveRoot(root_); | 90 ViewPrivate(root_).view_manager())->RemoveRoot(root_); |
91 view->RemoveObserver(this); | 91 view->RemoveObserver(this); |
92 delete this; | 92 delete this; |
93 } | 93 } |
94 | 94 |
95 View* root_; | 95 View* root_; |
96 | 96 |
97 DISALLOW_COPY_AND_ASSIGN(RootObserver); | 97 DISALLOW_COPY_AND_ASSIGN(RootObserver); |
98 }; | 98 }; |
99 | 99 |
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, | 100 ViewManagerClientImpl::ViewManagerClientImpl(ViewManagerDelegate* delegate, |
124 Shell* shell) | 101 Shell* shell) |
125 : connected_(false), | 102 : connected_(false), |
126 connection_id_(0), | 103 connection_id_(0), |
127 next_id_(1), | 104 next_id_(1), |
128 delegate_(delegate), | 105 delegate_(delegate), |
129 window_manager_delegate_(NULL), | 106 window_manager_delegate_(NULL), |
130 shell_(shell) { | 107 shell_(shell) { |
131 // TODO(beng): Come up with a better way of establishing a configuration for | 108 // TODO(beng): Come up with a better way of establishing a configuration for |
132 // what the active window manager is. | 109 // what the active window manager is. |
(...skipping 19 matching lines...) Expand all Loading... | |
152 non_owned.push_back(it->second); | 129 non_owned.push_back(it->second); |
153 views_.erase(it); | 130 views_.erase(it); |
154 } | 131 } |
155 } | 132 } |
156 // Delete the non-owned views last. In the typical case these are roots. The | 133 // 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 | 134 // exception is the window manager, which may know aboutother random views |
158 // that it doesn't own. | 135 // that it doesn't own. |
159 // NOTE: we manually delete as we're a friend. | 136 // NOTE: we manually delete as we're a friend. |
160 for (size_t i = 0; i < non_owned.size(); ++i) | 137 for (size_t i = 0; i < non_owned.size(); ++i) |
161 delete non_owned[i]; | 138 delete non_owned[i]; |
139 | |
140 for (BitmapUploaderMap::iterator it = bitmap_uploaders_.begin(); | |
141 it != bitmap_uploaders_.end(); | |
142 ++it) { | |
143 delete it->second; | |
Ben Goodger (Google)
2014/09/13 01:22:22
rather than track this here, do you think it makes
| |
144 } | |
162 delegate_->OnViewManagerDisconnected(this); | 145 delegate_->OnViewManagerDisconnected(this); |
163 } | 146 } |
164 | 147 |
165 Id ViewManagerClientImpl::CreateView() { | 148 Id ViewManagerClientImpl::CreateView() { |
166 DCHECK(connected_); | 149 DCHECK(connected_); |
167 const Id view_id = MakeTransportId(connection_id_, ++next_id_); | 150 const Id view_id = MakeTransportId(connection_id_, ++next_id_); |
168 service_->CreateView(view_id, ActionCompletedCallbackWithErrorCode()); | 151 service_->CreateView(view_id, ActionCompletedCallbackWithErrorCode()); |
169 return view_id; | 152 return view_id; |
170 } | 153 } |
171 | 154 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 DCHECK(connected_); | 190 DCHECK(connected_); |
208 if (surface_id.is_null()) | 191 if (surface_id.is_null()) |
209 return; | 192 return; |
210 service_->SetViewSurfaceId( | 193 service_->SetViewSurfaceId( |
211 view_id, surface_id.Pass(), ActionCompletedCallback()); | 194 view_id, surface_id.Pass(), ActionCompletedCallback()); |
212 } | 195 } |
213 | 196 |
214 void ViewManagerClientImpl::SetViewContents(Id view_id, | 197 void ViewManagerClientImpl::SetViewContents(Id view_id, |
215 const SkBitmap& contents) { | 198 const SkBitmap& contents) { |
216 DCHECK(connected_); | 199 DCHECK(connected_); |
217 if (!bitmap_uploader_) { | 200 BitmapUploaderForView(view_id)->SetBitmap(contents); |
218 SurfacesServicePtr surfaces_service; | 201 } |
219 InterfacePtr<ServiceProvider> surfaces_service_provider; | 202 |
220 shell_->ConnectToApplication("mojo:mojo_surfaces_service", | 203 void ViewManagerClientImpl::SetViewColor(Id view_id, SkColor color) { |
221 Get(&surfaces_service_provider)); | 204 DCHECK(connected_); |
222 ConnectToService(surfaces_service_provider.get(), &surfaces_service); | 205 BitmapUploaderForView(view_id)->SetColor(color); |
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 } | 206 } |
239 | 207 |
240 void ViewManagerClientImpl::SetFocus(Id view_id) { | 208 void ViewManagerClientImpl::SetFocus(Id view_id) { |
241 window_manager_->FocusWindow(view_id, ActionCompletedCallback()); | 209 window_manager_->FocusWindow(view_id, ActionCompletedCallback()); |
242 } | 210 } |
243 | 211 |
244 void ViewManagerClientImpl::SetVisible(Id view_id, bool visible) { | 212 void ViewManagerClientImpl::SetVisible(Id view_id, bool visible) { |
245 DCHECK(connected_); | 213 DCHECK(connected_); |
246 service_->SetViewVisibility(view_id, visible, ActionCompletedCallback()); | 214 service_->SetViewVisibility(view_id, visible, ActionCompletedCallback()); |
247 } | 215 } |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
465 return base::Bind(&ViewManagerClientImpl::OnActionCompleted, | 433 return base::Bind(&ViewManagerClientImpl::OnActionCompleted, |
466 base::Unretained(this)); | 434 base::Unretained(this)); |
467 } | 435 } |
468 | 436 |
469 base::Callback<void(ErrorCode)> | 437 base::Callback<void(ErrorCode)> |
470 ViewManagerClientImpl::ActionCompletedCallbackWithErrorCode() { | 438 ViewManagerClientImpl::ActionCompletedCallbackWithErrorCode() { |
471 return base::Bind(&ViewManagerClientImpl::OnActionCompletedWithErrorCode, | 439 return base::Bind(&ViewManagerClientImpl::OnActionCompletedWithErrorCode, |
472 base::Unretained(this)); | 440 base::Unretained(this)); |
473 } | 441 } |
474 | 442 |
443 BitmapUploader* ViewManagerClientImpl::BitmapUploaderForView(Id view_id) { | |
444 BitmapUploader* uploader = bitmap_uploaders_[view_id]; | |
445 if (!uploader) { | |
446 SurfacesServicePtr surfaces_service; | |
447 InterfacePtr<ServiceProvider> surfaces_service_provider; | |
448 shell_->ConnectToApplication("mojo:mojo_surfaces_service", | |
449 Get(&surfaces_service_provider)); | |
450 ConnectToService(surfaces_service_provider.get(), &surfaces_service); | |
451 GpuPtr gpu_service; | |
452 InterfacePtr<ServiceProvider> gpu_service_provider; | |
453 shell_->ConnectToApplication("mojo:mojo_native_viewport_service", | |
454 Get(&gpu_service_provider)); | |
455 ConnectToService(gpu_service_provider.get(), &gpu_service); | |
456 uploader = new BitmapUploader( | |
457 this, view_id, surfaces_service.Pass(), gpu_service.Pass()); | |
458 | |
459 bitmap_uploaders_[view_id] = uploader; | |
460 } | |
461 View* view = GetViewById(view_id); | |
462 uploader->SetSize(view->bounds().size()); | |
463 return uploader; | |
464 } | |
465 | |
475 } // namespace mojo | 466 } // namespace mojo |
OLD | NEW |