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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 overscroll_effect_(OverscrollGlow::Create(overscroll_effect_enabled_)), | 140 overscroll_effect_(OverscrollGlow::Create(overscroll_effect_enabled_)), |
| 141 flush_input_requested_(false), | 141 flush_input_requested_(false), |
| 142 accelerated_surface_route_id_(0), | 142 accelerated_surface_route_id_(0), |
| 143 using_synchronous_compositor_(SynchronousCompositorImpl::FromID( | 143 using_synchronous_compositor_(SynchronousCompositorImpl::FromID( |
| 144 widget_host->GetProcess()->GetID(), | 144 widget_host->GetProcess()->GetID(), |
| 145 widget_host->GetRoutingID()) != NULL), | 145 widget_host->GetRoutingID()) != NULL), |
| 146 frame_evictor_(new DelegatedFrameEvictor(this)), | 146 frame_evictor_(new DelegatedFrameEvictor(this)), |
| 147 using_delegated_renderer_(CommandLine::ForCurrentProcess()->HasSwitch( | 147 using_delegated_renderer_(CommandLine::ForCurrentProcess()->HasSwitch( |
| 148 switches::kEnableDelegatedRenderer) && | 148 switches::kEnableDelegatedRenderer) && |
| 149 !CommandLine::ForCurrentProcess()->HasSwitch( | 149 !CommandLine::ForCurrentProcess()->HasSwitch( |
| 150 switches::kDisableDelegatedRenderer)) { | 150 switches::kDisableDelegatedRenderer)), |
| 151 locks_on_frame_count_(0) { | |
| 151 if (!using_delegated_renderer_) { | 152 if (!using_delegated_renderer_) { |
| 152 texture_layer_ = cc::TextureLayer::Create(NULL); | 153 texture_layer_ = cc::TextureLayer::Create(NULL); |
| 153 layer_ = texture_layer_; | 154 layer_ = texture_layer_; |
| 154 } | 155 } |
| 155 | 156 |
| 156 host_->SetView(this); | 157 host_->SetView(this); |
| 157 SetContentViewCore(content_view_core); | 158 SetContentViewCore(content_view_core); |
| 158 ImageTransportFactoryAndroid::AddObserver(this); | 159 ImageTransportFactoryAndroid::AddObserver(this); |
| 159 } | 160 } |
| 160 | 161 |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 278 | 279 |
| 279 bool RenderWidgetHostViewAndroid::HasValidFrame() const { | 280 bool RenderWidgetHostViewAndroid::HasValidFrame() const { |
| 280 if (!content_view_core_) | 281 if (!content_view_core_) |
| 281 return false; | 282 return false; |
| 282 if (!layer_) | 283 if (!layer_) |
| 283 return false; | 284 return false; |
| 284 | 285 |
| 285 if (texture_size_in_layer_.IsEmpty()) | 286 if (texture_size_in_layer_.IsEmpty()) |
| 286 return false; | 287 return false; |
| 287 | 288 |
| 289 if (!frame_evictor_->HasFrame()) | |
| 290 return false; | |
| 291 | |
| 288 if (using_delegated_renderer_) { | 292 if (using_delegated_renderer_) { |
| 289 if (!delegated_renderer_layer_.get()) | 293 if (!delegated_renderer_layer_.get()) |
| 290 return false; | 294 return false; |
| 291 } else { | 295 } else { |
| 292 if (texture_id_in_layer_ == 0) | 296 if (texture_id_in_layer_ == 0) |
| 293 return false; | 297 return false; |
| 294 } | 298 } |
| 295 | 299 |
| 296 return true; | 300 return true; |
| 297 } | 301 } |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 368 WasHidden(); | 372 WasHidden(); |
| 369 } | 373 } |
| 370 | 374 |
| 371 bool RenderWidgetHostViewAndroid::IsShowing() { | 375 bool RenderWidgetHostViewAndroid::IsShowing() { |
| 372 // ContentViewCoreImpl represents the native side of the Java | 376 // ContentViewCoreImpl represents the native side of the Java |
| 373 // ContentViewCore. It being NULL means that it is not attached | 377 // ContentViewCore. It being NULL means that it is not attached |
| 374 // to the View system yet, so we treat this RWHVA as hidden. | 378 // to the View system yet, so we treat this RWHVA as hidden. |
| 375 return is_showing_ && content_view_core_; | 379 return is_showing_ && content_view_core_; |
| 376 } | 380 } |
| 377 | 381 |
| 378 void RenderWidgetHostViewAndroid::LockResources() { | 382 void RenderWidgetHostViewAndroid::LockSurfaceForCopy() { |
| 379 DCHECK(HasValidFrame()); | 383 DCHECK(HasValidFrame()); |
| 380 DCHECK(host_); | 384 DCHECK(host_); |
| 381 DCHECK(!host_->is_hidden()); | 385 DCHECK(frame_evictor_->HasFrame()); |
| 382 frame_evictor_->LockFrame(); | 386 frame_evictor_->LockFrame(); |
| 387 locks_on_frame_count_++; | |
| 383 } | 388 } |
| 384 | 389 |
| 385 void RenderWidgetHostViewAndroid::UnlockResources() { | 390 void RenderWidgetHostViewAndroid::UnlockSurfaceForCopy() { |
| 391 if (!frame_evictor_->HasFrame() || locks_on_frame_count_ == 0) | |
| 392 return; | |
| 393 | |
| 386 DCHECK(HasValidFrame()); | 394 DCHECK(HasValidFrame()); |
| 387 frame_evictor_->UnlockFrame(); | 395 frame_evictor_->UnlockFrame(); |
| 396 locks_on_frame_count_--; | |
| 397 } | |
| 398 | |
| 399 void RenderWidgetHostViewAndroid::ReleaseLocksOnSurface() { | |
| 400 if (!frame_evictor_->HasFrame()) { | |
| 401 DCHECK_EQ(locks_on_frame_count_, 0u); | |
| 402 return; | |
| 403 } | |
| 404 while (locks_on_frame_count_ > 0) { | |
| 405 UnlockSurfaceForCopy(); | |
| 406 } | |
| 388 } | 407 } |
| 389 | 408 |
| 390 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const { | 409 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const { |
| 391 if (!content_view_core_) | 410 if (!content_view_core_) |
| 392 return gfx::Rect(default_size_); | 411 return gfx::Rect(default_size_); |
| 393 | 412 |
| 394 gfx::Size size = content_view_core_->GetViewportSizeDip(); | 413 gfx::Size size = content_view_core_->GetViewportSizeDip(); |
| 395 gfx::Size offset = content_view_core_->GetViewportSizeOffsetDip(); | 414 gfx::Size offset = content_view_core_->GetViewportSizeOffsetDip(); |
| 396 size.Enlarge(-offset.width(), -offset.height()); | 415 size.Enlarge(-offset.width(), -offset.height()); |
| 397 | 416 |
| (...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 801 layer_->layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); | 820 layer_->layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); |
| 802 } | 821 } |
| 803 } | 822 } |
| 804 | 823 |
| 805 if (frame->delegated_frame_data) { | 824 if (frame->delegated_frame_data) { |
| 806 DCHECK(using_delegated_renderer_); | 825 DCHECK(using_delegated_renderer_); |
| 807 | 826 |
| 808 DCHECK(frame->delegated_frame_data); | 827 DCHECK(frame->delegated_frame_data); |
| 809 DCHECK(!frame->delegated_frame_data->render_pass_list.empty()); | 828 DCHECK(!frame->delegated_frame_data->render_pass_list.empty()); |
| 810 | 829 |
| 830 if (locks_on_frame_count_ > 0) { | |
| 831 DCHECK(HasValidFrame()); | |
| 832 base::Closure ack_callback = | |
| 833 base::Bind(&RenderWidgetHostViewAndroid::SendDelegatedFrameAck, | |
| 834 weak_ptr_factory_.GetWeakPtr(), | |
| 835 output_surface_id); | |
| 836 if (host_->is_hidden()) | |
| 837 ack_callback.Run(); | |
| 838 else | |
| 839 ack_callbacks_.push(ack_callback); | |
| 840 return; | |
|
piman
2014/03/05 20:14:36
So, if my understanding is correct, while there is
powei
2014/03/06 07:41:40
Yes
| |
| 841 } | |
| 811 cc::RenderPass* root_pass = | 842 cc::RenderPass* root_pass = |
| 812 frame->delegated_frame_data->render_pass_list.back(); | 843 frame->delegated_frame_data->render_pass_list.back(); |
| 813 texture_size_in_layer_ = root_pass->output_rect.size(); | 844 texture_size_in_layer_ = root_pass->output_rect.size(); |
| 814 ComputeContentsSize(frame->metadata); | 845 ComputeContentsSize(frame->metadata); |
| 815 | 846 |
| 816 SwapDelegatedFrame(output_surface_id, frame->delegated_frame_data.Pass()); | 847 SwapDelegatedFrame(output_surface_id, frame->delegated_frame_data.Pass()); |
| 817 frame_evictor_->SwappedFrame(!host_->is_hidden()); | 848 frame_evictor_->SwappedFrame(!host_->is_hidden()); |
| 818 return; | 849 return; |
| 819 } | 850 } |
| 820 | 851 |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1253 } | 1284 } |
| 1254 | 1285 |
| 1255 void RenderWidgetHostViewAndroid::SetContentViewCore( | 1286 void RenderWidgetHostViewAndroid::SetContentViewCore( |
| 1256 ContentViewCoreImpl* content_view_core) { | 1287 ContentViewCoreImpl* content_view_core) { |
| 1257 RunAckCallbacks(); | 1288 RunAckCallbacks(); |
| 1258 | 1289 |
| 1259 RemoveLayers(); | 1290 RemoveLayers(); |
| 1260 if (content_view_core_ && !using_synchronous_compositor_) | 1291 if (content_view_core_ && !using_synchronous_compositor_) |
| 1261 content_view_core_->GetWindowAndroid()->RemoveObserver(this); | 1292 content_view_core_->GetWindowAndroid()->RemoveObserver(this); |
| 1262 | 1293 |
| 1294 if (content_view_core != content_view_core_) | |
| 1295 ReleaseLocksOnSurface(); | |
| 1296 | |
| 1263 content_view_core_ = content_view_core; | 1297 content_view_core_ = content_view_core; |
| 1264 | 1298 |
| 1265 if (GetBrowserAccessibilityManager()) { | 1299 if (GetBrowserAccessibilityManager()) { |
| 1266 base::android::ScopedJavaLocalRef<jobject> obj; | 1300 base::android::ScopedJavaLocalRef<jobject> obj; |
| 1267 if (content_view_core_) | 1301 if (content_view_core_) |
| 1268 obj = content_view_core_->GetJavaObject(); | 1302 obj = content_view_core_->GetJavaObject(); |
| 1269 GetBrowserAccessibilityManager()->ToBrowserAccessibilityManagerAndroid()-> | 1303 GetBrowserAccessibilityManager()->ToBrowserAccessibilityManagerAndroid()-> |
| 1270 SetContentViewCore(obj); | 1304 SetContentViewCore(obj); |
| 1271 } | 1305 } |
| 1272 | 1306 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1286 RunAckCallbacks(); | 1320 RunAckCallbacks(); |
| 1287 } | 1321 } |
| 1288 | 1322 |
| 1289 void RenderWidgetHostViewAndroid::OnDetachCompositor() { | 1323 void RenderWidgetHostViewAndroid::OnDetachCompositor() { |
| 1290 DCHECK(content_view_core_); | 1324 DCHECK(content_view_core_); |
| 1291 DCHECK(!using_synchronous_compositor_); | 1325 DCHECK(!using_synchronous_compositor_); |
| 1292 RunAckCallbacks(); | 1326 RunAckCallbacks(); |
| 1293 } | 1327 } |
| 1294 | 1328 |
| 1295 void RenderWidgetHostViewAndroid::OnLostResources() { | 1329 void RenderWidgetHostViewAndroid::OnLostResources() { |
| 1330 ReleaseLocksOnSurface(); | |
| 1296 if (texture_layer_.get()) | 1331 if (texture_layer_.get()) |
| 1297 texture_layer_->SetIsDrawable(false); | 1332 texture_layer_->SetIsDrawable(false); |
| 1298 if (delegated_renderer_layer_.get()) | 1333 if (delegated_renderer_layer_.get()) |
| 1299 DestroyDelegatedContent(); | 1334 DestroyDelegatedContent(); |
| 1300 texture_id_in_layer_ = 0; | 1335 texture_id_in_layer_ = 0; |
| 1301 RunAckCallbacks(); | 1336 RunAckCallbacks(); |
| 1302 } | 1337 } |
| 1303 | 1338 |
| 1304 // static | 1339 // static |
| 1305 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | 1340 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1410 // RenderWidgetHostView, public: | 1445 // RenderWidgetHostView, public: |
| 1411 | 1446 |
| 1412 // static | 1447 // static |
| 1413 RenderWidgetHostView* | 1448 RenderWidgetHostView* |
| 1414 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 1449 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
| 1415 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 1450 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
| 1416 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 1451 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
| 1417 } | 1452 } |
| 1418 | 1453 |
| 1419 } // namespace content | 1454 } // namespace content |
| OLD | NEW |