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 578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
589 | 589 |
590 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { | 590 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { |
591 return HasValidFrame(); | 591 return HasValidFrame(); |
592 } | 592 } |
593 | 593 |
594 void RenderWidgetHostViewAndroid::Show() { | 594 void RenderWidgetHostViewAndroid::Show() { |
595 if (is_showing_) | 595 if (is_showing_) |
596 return; | 596 return; |
597 | 597 |
598 is_showing_ = true; | 598 is_showing_ = true; |
599 if (layer_.get()) | 599 ShowInternal(); |
600 layer_->SetHideLayerAndSubtree(false); | |
601 | |
602 if (overscroll_controller_) | |
603 overscroll_controller_->Enable(); | |
604 | |
605 frame_evictor_->SetVisible(true); | |
606 | |
607 if (!host_ || !host_->is_hidden()) | |
608 return; | |
609 | |
610 host_->WasShown(ui::LatencyInfo()); | |
611 | |
612 if (content_view_core_) { | |
613 StartObservingRootWindow(); | |
614 RequestVSyncUpdate(BEGIN_FRAME); | |
615 } | |
616 } | 600 } |
617 | 601 |
618 void RenderWidgetHostViewAndroid::Hide() { | 602 void RenderWidgetHostViewAndroid::Hide() { |
619 if (!is_showing_) | 603 if (!is_showing_) |
620 return; | 604 return; |
621 | 605 |
622 is_showing_ = false; | 606 is_showing_ = false; |
623 if (layer_.get() && locks_on_frame_count_ == 0) | |
624 layer_->SetHideLayerAndSubtree(true); | |
625 | 607 |
626 if (overscroll_controller_) | 608 bool hide_frontbuffer = true; |
627 overscroll_controller_->Disable(); | 609 bool stop_observing_root_window = true; |
628 | 610 HideInternal(hide_frontbuffer, stop_observing_root_window); |
629 frame_evictor_->SetVisible(false); | |
630 // We don't know if we will ever get a frame if we are hiding the renderer, so | |
631 // we need to cancel all requests | |
632 AbortPendingReadbackRequests(); | |
633 | |
634 RunAckCallbacks(cc::SurfaceDrawStatus::DRAW_SKIPPED); | |
635 | |
636 if (!host_ || host_->is_hidden()) | |
637 return; | |
638 | |
639 // Inform the renderer that we are being hidden so it can reduce its resource | |
640 // utilization. | |
641 host_->WasHidden(); | |
642 | |
643 StopObservingRootWindow(); | |
644 } | 611 } |
645 | 612 |
646 bool RenderWidgetHostViewAndroid::IsShowing() { | 613 bool RenderWidgetHostViewAndroid::IsShowing() { |
647 // ContentViewCoreImpl represents the native side of the Java | 614 // ContentViewCoreImpl represents the native side of the Java |
648 // ContentViewCore. It being NULL means that it is not attached | 615 // ContentViewCore. It being NULL means that it is not attached |
649 // to the View system yet, so we treat this RWHVA as hidden. | 616 // to the View system yet, so we treat this RWHVA as hidden. |
650 return is_showing_ && content_view_core_; | 617 return is_showing_ && content_view_core_; |
651 } | 618 } |
652 | 619 |
653 void RenderWidgetHostViewAndroid::LockCompositingSurface() { | 620 void RenderWidgetHostViewAndroid::LockCompositingSurface() { |
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1480 web_contents_impl->media_web_contents_observer()->OnFrameInfoUpdated(); | 1447 web_contents_impl->media_web_contents_observer()->OnFrameInfoUpdated(); |
1481 } | 1448 } |
1482 #endif // defined(VIDEO_HOLE) | 1449 #endif // defined(VIDEO_HOLE) |
1483 } | 1450 } |
1484 | 1451 |
1485 void RenderWidgetHostViewAndroid::AcceleratedSurfaceInitialized(int route_id) { | 1452 void RenderWidgetHostViewAndroid::AcceleratedSurfaceInitialized(int route_id) { |
1486 // TODO: remove need for the surface id here | 1453 // TODO: remove need for the surface id here |
1487 accelerated_surface_route_id_ = route_id; | 1454 accelerated_surface_route_id_ = route_id; |
1488 } | 1455 } |
1489 | 1456 |
1457 void RenderWidgetHostViewAndroid::ShowInternal() { | |
1458 DCHECK(is_showing_); | |
1459 | |
1460 bool was_showing_frontbuffer = | |
1461 layer_.get() && !layer_->hide_layer_and_subtree(); | |
1462 if (!was_showing_frontbuffer) { | |
1463 if (layer_.get()) | |
1464 layer_->SetHideLayerAndSubtree(false); | |
1465 frame_evictor_->SetVisible(true); | |
1466 } | |
1467 | |
1468 if (overscroll_controller_) | |
1469 overscroll_controller_->Enable(); | |
1470 | |
1471 if (!host_ || !host_->is_hidden()) | |
1472 return; | |
no sievers
2015/03/19 20:21:52
Can we move this early-out to the top?
We should
jdduke (slow)
2015/03/20 14:59:29
We can probably move this call up, but I'm not sur
| |
1473 | |
1474 host_->WasShown(ui::LatencyInfo()); | |
1475 | |
1476 if (content_view_core_) { | |
1477 StartObservingRootWindow(); | |
1478 RequestVSyncUpdate(BEGIN_FRAME); | |
1479 } | |
1480 } | |
1481 | |
1482 void RenderWidgetHostViewAndroid::HideInternal( | |
1483 bool hide_frontbuffer, | |
1484 bool stop_observing_root_window) { | |
1485 if (hide_frontbuffer) { | |
1486 if (layer_.get() && locks_on_frame_count_ == 0) | |
1487 layer_->SetHideLayerAndSubtree(true); | |
1488 | |
1489 frame_evictor_->SetVisible(false); | |
1490 } | |
1491 | |
1492 if (stop_observing_root_window) | |
1493 StopObservingRootWindow(); | |
1494 | |
1495 if (overscroll_controller_) | |
1496 overscroll_controller_->Disable(); | |
1497 | |
1498 // We don't know if we will ever get a frame if we are hiding the renderer, so | |
1499 // we need to cancel all requests | |
1500 AbortPendingReadbackRequests(); | |
1501 | |
1502 RunAckCallbacks(cc::SurfaceDrawStatus::DRAW_SKIPPED); | |
1503 | |
1504 if (!host_ || host_->is_hidden()) | |
no sievers
2015/03/19 20:21:52
Same here.
jdduke (slow)
2015/03/20 14:59:29
We can't move this call up because the the host ma
| |
1505 return; | |
1506 | |
1507 // Inform the renderer that we are being hidden so it can reduce its resource | |
1508 // utilization. | |
1509 host_->WasHidden(); | |
1510 } | |
1511 | |
1490 void RenderWidgetHostViewAndroid::AttachLayers() { | 1512 void RenderWidgetHostViewAndroid::AttachLayers() { |
1491 if (!content_view_core_) | 1513 if (!content_view_core_) |
1492 return; | 1514 return; |
1493 if (!layer_.get()) | 1515 if (!layer_.get()) |
1494 return; | 1516 return; |
1495 | 1517 |
1496 content_view_core_->AttachLayer(layer_); | 1518 content_view_core_->AttachLayer(layer_); |
1497 if (overscroll_controller_) | 1519 if (overscroll_controller_) |
1498 overscroll_controller_->Enable(); | 1520 overscroll_controller_->Enable(); |
1499 layer_->SetHideLayerAndSubtree(!is_showing_); | 1521 layer_->SetHideLayerAndSubtree(!is_showing_); |
(...skipping 11 matching lines...) Expand all Loading... | |
1511 overscroll_controller_->Disable(); | 1533 overscroll_controller_->Disable(); |
1512 } | 1534 } |
1513 | 1535 |
1514 void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32 requests) { | 1536 void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32 requests) { |
1515 // The synchronous compositor does not requre BeginFrame messages. | 1537 // The synchronous compositor does not requre BeginFrame messages. |
1516 if (!using_browser_compositor_) | 1538 if (!using_browser_compositor_) |
1517 requests &= FLUSH_INPUT; | 1539 requests &= FLUSH_INPUT; |
1518 | 1540 |
1519 bool should_request_vsync = !outstanding_vsync_requests_ && requests; | 1541 bool should_request_vsync = !outstanding_vsync_requests_ && requests; |
1520 outstanding_vsync_requests_ |= requests; | 1542 outstanding_vsync_requests_ |= requests; |
1543 | |
1544 // If the host has been hidden, defer vsync requests until it is shown | |
1545 // again via |Show()|. | |
1546 if (!host_ || host_->is_hidden()) | |
no sievers
2015/03/18 21:04:48
see question below
| |
1547 return; | |
1548 | |
1521 // Note that if we're not currently observing the root window, outstanding | 1549 // Note that if we're not currently observing the root window, outstanding |
1522 // vsync requests will be pushed if/when we resume observing in | 1550 // vsync requests will be pushed if/when we resume observing in |
1523 // |StartObservingRootWindow()|. | 1551 // |StartObservingRootWindow()|. |
1524 if (observing_root_window_ && should_request_vsync) | 1552 if (observing_root_window_ && should_request_vsync) |
1525 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); | 1553 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); |
1526 } | 1554 } |
1527 | 1555 |
1528 void RenderWidgetHostViewAndroid::StartObservingRootWindow() { | 1556 void RenderWidgetHostViewAndroid::StartObservingRootWindow() { |
1529 DCHECK(content_view_core_); | 1557 DCHECK(content_view_core_); |
1558 DCHECK(is_showing_); | |
1530 if (observing_root_window_) | 1559 if (observing_root_window_) |
1531 return; | 1560 return; |
1532 | 1561 |
1533 observing_root_window_ = true; | 1562 observing_root_window_ = true; |
1534 content_view_core_->GetWindowAndroid()->AddObserver(this); | 1563 content_view_core_->GetWindowAndroid()->AddObserver(this); |
1535 | 1564 |
1536 // Clear existing vsync requests to allow a request to the new window. | 1565 // Clear existing vsync requests to allow a request to the new window. |
1537 uint32 outstanding_vsync_requests = outstanding_vsync_requests_; | 1566 uint32 outstanding_vsync_requests = outstanding_vsync_requests_; |
1538 outstanding_vsync_requests_ = 0; | 1567 outstanding_vsync_requests_ = 0; |
1539 RequestVSyncUpdate(outstanding_vsync_requests); | 1568 RequestVSyncUpdate(outstanding_vsync_requests); |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1820 if (content_view_core_) | 1849 if (content_view_core_) |
1821 obj = content_view_core_->GetJavaObject(); | 1850 obj = content_view_core_->GetJavaObject(); |
1822 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj); | 1851 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj); |
1823 } | 1852 } |
1824 | 1853 |
1825 AttachLayers(); | 1854 AttachLayers(); |
1826 | 1855 |
1827 if (!content_view_core_) | 1856 if (!content_view_core_) |
1828 return; | 1857 return; |
1829 | 1858 |
1830 StartObservingRootWindow(); | 1859 if (is_showing_) |
1860 StartObservingRootWindow(); | |
1831 | 1861 |
1832 if (resize) | 1862 if (resize) |
1833 WasResized(); | 1863 WasResized(); |
1834 | 1864 |
1835 if (!selection_controller_) | 1865 if (!selection_controller_) |
1836 selection_controller_ = CreateSelectionController(this, content_view_core_); | 1866 selection_controller_ = CreateSelectionController(this, content_view_core_); |
1837 | 1867 |
1838 if (!overscroll_controller_ && | 1868 if (!overscroll_controller_ && |
1839 content_view_core_->GetWindowAndroid()->GetCompositor()) { | 1869 content_view_core_->GetWindowAndroid()->GetCompositor()) { |
1840 overscroll_controller_ = CreateOverscrollController(content_view_core_); | 1870 overscroll_controller_ = CreateOverscrollController(content_view_core_); |
(...skipping 20 matching lines...) Expand all Loading... | |
1861 web_gesture.modifiers == blink::WebInputEvent::ShiftKey) { | 1891 web_gesture.modifiers == blink::WebInputEvent::ShiftKey) { |
1862 web_gesture.modifiers = 0; | 1892 web_gesture.modifiers = 0; |
1863 } | 1893 } |
1864 SendGestureEvent(web_gesture); | 1894 SendGestureEvent(web_gesture); |
1865 } | 1895 } |
1866 | 1896 |
1867 void RenderWidgetHostViewAndroid::OnCompositingDidCommit() { | 1897 void RenderWidgetHostViewAndroid::OnCompositingDidCommit() { |
1868 RunAckCallbacks(cc::SurfaceDrawStatus::DRAWN); | 1898 RunAckCallbacks(cc::SurfaceDrawStatus::DRAWN); |
1869 } | 1899 } |
1870 | 1900 |
1901 void RenderWidgetHostViewAndroid::OnVisibilityChanged(bool visible) { | |
1902 DCHECK(is_showing_); | |
1903 if (visible) { | |
1904 ShowInternal(); | |
1905 } else { | |
1906 bool hide_frontbuffer = true; | |
1907 bool stop_observing_root_window = false; | |
1908 HideInternal(hide_frontbuffer, stop_observing_root_window); | |
1909 } | |
1910 } | |
1911 | |
1871 void RenderWidgetHostViewAndroid::OnAttachCompositor() { | 1912 void RenderWidgetHostViewAndroid::OnAttachCompositor() { |
1872 DCHECK(content_view_core_); | 1913 DCHECK(content_view_core_); |
1873 if (!overscroll_controller_) | 1914 if (!overscroll_controller_) |
1874 overscroll_controller_ = CreateOverscrollController(content_view_core_); | 1915 overscroll_controller_ = CreateOverscrollController(content_view_core_); |
1875 } | 1916 } |
1876 | 1917 |
1877 void RenderWidgetHostViewAndroid::OnDetachCompositor() { | 1918 void RenderWidgetHostViewAndroid::OnDetachCompositor() { |
1878 DCHECK(content_view_core_); | 1919 DCHECK(content_view_core_); |
1879 DCHECK(using_browser_compositor_); | 1920 DCHECK(using_browser_compositor_); |
1880 RunAckCallbacks(cc::SurfaceDrawStatus::DRAW_SKIPPED); | 1921 RunAckCallbacks(cc::SurfaceDrawStatus::DRAW_SKIPPED); |
1881 overscroll_controller_.reset(); | 1922 overscroll_controller_.reset(); |
1882 } | 1923 } |
1883 | 1924 |
1884 void RenderWidgetHostViewAndroid::OnVSync(base::TimeTicks frame_time, | 1925 void RenderWidgetHostViewAndroid::OnVSync(base::TimeTicks frame_time, |
1885 base::TimeDelta vsync_period) { | 1926 base::TimeDelta vsync_period) { |
1886 TRACE_EVENT0("cc,benchmark", "RenderWidgetHostViewAndroid::OnVSync"); | 1927 TRACE_EVENT0("cc,benchmark", "RenderWidgetHostViewAndroid::OnVSync"); |
1887 if (!host_) | 1928 if (!host_ || host_->is_hidden()) |
no sievers
2015/03/18 21:04:48
Doesn't the renderer turn beginFrame off when it g
jdduke (slow)
2015/03/20 14:59:29
Right, this preserves the original behavior which
| |
1888 return; | 1929 return; |
1889 | 1930 |
1890 const uint32 current_vsync_requests = outstanding_vsync_requests_; | 1931 const uint32 current_vsync_requests = outstanding_vsync_requests_; |
1891 outstanding_vsync_requests_ = 0; | 1932 outstanding_vsync_requests_ = 0; |
1892 | 1933 |
1893 if (current_vsync_requests & FLUSH_INPUT) | 1934 if (current_vsync_requests & FLUSH_INPUT) |
1894 host_->FlushInput(); | 1935 host_->FlushInput(); |
1895 | 1936 |
1896 if (current_vsync_requests & BEGIN_FRAME || | 1937 if (current_vsync_requests & BEGIN_FRAME || |
1897 current_vsync_requests & PERSISTENT_BEGIN_FRAME) { | 1938 current_vsync_requests & PERSISTENT_BEGIN_FRAME) { |
1898 SendBeginFrame(frame_time, vsync_period); | 1939 SendBeginFrame(frame_time, vsync_period); |
1899 } | 1940 } |
1900 | 1941 |
1901 if (current_vsync_requests & PERSISTENT_BEGIN_FRAME) | 1942 if (current_vsync_requests & PERSISTENT_BEGIN_FRAME) |
1902 RequestVSyncUpdate(PERSISTENT_BEGIN_FRAME); | 1943 RequestVSyncUpdate(PERSISTENT_BEGIN_FRAME); |
1903 } | 1944 } |
1904 | 1945 |
1905 void RenderWidgetHostViewAndroid::OnAnimate(base::TimeTicks begin_frame_time) { | 1946 void RenderWidgetHostViewAndroid::OnAnimate(base::TimeTicks begin_frame_time) { |
1906 if (Animate(begin_frame_time)) | 1947 if (Animate(begin_frame_time)) |
1907 SetNeedsAnimate(); | 1948 SetNeedsAnimate(); |
1908 } | 1949 } |
1909 | 1950 |
1951 void RenderWidgetHostViewAndroid::OnActivityResumed() { | |
1952 DCHECK(is_showing_); | |
1953 ShowInternal(); | |
1954 } | |
1955 | |
1956 void RenderWidgetHostViewAndroid::OnActivityPaused() { | |
1957 DCHECK(is_showing_); | |
1958 bool hide_frontbuffer = false; | |
1959 bool stop_observing_root_window = false; | |
1960 HideInternal(hide_frontbuffer, stop_observing_root_window); | |
1961 } | |
1962 | |
1910 void RenderWidgetHostViewAndroid::OnLostResources() { | 1963 void RenderWidgetHostViewAndroid::OnLostResources() { |
1911 ReleaseLocksOnSurface(); | 1964 ReleaseLocksOnSurface(); |
1912 if (layer_.get()) | 1965 if (layer_.get()) |
1913 DestroyDelegatedContent(); | 1966 DestroyDelegatedContent(); |
1914 DCHECK(ack_callbacks_.empty()); | 1967 DCHECK(ack_callbacks_.empty()); |
1915 // We should not loose a frame if we have readback requests pending. | 1968 // We should not loose a frame if we have readback requests pending. |
1916 DCHECK(readbacks_waiting_for_frame_.empty()); | 1969 DCHECK(readbacks_waiting_for_frame_.empty()); |
1917 } | 1970 } |
1918 | 1971 |
1919 // static | 1972 // static |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2047 results->orientationAngle = display.RotationAsDegree(); | 2100 results->orientationAngle = display.RotationAsDegree(); |
2048 results->orientationType = | 2101 results->orientationType = |
2049 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); | 2102 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); |
2050 gfx::DeviceDisplayInfo info; | 2103 gfx::DeviceDisplayInfo info; |
2051 results->depth = info.GetBitsPerPixel(); | 2104 results->depth = info.GetBitsPerPixel(); |
2052 results->depthPerComponent = info.GetBitsPerComponent(); | 2105 results->depthPerComponent = info.GetBitsPerComponent(); |
2053 results->isMonochrome = (results->depthPerComponent == 0); | 2106 results->isMonochrome = (results->depthPerComponent == 0); |
2054 } | 2107 } |
2055 | 2108 |
2056 } // namespace content | 2109 } // namespace content |
OLD | NEW |