Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/renderer_host/render_widget_host_view_android.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_android.h" |
| 6 | 6 |
| 7 #include <android/bitmap.h> | 7 #include <android/bitmap.h> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 | 278 |
| 279 bool RenderWidgetHostViewAndroid::HasValidFrame() const { | 279 bool RenderWidgetHostViewAndroid::HasValidFrame() const { |
| 280 if (!content_view_core_) | 280 if (!content_view_core_) |
| 281 return false; | 281 return false; |
| 282 if (!layer_) | 282 if (!layer_) |
| 283 return false; | 283 return false; |
| 284 | 284 |
| 285 if (texture_size_in_layer_.IsEmpty()) | 285 if (texture_size_in_layer_.IsEmpty()) |
| 286 return false; | 286 return false; |
| 287 | 287 |
| 288 if (!frame_evictor_->HasFrame()) | |
| 289 return false; | |
| 290 | |
| 288 if (using_delegated_renderer_) { | 291 if (using_delegated_renderer_) { |
| 289 if (!delegated_renderer_layer_.get()) | 292 if (!delegated_renderer_layer_.get()) |
| 290 return false; | 293 return false; |
| 291 } else { | 294 } else { |
| 292 if (texture_id_in_layer_ == 0) | 295 if (texture_id_in_layer_ == 0) |
| 293 return false; | 296 return false; |
| 294 } | 297 } |
| 295 | 298 |
| 296 return true; | 299 return true; |
| 297 } | 300 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 WasHidden(); | 371 WasHidden(); |
| 369 } | 372 } |
| 370 | 373 |
| 371 bool RenderWidgetHostViewAndroid::IsShowing() { | 374 bool RenderWidgetHostViewAndroid::IsShowing() { |
| 372 // ContentViewCoreImpl represents the native side of the Java | 375 // ContentViewCoreImpl represents the native side of the Java |
| 373 // ContentViewCore. It being NULL means that it is not attached | 376 // ContentViewCore. It being NULL means that it is not attached |
| 374 // to the View system yet, so we treat this RWHVA as hidden. | 377 // to the View system yet, so we treat this RWHVA as hidden. |
| 375 return is_showing_ && content_view_core_; | 378 return is_showing_ && content_view_core_; |
| 376 } | 379 } |
| 377 | 380 |
| 378 void RenderWidgetHostViewAndroid::LockResources() { | 381 void RenderWidgetHostViewAndroid::LockSurfaceForCopy() { |
| 379 DCHECK(HasValidFrame()); | 382 DCHECK(HasValidFrame()); |
| 380 DCHECK(host_); | 383 DCHECK(host_); |
| 381 DCHECK(!host_->is_hidden()); | 384 DCHECK(frame_evictor_->HasFrame()); |
| 382 frame_evictor_->LockFrame(); | 385 frame_evictor_->LockFrame(); |
| 383 } | 386 } |
| 384 | 387 |
| 385 void RenderWidgetHostViewAndroid::UnlockResources() { | 388 void RenderWidgetHostViewAndroid::UnlockSurfaceForCopy() { |
| 389 if (!frame_evictor_->HasFrame()) | |
| 390 return; | |
| 391 | |
| 392 size_t target_lock_count = is_showing_ ? 1 : 0; | |
| 393 DCHECK_GE(frame_evictor_->FrameLockCount(), target_lock_count); | |
| 394 if (frame_evictor_->FrameLockCount() == target_lock_count) | |
|
piman
2014/03/04 19:09:55
This feels iffy.
If some other code starts talkin
powei
2014/03/04 20:49:22
Done.
| |
| 395 return; | |
| 396 | |
| 386 DCHECK(HasValidFrame()); | 397 DCHECK(HasValidFrame()); |
| 387 frame_evictor_->UnlockFrame(); | 398 frame_evictor_->UnlockFrame(); |
| 388 } | 399 } |
| 389 | 400 |
| 401 void RenderWidgetHostViewAndroid::ReleaseLocksOnSurface() { | |
| 402 size_t target_lock_count = is_showing_ ? 1 : 0; | |
| 403 while (frame_evictor_->FrameLockCount() > target_lock_count ) { | |
| 404 UnlockSurfaceForCopy(); | |
| 405 } | |
| 406 } | |
| 407 | |
| 390 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const { | 408 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const { |
| 391 if (!content_view_core_) | 409 if (!content_view_core_) |
| 392 return gfx::Rect(default_size_); | 410 return gfx::Rect(default_size_); |
| 393 | 411 |
| 394 gfx::Size size = content_view_core_->GetViewportSizeDip(); | 412 gfx::Size size = content_view_core_->GetViewportSizeDip(); |
| 395 gfx::Size offset = content_view_core_->GetViewportSizeOffsetDip(); | 413 gfx::Size offset = content_view_core_->GetViewportSizeOffsetDip(); |
| 396 size.Enlarge(-offset.width(), -offset.height()); | 414 size.Enlarge(-offset.width(), -offset.height()); |
| 397 | 415 |
| 398 return gfx::Rect(size); | 416 return gfx::Rect(size); |
| 399 } | 417 } |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 801 layer_->layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); | 819 layer_->layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); |
| 802 } | 820 } |
| 803 } | 821 } |
| 804 | 822 |
| 805 if (frame->delegated_frame_data) { | 823 if (frame->delegated_frame_data) { |
| 806 DCHECK(using_delegated_renderer_); | 824 DCHECK(using_delegated_renderer_); |
| 807 | 825 |
| 808 DCHECK(frame->delegated_frame_data); | 826 DCHECK(frame->delegated_frame_data); |
| 809 DCHECK(!frame->delegated_frame_data->render_pass_list.empty()); | 827 DCHECK(!frame->delegated_frame_data->render_pass_list.empty()); |
| 810 | 828 |
| 829 size_t target_lock_count = is_showing_ ? 1 : 0; | |
| 830 if (frame_evictor_->FrameLockCount() > target_lock_count) { | |
| 831 base::Closure ack_callback = | |
| 832 base::Bind(&RenderWidgetHostViewAndroid::SendDelegatedFrameAck, | |
| 833 weak_ptr_factory_.GetWeakPtr(), | |
| 834 output_surface_id); | |
| 835 if (host_->is_hidden()) | |
| 836 ack_callback.Run(); | |
| 837 else | |
| 838 ack_callbacks_.push(ack_callback); | |
| 839 return; | |
| 840 } | |
| 811 cc::RenderPass* root_pass = | 841 cc::RenderPass* root_pass = |
| 812 frame->delegated_frame_data->render_pass_list.back(); | 842 frame->delegated_frame_data->render_pass_list.back(); |
| 813 texture_size_in_layer_ = root_pass->output_rect.size(); | 843 texture_size_in_layer_ = root_pass->output_rect.size(); |
| 814 ComputeContentsSize(frame->metadata); | 844 ComputeContentsSize(frame->metadata); |
| 815 | 845 |
| 816 SwapDelegatedFrame(output_surface_id, frame->delegated_frame_data.Pass()); | 846 SwapDelegatedFrame(output_surface_id, frame->delegated_frame_data.Pass()); |
| 817 frame_evictor_->SwappedFrame(!host_->is_hidden()); | 847 frame_evictor_->SwappedFrame(!host_->is_hidden()); |
| 818 return; | 848 return; |
| 819 } | 849 } |
| 820 | 850 |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1253 } | 1283 } |
| 1254 | 1284 |
| 1255 void RenderWidgetHostViewAndroid::SetContentViewCore( | 1285 void RenderWidgetHostViewAndroid::SetContentViewCore( |
| 1256 ContentViewCoreImpl* content_view_core) { | 1286 ContentViewCoreImpl* content_view_core) { |
| 1257 RunAckCallbacks(); | 1287 RunAckCallbacks(); |
| 1258 | 1288 |
| 1259 RemoveLayers(); | 1289 RemoveLayers(); |
| 1260 if (content_view_core_ && !using_synchronous_compositor_) | 1290 if (content_view_core_ && !using_synchronous_compositor_) |
| 1261 content_view_core_->GetWindowAndroid()->RemoveObserver(this); | 1291 content_view_core_->GetWindowAndroid()->RemoveObserver(this); |
| 1262 | 1292 |
| 1293 if (content_view_core != content_view_core_) | |
| 1294 ReleaseLocksOnSurface(); | |
| 1295 | |
| 1263 content_view_core_ = content_view_core; | 1296 content_view_core_ = content_view_core; |
| 1264 | 1297 |
| 1265 if (GetBrowserAccessibilityManager()) { | 1298 if (GetBrowserAccessibilityManager()) { |
| 1266 base::android::ScopedJavaLocalRef<jobject> obj; | 1299 base::android::ScopedJavaLocalRef<jobject> obj; |
| 1267 if (content_view_core_) | 1300 if (content_view_core_) |
| 1268 obj = content_view_core_->GetJavaObject(); | 1301 obj = content_view_core_->GetJavaObject(); |
| 1269 GetBrowserAccessibilityManager()->ToBrowserAccessibilityManagerAndroid()-> | 1302 GetBrowserAccessibilityManager()->ToBrowserAccessibilityManagerAndroid()-> |
| 1270 SetContentViewCore(obj); | 1303 SetContentViewCore(obj); |
| 1271 } | 1304 } |
| 1272 | 1305 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1286 RunAckCallbacks(); | 1319 RunAckCallbacks(); |
| 1287 } | 1320 } |
| 1288 | 1321 |
| 1289 void RenderWidgetHostViewAndroid::OnDetachCompositor() { | 1322 void RenderWidgetHostViewAndroid::OnDetachCompositor() { |
| 1290 DCHECK(content_view_core_); | 1323 DCHECK(content_view_core_); |
| 1291 DCHECK(!using_synchronous_compositor_); | 1324 DCHECK(!using_synchronous_compositor_); |
| 1292 RunAckCallbacks(); | 1325 RunAckCallbacks(); |
| 1293 } | 1326 } |
| 1294 | 1327 |
| 1295 void RenderWidgetHostViewAndroid::OnLostResources() { | 1328 void RenderWidgetHostViewAndroid::OnLostResources() { |
| 1329 ReleaseLocksOnSurface(); | |
| 1296 if (texture_layer_.get()) | 1330 if (texture_layer_.get()) |
| 1297 texture_layer_->SetIsDrawable(false); | 1331 texture_layer_->SetIsDrawable(false); |
| 1298 if (delegated_renderer_layer_.get()) | 1332 if (delegated_renderer_layer_.get()) |
| 1299 DestroyDelegatedContent(); | 1333 DestroyDelegatedContent(); |
| 1300 texture_id_in_layer_ = 0; | 1334 texture_id_in_layer_ = 0; |
| 1301 RunAckCallbacks(); | 1335 RunAckCallbacks(); |
| 1302 } | 1336 } |
| 1303 | 1337 |
| 1304 // static | 1338 // static |
| 1305 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | 1339 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1410 // RenderWidgetHostView, public: | 1444 // RenderWidgetHostView, public: |
| 1411 | 1445 |
| 1412 // static | 1446 // static |
| 1413 RenderWidgetHostView* | 1447 RenderWidgetHostView* |
| 1414 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 1448 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
| 1415 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 1449 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
| 1416 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 1450 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
| 1417 } | 1451 } |
| 1418 | 1452 |
| 1419 } // namespace content | 1453 } // namespace content |
| OLD | NEW |