Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(500)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_android.cc

Issue 1001573003: [Android] Stop hiding the RWHV layer subtree when hiding the widget (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 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 (overscroll_controller_)
1492 overscroll_controller_->Disable();
1493
1494 // We don't know if we will ever get a frame if we are hiding the renderer, so
1495 // we need to cancel all requests
1496 AbortPendingReadbackRequests();
1497
1498 RunAckCallbacks(cc::SurfaceDrawStatus::DRAW_SKIPPED);
1499
1500 if (!host_ || host_->is_hidden())
no sievers 2015/03/20 21:48:25 Can you move this up to line 1487 though?
jdduke (slow) 2015/03/20 22:48:18 I'll move it up to 1491. I can't move it to 1487,
1501 return;
1502
1503 // Inform the renderer that we are being hidden so it can reduce its resource
1504 // utilization.
1505 host_->WasHidden();
1506 }
1507
1490 void RenderWidgetHostViewAndroid::AttachLayers() { 1508 void RenderWidgetHostViewAndroid::AttachLayers() {
1491 if (!content_view_core_) 1509 if (!content_view_core_)
1492 return; 1510 return;
1493 if (!layer_.get()) 1511 if (!layer_.get())
1494 return; 1512 return;
1495 1513
1496 content_view_core_->AttachLayer(layer_); 1514 content_view_core_->AttachLayer(layer_);
1497 if (overscroll_controller_) 1515 if (overscroll_controller_)
1498 overscroll_controller_->Enable(); 1516 overscroll_controller_->Enable();
1499 layer_->SetHideLayerAndSubtree(!is_showing_); 1517 layer_->SetHideLayerAndSubtree(!is_showing_);
(...skipping 11 matching lines...) Expand all
1511 overscroll_controller_->Disable(); 1529 overscroll_controller_->Disable();
1512 } 1530 }
1513 1531
1514 void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32 requests) { 1532 void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32 requests) {
1515 // The synchronous compositor does not requre BeginFrame messages. 1533 // The synchronous compositor does not requre BeginFrame messages.
1516 if (!using_browser_compositor_) 1534 if (!using_browser_compositor_)
1517 requests &= FLUSH_INPUT; 1535 requests &= FLUSH_INPUT;
1518 1536
1519 bool should_request_vsync = !outstanding_vsync_requests_ && requests; 1537 bool should_request_vsync = !outstanding_vsync_requests_ && requests;
1520 outstanding_vsync_requests_ |= requests; 1538 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
1521 // Note that if we're not currently observing the root window, outstanding 1545 // Note that if we're not currently observing the root window, outstanding
1522 // vsync requests will be pushed if/when we resume observing in 1546 // vsync requests will be pushed if/when we resume observing in
1523 // |StartObservingRootWindow()|. 1547 // |StartObservingRootWindow()|.
1524 if (observing_root_window_ && should_request_vsync) 1548 if (observing_root_window_ && should_request_vsync)
1525 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate(); 1549 content_view_core_->GetWindowAndroid()->RequestVSyncUpdate();
1526 } 1550 }
1527 1551
1528 void RenderWidgetHostViewAndroid::StartObservingRootWindow() { 1552 void RenderWidgetHostViewAndroid::StartObservingRootWindow() {
1529 DCHECK(content_view_core_); 1553 DCHECK(content_view_core_);
1554 DCHECK(is_showing_);
1530 if (observing_root_window_) 1555 if (observing_root_window_)
1531 return; 1556 return;
1532 1557
1533 observing_root_window_ = true; 1558 observing_root_window_ = true;
1534 content_view_core_->GetWindowAndroid()->AddObserver(this); 1559 content_view_core_->GetWindowAndroid()->AddObserver(this);
1535 1560
1536 // Clear existing vsync requests to allow a request to the new window. 1561 // Clear existing vsync requests to allow a request to the new window.
1537 uint32 outstanding_vsync_requests = outstanding_vsync_requests_; 1562 uint32 outstanding_vsync_requests = outstanding_vsync_requests_;
1538 outstanding_vsync_requests_ = 0; 1563 outstanding_vsync_requests_ = 0;
1539 RequestVSyncUpdate(outstanding_vsync_requests); 1564 RequestVSyncUpdate(outstanding_vsync_requests);
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1820 if (content_view_core_) 1845 if (content_view_core_)
1821 obj = content_view_core_->GetJavaObject(); 1846 obj = content_view_core_->GetJavaObject();
1822 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj); 1847 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj);
1823 } 1848 }
1824 1849
1825 AttachLayers(); 1850 AttachLayers();
1826 1851
1827 if (!content_view_core_) 1852 if (!content_view_core_)
1828 return; 1853 return;
1829 1854
1830 StartObservingRootWindow(); 1855 if (is_showing_)
1856 StartObservingRootWindow();
1831 1857
1832 if (resize) 1858 if (resize)
1833 WasResized(); 1859 WasResized();
1834 1860
1835 if (!selection_controller_) 1861 if (!selection_controller_)
1836 selection_controller_ = CreateSelectionController(this, content_view_core_); 1862 selection_controller_ = CreateSelectionController(this, content_view_core_);
1837 1863
1838 if (!overscroll_controller_ && 1864 if (!overscroll_controller_ &&
1839 content_view_core_->GetWindowAndroid()->GetCompositor()) { 1865 content_view_core_->GetWindowAndroid()->GetCompositor()) {
1840 overscroll_controller_ = CreateOverscrollController(content_view_core_); 1866 overscroll_controller_ = CreateOverscrollController(content_view_core_);
(...skipping 20 matching lines...) Expand all
1861 web_gesture.modifiers == blink::WebInputEvent::ShiftKey) { 1887 web_gesture.modifiers == blink::WebInputEvent::ShiftKey) {
1862 web_gesture.modifiers = 0; 1888 web_gesture.modifiers = 0;
1863 } 1889 }
1864 SendGestureEvent(web_gesture); 1890 SendGestureEvent(web_gesture);
1865 } 1891 }
1866 1892
1867 void RenderWidgetHostViewAndroid::OnCompositingDidCommit() { 1893 void RenderWidgetHostViewAndroid::OnCompositingDidCommit() {
1868 RunAckCallbacks(cc::SurfaceDrawStatus::DRAWN); 1894 RunAckCallbacks(cc::SurfaceDrawStatus::DRAWN);
1869 } 1895 }
1870 1896
1897 void RenderWidgetHostViewAndroid::OnVisibilityChanged(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
1871 void RenderWidgetHostViewAndroid::OnAttachCompositor() { 1908 void RenderWidgetHostViewAndroid::OnAttachCompositor() {
1872 DCHECK(content_view_core_); 1909 DCHECK(content_view_core_);
1873 if (!overscroll_controller_) 1910 if (!overscroll_controller_)
1874 overscroll_controller_ = CreateOverscrollController(content_view_core_); 1911 overscroll_controller_ = CreateOverscrollController(content_view_core_);
1875 } 1912 }
1876 1913
1877 void RenderWidgetHostViewAndroid::OnDetachCompositor() { 1914 void RenderWidgetHostViewAndroid::OnDetachCompositor() {
1878 DCHECK(content_view_core_); 1915 DCHECK(content_view_core_);
1879 DCHECK(using_browser_compositor_); 1916 DCHECK(using_browser_compositor_);
1880 RunAckCallbacks(cc::SurfaceDrawStatus::DRAW_SKIPPED); 1917 RunAckCallbacks(cc::SurfaceDrawStatus::DRAW_SKIPPED);
1881 overscroll_controller_.reset(); 1918 overscroll_controller_.reset();
1882 } 1919 }
1883 1920
1884 void RenderWidgetHostViewAndroid::OnVSync(base::TimeTicks frame_time, 1921 void RenderWidgetHostViewAndroid::OnVSync(base::TimeTicks frame_time,
1885 base::TimeDelta vsync_period) { 1922 base::TimeDelta vsync_period) {
1886 TRACE_EVENT0("cc,benchmark", "RenderWidgetHostViewAndroid::OnVSync"); 1923 TRACE_EVENT0("cc,benchmark", "RenderWidgetHostViewAndroid::OnVSync");
1887 if (!host_) 1924 if (!host_ || host_->is_hidden())
1888 return; 1925 return;
1889 1926
1890 const uint32 current_vsync_requests = outstanding_vsync_requests_; 1927 const uint32 current_vsync_requests = outstanding_vsync_requests_;
1891 outstanding_vsync_requests_ = 0; 1928 outstanding_vsync_requests_ = 0;
1892 1929
1893 if (current_vsync_requests & FLUSH_INPUT) 1930 if (current_vsync_requests & FLUSH_INPUT)
1894 host_->FlushInput(); 1931 host_->FlushInput();
1895 1932
1896 if (current_vsync_requests & BEGIN_FRAME || 1933 if (current_vsync_requests & BEGIN_FRAME ||
1897 current_vsync_requests & PERSISTENT_BEGIN_FRAME) { 1934 current_vsync_requests & PERSISTENT_BEGIN_FRAME) {
1898 SendBeginFrame(frame_time, vsync_period); 1935 SendBeginFrame(frame_time, vsync_period);
1899 } 1936 }
1900 1937
1901 if (current_vsync_requests & PERSISTENT_BEGIN_FRAME) 1938 if (current_vsync_requests & PERSISTENT_BEGIN_FRAME)
1902 RequestVSyncUpdate(PERSISTENT_BEGIN_FRAME); 1939 RequestVSyncUpdate(PERSISTENT_BEGIN_FRAME);
1903 } 1940 }
1904 1941
1905 void RenderWidgetHostViewAndroid::OnAnimate(base::TimeTicks begin_frame_time) { 1942 void RenderWidgetHostViewAndroid::OnAnimate(base::TimeTicks begin_frame_time) {
1906 if (Animate(begin_frame_time)) 1943 if (Animate(begin_frame_time))
1907 SetNeedsAnimate(); 1944 SetNeedsAnimate();
1908 } 1945 }
1909 1946
1947 void RenderWidgetHostViewAndroid::OnActivityResumed() {
1948 DCHECK(is_showing_);
1949 ShowInternal();
1950 }
1951
1952 void RenderWidgetHostViewAndroid::OnActivityPaused() {
1953 DCHECK(is_showing_);
1954 bool hide_frontbuffer = false;
1955 bool stop_observing_root_window = false;
1956 HideInternal(hide_frontbuffer, stop_observing_root_window);
1957 }
1958
1910 void RenderWidgetHostViewAndroid::OnLostResources() { 1959 void RenderWidgetHostViewAndroid::OnLostResources() {
1911 ReleaseLocksOnSurface(); 1960 ReleaseLocksOnSurface();
1912 if (layer_.get()) 1961 if (layer_.get())
1913 DestroyDelegatedContent(); 1962 DestroyDelegatedContent();
1914 DCHECK(ack_callbacks_.empty()); 1963 DCHECK(ack_callbacks_.empty());
1915 // We should not loose a frame if we have readback requests pending. 1964 // We should not loose a frame if we have readback requests pending.
1916 DCHECK(readbacks_waiting_for_frame_.empty()); 1965 DCHECK(readbacks_waiting_for_frame_.empty());
1917 } 1966 }
1918 1967
1919 // static 1968 // static
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
2047 results->orientationAngle = display.RotationAsDegree(); 2096 results->orientationAngle = display.RotationAsDegree();
2048 results->orientationType = 2097 results->orientationType =
2049 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); 2098 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display);
2050 gfx::DeviceDisplayInfo info; 2099 gfx::DeviceDisplayInfo info;
2051 results->depth = info.GetBitsPerPixel(); 2100 results->depth = info.GetBitsPerPixel();
2052 results->depthPerComponent = info.GetBitsPerComponent(); 2101 results->depthPerComponent = info.GetBitsPerComponent();
2053 results->isMonochrome = (results->depthPerComponent == 0); 2102 results->isMonochrome = (results->depthPerComponent == 0);
2054 } 2103 }
2055 2104
2056 } // namespace content 2105 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698