| 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 <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 964 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( | 975 void RenderWidgetHostViewAndroid::CopyFromCompositingSurface( |
| 976 const gfx::Rect& src_subrect, | 976 const gfx::Rect& src_subrect, |
| 977 const gfx::Size& dst_size, | 977 const gfx::Size& dst_size, |
| 978 const ReadbackRequestCallback& callback, | 978 const ReadbackRequestCallback& callback, |
| 979 const SkColorType preferred_color_type) { | 979 const SkColorType preferred_color_type) { |
| 980 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::CopyFromCompositingSurface"); | 980 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::CopyFromCompositingSurface"); |
| 981 if (!host_ || !IsSurfaceAvailableForCopy()) { | 981 if (!host_ || !IsSurfaceAvailableForCopy()) { |
| 982 callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); | 982 callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); |
| 983 return; | 983 return; |
| 984 } | 984 } |
| 985 if (!content_view_core_ || !(content_view_core_->GetWindowAndroid())) { | 985 if (!(view_.GetWindowAndroid())) { |
| 986 callback.Run(SkBitmap(), READBACK_FAILED); | 986 callback.Run(SkBitmap(), READBACK_FAILED); |
| 987 return; | 987 return; |
| 988 } | 988 } |
| 989 | 989 |
| 990 base::TimeTicks start_time = base::TimeTicks::Now(); | 990 base::TimeTicks start_time = base::TimeTicks::Now(); |
| 991 const display::Display& display = | 991 const display::Display& display = |
| 992 display::Screen::GetScreen()->GetPrimaryDisplay(); | 992 display::Screen::GetScreen()->GetPrimaryDisplay(); |
| 993 float device_scale_factor = display.device_scale_factor(); | 993 float device_scale_factor = display.device_scale_factor(); |
| 994 gfx::Size dst_size_in_pixel = | 994 gfx::Size dst_size_in_pixel = |
| 995 gfx::ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); | 995 gfx::ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); |
| 996 gfx::Rect src_subrect_in_pixel = | 996 gfx::Rect src_subrect_in_pixel = |
| 997 gfx::ConvertRectToPixel(device_scale_factor, src_subrect); | 997 gfx::ConvertRectToPixel(device_scale_factor, src_subrect); |
| 998 | 998 |
| 999 if (!using_browser_compositor_) { | 999 if (!using_browser_compositor_) { |
| 1000 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, | 1000 SynchronousCopyContents(src_subrect_in_pixel, dst_size_in_pixel, callback, |
| 1001 preferred_color_type); | 1001 preferred_color_type); |
| 1002 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", | 1002 UMA_HISTOGRAM_TIMES("Compositing.CopyFromSurfaceTimeSynchronous", |
| 1003 base::TimeTicks::Now() - start_time); | 1003 base::TimeTicks::Now() - start_time); |
| 1004 return; | 1004 return; |
| 1005 } | 1005 } |
| 1006 | 1006 |
| 1007 ui::WindowAndroidCompositor* compositor = | 1007 ui::WindowAndroidCompositor* compositor = |
| 1008 content_view_core_->GetWindowAndroid()->GetCompositor(); | 1008 view_.GetWindowAndroid()->GetCompositor(); |
| 1009 DCHECK(compositor); | 1009 DCHECK(compositor); |
| 1010 DCHECK(delegated_frame_host_); | 1010 DCHECK(delegated_frame_host_); |
| 1011 scoped_refptr<PendingReadbackLock> readback_lock( | 1011 scoped_refptr<PendingReadbackLock> readback_lock( |
| 1012 g_pending_readback_lock ? g_pending_readback_lock | 1012 g_pending_readback_lock ? g_pending_readback_lock |
| 1013 : new PendingReadbackLock); | 1013 : new PendingReadbackLock); |
| 1014 delegated_frame_host_->RequestCopyOfSurface( | 1014 delegated_frame_host_->RequestCopyOfSurface( |
| 1015 compositor, src_subrect_in_pixel, | 1015 compositor, src_subrect_in_pixel, |
| 1016 base::Bind(&PrepareTextureCopyOutputResult, dst_size_in_pixel, | 1016 base::Bind(&PrepareTextureCopyOutputResult, dst_size_in_pixel, |
| 1017 preferred_color_type, start_time, callback, readback_lock)); | 1017 preferred_color_type, start_time, callback, readback_lock)); |
| 1018 } | 1018 } |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1206 } | 1206 } |
| 1207 } | 1207 } |
| 1208 | 1208 |
| 1209 bool RenderWidgetHostViewAndroid::SupportsAnimation() const { | 1209 bool RenderWidgetHostViewAndroid::SupportsAnimation() const { |
| 1210 // The synchronous (WebView) compositor does not have a proper browser | 1210 // The synchronous (WebView) compositor does not have a proper browser |
| 1211 // compositor with which to drive animations. | 1211 // compositor with which to drive animations. |
| 1212 return using_browser_compositor_; | 1212 return using_browser_compositor_; |
| 1213 } | 1213 } |
| 1214 | 1214 |
| 1215 void RenderWidgetHostViewAndroid::SetNeedsAnimate() { | 1215 void RenderWidgetHostViewAndroid::SetNeedsAnimate() { |
| 1216 DCHECK(content_view_core_ && content_view_core_->GetWindowAndroid()); | 1216 DCHECK(view_.GetWindowAndroid()); |
| 1217 DCHECK(using_browser_compositor_); | 1217 DCHECK(using_browser_compositor_); |
| 1218 content_view_core_->GetWindowAndroid()->SetNeedsAnimate(); | 1218 view_.GetWindowAndroid()->SetNeedsAnimate(); |
| 1219 } | 1219 } |
| 1220 | 1220 |
| 1221 void RenderWidgetHostViewAndroid::MoveCaret(const gfx::PointF& position) { | 1221 void RenderWidgetHostViewAndroid::MoveCaret(const gfx::PointF& position) { |
| 1222 MoveCaret(gfx::Point(position.x(), position.y())); | 1222 MoveCaret(gfx::Point(position.x(), position.y())); |
| 1223 } | 1223 } |
| 1224 | 1224 |
| 1225 void RenderWidgetHostViewAndroid::MoveRangeSelectionExtent( | 1225 void RenderWidgetHostViewAndroid::MoveRangeSelectionExtent( |
| 1226 const gfx::PointF& extent) { | 1226 const gfx::PointF& extent) { |
| 1227 DCHECK(content_view_core_); | 1227 DCHECK(content_view_core_); |
| 1228 content_view_core_->MoveRangeSelectionExtent(extent); | 1228 content_view_core_->MoveRangeSelectionExtent(extent); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1420 } | 1420 } |
| 1421 | 1421 |
| 1422 void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32_t requests) { | 1422 void RenderWidgetHostViewAndroid::RequestVSyncUpdate(uint32_t requests) { |
| 1423 bool should_request_vsync = !outstanding_vsync_requests_ && requests; | 1423 bool should_request_vsync = !outstanding_vsync_requests_ && requests; |
| 1424 outstanding_vsync_requests_ |= requests; | 1424 outstanding_vsync_requests_ |= requests; |
| 1425 | 1425 |
| 1426 // Note that if we're not currently observing the root window, outstanding | 1426 // Note that if we're not currently observing the root window, outstanding |
| 1427 // vsync requests will be pushed if/when we resume observing in | 1427 // vsync requests will be pushed if/when we resume observing in |
| 1428 // |StartObservingRootWindow()|. | 1428 // |StartObservingRootWindow()|. |
| 1429 if (observing_root_window_ && should_request_vsync) { | 1429 if (observing_root_window_ && should_request_vsync) { |
| 1430 ui::WindowAndroid* windowAndroid = content_view_core_->GetWindowAndroid(); | 1430 ui::WindowAndroid* windowAndroid = view_.GetWindowAndroid(); |
| 1431 DCHECK(windowAndroid); | 1431 DCHECK(windowAndroid); |
| 1432 // TODO(boliu): This check should be redundant with | 1432 // TODO(boliu): This check should be redundant with |
| 1433 // |observing_root_window_| check above. However we are receiving trickle | 1433 // |observing_root_window_| check above. However we are receiving trickle |
| 1434 // of crash reports (crbug.com/639868) with no root cause. Should | 1434 // of crash reports (crbug.com/639868) with no root cause. Should |
| 1435 // investigate more when time allows what corner case is missed. | 1435 // investigate more when time allows what corner case is missed. |
| 1436 if (windowAndroid) | 1436 if (windowAndroid) |
| 1437 windowAndroid->RequestVSyncUpdate(); | 1437 windowAndroid->RequestVSyncUpdate(); |
| 1438 } | 1438 } |
| 1439 } | 1439 } |
| 1440 | 1440 |
| 1441 void RenderWidgetHostViewAndroid::StartObservingRootWindow() { | 1441 void RenderWidgetHostViewAndroid::StartObservingRootWindow() { |
| 1442 DCHECK(content_view_core_); | 1442 DCHECK(content_view_core_); |
| 1443 // TODO(yusufo): This will need to have a better fallback for cases where | 1443 // TODO(yusufo): This will need to have a better fallback for cases where |
| 1444 // setContentViewCore is called with a valid ContentViewCore without a window. | 1444 // setContentViewCore is called with a valid ContentViewCore without a window. |
| 1445 DCHECK(content_view_core_->GetWindowAndroid()); | 1445 DCHECK(view_.GetWindowAndroid()); |
| 1446 DCHECK(is_showing_); | 1446 DCHECK(is_showing_); |
| 1447 if (observing_root_window_) | 1447 if (observing_root_window_) |
| 1448 return; | 1448 return; |
| 1449 | 1449 |
| 1450 observing_root_window_ = true; | 1450 observing_root_window_ = true; |
| 1451 if (host_) | 1451 if (host_) |
| 1452 host_->Send(new ViewMsg_SetBeginFramePaused(host_->GetRoutingID(), false)); | 1452 host_->Send(new ViewMsg_SetBeginFramePaused(host_->GetRoutingID(), false)); |
| 1453 content_view_core_->GetWindowAndroid()->AddObserver(this); | 1453 view_.GetWindowAndroid()->AddObserver(this); |
| 1454 | 1454 |
| 1455 // Clear existing vsync requests to allow a request to the new window. | 1455 // Clear existing vsync requests to allow a request to the new window. |
| 1456 uint32_t outstanding_vsync_requests = outstanding_vsync_requests_; | 1456 uint32_t outstanding_vsync_requests = outstanding_vsync_requests_; |
| 1457 outstanding_vsync_requests_ = 0; | 1457 outstanding_vsync_requests_ = 0; |
| 1458 RequestVSyncUpdate(outstanding_vsync_requests); | 1458 RequestVSyncUpdate(outstanding_vsync_requests); |
| 1459 | 1459 |
| 1460 ui::WindowAndroidCompositor* compositor = | 1460 ui::WindowAndroidCompositor* compositor = |
| 1461 content_view_core_->GetWindowAndroid()->GetCompositor(); | 1461 view_.GetWindowAndroid()->GetCompositor(); |
| 1462 if (compositor) { | 1462 if (compositor) { |
| 1463 delegated_frame_host_->RegisterFrameSinkHierarchy( | 1463 delegated_frame_host_->RegisterFrameSinkHierarchy( |
| 1464 compositor->GetFrameSinkId()); | 1464 compositor->GetFrameSinkId()); |
| 1465 } | 1465 } |
| 1466 } | 1466 } |
| 1467 | 1467 |
| 1468 void RenderWidgetHostViewAndroid::StopObservingRootWindow() { | 1468 void RenderWidgetHostViewAndroid::StopObservingRootWindow() { |
| 1469 if (!content_view_core_ || !(content_view_core_->GetWindowAndroid())) { | 1469 if (!(view_.GetWindowAndroid())) { |
| 1470 DCHECK(!observing_root_window_); | 1470 DCHECK(!observing_root_window_); |
| 1471 return; | 1471 return; |
| 1472 } | 1472 } |
| 1473 | 1473 |
| 1474 if (!observing_root_window_) | 1474 if (!observing_root_window_) |
| 1475 return; | 1475 return; |
| 1476 | 1476 |
| 1477 // Reset window state variables to their defaults. | 1477 // Reset window state variables to their defaults. |
| 1478 is_window_activity_started_ = true; | 1478 is_window_activity_started_ = true; |
| 1479 is_window_visible_ = true; | 1479 is_window_visible_ = true; |
| 1480 observing_root_window_ = false; | 1480 observing_root_window_ = false; |
| 1481 if (host_) | 1481 if (host_) |
| 1482 host_->Send(new ViewMsg_SetBeginFramePaused(host_->GetRoutingID(), true)); | 1482 host_->Send(new ViewMsg_SetBeginFramePaused(host_->GetRoutingID(), true)); |
| 1483 content_view_core_->GetWindowAndroid()->RemoveObserver(this); | 1483 view_.GetWindowAndroid()->RemoveObserver(this); |
| 1484 // If the DFH has already been destroyed, it will have cleaned itself up. | 1484 // If the DFH has already been destroyed, it will have cleaned itself up. |
| 1485 // This happens in some WebView cases. | 1485 // This happens in some WebView cases. |
| 1486 if (delegated_frame_host_) | 1486 if (delegated_frame_host_) |
| 1487 delegated_frame_host_->UnregisterFrameSinkHierarchy(); | 1487 delegated_frame_host_->UnregisterFrameSinkHierarchy(); |
| 1488 } | 1488 } |
| 1489 | 1489 |
| 1490 void RenderWidgetHostViewAndroid::SendBeginFrame(base::TimeTicks frame_time, | 1490 void RenderWidgetHostViewAndroid::SendBeginFrame(base::TimeTicks frame_time, |
| 1491 base::TimeDelta vsync_period) { | 1491 base::TimeDelta vsync_period) { |
| 1492 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::SendBeginFrame", | 1492 TRACE_EVENT1("cc", "RenderWidgetHostViewAndroid::SendBeginFrame", |
| 1493 "frame_time_us", frame_time.ToInternalValue()); | 1493 "frame_time_us", frame_time.ToInternalValue()); |
| 1494 | 1494 |
| 1495 // Synchronous compositor does not use deadline-based scheduling. | 1495 // Synchronous compositor does not use deadline-based scheduling. |
| 1496 // TODO(brianderson): Replace this hardcoded deadline after Android | 1496 // TODO(brianderson): Replace this hardcoded deadline after Android |
| 1497 // switches to Surfaces and the Browser's commit isn't in the critcal path. | 1497 // switches to Surfaces and the Browser's commit isn't in the critcal path. |
| 1498 base::TimeTicks deadline = | 1498 base::TimeTicks deadline = |
| 1499 sync_compositor_ ? base::TimeTicks() : frame_time + (vsync_period * 0.6); | 1499 sync_compositor_ ? base::TimeTicks() : frame_time + (vsync_period * 0.6); |
| 1500 host_->Send(new ViewMsg_BeginFrame( | 1500 host_->Send(new ViewMsg_BeginFrame( |
| 1501 host_->GetRoutingID(), | 1501 host_->GetRoutingID(), |
| 1502 cc::BeginFrameArgs::Create(BEGINFRAME_FROM_HERE, frame_time, deadline, | 1502 cc::BeginFrameArgs::Create(BEGINFRAME_FROM_HERE, frame_time, deadline, |
| 1503 vsync_period, cc::BeginFrameArgs::NORMAL))); | 1503 vsync_period, cc::BeginFrameArgs::NORMAL))); |
| 1504 if (sync_compositor_) | 1504 if (sync_compositor_) |
| 1505 sync_compositor_->DidSendBeginFrame(content_view_core_->GetWindowAndroid()); | 1505 sync_compositor_->DidSendBeginFrame(view_.GetWindowAndroid()); |
| 1506 } | 1506 } |
| 1507 | 1507 |
| 1508 bool RenderWidgetHostViewAndroid::Animate(base::TimeTicks frame_time) { | 1508 bool RenderWidgetHostViewAndroid::Animate(base::TimeTicks frame_time) { |
| 1509 bool needs_animate = false; | 1509 bool needs_animate = false; |
| 1510 if (overscroll_controller_) { | 1510 if (overscroll_controller_) { |
| 1511 needs_animate |= overscroll_controller_->Animate( | 1511 needs_animate |= overscroll_controller_->Animate( |
| 1512 frame_time, content_view_core_->GetViewAndroid()->GetLayer()); | 1512 frame_time, content_view_core_->GetViewAndroid()->GetLayer()); |
| 1513 } | 1513 } |
| 1514 if (selection_controller_) | 1514 if (selection_controller_) |
| 1515 needs_animate |= selection_controller_->Animate(frame_time); | 1515 needs_animate |= selection_controller_->Animate(frame_time); |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1799 if (is_showing_) | 1799 if (is_showing_) |
| 1800 StartObservingRootWindow(); | 1800 StartObservingRootWindow(); |
| 1801 | 1801 |
| 1802 if (resize) | 1802 if (resize) |
| 1803 WasResized(); | 1803 WasResized(); |
| 1804 | 1804 |
| 1805 if (!selection_controller_) | 1805 if (!selection_controller_) |
| 1806 selection_controller_ = CreateSelectionController(this, content_view_core_); | 1806 selection_controller_ = CreateSelectionController(this, content_view_core_); |
| 1807 | 1807 |
| 1808 if (!overscroll_controller_ && | 1808 if (!overscroll_controller_ && |
| 1809 content_view_core_->GetWindowAndroid()->GetCompositor()) { | 1809 view_.GetWindowAndroid()->GetCompositor()) { |
| 1810 overscroll_controller_ = CreateOverscrollController( | 1810 overscroll_controller_ = CreateOverscrollController( |
| 1811 content_view_core_, ui::GetScaleFactorForNativeView(GetNativeView())); | 1811 content_view_core_, ui::GetScaleFactorForNativeView(GetNativeView())); |
| 1812 } | 1812 } |
| 1813 | 1813 |
| 1814 if (!sync_compositor_) { | 1814 if (!sync_compositor_) { |
| 1815 sync_compositor_ = SynchronousCompositorHost::Create( | 1815 sync_compositor_ = SynchronousCompositorHost::Create( |
| 1816 this, content_view_core_->GetWebContents()); | 1816 this, content_view_core_->GetWebContents()); |
| 1817 } | 1817 } |
| 1818 } | 1818 } |
| 1819 | 1819 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1859 | 1859 |
| 1860 if (visible) | 1860 if (visible) |
| 1861 ShowInternal(); | 1861 ShowInternal(); |
| 1862 else | 1862 else |
| 1863 HideInternal(); | 1863 HideInternal(); |
| 1864 } | 1864 } |
| 1865 | 1865 |
| 1866 void RenderWidgetHostViewAndroid::OnAttachedToWindow() { | 1866 void RenderWidgetHostViewAndroid::OnAttachedToWindow() { |
| 1867 if (is_showing_) | 1867 if (is_showing_) |
| 1868 StartObservingRootWindow(); | 1868 StartObservingRootWindow(); |
| 1869 DCHECK(content_view_core_ && content_view_core_->GetWindowAndroid()); | 1869 DCHECK(view_.GetWindowAndroid()); |
| 1870 if (content_view_core_->GetWindowAndroid()->GetCompositor()) | 1870 if (view_.GetWindowAndroid()->GetCompositor()) |
| 1871 OnAttachCompositor(); | 1871 OnAttachCompositor(); |
| 1872 } | 1872 } |
| 1873 | 1873 |
| 1874 void RenderWidgetHostViewAndroid::OnDetachedFromWindow() { | 1874 void RenderWidgetHostViewAndroid::OnDetachedFromWindow() { |
| 1875 StopObservingRootWindow(); | 1875 StopObservingRootWindow(); |
| 1876 OnDetachCompositor(); | 1876 OnDetachCompositor(); |
| 1877 } | 1877 } |
| 1878 | 1878 |
| 1879 void RenderWidgetHostViewAndroid::OnAttachCompositor() { | 1879 void RenderWidgetHostViewAndroid::OnAttachCompositor() { |
| 1880 DCHECK(content_view_core_); | 1880 DCHECK(content_view_core_); |
| 1881 if (!overscroll_controller_) | 1881 if (!overscroll_controller_) |
| 1882 overscroll_controller_ = CreateOverscrollController( | 1882 overscroll_controller_ = CreateOverscrollController( |
| 1883 content_view_core_, ui::GetScaleFactorForNativeView(GetNativeView())); | 1883 content_view_core_, ui::GetScaleFactorForNativeView(GetNativeView())); |
| 1884 ui::WindowAndroidCompositor* compositor = | 1884 ui::WindowAndroidCompositor* compositor = |
| 1885 content_view_core_->GetWindowAndroid()->GetCompositor(); | 1885 view_.GetWindowAndroid()->GetCompositor(); |
| 1886 delegated_frame_host_->RegisterFrameSinkHierarchy( | 1886 delegated_frame_host_->RegisterFrameSinkHierarchy( |
| 1887 compositor->GetFrameSinkId()); | 1887 compositor->GetFrameSinkId()); |
| 1888 } | 1888 } |
| 1889 | 1889 |
| 1890 void RenderWidgetHostViewAndroid::OnDetachCompositor() { | 1890 void RenderWidgetHostViewAndroid::OnDetachCompositor() { |
| 1891 DCHECK(content_view_core_); | 1891 DCHECK(content_view_core_); |
| 1892 DCHECK(using_browser_compositor_); | 1892 DCHECK(using_browser_compositor_); |
| 1893 RunAckCallbacks(); | 1893 RunAckCallbacks(); |
| 1894 overscroll_controller_.reset(); | 1894 overscroll_controller_.reset(); |
| 1895 delegated_frame_host_->UnregisterFrameSinkHierarchy(); | 1895 delegated_frame_host_->UnregisterFrameSinkHierarchy(); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1988 case ui::MotionEvent::ACTION_UP: | 1988 case ui::MotionEvent::ACTION_UP: |
| 1989 case ui::MotionEvent::ACTION_POINTER_UP: | 1989 case ui::MotionEvent::ACTION_POINTER_UP: |
| 1990 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", | 1990 UMA_HISTOGRAM_CUSTOM_COUNTS("Event.Latency.OS.TOUCH_RELEASED", |
| 1991 delta.InMicroseconds(), 1, 1000000, 50); | 1991 delta.InMicroseconds(), 1, 1000000, 50); |
| 1992 default: | 1992 default: |
| 1993 return; | 1993 return; |
| 1994 } | 1994 } |
| 1995 } | 1995 } |
| 1996 | 1996 |
| 1997 } // namespace content | 1997 } // namespace content |
| OLD | NEW |