| 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 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 | 542 |
| 543 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { | 543 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { |
| 544 return HasValidFrame(); | 544 return HasValidFrame(); |
| 545 } | 545 } |
| 546 | 546 |
| 547 void RenderWidgetHostViewAndroid::Show() { | 547 void RenderWidgetHostViewAndroid::Show() { |
| 548 if (is_showing_) | 548 if (is_showing_) |
| 549 return; | 549 return; |
| 550 | 550 |
| 551 is_showing_ = true; | 551 is_showing_ = true; |
| 552 if (layer_.get()) | 552 ShowInternal(); |
| 553 layer_->SetHideLayerAndSubtree(false); | |
| 554 | |
| 555 if (overscroll_controller_) | |
| 556 overscroll_controller_->Enable(); | |
| 557 | |
| 558 frame_evictor_->SetVisible(true); | |
| 559 | |
| 560 if (!host_ || !host_->is_hidden()) | |
| 561 return; | |
| 562 | |
| 563 host_->WasShown(ui::LatencyInfo()); | |
| 564 | |
| 565 if (content_view_core_) { | |
| 566 StartObservingRootWindow(); | |
| 567 RequestVSyncUpdate(BEGIN_FRAME); | |
| 568 } | |
| 569 } | 553 } |
| 570 | 554 |
| 571 void RenderWidgetHostViewAndroid::Hide() { | 555 void RenderWidgetHostViewAndroid::Hide() { |
| 572 if (!is_showing_) | 556 if (!is_showing_) |
| 573 return; | 557 return; |
| 574 | 558 |
| 575 is_showing_ = false; | 559 is_showing_ = false; |
| 576 if (layer_.get() && locks_on_frame_count_ == 0) | |
| 577 layer_->SetHideLayerAndSubtree(true); | |
| 578 | 560 |
| 579 if (overscroll_controller_) | 561 bool hide_frontbuffer = true; |
| 580 overscroll_controller_->Disable(); | 562 bool stop_observing_root_window = true; |
| 581 | 563 HideInternal(hide_frontbuffer, stop_observing_root_window); |
| 582 frame_evictor_->SetVisible(false); | |
| 583 | |
| 584 RunAckCallbacks(cc::SurfaceDrawStatus::DRAW_SKIPPED); | |
| 585 | |
| 586 if (!host_ || host_->is_hidden()) | |
| 587 return; | |
| 588 | |
| 589 // Inform the renderer that we are being hidden so it can reduce its resource | |
| 590 // utilization. | |
| 591 host_->WasHidden(); | |
| 592 | |
| 593 StopObservingRootWindow(); | |
| 594 } | 564 } |
| 595 | 565 |
| 596 bool RenderWidgetHostViewAndroid::IsShowing() { | 566 bool RenderWidgetHostViewAndroid::IsShowing() { |
| 597 // ContentViewCoreImpl represents the native side of the Java | 567 // ContentViewCoreImpl represents the native side of the Java |
| 598 // ContentViewCore. It being NULL means that it is not attached | 568 // ContentViewCore. It being NULL means that it is not attached |
| 599 // to the View system yet, so we treat this RWHVA as hidden. | 569 // to the View system yet, so we treat this RWHVA as hidden. |
| 600 return is_showing_ && content_view_core_; | 570 return is_showing_ && content_view_core_; |
| 601 } | 571 } |
| 602 | 572 |
| 603 void RenderWidgetHostViewAndroid::LockCompositingSurface() { | 573 void RenderWidgetHostViewAndroid::LockCompositingSurface() { |
| (...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1400 web_contents_impl->media_web_contents_observer()->OnFrameInfoUpdated(); | 1370 web_contents_impl->media_web_contents_observer()->OnFrameInfoUpdated(); |
| 1401 } | 1371 } |
| 1402 #endif // defined(VIDEO_HOLE) | 1372 #endif // defined(VIDEO_HOLE) |
| 1403 } | 1373 } |
| 1404 | 1374 |
| 1405 void RenderWidgetHostViewAndroid::AcceleratedSurfaceInitialized(int route_id) { | 1375 void RenderWidgetHostViewAndroid::AcceleratedSurfaceInitialized(int route_id) { |
| 1406 // TODO: remove need for the surface id here | 1376 // TODO: remove need for the surface id here |
| 1407 accelerated_surface_route_id_ = route_id; | 1377 accelerated_surface_route_id_ = route_id; |
| 1408 } | 1378 } |
| 1409 | 1379 |
| 1380 void RenderWidgetHostViewAndroid::ShowInternal() { |
| 1381 DCHECK(is_showing_); |
| 1382 if (!host_ || !host_->is_hidden()) |
| 1383 return; |
| 1384 |
| 1385 if (layer_.get()) |
| 1386 layer_->SetHideLayerAndSubtree(false); |
| 1387 |
| 1388 frame_evictor_->SetVisible(true); |
| 1389 |
| 1390 if (overscroll_controller_) |
| 1391 overscroll_controller_->Enable(); |
| 1392 |
| 1393 host_->WasShown(ui::LatencyInfo()); |
| 1394 |
| 1395 if (content_view_core_) { |
| 1396 StartObservingRootWindow(); |
| 1397 RequestVSyncUpdate(BEGIN_FRAME); |
| 1398 } |
| 1399 } |
| 1400 |
| 1401 void RenderWidgetHostViewAndroid::HideInternal( |
| 1402 bool hide_frontbuffer, |
| 1403 bool stop_observing_root_window) { |
| 1404 if (hide_frontbuffer) { |
| 1405 if (layer_.get() && locks_on_frame_count_ == 0) |
| 1406 layer_->SetHideLayerAndSubtree(true); |
| 1407 |
| 1408 frame_evictor_->SetVisible(false); |
| 1409 } |
| 1410 |
| 1411 if (stop_observing_root_window) |
| 1412 StopObservingRootWindow(); |
| 1413 |
| 1414 if (!host_ || host_->is_hidden()) |
| 1415 return; |
| 1416 |
| 1417 if (overscroll_controller_) |
| 1418 overscroll_controller_->Disable(); |
| 1419 |
| 1420 RunAckCallbacks(cc::SurfaceDrawStatus::DRAW_SKIPPED); |
| 1421 |
| 1422 // Inform the renderer that we are being hidden so it can reduce its resource |
| 1423 // utilization. |
| 1424 host_->WasHidden(); |
| 1425 } |
| 1426 |
| 1410 void RenderWidgetHostViewAndroid::AttachLayers() { | 1427 void RenderWidgetHostViewAndroid::AttachLayers() { |
| 1411 if (!content_view_core_) | 1428 if (!content_view_core_) |
| 1412 return; | 1429 return; |
| 1413 if (!layer_.get()) | 1430 if (!layer_.get()) |
| 1414 return; | 1431 return; |
| 1415 | 1432 |
| 1416 content_view_core_->AttachLayer(layer_); | 1433 content_view_core_->AttachLayer(layer_); |
| 1417 if (overscroll_controller_) | 1434 if (overscroll_controller_) |
| 1418 overscroll_controller_->Enable(); | 1435 overscroll_controller_->Enable(); |
| 1419 layer_->SetHideLayerAndSubtree(!is_showing_); | 1436 layer_->SetHideLayerAndSubtree(!is_showing_); |
| 1420 } | 1437 } |
| 1421 | 1438 |
| 1422 void RenderWidgetHostViewAndroid::RemoveLayers() { | 1439 void RenderWidgetHostViewAndroid::RemoveLayers() { |
| 1423 if (!content_view_core_) | 1440 if (!content_view_core_) |
| 1424 return; | 1441 return; |
| 1425 | 1442 |
| 1426 if (!layer_.get()) | 1443 if (!layer_.get()) |
| 1427 return; | 1444 return; |
| 1428 | 1445 |
| 1429 content_view_core_->RemoveLayer(layer_); | 1446 content_view_core_->RemoveLayer(layer_); |
| 1430 if (overscroll_controller_) | 1447 if (overscroll_controller_) |
| 1431 overscroll_controller_->Disable(); | 1448 overscroll_controller_->Disable(); |
| 1432 } | 1449 } |
| 1433 | 1450 |
| 1434 void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32 requests) { | 1451 void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32 requests) { |
| 1435 bool should_request_vsync = !outstanding_vsync_requests_ && requests; | 1452 bool should_request_vsync = !outstanding_vsync_requests_ && requests; |
| 1436 outstanding_vsync_requests_ |= requests; | 1453 outstanding_vsync_requests_ |= requests; |
| 1454 |
| 1455 // If the host has been hidden, defer vsync requests until it is shown |
| 1456 // again via |Show()|. |
| 1457 if (!host_ || host_->is_hidden()) |
| 1458 return; |
| 1459 |
| 1437 // Note that if we're not currently observing the root window, outstanding | 1460 // Note that if we're not currently observing the root window, outstanding |
| 1438 // vsync requests will be pushed if/when we resume observing in | 1461 // vsync requests will be pushed if/when we resume observing in |
| 1439 // |StartObservingRootWindow()|. | 1462 // |StartObservingRootWindow()|. |
| 1440 if (observing_root_window_ && should_request_vsync) | 1463 if (observing_root_window_ && should_request_vsync) |
| 1441 content_view_core_window_android_->RequestVSyncUpdate(); | 1464 content_view_core_window_android_->RequestVSyncUpdate(); |
| 1442 } | 1465 } |
| 1443 | 1466 |
| 1444 void RenderWidgetHostViewAndroid::StartObservingRootWindow() { | 1467 void RenderWidgetHostViewAndroid::StartObservingRootWindow() { |
| 1445 DCHECK(content_view_core_window_android_); | 1468 DCHECK(content_view_core_window_android_); |
| 1469 DCHECK(is_showing_); |
| 1446 if (observing_root_window_) | 1470 if (observing_root_window_) |
| 1447 return; | 1471 return; |
| 1448 | 1472 |
| 1449 observing_root_window_ = true; | 1473 observing_root_window_ = true; |
| 1450 content_view_core_window_android_->AddObserver(this); | 1474 content_view_core_window_android_->AddObserver(this); |
| 1451 | 1475 |
| 1452 // Clear existing vsync requests to allow a request to the new window. | 1476 // Clear existing vsync requests to allow a request to the new window. |
| 1453 uint32 outstanding_vsync_requests = outstanding_vsync_requests_; | 1477 uint32 outstanding_vsync_requests = outstanding_vsync_requests_; |
| 1454 outstanding_vsync_requests_ = 0; | 1478 outstanding_vsync_requests_ = 0; |
| 1455 RequestVSyncUpdate(outstanding_vsync_requests); | 1479 RequestVSyncUpdate(outstanding_vsync_requests); |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1748 if (content_view_core_) | 1772 if (content_view_core_) |
| 1749 obj = content_view_core_->GetJavaObject(); | 1773 obj = content_view_core_->GetJavaObject(); |
| 1750 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj); | 1774 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj); |
| 1751 } | 1775 } |
| 1752 | 1776 |
| 1753 AttachLayers(); | 1777 AttachLayers(); |
| 1754 | 1778 |
| 1755 if (!content_view_core_) | 1779 if (!content_view_core_) |
| 1756 return; | 1780 return; |
| 1757 | 1781 |
| 1758 StartObservingRootWindow(); | 1782 if (is_showing_) |
| 1783 StartObservingRootWindow(); |
| 1759 | 1784 |
| 1760 if (resize) | 1785 if (resize) |
| 1761 WasResized(); | 1786 WasResized(); |
| 1762 | 1787 |
| 1763 if (!selection_controller_) | 1788 if (!selection_controller_) |
| 1764 selection_controller_ = CreateSelectionController(this, content_view_core_); | 1789 selection_controller_ = CreateSelectionController(this, content_view_core_); |
| 1765 | 1790 |
| 1766 if (!overscroll_controller_ && | 1791 if (!overscroll_controller_ && |
| 1767 content_view_core_window_android_->GetCompositor()) { | 1792 content_view_core_window_android_->GetCompositor()) { |
| 1768 overscroll_controller_ = CreateOverscrollController(content_view_core_); | 1793 overscroll_controller_ = CreateOverscrollController(content_view_core_); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1789 web_gesture.modifiers == blink::WebInputEvent::ShiftKey) { | 1814 web_gesture.modifiers == blink::WebInputEvent::ShiftKey) { |
| 1790 web_gesture.modifiers = 0; | 1815 web_gesture.modifiers = 0; |
| 1791 } | 1816 } |
| 1792 SendGestureEvent(web_gesture); | 1817 SendGestureEvent(web_gesture); |
| 1793 } | 1818 } |
| 1794 | 1819 |
| 1795 void RenderWidgetHostViewAndroid::OnCompositingDidCommit() { | 1820 void RenderWidgetHostViewAndroid::OnCompositingDidCommit() { |
| 1796 RunAckCallbacks(cc::SurfaceDrawStatus::DRAWN); | 1821 RunAckCallbacks(cc::SurfaceDrawStatus::DRAWN); |
| 1797 } | 1822 } |
| 1798 | 1823 |
| 1824 void RenderWidgetHostViewAndroid::OnRootWindowVisibilityChanged(bool visible) { |
| 1825 DCHECK(is_showing_); |
| 1826 if (visible) { |
| 1827 ShowInternal(); |
| 1828 } else { |
| 1829 bool hide_frontbuffer = true; |
| 1830 bool stop_observing_root_window = false; |
| 1831 HideInternal(hide_frontbuffer, stop_observing_root_window); |
| 1832 } |
| 1833 } |
| 1834 |
| 1799 void RenderWidgetHostViewAndroid::OnAttachCompositor() { | 1835 void RenderWidgetHostViewAndroid::OnAttachCompositor() { |
| 1800 DCHECK(content_view_core_); | 1836 DCHECK(content_view_core_); |
| 1801 if (!overscroll_controller_) | 1837 if (!overscroll_controller_) |
| 1802 overscroll_controller_ = CreateOverscrollController(content_view_core_); | 1838 overscroll_controller_ = CreateOverscrollController(content_view_core_); |
| 1803 } | 1839 } |
| 1804 | 1840 |
| 1805 void RenderWidgetHostViewAndroid::OnDetachCompositor() { | 1841 void RenderWidgetHostViewAndroid::OnDetachCompositor() { |
| 1806 DCHECK(content_view_core_); | 1842 DCHECK(content_view_core_); |
| 1807 DCHECK(using_browser_compositor_); | 1843 DCHECK(using_browser_compositor_); |
| 1808 RunAckCallbacks(cc::SurfaceDrawStatus::DRAW_SKIPPED); | 1844 RunAckCallbacks(cc::SurfaceDrawStatus::DRAW_SKIPPED); |
| 1809 overscroll_controller_.reset(); | 1845 overscroll_controller_.reset(); |
| 1810 } | 1846 } |
| 1811 | 1847 |
| 1812 void RenderWidgetHostViewAndroid::OnVSync(base::TimeTicks frame_time, | 1848 void RenderWidgetHostViewAndroid::OnVSync(base::TimeTicks frame_time, |
| 1813 base::TimeDelta vsync_period) { | 1849 base::TimeDelta vsync_period) { |
| 1814 TRACE_EVENT0("cc,benchmark", "RenderWidgetHostViewAndroid::OnVSync"); | 1850 TRACE_EVENT0("cc,benchmark", "RenderWidgetHostViewAndroid::OnVSync"); |
| 1815 if (!host_) | 1851 if (!host_ || host_->is_hidden()) |
| 1816 return; | 1852 return; |
| 1817 | 1853 |
| 1818 if (outstanding_vsync_requests_ & FLUSH_INPUT) { | 1854 if (outstanding_vsync_requests_ & FLUSH_INPUT) { |
| 1819 outstanding_vsync_requests_ &= ~FLUSH_INPUT; | 1855 outstanding_vsync_requests_ &= ~FLUSH_INPUT; |
| 1820 host_->FlushInput(); | 1856 host_->FlushInput(); |
| 1821 } | 1857 } |
| 1822 | 1858 |
| 1823 if (outstanding_vsync_requests_ & BEGIN_FRAME || | 1859 if (outstanding_vsync_requests_ & BEGIN_FRAME || |
| 1824 outstanding_vsync_requests_ & PERSISTENT_BEGIN_FRAME) { | 1860 outstanding_vsync_requests_ & PERSISTENT_BEGIN_FRAME) { |
| 1825 outstanding_vsync_requests_ &= ~BEGIN_FRAME; | 1861 outstanding_vsync_requests_ &= ~BEGIN_FRAME; |
| 1826 SendBeginFrame(frame_time, vsync_period); | 1862 SendBeginFrame(frame_time, vsync_period); |
| 1827 } | 1863 } |
| 1828 | 1864 |
| 1829 // This allows for SendBeginFrame and FlushInput to modify | 1865 // This allows for SendBeginFrame and FlushInput to modify |
| 1830 // outstanding_vsync_requests. | 1866 // outstanding_vsync_requests. |
| 1831 uint32 outstanding_vsync_requests = outstanding_vsync_requests_; | 1867 uint32 outstanding_vsync_requests = outstanding_vsync_requests_; |
| 1832 outstanding_vsync_requests_ = 0; | 1868 outstanding_vsync_requests_ = 0; |
| 1833 RequestVSyncUpdate(outstanding_vsync_requests); | 1869 RequestVSyncUpdate(outstanding_vsync_requests); |
| 1834 } | 1870 } |
| 1835 | 1871 |
| 1836 void RenderWidgetHostViewAndroid::OnAnimate(base::TimeTicks begin_frame_time) { | 1872 void RenderWidgetHostViewAndroid::OnAnimate(base::TimeTicks begin_frame_time) { |
| 1837 if (Animate(begin_frame_time)) | 1873 if (Animate(begin_frame_time)) |
| 1838 SetNeedsAnimate(); | 1874 SetNeedsAnimate(); |
| 1839 } | 1875 } |
| 1840 | 1876 |
| 1877 void RenderWidgetHostViewAndroid::OnActivityPaused() { |
| 1878 TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityPaused"); |
| 1879 DCHECK(is_showing_); |
| 1880 bool hide_frontbuffer = false; |
| 1881 bool stop_observing_root_window = false; |
| 1882 HideInternal(hide_frontbuffer, stop_observing_root_window); |
| 1883 } |
| 1884 |
| 1885 void RenderWidgetHostViewAndroid::OnActivityResumed() { |
| 1886 TRACE_EVENT0("browser", "RenderWidgetHostViewAndroid::OnActivityResumed"); |
| 1887 DCHECK(is_showing_); |
| 1888 ShowInternal(); |
| 1889 } |
| 1890 |
| 1841 void RenderWidgetHostViewAndroid::OnLostResources() { | 1891 void RenderWidgetHostViewAndroid::OnLostResources() { |
| 1842 ReleaseLocksOnSurface(); | 1892 ReleaseLocksOnSurface(); |
| 1843 if (layer_.get()) | 1893 if (layer_.get()) |
| 1844 DestroyDelegatedContent(); | 1894 DestroyDelegatedContent(); |
| 1845 DCHECK(ack_callbacks_.empty()); | 1895 DCHECK(ack_callbacks_.empty()); |
| 1846 } | 1896 } |
| 1847 | 1897 |
| 1848 // static | 1898 // static |
| 1849 void RenderWidgetHostViewAndroid:: | 1899 void RenderWidgetHostViewAndroid:: |
| 1850 PrepareTextureCopyOutputResultForDelegatedReadback( | 1900 PrepareTextureCopyOutputResultForDelegatedReadback( |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1965 results->orientationAngle = display.RotationAsDegree(); | 2015 results->orientationAngle = display.RotationAsDegree(); |
| 1966 results->orientationType = | 2016 results->orientationType = |
| 1967 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); | 2017 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); |
| 1968 gfx::DeviceDisplayInfo info; | 2018 gfx::DeviceDisplayInfo info; |
| 1969 results->depth = info.GetBitsPerPixel(); | 2019 results->depth = info.GetBitsPerPixel(); |
| 1970 results->depthPerComponent = info.GetBitsPerComponent(); | 2020 results->depthPerComponent = info.GetBitsPerComponent(); |
| 1971 results->isMonochrome = (results->depthPerComponent == 0); | 2021 results->isMonochrome = (results->depthPerComponent == 0); |
| 1972 } | 2022 } |
| 1973 | 2023 |
| 1974 } // namespace content | 2024 } // namespace content |
| OLD | NEW |