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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 switches::kDisableOverscrollEdgeEffect)), | 194 switches::kDisableOverscrollEdgeEffect)), |
| 195 gesture_provider_(CreateGestureProviderConfig(), this), | 195 gesture_provider_(CreateGestureProviderConfig(), this), |
| 196 gesture_text_selector_(this), | 196 gesture_text_selector_(this), |
| 197 touch_scrolling_(false), | 197 touch_scrolling_(false), |
| 198 potentially_active_fling_count_(0), | 198 potentially_active_fling_count_(0), |
| 199 flush_input_requested_(false), | 199 flush_input_requested_(false), |
| 200 accelerated_surface_route_id_(0), | 200 accelerated_surface_route_id_(0), |
| 201 using_synchronous_compositor_(SynchronousCompositorImpl::FromID( | 201 using_synchronous_compositor_(SynchronousCompositorImpl::FromID( |
| 202 widget_host->GetProcess()->GetID(), | 202 widget_host->GetProcess()->GetID(), |
| 203 widget_host->GetRoutingID()) != NULL), | 203 widget_host->GetRoutingID()) != NULL), |
| 204 vsync_subscribers_bitmask_(0), | |
| 204 frame_evictor_(new DelegatedFrameEvictor(this)), | 205 frame_evictor_(new DelegatedFrameEvictor(this)), |
| 205 locks_on_frame_count_(0), | 206 locks_on_frame_count_(0) { |
| 206 observing_root_window_(false) { | |
| 207 host_->SetView(this); | 207 host_->SetView(this); |
| 208 SetContentViewCore(content_view_core); | 208 SetContentViewCore(content_view_core); |
| 209 ImageTransportFactoryAndroid::AddObserver(this); | 209 ImageTransportFactoryAndroid::AddObserver(this); |
| 210 } | 210 } |
| 211 | 211 |
| 212 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { | 212 RenderWidgetHostViewAndroid::~RenderWidgetHostViewAndroid() { |
| 213 ImageTransportFactoryAndroid::RemoveObserver(this); | 213 ImageTransportFactoryAndroid::RemoveObserver(this); |
| 214 SetContentViewCore(NULL); | 214 SetContentViewCore(NULL); |
| 215 DCHECK(ack_callbacks_.empty()); | 215 DCHECK(ack_callbacks_.empty()); |
| 216 if (resource_collection_.get()) | 216 if (resource_collection_.get()) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 return host_; | 253 return host_; |
| 254 } | 254 } |
| 255 | 255 |
| 256 void RenderWidgetHostViewAndroid::WasShown() { | 256 void RenderWidgetHostViewAndroid::WasShown() { |
| 257 if (!host_ || !host_->is_hidden()) | 257 if (!host_ || !host_->is_hidden()) |
| 258 return; | 258 return; |
| 259 | 259 |
| 260 host_->WasShown(ui::LatencyInfo()); | 260 host_->WasShown(ui::LatencyInfo()); |
| 261 | 261 |
| 262 if (content_view_core_ && !using_synchronous_compositor_) { | 262 if (content_view_core_ && !using_synchronous_compositor_) { |
| 263 content_view_core_->GetWindowAndroid()->AddObserver(this); | 263 SubscribeToVSync(INPUT | BEGIN_FRAME); |
| 264 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); | 264 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); |
| 265 observing_root_window_ = true; | |
| 266 } | 265 } |
| 267 } | 266 } |
| 268 | 267 |
| 269 void RenderWidgetHostViewAndroid::WasHidden() { | 268 void RenderWidgetHostViewAndroid::WasHidden() { |
| 270 RunAckCallbacks(); | 269 RunAckCallbacks(); |
| 271 | 270 |
| 272 if (!host_ || host_->is_hidden()) | 271 if (!host_ || host_->is_hidden()) |
| 273 return; | 272 return; |
| 274 | 273 |
| 275 // Inform the renderer that we are being hidden so it can reduce its resource | 274 // Inform the renderer that we are being hidden so it can reduce its resource |
| 276 // utilization. | 275 // utilization. |
| 277 host_->WasHidden(); | 276 host_->WasHidden(); |
| 278 | 277 |
| 279 if (content_view_core_ && !using_synchronous_compositor_) { | 278 if (content_view_core_ && !using_synchronous_compositor_) |
| 280 content_view_core_->GetWindowAndroid()->RemoveObserver(this); | 279 UnsubscribeToVSync(INPUT | BEGIN_FRAME); |
|
jdduke (slow)
2014/08/20 04:11:53
Hmm, this isn't quite what I had in mind. I was th
hush (inactive)
2014/08/20 18:06:50
I see.
I will remove |flush_input_requested_| and
| |
| 281 observing_root_window_ = false; | |
| 282 } | |
| 283 } | 280 } |
| 284 | 281 |
| 285 void RenderWidgetHostViewAndroid::WasResized() { | 282 void RenderWidgetHostViewAndroid::WasResized() { |
| 286 host_->WasResized(); | 283 host_->WasResized(); |
| 287 } | 284 } |
| 288 | 285 |
| 289 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { | 286 void RenderWidgetHostViewAndroid::SetSize(const gfx::Size& size) { |
| 290 // Ignore the given size as only the Java code has the power to | 287 // Ignore the given size as only the Java code has the power to |
| 291 // resize the view on Android. | 288 // resize the view on Android. |
| 292 default_size_ = size; | 289 default_size_ = size; |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 804 void RenderWidgetHostViewAndroid::ShowDisambiguationPopup( | 801 void RenderWidgetHostViewAndroid::ShowDisambiguationPopup( |
| 805 const gfx::Rect& target_rect, const SkBitmap& zoomed_bitmap) { | 802 const gfx::Rect& target_rect, const SkBitmap& zoomed_bitmap) { |
| 806 if (!content_view_core_) | 803 if (!content_view_core_) |
| 807 return; | 804 return; |
| 808 | 805 |
| 809 content_view_core_->ShowDisambiguationPopup(target_rect, zoomed_bitmap); | 806 content_view_core_->ShowDisambiguationPopup(target_rect, zoomed_bitmap); |
| 810 } | 807 } |
| 811 | 808 |
| 812 scoped_ptr<SyntheticGestureTarget> | 809 scoped_ptr<SyntheticGestureTarget> |
| 813 RenderWidgetHostViewAndroid::CreateSyntheticGestureTarget() { | 810 RenderWidgetHostViewAndroid::CreateSyntheticGestureTarget() { |
| 811 DCHECK(content_view_core_); | |
| 812 if (using_synchronous_compositor_) | |
| 813 SubscribeToVSync(INPUT); | |
| 814 | |
| 814 return scoped_ptr<SyntheticGestureTarget>(new SyntheticGestureTargetAndroid( | 815 return scoped_ptr<SyntheticGestureTarget>(new SyntheticGestureTargetAndroid( |
| 815 host_, content_view_core_->CreateTouchEventSynthesizer())); | 816 host_, content_view_core_->CreateTouchEventSynthesizer())); |
| 816 } | 817 } |
| 817 | 818 |
| 818 void RenderWidgetHostViewAndroid::SendDelegatedFrameAck( | 819 void RenderWidgetHostViewAndroid::SendDelegatedFrameAck( |
| 819 uint32 output_surface_id) { | 820 uint32 output_surface_id) { |
| 820 DCHECK(host_); | 821 DCHECK(host_); |
| 821 cc::CompositorFrameAck ack; | 822 cc::CompositorFrameAck ack; |
| 822 if (resource_collection_.get()) | 823 if (resource_collection_.get()) |
| 823 resource_collection_->TakeUnusedResourcesForChildCompositor(&ack.resources); | 824 resource_collection_->TakeUnusedResourcesForChildCompositor(&ack.resources); |
| (...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1433 OnContentScrollingChange(); | 1434 OnContentScrollingChange(); |
| 1434 } | 1435 } |
| 1435 | 1436 |
| 1436 if (content_view_core_) | 1437 if (content_view_core_) |
| 1437 content_view_core_->DidStopFlinging(); | 1438 content_view_core_->DidStopFlinging(); |
| 1438 } | 1439 } |
| 1439 | 1440 |
| 1440 void RenderWidgetHostViewAndroid::SetContentViewCore( | 1441 void RenderWidgetHostViewAndroid::SetContentViewCore( |
| 1441 ContentViewCoreImpl* content_view_core) { | 1442 ContentViewCoreImpl* content_view_core) { |
| 1442 RemoveLayers(); | 1443 RemoveLayers(); |
| 1443 if (observing_root_window_ && content_view_core_) { | 1444 if (vsync_subscribers_bitmask_ && content_view_core_) |
| 1444 content_view_core_->GetWindowAndroid()->RemoveObserver(this); | 1445 UnsubscribeToVSync(INPUT | BEGIN_FRAME); |
| 1445 observing_root_window_ = false; | |
| 1446 } | |
| 1447 | 1446 |
| 1448 bool resize = false; | 1447 bool resize = false; |
| 1449 if (content_view_core != content_view_core_) { | 1448 if (content_view_core != content_view_core_) { |
| 1450 selection_controller_.reset(); | 1449 selection_controller_.reset(); |
| 1451 ReleaseLocksOnSurface(); | 1450 ReleaseLocksOnSurface(); |
| 1452 resize = true; | 1451 resize = true; |
| 1453 } | 1452 } |
| 1454 | 1453 |
| 1455 content_view_core_ = content_view_core; | 1454 content_view_core_ = content_view_core; |
| 1456 | 1455 |
| 1457 BrowserAccessibilityManager* manager = NULL; | 1456 BrowserAccessibilityManager* manager = NULL; |
| 1458 if (host_) | 1457 if (host_) |
| 1459 manager = host_->GetRootBrowserAccessibilityManager(); | 1458 manager = host_->GetRootBrowserAccessibilityManager(); |
| 1460 if (manager) { | 1459 if (manager) { |
| 1461 base::android::ScopedJavaLocalRef<jobject> obj; | 1460 base::android::ScopedJavaLocalRef<jobject> obj; |
| 1462 if (content_view_core_) | 1461 if (content_view_core_) |
| 1463 obj = content_view_core_->GetJavaObject(); | 1462 obj = content_view_core_->GetJavaObject(); |
| 1464 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj); | 1463 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj); |
| 1465 } | 1464 } |
| 1466 | 1465 |
| 1467 AttachLayers(); | 1466 AttachLayers(); |
| 1468 | 1467 |
| 1469 if (!content_view_core_) | 1468 if (!content_view_core_) |
| 1470 return; | 1469 return; |
| 1471 | 1470 |
| 1472 if (!using_synchronous_compositor_) { | 1471 if (!using_synchronous_compositor_) { |
| 1473 content_view_core_->GetWindowAndroid()->AddObserver(this); | 1472 SubscribeToVSync(INPUT | BEGIN_FRAME); |
| 1474 observing_root_window_ = true; | |
| 1475 if (needs_begin_frame_) | 1473 if (needs_begin_frame_) |
| 1476 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); | 1474 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); |
| 1477 } | 1475 } |
| 1478 | 1476 |
| 1479 if (resize) | 1477 if (resize) |
| 1480 WasResized(); | 1478 WasResized(); |
| 1481 | 1479 |
| 1482 if (!selection_controller_) | 1480 if (!selection_controller_) |
| 1483 selection_controller_.reset(new TouchSelectionController(this)); | 1481 selection_controller_.reset(new TouchSelectionController(this)); |
| 1484 | 1482 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 1511 void RenderWidgetHostViewAndroid::OnCompositingDidCommit() { | 1509 void RenderWidgetHostViewAndroid::OnCompositingDidCommit() { |
| 1512 RunAckCallbacks(); | 1510 RunAckCallbacks(); |
| 1513 } | 1511 } |
| 1514 | 1512 |
| 1515 void RenderWidgetHostViewAndroid::OnDetachCompositor() { | 1513 void RenderWidgetHostViewAndroid::OnDetachCompositor() { |
| 1516 DCHECK(content_view_core_); | 1514 DCHECK(content_view_core_); |
| 1517 DCHECK(!using_synchronous_compositor_); | 1515 DCHECK(!using_synchronous_compositor_); |
| 1518 RunAckCallbacks(); | 1516 RunAckCallbacks(); |
| 1519 } | 1517 } |
| 1520 | 1518 |
| 1519 void RenderWidgetHostViewAndroid::SubscribeToVSync(uint32 type) { | |
| 1520 if (!vsync_subscribers_bitmask_) | |
| 1521 content_view_core_->GetWindowAndroid()->AddObserver(this); | |
| 1522 | |
| 1523 vsync_subscribers_bitmask_ |= type; | |
| 1524 // Synchronous compositor does not request begin frames OnVSync. | |
| 1525 DCHECK(!using_synchronous_compositor_ || | |
| 1526 !(vsync_subscribers_bitmask_ & BEGIN_FRAME)); | |
| 1527 } | |
| 1528 | |
| 1529 void RenderWidgetHostViewAndroid::UnsubscribeToVSync(uint32 type) { | |
| 1530 vsync_subscribers_bitmask_ &= ~type; | |
| 1531 if (!vsync_subscribers_bitmask_) | |
| 1532 content_view_core_->GetWindowAndroid()->RemoveObserver(this); | |
| 1533 } | |
| 1534 | |
| 1521 void RenderWidgetHostViewAndroid::OnVSync(base::TimeTicks frame_time, | 1535 void RenderWidgetHostViewAndroid::OnVSync(base::TimeTicks frame_time, |
| 1522 base::TimeDelta vsync_period) { | 1536 base::TimeDelta vsync_period) { |
| 1523 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::OnVSync"); | 1537 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::OnVSync"); |
| 1524 if (!host_) | 1538 if (!host_) |
| 1525 return; | 1539 return; |
| 1526 | 1540 |
| 1527 if (flush_input_requested_) { | 1541 if (vsync_subscribers_bitmask_ & INPUT & flush_input_requested_) { |
| 1528 flush_input_requested_ = false; | 1542 flush_input_requested_ = false; |
| 1529 host_->FlushInput(); | 1543 host_->FlushInput(); |
| 1530 } | 1544 } |
| 1531 | 1545 |
| 1546 if (!(vsync_subscribers_bitmask_ & BEGIN_FRAME)) | |
| 1547 return; | |
| 1548 | |
| 1532 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::SendBeginFrame"); | 1549 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::SendBeginFrame"); |
| 1533 base::TimeTicks display_time = frame_time + vsync_period; | 1550 base::TimeTicks display_time = frame_time + vsync_period; |
| 1534 | 1551 |
| 1535 // TODO(brianderson): Use adaptive draw-time estimation. | 1552 // TODO(brianderson): Use adaptive draw-time estimation. |
| 1536 base::TimeDelta estimated_browser_composite_time = | 1553 base::TimeDelta estimated_browser_composite_time = |
| 1537 base::TimeDelta::FromMicroseconds( | 1554 base::TimeDelta::FromMicroseconds( |
| 1538 (1.0f * base::Time::kMicrosecondsPerSecond) / (3.0f * 60)); | 1555 (1.0f * base::Time::kMicrosecondsPerSecond) / (3.0f * 60)); |
| 1539 | 1556 |
| 1540 base::TimeTicks deadline = display_time - estimated_browser_composite_time; | 1557 base::TimeTicks deadline = display_time - estimated_browser_composite_time; |
| 1541 | 1558 |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1691 results->orientationAngle = display.RotationAsDegree(); | 1708 results->orientationAngle = display.RotationAsDegree(); |
| 1692 results->orientationType = | 1709 results->orientationType = |
| 1693 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); | 1710 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); |
| 1694 gfx::DeviceDisplayInfo info; | 1711 gfx::DeviceDisplayInfo info; |
| 1695 results->depth = info.GetBitsPerPixel(); | 1712 results->depth = info.GetBitsPerPixel(); |
| 1696 results->depthPerComponent = info.GetBitsPerComponent(); | 1713 results->depthPerComponent = info.GetBitsPerComponent(); |
| 1697 results->isMonochrome = (results->depthPerComponent == 0); | 1714 results->isMonochrome = (results->depthPerComponent == 0); |
| 1698 } | 1715 } |
| 1699 | 1716 |
| 1700 } // namespace content | 1717 } // namespace content |
| OLD | NEW |