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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 DropFrame(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::DropFrame( | |
piman
2014/03/06 21:11:28
nit: RetainFrame or something would be a better na
powei
2014/03/06 21:26:10
Done.
| |
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 | |
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(); | |
883 else | |
884 ack_callbacks_.push(ack_callback); | |
885 return; | |
886 } | |
887 | |
888 last_frame_info_.reset(new LastFrameInfo(output_surface_id, frame.Pass())); | |
889 } | |
890 | |
831 void RenderWidgetHostViewAndroid::SynchronousFrameMetadata( | 891 void RenderWidgetHostViewAndroid::SynchronousFrameMetadata( |
832 const cc::CompositorFrameMetadata& frame_metadata) { | 892 const cc::CompositorFrameMetadata& frame_metadata) { |
833 // This is a subset of OnSwapCompositorFrame() used in the synchronous | 893 // This is a subset of OnSwapCompositorFrame() used in the synchronous |
834 // compositor flow. | 894 // compositor flow. |
835 UpdateContentViewCoreFrameMetadata(frame_metadata); | 895 UpdateContentViewCoreFrameMetadata(frame_metadata); |
836 ComputeContentsSize(frame_metadata); | 896 ComputeContentsSize(frame_metadata); |
837 | 897 |
838 // DevTools ScreenCast support for Android WebView. | 898 // DevTools ScreenCast support for Android WebView. |
839 if (DevToolsAgentHost::HasFor(RenderViewHost::From(GetRenderWidgetHost()))) { | 899 if (DevToolsAgentHost::HasFor(RenderViewHost::From(GetRenderWidgetHost()))) { |
840 scoped_refptr<DevToolsAgentHost> dtah = | 900 scoped_refptr<DevToolsAgentHost> dtah = |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1237 } | 1297 } |
1238 | 1298 |
1239 void RenderWidgetHostViewAndroid::SetContentViewCore( | 1299 void RenderWidgetHostViewAndroid::SetContentViewCore( |
1240 ContentViewCoreImpl* content_view_core) { | 1300 ContentViewCoreImpl* content_view_core) { |
1241 RunAckCallbacks(); | 1301 RunAckCallbacks(); |
1242 | 1302 |
1243 RemoveLayers(); | 1303 RemoveLayers(); |
1244 if (content_view_core_ && !using_synchronous_compositor_) | 1304 if (content_view_core_ && !using_synchronous_compositor_) |
1245 content_view_core_->GetWindowAndroid()->RemoveObserver(this); | 1305 content_view_core_->GetWindowAndroid()->RemoveObserver(this); |
1246 | 1306 |
1307 if (content_view_core != content_view_core_) | |
1308 ReleaseLocksOnSurface(); | |
1309 | |
1247 content_view_core_ = content_view_core; | 1310 content_view_core_ = content_view_core; |
1248 | 1311 |
1249 if (GetBrowserAccessibilityManager()) { | 1312 if (GetBrowserAccessibilityManager()) { |
1250 base::android::ScopedJavaLocalRef<jobject> obj; | 1313 base::android::ScopedJavaLocalRef<jobject> obj; |
1251 if (content_view_core_) | 1314 if (content_view_core_) |
1252 obj = content_view_core_->GetJavaObject(); | 1315 obj = content_view_core_->GetJavaObject(); |
1253 GetBrowserAccessibilityManager()->ToBrowserAccessibilityManagerAndroid()-> | 1316 GetBrowserAccessibilityManager()->ToBrowserAccessibilityManagerAndroid()-> |
1254 SetContentViewCore(obj); | 1317 SetContentViewCore(obj); |
1255 } | 1318 } |
1256 | 1319 |
(...skipping 13 matching lines...) Expand all Loading... | |
1270 RunAckCallbacks(); | 1333 RunAckCallbacks(); |
1271 } | 1334 } |
1272 | 1335 |
1273 void RenderWidgetHostViewAndroid::OnDetachCompositor() { | 1336 void RenderWidgetHostViewAndroid::OnDetachCompositor() { |
1274 DCHECK(content_view_core_); | 1337 DCHECK(content_view_core_); |
1275 DCHECK(!using_synchronous_compositor_); | 1338 DCHECK(!using_synchronous_compositor_); |
1276 RunAckCallbacks(); | 1339 RunAckCallbacks(); |
1277 } | 1340 } |
1278 | 1341 |
1279 void RenderWidgetHostViewAndroid::OnLostResources() { | 1342 void RenderWidgetHostViewAndroid::OnLostResources() { |
1343 ReleaseLocksOnSurface(); | |
1280 if (texture_layer_.get()) | 1344 if (texture_layer_.get()) |
1281 texture_layer_->SetIsDrawable(false); | 1345 texture_layer_->SetIsDrawable(false); |
1282 if (delegated_renderer_layer_.get()) | 1346 if (delegated_renderer_layer_.get()) |
1283 DestroyDelegatedContent(); | 1347 DestroyDelegatedContent(); |
1284 texture_id_in_layer_ = 0; | 1348 texture_id_in_layer_ = 0; |
1285 RunAckCallbacks(); | 1349 RunAckCallbacks(); |
1286 } | 1350 } |
1287 | 1351 |
1288 // static | 1352 // static |
1289 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( | 1353 void RenderWidgetHostViewAndroid::PrepareTextureCopyOutputResult( |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1405 // RenderWidgetHostView, public: | 1469 // RenderWidgetHostView, public: |
1406 | 1470 |
1407 // static | 1471 // static |
1408 RenderWidgetHostView* | 1472 RenderWidgetHostView* |
1409 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { | 1473 RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost* widget) { |
1410 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); | 1474 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(widget); |
1411 return new RenderWidgetHostViewAndroid(rwhi, NULL); | 1475 return new RenderWidgetHostViewAndroid(rwhi, NULL); |
1412 } | 1476 } |
1413 | 1477 |
1414 } // namespace content | 1478 } // namespace content |
OLD | NEW |