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 if (locks_on_frame_count_ == 0 && last_frame_info_) { | |
399 InternalSwapCompositorFrame(last_frame_info_->output_surface_id, | |
400 last_frame_info_->frame.Pass()); | |
401 last_frame_info_.reset(); | |
402 } | |
403 } | |
404 | |
405 void RenderWidgetHostViewAndroid::ReleaseLocksOnSurface() { | |
406 if (!frame_evictor_->HasFrame()) { | |
407 DCHECK_EQ(locks_on_frame_count_, 0u); | |
408 return; | |
409 } | |
410 while (locks_on_frame_count_ > 0) { | |
411 UnlockSurfaceForCopy(); | |
412 } | |
388 } | 413 } |
389 | 414 |
390 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const { | 415 gfx::Rect RenderWidgetHostViewAndroid::GetViewBounds() const { |
391 if (!content_view_core_) | 416 if (!content_view_core_) |
392 return gfx::Rect(default_size_); | 417 return gfx::Rect(default_size_); |
393 | 418 |
394 gfx::Size size = content_view_core_->GetViewportSizeDip(); | 419 gfx::Size size = content_view_core_->GetViewportSizeDip(); |
395 gfx::Size offset = content_view_core_->GetViewportSizeOffsetDip(); | 420 gfx::Size offset = content_view_core_->GetViewportSizeOffsetDip(); |
396 size.Enlarge(-offset.width(), -offset.height()); | 421 size.Enlarge(-offset.width(), -offset.height()); |
397 | 422 |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
744 delegated_renderer_layer_->SetBounds(content_size_in_layer_); | 769 delegated_renderer_layer_->SetBounds(content_size_in_layer_); |
745 delegated_renderer_layer_->SetNeedsDisplay(); | 770 delegated_renderer_layer_->SetNeedsDisplay(); |
746 } | 771 } |
747 | 772 |
748 base::Closure ack_callback = | 773 base::Closure ack_callback = |
749 base::Bind(&RenderWidgetHostViewAndroid::SendDelegatedFrameAck, | 774 base::Bind(&RenderWidgetHostViewAndroid::SendDelegatedFrameAck, |
750 weak_ptr_factory_.GetWeakPtr(), | 775 weak_ptr_factory_.GetWeakPtr(), |
751 output_surface_id); | 776 output_surface_id); |
752 | 777 |
753 if (host_->is_hidden()) | 778 if (host_->is_hidden()) |
754 ack_callback.Run(); | 779 ack_callback.Run(); |
no sievers
2014/03/18 23:44:07
Do we need to call RunAckCallbacks() here instead
powei
2014/03/19 17:50:42
Done.
| |
755 else | 780 else |
756 ack_callbacks_.push(ack_callback); | 781 ack_callbacks_.push(ack_callback); |
757 } | 782 } |
758 | 783 |
759 void RenderWidgetHostViewAndroid::ComputeContentsSize( | 784 void RenderWidgetHostViewAndroid::ComputeContentsSize( |
760 const cc::CompositorFrameMetadata& frame_metadata) { | 785 const cc::CompositorFrameMetadata& frame_metadata) { |
761 // Calculate the content size. This should be 0 if the texture_size is 0. | 786 // Calculate the content size. This should be 0 if the texture_size is 0. |
762 gfx::Vector2dF offset; | 787 gfx::Vector2dF offset; |
763 if (texture_size_in_layer_.GetArea() > 0) | 788 if (texture_size_in_layer_.GetArea() > 0) |
764 offset = frame_metadata.location_bar_content_translation; | 789 offset = frame_metadata.location_bar_content_translation; |
765 offset.set_y(offset.y() + frame_metadata.overdraw_bottom_height); | 790 offset.set_y(offset.y() + frame_metadata.overdraw_bottom_height); |
766 offset.Scale(frame_metadata.device_scale_factor); | 791 offset.Scale(frame_metadata.device_scale_factor); |
767 content_size_in_layer_ = | 792 content_size_in_layer_ = |
768 gfx::Size(texture_size_in_layer_.width() - offset.x(), | 793 gfx::Size(texture_size_in_layer_.width() - offset.x(), |
769 texture_size_in_layer_.height() - offset.y()); | 794 texture_size_in_layer_.height() - offset.y()); |
770 // Content size changes should be reflected in associated animation effects. | 795 // Content size changes should be reflected in associated animation effects. |
771 UpdateAnimationSize(frame_metadata); | 796 UpdateAnimationSize(frame_metadata); |
772 } | 797 } |
773 | 798 |
774 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( | 799 void RenderWidgetHostViewAndroid::InternalSwapCompositorFrame( |
775 uint32 output_surface_id, | 800 uint32 output_surface_id, |
776 scoped_ptr<cc::CompositorFrame> frame) { | 801 scoped_ptr<cc::CompositorFrame> frame) { |
802 if (locks_on_frame_count_ > 0) { | |
803 DCHECK(HasValidFrame()); | |
804 RetainFrame(output_surface_id, frame.Pass()); | |
805 return; | |
806 } | |
807 | |
777 // Always let ContentViewCore know about the new frame first, so it can decide | 808 // Always let ContentViewCore know about the new frame first, so it can decide |
778 // to schedule a Draw immediately when it sees the texture layer invalidation. | 809 // to schedule a Draw immediately when it sees the texture layer invalidation. |
779 UpdateContentViewCoreFrameMetadata(frame->metadata); | 810 UpdateContentViewCoreFrameMetadata(frame->metadata); |
780 | 811 |
781 if (layer_ && layer_->layer_tree_host()) { | 812 if (layer_ && layer_->layer_tree_host()) { |
782 for (size_t i = 0; i < frame->metadata.latency_info.size(); i++) { | 813 for (size_t i = 0; i < frame->metadata.latency_info.size(); i++) { |
783 scoped_ptr<cc::SwapPromise> swap_promise( | 814 scoped_ptr<cc::SwapPromise> swap_promise( |
784 new cc::LatencyInfoSwapPromise(frame->metadata.latency_info[i])); | 815 new cc::LatencyInfoSwapPromise(frame->metadata.latency_info[i])); |
785 layer_->layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); | 816 layer_->layer_tree_host()->QueueSwapPromise(swap_promise.Pass()); |
786 } | 817 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
821 ImageTransportFactoryAndroid::GetInstance()->WaitSyncPoint( | 852 ImageTransportFactoryAndroid::GetInstance()->WaitSyncPoint( |
822 frame->gl_frame_data->sync_point); | 853 frame->gl_frame_data->sync_point); |
823 | 854 |
824 texture_size_in_layer_ = frame->gl_frame_data->size; | 855 texture_size_in_layer_ = frame->gl_frame_data->size; |
825 ComputeContentsSize(frame->metadata); | 856 ComputeContentsSize(frame->metadata); |
826 | 857 |
827 BuffersSwapped(frame->gl_frame_data->mailbox, output_surface_id, callback); | 858 BuffersSwapped(frame->gl_frame_data->mailbox, output_surface_id, callback); |
828 frame_evictor_->SwappedFrame(!host_->is_hidden()); | 859 frame_evictor_->SwappedFrame(!host_->is_hidden()); |
829 } | 860 } |
830 | 861 |
862 void RenderWidgetHostViewAndroid::OnSwapCompositorFrame( | |
863 uint32 output_surface_id, | |
864 scoped_ptr<cc::CompositorFrame> frame) { | |
865 InternalSwapCompositorFrame(output_surface_id, frame.Pass()); | |
866 } | |
867 | |
868 void RenderWidgetHostViewAndroid::RetainFrame( | |
869 uint32 output_surface_id, | |
870 scoped_ptr<cc::CompositorFrame> frame) { | |
871 DCHECK(locks_on_frame_count_); | |
872 | |
873 // Store the incoming frame so that it can be swapped when all the locks have | |
874 // been released. If there is already a stored frame, then send | |
no sievers
2014/03/18 23:44:07
nit: extra space
powei
2014/03/19 17:50:42
Done.
| |
875 // acknowledgement and drop it. | |
876 if (last_frame_info_) { | |
877 base::Closure ack_callback = | |
878 base::Bind(&RenderWidgetHostViewAndroid::SendDelegatedFrameAck, | |
879 weak_ptr_factory_.GetWeakPtr(), | |
880 last_frame_info_->output_surface_id); | |
881 if (host_->is_hidden()) | |
882 ack_callback.Run(); | |
no sievers
2014/03/18 23:44:07
The code does actually not match the comment above
powei
2014/03/19 17:50:42
Done.
| |
883 else | |
884 ack_callbacks_.push(ack_callback); | |
885 } | |
886 | |
887 last_frame_info_.reset(new LastFrameInfo(output_surface_id, frame.Pass())); | |
888 } | |
889 | |
831 void RenderWidgetHostViewAndroid::SynchronousFrameMetadata( | 890 void RenderWidgetHostViewAndroid::SynchronousFrameMetadata( |
832 const cc::CompositorFrameMetadata& frame_metadata) { | 891 const cc::CompositorFrameMetadata& frame_metadata) { |
833 // This is a subset of OnSwapCompositorFrame() used in the synchronous | 892 // This is a subset of OnSwapCompositorFrame() used in the synchronous |
834 // compositor flow. | 893 // compositor flow. |
835 UpdateContentViewCoreFrameMetadata(frame_metadata); | 894 UpdateContentViewCoreFrameMetadata(frame_metadata); |
836 ComputeContentsSize(frame_metadata); | 895 ComputeContentsSize(frame_metadata); |
837 | 896 |
838 // DevTools ScreenCast support for Android WebView. | 897 // DevTools ScreenCast support for Android WebView. |
839 if (DevToolsAgentHost::HasFor(RenderViewHost::From(GetRenderWidgetHost()))) { | 898 if (DevToolsAgentHost::HasFor(RenderViewHost::From(GetRenderWidgetHost()))) { |
840 scoped_refptr<DevToolsAgentHost> dtah = | 899 scoped_refptr<DevToolsAgentHost> dtah = |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
921 texture_layer_->SetContentsOpaque(true); | 980 texture_layer_->SetContentsOpaque(true); |
922 } | 981 } |
923 | 982 |
924 ImageTransportFactoryAndroid::GetInstance()->AcquireTexture( | 983 ImageTransportFactoryAndroid::GetInstance()->AcquireTexture( |
925 texture_id_in_layer_, mailbox.name); | 984 texture_id_in_layer_, mailbox.name); |
926 | 985 |
927 current_mailbox_ = mailbox; | 986 current_mailbox_ = mailbox; |
928 last_output_surface_id_ = output_surface_id; | 987 last_output_surface_id_ = output_surface_id; |
929 | 988 |
930 if (host_->is_hidden()) | 989 if (host_->is_hidden()) |
931 ack_callback.Run(); | 990 ack_callback.Run(); |
no sievers
2014/03/18 23:44:07
see comment in SwapDelegatedFrame(), although this
powei
2014/03/19 17:50:42
Done.
| |
932 else | 991 else |
933 ack_callbacks_.push(ack_callback); | 992 ack_callbacks_.push(ack_callback); |
934 } | 993 } |
935 | 994 |
936 void RenderWidgetHostViewAndroid::AttachLayers() { | 995 void RenderWidgetHostViewAndroid::AttachLayers() { |
937 if (!content_view_core_) | 996 if (!content_view_core_) |
938 return; | 997 return; |
939 if (!layer_.get()) | 998 if (!layer_.get()) |
940 return; | 999 return; |
941 | 1000 |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1237 } | 1296 } |
1238 | 1297 |
1239 void RenderWidgetHostViewAndroid::SetContentViewCore( | 1298 void RenderWidgetHostViewAndroid::SetContentViewCore( |
1240 ContentViewCoreImpl* content_view_core) { | 1299 ContentViewCoreImpl* content_view_core) { |
1241 RunAckCallbacks(); | 1300 RunAckCallbacks(); |
1242 | 1301 |
1243 RemoveLayers(); | 1302 RemoveLayers(); |
1244 if (content_view_core_ && !using_synchronous_compositor_) | 1303 if (content_view_core_ && !using_synchronous_compositor_) |
1245 content_view_core_->GetWindowAndroid()->RemoveObserver(this); | 1304 content_view_core_->GetWindowAndroid()->RemoveObserver(this); |
1246 | 1305 |
1306 if (content_view_core != content_view_core_) | |
1307 ReleaseLocksOnSurface(); | |
1308 | |
1247 content_view_core_ = content_view_core; | 1309 content_view_core_ = content_view_core; |
1248 | 1310 |
1249 if (GetBrowserAccessibilityManager()) { | 1311 if (GetBrowserAccessibilityManager()) { |
1250 base::android::ScopedJavaLocalRef<jobject> obj; | 1312 base::android::ScopedJavaLocalRef<jobject> obj; |
1251 if (content_view_core_) | 1313 if (content_view_core_) |
1252 obj = content_view_core_->GetJavaObject(); | 1314 obj = content_view_core_->GetJavaObject(); |
1253 GetBrowserAccessibilityManager()->ToBrowserAccessibilityManagerAndroid()-> | 1315 GetBrowserAccessibilityManager()->ToBrowserAccessibilityManagerAndroid()-> |
1254 SetContentViewCore(obj); | 1316 SetContentViewCore(obj); |
1255 } | 1317 } |
1256 | 1318 |
(...skipping 13 matching lines...) Expand all Loading... | |
1270 RunAckCallbacks(); | 1332 RunAckCallbacks(); |
1271 } | 1333 } |
1272 | 1334 |
1273 void RenderWidgetHostViewAndroid::OnDetachCompositor() { | 1335 void RenderWidgetHostViewAndroid::OnDetachCompositor() { |
1274 DCHECK(content_view_core_); | 1336 DCHECK(content_view_core_); |
1275 DCHECK(!using_synchronous_compositor_); | 1337 DCHECK(!using_synchronous_compositor_); |
1276 RunAckCallbacks(); | 1338 RunAckCallbacks(); |
1277 } | 1339 } |
1278 | 1340 |
1279 void RenderWidgetHostViewAndroid::OnLostResources() { | 1341 void RenderWidgetHostViewAndroid::OnLostResources() { |
1342 ReleaseLocksOnSurface(); | |
1280 if (texture_layer_.get()) | 1343 if (texture_layer_.get()) |
1281 texture_layer_->SetIsDrawable(false); | 1344 texture_layer_->SetIsDrawable(false); |
1282 if (delegated_renderer_layer_.get()) | 1345 if (delegated_renderer_layer_.get()) |
1283 DestroyDelegatedContent(); | 1346 DestroyDelegatedContent(); |
1284 texture_id_in_layer_ = 0; | 1347 texture_id_in_layer_ = 0; |
1285 RunAckCallbacks(); | 1348 RunAckCallbacks(); |
1286 } | 1349 } |
1287 | 1350 |
1288 // static | 1351 // static |
1289 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | 1352 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1405 // RenderWidgetHostView, public: | 1468 // RenderWidgetHostView, public: |
1406 | 1469 |
1407 // static | 1470 // static |
1408 RenderWidgetHostView* | 1471 RenderWidgetHostView* |
1409 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 1472 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
1410 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 1473 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
1411 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 1474 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
1412 } | 1475 } |
1413 | 1476 |
1414 } // namespace content | 1477 } // namespace content |
OLD | NEW |