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