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/android/build_info.h" | 9 #include "base/android/build_info.h" |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
238 uint32 output_id, | 238 uint32 output_id, |
239 scoped_ptr<cc::CompositorFrame> output_frame) | 239 scoped_ptr<cc::CompositorFrame> output_frame) |
240 : output_surface_id(output_id), frame(output_frame.Pass()) {} | 240 : output_surface_id(output_id), frame(output_frame.Pass()) {} |
241 | 241 |
242 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {} | 242 RenderWidgetHostViewAndroid::LastFrameInfo::~LastFrameInfo() {} |
243 | 243 |
244 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( | 244 RenderWidgetHostViewAndroid::RenderWidgetHostViewAndroid( |
245 RenderWidgetHostImpl* widget_host, | 245 RenderWidgetHostImpl* widget_host, |
246 ContentViewCoreImpl* content_view_core) | 246 ContentViewCoreImpl* content_view_core) |
247 : host_(widget_host), | 247 : host_(widget_host), |
248 needs_begin_frame_(false), | 248 outstanding_vsync_requests_(0), |
249 is_showing_(!widget_host->is_hidden()), | 249 is_showing_(!widget_host->is_hidden()), |
250 content_view_core_(NULL), | 250 content_view_core_(NULL), |
251 ime_adapter_android_(this), | 251 ime_adapter_android_(this), |
252 cached_background_color_(SK_ColorWHITE), | 252 cached_background_color_(SK_ColorWHITE), |
253 last_output_surface_id_(kUndefinedOutputSurfaceId), | 253 last_output_surface_id_(kUndefinedOutputSurfaceId), |
254 weak_ptr_factory_(this), | 254 weak_ptr_factory_(this), |
255 overscroll_effect_enabled_( | 255 overscroll_effect_enabled_( |
256 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 256 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
257 switches::kDisableOverscrollEdgeEffect)), | 257 switches::kDisableOverscrollEdgeEffect)), |
258 gesture_provider_(CreateGestureProviderConfig(), this), | 258 gesture_provider_(CreateGestureProviderConfig(), this), |
259 gesture_text_selector_(this), | 259 gesture_text_selector_(this), |
260 touch_scrolling_(false), | 260 touch_scrolling_(false), |
261 potentially_active_fling_count_(0), | 261 potentially_active_fling_count_(0), |
262 flush_input_requested_(false), | |
263 accelerated_surface_route_id_(0), | 262 accelerated_surface_route_id_(0), |
264 using_synchronous_compositor_(SynchronousCompositorImpl::FromID( | 263 using_synchronous_compositor_(SynchronousCompositorImpl::FromID( |
265 widget_host->GetProcess()->GetID(), | 264 widget_host->GetProcess()->GetID(), |
266 widget_host->GetRoutingID()) != NULL), | 265 widget_host->GetRoutingID()) != NULL), |
267 frame_evictor_(new DelegatedFrameEvictor(this)), | 266 frame_evictor_(new DelegatedFrameEvictor(this)), |
268 locks_on_frame_count_(0), | 267 locks_on_frame_count_(0), |
269 observing_root_window_(false) { | 268 observing_root_window_(false) { |
270 host_->SetView(this); | 269 host_->SetView(this); |
271 SetContentViewCore(content_view_core); | 270 SetContentViewCore(content_view_core); |
272 ImageTransportFactoryAndroid::AddObserver(this); | 271 ImageTransportFactoryAndroid::AddObserver(this); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
318 } | 317 } |
319 | 318 |
320 void RenderWidgetHostViewAndroid::WasShown() { | 319 void RenderWidgetHostViewAndroid::WasShown() { |
321 if (!host_ || !host_->is_hidden()) | 320 if (!host_ || !host_->is_hidden()) |
322 return; | 321 return; |
323 | 322 |
324 host_->WasShown(ui::LatencyInfo()); | 323 host_->WasShown(ui::LatencyInfo()); |
325 | 324 |
326 if (content_view_core_ && !using_synchronous_compositor_) { | 325 if (content_view_core_ && !using_synchronous_compositor_) { |
327 content_view_core_->GetWindowAndroid()->AddObserver(this); | 326 content_view_core_->GetWindowAndroid()->AddObserver(this); |
328 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); | |
329 observing_root_window_ = true; | 327 observing_root_window_ = true; |
328 RequestVSyncUpdate(BEGIN_FRAME); | |
330 } | 329 } |
331 } | 330 } |
332 | 331 |
333 void RenderWidgetHostViewAndroid::WasHidden() { | 332 void RenderWidgetHostViewAndroid::WasHidden() { |
334 RunAckCallbacks(); | 333 RunAckCallbacks(); |
335 | 334 |
336 if (!host_ || host_->is_hidden()) | 335 if (!host_ || host_->is_hidden()) |
337 return; | 336 return; |
338 | 337 |
339 // Inform the renderer that we are being hidden so it can reduce its resource | 338 // Inform the renderer that we are being hidden so it can reduce its resource |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
621 SkColor color) { | 620 SkColor color) { |
622 if (cached_background_color_ == color) | 621 if (cached_background_color_ == color) |
623 return; | 622 return; |
624 | 623 |
625 cached_background_color_ = color; | 624 cached_background_color_ = color; |
626 if (content_view_core_) | 625 if (content_view_core_) |
627 content_view_core_->OnBackgroundColorChanged(color); | 626 content_view_core_->OnBackgroundColorChanged(color); |
628 } | 627 } |
629 | 628 |
630 void RenderWidgetHostViewAndroid::OnSetNeedsBeginFrame(bool enabled) { | 629 void RenderWidgetHostViewAndroid::OnSetNeedsBeginFrame(bool enabled) { |
631 if (enabled == needs_begin_frame_) | |
632 return; | |
633 | |
634 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::OnSetNeedsBeginFrame", | 630 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::OnSetNeedsBeginFrame", |
635 "enabled", enabled); | 631 "enabled", enabled); |
636 if (content_view_core_ && enabled) | 632 if (enabled) |
637 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); | 633 RequestVSyncUpdate(PERSISTENT_BEGIN_FRAME); |
638 | 634 else |
639 needs_begin_frame_ = enabled; | 635 outstanding_vsync_requests_ &= ~PERSISTENT_BEGIN_FRAME; |
640 } | 636 } |
641 | 637 |
642 void RenderWidgetHostViewAndroid::OnStartContentIntent( | 638 void RenderWidgetHostViewAndroid::OnStartContentIntent( |
643 const GURL& content_url) { | 639 const GURL& content_url) { |
644 if (content_view_core_) | 640 if (content_view_core_) |
645 content_view_core_->StartContentIntent(content_url); | 641 content_view_core_->StartContentIntent(content_url); |
646 } | 642 } |
647 | 643 |
648 void RenderWidgetHostViewAndroid::OnSmartClipDataExtracted( | 644 void RenderWidgetHostViewAndroid::OnSmartClipDataExtracted( |
649 const base::string16& text, | 645 const base::string16& text, |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1250 return; | 1246 return; |
1251 | 1247 |
1252 if (!layer_.get()) | 1248 if (!layer_.get()) |
1253 return; | 1249 return; |
1254 | 1250 |
1255 content_view_core_->RemoveLayer(layer_); | 1251 content_view_core_->RemoveLayer(layer_); |
1256 if (overscroll_effect_) | 1252 if (overscroll_effect_) |
1257 overscroll_effect_->Disable(); | 1253 overscroll_effect_->Disable(); |
1258 } | 1254 } |
1259 | 1255 |
1256 void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32 requests) { | |
1257 DCHECK(observing_root_window_); | |
no sievers
2014/08/21 17:57:10
I'm not sure this is always true. I think receivin
jdduke (slow)
2014/08/21 20:50:39
Ah, I see, it looks like I might need to be more c
| |
1258 bool should_request_vsync = !outstanding_vsync_requests_ && requests; | |
1259 outstanding_vsync_requests_ |= requests; | |
1260 // Note that if |content_view_core_| is NULL, outstanding vsync requests will | |
1261 // be pushed if/when it next becomes valid via |SetContentViewCore()|. | |
1262 if (content_view_core_ && should_request_vsync) { | |
1263 DCHECK(!using_synchronous_compositor_ || requests == FLUSH_INPUT); | |
1264 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); | |
1265 } | |
1266 } | |
1267 | |
1268 void RenderWidgetHostViewAndroid::SendBeginFrame(base::TimeTicks frame_time, | |
1269 base::TimeDelta vsync_period) { | |
1270 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::SendBeginFrame"); | |
1271 base::TimeTicks display_time = frame_time + vsync_period; | |
1272 | |
1273 // TODO(brianderson): Use adaptive draw-time estimation. | |
1274 base::TimeDelta estimated_browser_composite_time = | |
1275 base::TimeDelta::FromMicroseconds( | |
1276 (1.0f * base::Time::kMicrosecondsPerSecond) / (3.0f * 60)); | |
1277 | |
1278 base::TimeTicks deadline = display_time - estimated_browser_composite_time; | |
1279 | |
1280 host_->Send(new ViewMsg_BeginFrame( | |
1281 host_->GetRoutingID(), | |
1282 cc::BeginFrameArgs::Create(frame_time, deadline, vsync_period))); | |
1283 } | |
1284 | |
1260 bool RenderWidgetHostViewAndroid::Animate(base::TimeTicks frame_time) { | 1285 bool RenderWidgetHostViewAndroid::Animate(base::TimeTicks frame_time) { |
1261 bool needs_animate = | 1286 bool needs_animate = |
1262 overscroll_effect_ ? overscroll_effect_->Animate(frame_time) : false; | 1287 overscroll_effect_ ? overscroll_effect_->Animate(frame_time) : false; |
1263 if (selection_controller_) | 1288 if (selection_controller_) |
1264 needs_animate |= selection_controller_->Animate(frame_time); | 1289 needs_animate |= selection_controller_->Animate(frame_time); |
1265 return needs_animate; | 1290 return needs_animate; |
1266 } | 1291 } |
1267 | 1292 |
1268 void RenderWidgetHostViewAndroid::OnContentScrollingChange() { | 1293 void RenderWidgetHostViewAndroid::OnContentScrollingChange() { |
1269 if (selection_controller_) | 1294 if (selection_controller_) |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1398 | 1423 |
1399 SynchronousCompositorImpl* compositor = | 1424 SynchronousCompositorImpl* compositor = |
1400 SynchronousCompositorImpl::FromID(host_->GetProcess()->GetID(), | 1425 SynchronousCompositorImpl::FromID(host_->GetProcess()->GetID(), |
1401 host_->GetRoutingID()); | 1426 host_->GetRoutingID()); |
1402 if (compositor) | 1427 if (compositor) |
1403 return compositor->HandleInputEvent(input_event); | 1428 return compositor->HandleInputEvent(input_event); |
1404 return INPUT_EVENT_ACK_STATE_NOT_CONSUMED; | 1429 return INPUT_EVENT_ACK_STATE_NOT_CONSUMED; |
1405 } | 1430 } |
1406 | 1431 |
1407 void RenderWidgetHostViewAndroid::OnSetNeedsFlushInput() { | 1432 void RenderWidgetHostViewAndroid::OnSetNeedsFlushInput() { |
1408 if (flush_input_requested_ || !content_view_core_) | |
1409 return; | |
1410 TRACE_EVENT0("input", "RenderWidgetHostViewAndroid::OnSetNeedsFlushInput"); | 1433 TRACE_EVENT0("input", "RenderWidgetHostViewAndroid::OnSetNeedsFlushInput"); |
1411 flush_input_requested_ = true; | 1434 RequestVSyncUpdate(FLUSH_INPUT); |
1412 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); | |
1413 } | 1435 } |
1414 | 1436 |
1415 BrowserAccessibilityManager* | 1437 BrowserAccessibilityManager* |
1416 RenderWidgetHostViewAndroid::CreateBrowserAccessibilityManager( | 1438 RenderWidgetHostViewAndroid::CreateBrowserAccessibilityManager( |
1417 BrowserAccessibilityDelegate* delegate) { | 1439 BrowserAccessibilityDelegate* delegate) { |
1418 base::android::ScopedJavaLocalRef<jobject> obj; | 1440 base::android::ScopedJavaLocalRef<jobject> obj; |
1419 if (content_view_core_) | 1441 if (content_view_core_) |
1420 obj = content_view_core_->GetJavaObject(); | 1442 obj = content_view_core_->GetJavaObject(); |
1421 return new BrowserAccessibilityManagerAndroid( | 1443 return new BrowserAccessibilityManagerAndroid( |
1422 obj, | 1444 obj, |
(...skipping 20 matching lines...) Expand all Loading... | |
1443 | 1465 |
1444 void RenderWidgetHostViewAndroid::SendTouchEvent( | 1466 void RenderWidgetHostViewAndroid::SendTouchEvent( |
1445 const blink::WebTouchEvent& event) { | 1467 const blink::WebTouchEvent& event) { |
1446 if (host_) | 1468 if (host_) |
1447 host_->ForwardTouchEventWithLatencyInfo(event, CreateLatencyInfo(event)); | 1469 host_->ForwardTouchEventWithLatencyInfo(event, CreateLatencyInfo(event)); |
1448 | 1470 |
1449 // Send a proactive BeginFrame on the next vsync to reduce latency. | 1471 // Send a proactive BeginFrame on the next vsync to reduce latency. |
1450 // This is good enough as long as the first touch event has Begin semantics | 1472 // This is good enough as long as the first touch event has Begin semantics |
1451 // and the actual scroll happens on the next vsync. | 1473 // and the actual scroll happens on the next vsync. |
1452 // TODO: Is this actually still needed? | 1474 // TODO: Is this actually still needed? |
1453 if (content_view_core_ && observing_root_window_) { | 1475 if (content_view_core_ && observing_root_window_) |
1454 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); | 1476 RequestVSyncUpdate(BEGIN_FRAME); |
1455 } | |
1456 } | 1477 } |
1457 | 1478 |
1458 void RenderWidgetHostViewAndroid::SendMouseEvent( | 1479 void RenderWidgetHostViewAndroid::SendMouseEvent( |
1459 const blink::WebMouseEvent& event) { | 1480 const blink::WebMouseEvent& event) { |
1460 if (host_) | 1481 if (host_) |
1461 host_->ForwardMouseEvent(event); | 1482 host_->ForwardMouseEvent(event); |
1462 } | 1483 } |
1463 | 1484 |
1464 void RenderWidgetHostViewAndroid::SendMouseWheelEvent( | 1485 void RenderWidgetHostViewAndroid::SendMouseWheelEvent( |
1465 const blink::WebMouseWheelEvent& event) { | 1486 const blink::WebMouseWheelEvent& event) { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1573 } | 1594 } |
1574 | 1595 |
1575 AttachLayers(); | 1596 AttachLayers(); |
1576 | 1597 |
1577 if (!content_view_core_) | 1598 if (!content_view_core_) |
1578 return; | 1599 return; |
1579 | 1600 |
1580 if (!using_synchronous_compositor_) { | 1601 if (!using_synchronous_compositor_) { |
1581 content_view_core_->GetWindowAndroid()->AddObserver(this); | 1602 content_view_core_->GetWindowAndroid()->AddObserver(this); |
1582 observing_root_window_ = true; | 1603 observing_root_window_ = true; |
1583 if (needs_begin_frame_) | 1604 // Clear existing vsync requests to allow a request to the new window. |
1584 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); | 1605 uint32 outstanding_vsync_requests = outstanding_vsync_requests_; |
1606 outstanding_vsync_requests_ = 0; | |
1607 RequestVSyncUpdate(outstanding_vsync_requests); | |
1585 } | 1608 } |
1586 | 1609 |
1587 if (resize) | 1610 if (resize) |
1588 WasResized(); | 1611 WasResized(); |
1589 | 1612 |
1590 if (!selection_controller_) | 1613 if (!selection_controller_) |
1591 selection_controller_.reset(new TouchSelectionController(this)); | 1614 selection_controller_.reset(new TouchSelectionController(this)); |
1592 | 1615 |
1593 if (!content_view_core_) | 1616 if (!content_view_core_) |
1594 overscroll_effect_.reset(); | 1617 overscroll_effect_.reset(); |
(...skipping 25 matching lines...) Expand all Loading... | |
1620 DCHECK(!using_synchronous_compositor_); | 1643 DCHECK(!using_synchronous_compositor_); |
1621 RunAckCallbacks(); | 1644 RunAckCallbacks(); |
1622 } | 1645 } |
1623 | 1646 |
1624 void RenderWidgetHostViewAndroid::OnVSync(base::TimeTicks frame_time, | 1647 void RenderWidgetHostViewAndroid::OnVSync(base::TimeTicks frame_time, |
1625 base::TimeDelta vsync_period) { | 1648 base::TimeDelta vsync_period) { |
1626 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::OnVSync"); | 1649 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::OnVSync"); |
1627 if (!host_) | 1650 if (!host_) |
1628 return; | 1651 return; |
1629 | 1652 |
1630 if (flush_input_requested_) { | 1653 const uint32 current_vsync_requests = outstanding_vsync_requests_; |
1631 flush_input_requested_ = false; | 1654 outstanding_vsync_requests_ = 0; |
1632 host_->FlushInput(); | |
1633 } | |
1634 | 1655 |
1635 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::SendBeginFrame"); | 1656 if (current_vsync_requests & FLUSH_INPUT) |
1636 base::TimeTicks display_time = frame_time + vsync_period; | 1657 host_->FlushInput(frame_time); |
1637 | 1658 |
1638 // TODO(brianderson): Use adaptive draw-time estimation. | 1659 if (current_vsync_requests & BEGIN_FRAME || |
1639 base::TimeDelta estimated_browser_composite_time = | 1660 current_vsync_requests & PERSISTENT_BEGIN_FRAME) |
no sievers
2014/08/21 17:57:10
nit: braces
jdduke (slow)
2014/08/21 20:50:39
Done.
| |
1640 base::TimeDelta::FromMicroseconds( | 1661 SendBeginFrame(frame_time, vsync_period); |
1641 (1.0f * base::Time::kMicrosecondsPerSecond) / (3.0f * 60)); | |
1642 | 1662 |
1643 base::TimeTicks deadline = display_time - estimated_browser_composite_time; | 1663 if (current_vsync_requests & PERSISTENT_BEGIN_FRAME) |
1644 | 1664 RequestVSyncUpdate(PERSISTENT_BEGIN_FRAME); |
1645 host_->Send(new ViewMsg_BeginFrame( | |
1646 host_->GetRoutingID(), | |
1647 cc::BeginFrameArgs::Create(frame_time, deadline, vsync_period))); | |
1648 | |
1649 if (needs_begin_frame_) | |
1650 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); | |
1651 } | 1665 } |
1652 | 1666 |
1653 void RenderWidgetHostViewAndroid::OnAnimate(base::TimeTicks begin_frame_time) { | 1667 void RenderWidgetHostViewAndroid::OnAnimate(base::TimeTicks begin_frame_time) { |
1654 if (Animate(begin_frame_time)) | 1668 if (Animate(begin_frame_time)) |
1655 SetNeedsAnimate(); | 1669 SetNeedsAnimate(); |
1656 } | 1670 } |
1657 | 1671 |
1658 void RenderWidgetHostViewAndroid::OnLostResources() { | 1672 void RenderWidgetHostViewAndroid::OnLostResources() { |
1659 ReleaseLocksOnSurface(); | 1673 ReleaseLocksOnSurface(); |
1660 if (layer_.get()) | 1674 if (layer_.get()) |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1796 results->orientationAngle = display.RotationAsDegree(); | 1810 results->orientationAngle = display.RotationAsDegree(); |
1797 results->orientationType = | 1811 results->orientationType = |
1798 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); | 1812 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); |
1799 gfx::DeviceDisplayInfo info; | 1813 gfx::DeviceDisplayInfo info; |
1800 results->depth = info.GetBitsPerPixel(); | 1814 results->depth = info.GetBitsPerPixel(); |
1801 results->depthPerComponent = info.GetBitsPerComponent(); | 1815 results->depthPerComponent = info.GetBitsPerComponent(); |
1802 results->isMonochrome = (results->depthPerComponent == 0); | 1816 results->isMonochrome = (results->depthPerComponent == 0); |
1803 } | 1817 } |
1804 | 1818 |
1805 } // namespace content | 1819 } // namespace content |
OLD | NEW |