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 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
508 } | 508 } |
509 | 509 |
510 bool RenderWidgetHostViewAndroid::HasFocus() const { | 510 bool RenderWidgetHostViewAndroid::HasFocus() const { |
511 if (!content_view_core_) | 511 if (!content_view_core_) |
512 return false; // ContentViewCore not created yet. | 512 return false; // ContentViewCore not created yet. |
513 | 513 |
514 return content_view_core_->HasFocus(); | 514 return content_view_core_->HasFocus(); |
515 } | 515 } |
516 | 516 |
517 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { | 517 bool RenderWidgetHostViewAndroid::IsSurfaceAvailableForCopy() const { |
518 return HasValidFrame(); | 518 return !using_browser_compositor_ || HasValidFrame(); |
519 } | 519 } |
520 | 520 |
521 void RenderWidgetHostViewAndroid::Show() { | 521 void RenderWidgetHostViewAndroid::Show() { |
522 if (is_showing_) | 522 if (is_showing_) |
523 return; | 523 return; |
524 | 524 |
525 is_showing_ = true; | 525 is_showing_ = true; |
526 ShowInternal(); | 526 ShowInternal(); |
527 } | 527 } |
528 | 528 |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
865 const gfx::Rect& src_subrect, | 865 const gfx::Rect& src_subrect, |
866 const gfx::Size& dst_size, | 866 const gfx::Size& dst_size, |
867 const ReadbackRequestCallback& callback, | 867 const ReadbackRequestCallback& callback, |
868 const SkColorType preferred_color_type) { | 868 const SkColorType preferred_color_type) { |
869 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::CopyFromCompositingSurface"); | 869 TRACE_EVENT0("cc", "RenderWidgetHostViewAndroid::CopyFromCompositingSurface"); |
870 if (!host_ || host_->is_hidden()) { | 870 if (!host_ || host_->is_hidden()) { |
871 callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); | 871 callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); |
872 return; | 872 return; |
873 } | 873 } |
874 base::TimeTicks start_time = base::TimeTicks::Now(); | 874 base::TimeTicks start_time = base::TimeTicks::Now(); |
875 if (using_browser_compositor_ && !IsSurfaceAvailableForCopy()) { | 875 if (!IsSurfaceAvailableForCopy()) { |
876 callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); | 876 callback.Run(SkBitmap(), READBACK_SURFACE_UNAVAILABLE); |
877 return; | 877 return; |
878 } | 878 } |
879 const gfx::Display& display = | 879 const gfx::Display& display = |
880 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); | 880 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
881 float device_scale_factor = display.device_scale_factor(); | 881 float device_scale_factor = display.device_scale_factor(); |
882 gfx::Size dst_size_in_pixel = | 882 gfx::Size dst_size_in_pixel = |
883 gfx::ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); | 883 gfx::ConvertRectToPixel(device_scale_factor, gfx::Rect(dst_size)).size(); |
884 gfx::Rect src_subrect_in_pixel = | 884 gfx::Rect src_subrect_in_pixel = |
885 gfx::ConvertRectToPixel(device_scale_factor, src_subrect); | 885 gfx::ConvertRectToPixel(device_scale_factor, src_subrect); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1169 base::Bind(&RenderWidgetHostViewAndroid::SendDelegatedFrameAck, | 1169 base::Bind(&RenderWidgetHostViewAndroid::SendDelegatedFrameAck, |
1170 weak_ptr_factory_.GetWeakPtr(), | 1170 weak_ptr_factory_.GetWeakPtr(), |
1171 last_frame_info_->output_surface_id); | 1171 last_frame_info_->output_surface_id); |
1172 | 1172 |
1173 ack_callbacks_.push(ack_callback); | 1173 ack_callbacks_.push(ack_callback); |
1174 } | 1174 } |
1175 | 1175 |
1176 last_frame_info_.reset(new LastFrameInfo(output_surface_id, frame.Pass())); | 1176 last_frame_info_.reset(new LastFrameInfo(output_surface_id, frame.Pass())); |
1177 } | 1177 } |
1178 | 1178 |
1179 SynchronousCompositorImpl* | |
1180 RenderWidgetHostViewAndroid::GetSynchronousCompositorImpl() { | |
1181 return sync_compositor_.get(); | |
1182 } | |
1183 | |
1179 void RenderWidgetHostViewAndroid::SynchronousFrameMetadata( | 1184 void RenderWidgetHostViewAndroid::SynchronousFrameMetadata( |
1180 const cc::CompositorFrameMetadata& frame_metadata) { | 1185 const cc::CompositorFrameMetadata& frame_metadata) { |
1181 if (!content_view_core_) | 1186 if (!content_view_core_) |
1182 return; | 1187 return; |
1183 | 1188 |
1184 // This is a subset of OnSwapCompositorFrame() used in the synchronous | 1189 // This is a subset of OnSwapCompositorFrame() used in the synchronous |
1185 // compositor flow. | 1190 // compositor flow. |
1186 OnFrameMetadataUpdated(frame_metadata); | 1191 OnFrameMetadataUpdated(frame_metadata); |
1187 | 1192 |
1188 // DevTools ScreenCast support for Android WebView. | 1193 // DevTools ScreenCast support for Android WebView. |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1274 input_size_in_pixel = src_subrect_in_pixel.size(); | 1279 input_size_in_pixel = src_subrect_in_pixel.size(); |
1275 | 1280 |
1276 gfx::Size output_size_in_pixel; | 1281 gfx::Size output_size_in_pixel; |
1277 if (dst_size_in_pixel.IsEmpty()) | 1282 if (dst_size_in_pixel.IsEmpty()) |
1278 output_size_in_pixel = input_size_in_pixel; | 1283 output_size_in_pixel = input_size_in_pixel; |
1279 else | 1284 else |
1280 output_size_in_pixel = dst_size_in_pixel; | 1285 output_size_in_pixel = dst_size_in_pixel; |
1281 int output_width = output_size_in_pixel.width(); | 1286 int output_width = output_size_in_pixel.width(); |
1282 int output_height = output_size_in_pixel.height(); | 1287 int output_height = output_size_in_pixel.height(); |
1283 | 1288 |
1284 SynchronousCompositor* compositor = | 1289 if (!sync_compositor_) { |
1285 SynchronousCompositorImpl::FromID(host_->GetProcess()->GetID(), | |
1286 host_->GetRoutingID()); | |
1287 if (!compositor) { | |
1288 callback.Run(SkBitmap(), READBACK_FAILED); | 1290 callback.Run(SkBitmap(), READBACK_FAILED); |
1289 return; | 1291 return; |
1290 } | 1292 } |
1291 | 1293 |
1292 SkBitmap bitmap; | 1294 SkBitmap bitmap; |
1293 bitmap.allocPixels(SkImageInfo::Make(output_width, | 1295 bitmap.allocPixels(SkImageInfo::Make(output_width, |
1294 output_height, | 1296 output_height, |
1295 color_type, | 1297 color_type, |
1296 kPremul_SkAlphaType)); | 1298 kPremul_SkAlphaType)); |
1297 SkCanvas canvas(bitmap); | 1299 SkCanvas canvas(bitmap); |
1298 canvas.scale( | 1300 canvas.scale( |
1299 (float)output_width / (float)input_size_in_pixel.width(), | 1301 (float)output_width / (float)input_size_in_pixel.width(), |
1300 (float)output_height / (float)input_size_in_pixel.height()); | 1302 (float)output_height / (float)input_size_in_pixel.height()); |
1301 compositor->DemandDrawSw(&canvas); | 1303 sync_compositor_->DemandDrawSw(&canvas); |
1302 callback.Run(bitmap, READBACK_SUCCESS); | 1304 callback.Run(bitmap, READBACK_SUCCESS); |
1303 } | 1305 } |
1304 | 1306 |
1305 void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated( | 1307 void RenderWidgetHostViewAndroid::OnFrameMetadataUpdated( |
1306 const cc::CompositorFrameMetadata& frame_metadata) { | 1308 const cc::CompositorFrameMetadata& frame_metadata) { |
1307 bool is_mobile_optimized = IsMobileOptimizedFrame(frame_metadata); | 1309 bool is_mobile_optimized = IsMobileOptimizedFrame(frame_metadata); |
1308 gesture_provider_.SetDoubleTapSupportForPageEnabled(!is_mobile_optimized); | 1310 gesture_provider_.SetDoubleTapSupportForPageEnabled(!is_mobile_optimized); |
1309 | 1311 |
1310 if (!content_view_core_) | 1312 if (!content_view_core_) |
1311 return; | 1313 return; |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1475 | 1477 |
1476 if (using_browser_compositor_) { | 1478 if (using_browser_compositor_) { |
1477 // TODO(brianderson): Replace this hardcoded deadline after Android | 1479 // TODO(brianderson): Replace this hardcoded deadline after Android |
1478 // switches to Surfaces and the Browser's commit isn't in the critcal path. | 1480 // switches to Surfaces and the Browser's commit isn't in the critcal path. |
1479 base::TimeTicks deadline = frame_time + (vsync_period * 0.6); | 1481 base::TimeTicks deadline = frame_time + (vsync_period * 0.6); |
1480 | 1482 |
1481 host_->Send(new ViewMsg_BeginFrame( | 1483 host_->Send(new ViewMsg_BeginFrame( |
1482 host_->GetRoutingID(), | 1484 host_->GetRoutingID(), |
1483 cc::BeginFrameArgs::Create(BEGINFRAME_FROM_HERE, frame_time, deadline, | 1485 cc::BeginFrameArgs::Create(BEGINFRAME_FROM_HERE, frame_time, deadline, |
1484 vsync_period, cc::BeginFrameArgs::NORMAL))); | 1486 vsync_period, cc::BeginFrameArgs::NORMAL))); |
1485 } else { | 1487 } else if (sync_compositor_) { |
1486 SynchronousCompositorImpl* compositor = SynchronousCompositorImpl::FromID( | 1488 // The synchronous compositor synchronously does it's work in this call. |
1487 host_->GetProcess()->GetID(), host_->GetRoutingID()); | 1489 // It does not use a deadline. |
1488 if (compositor) { | 1490 sync_compositor_->BeginFrame(cc::BeginFrameArgs::Create( |
1489 // The synchronous compositor synchronously does it's work in this call. | 1491 BEGINFRAME_FROM_HERE, frame_time, base::TimeTicks(), vsync_period, |
1490 // It does not use a deadline. | 1492 cc::BeginFrameArgs::NORMAL)); |
1491 compositor->BeginFrame(cc::BeginFrameArgs::Create( | |
1492 BEGINFRAME_FROM_HERE, frame_time, base::TimeTicks(), vsync_period, | |
1493 cc::BeginFrameArgs::NORMAL)); | |
1494 } | |
1495 } | 1493 } |
1496 } | 1494 } |
1497 | 1495 |
1498 bool RenderWidgetHostViewAndroid::Animate(base::TimeTicks frame_time) { | 1496 bool RenderWidgetHostViewAndroid::Animate(base::TimeTicks frame_time) { |
1499 bool needs_animate = false; | 1497 bool needs_animate = false; |
1500 if (overscroll_controller_) { | 1498 if (overscroll_controller_) { |
1501 needs_animate |= overscroll_controller_->Animate( | 1499 needs_animate |= overscroll_controller_->Animate( |
1502 frame_time, content_view_core_->GetLayer().get()); | 1500 frame_time, content_view_core_->GetLayer().get()); |
1503 } | 1501 } |
1504 if (selection_controller_) | 1502 if (selection_controller_) |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1602 | 1600 |
1603 if (input_event.type == blink::WebInputEvent::GestureTapDown || | 1601 if (input_event.type == blink::WebInputEvent::GestureTapDown || |
1604 input_event.type == blink::WebInputEvent::TouchStart) { | 1602 input_event.type == blink::WebInputEvent::TouchStart) { |
1605 GpuDataManagerImpl* gpu_data = GpuDataManagerImpl::GetInstance(); | 1603 GpuDataManagerImpl* gpu_data = GpuDataManagerImpl::GetInstance(); |
1606 GpuProcessHostUIShim* shim = GpuProcessHostUIShim::GetOneInstance(); | 1604 GpuProcessHostUIShim* shim = GpuProcessHostUIShim::GetOneInstance(); |
1607 if (shim && gpu_data && | 1605 if (shim && gpu_data && |
1608 gpu_data->IsDriverBugWorkaroundActive(gpu::WAKE_UP_GPU_BEFORE_DRAWING)) | 1606 gpu_data->IsDriverBugWorkaroundActive(gpu::WAKE_UP_GPU_BEFORE_DRAWING)) |
1609 shim->Send(new GpuMsg_WakeUpGpu); | 1607 shim->Send(new GpuMsg_WakeUpGpu); |
1610 } | 1608 } |
1611 | 1609 |
1612 SynchronousCompositorImpl* compositor = | 1610 if (sync_compositor_) |
1613 SynchronousCompositorImpl::FromID(host_->GetProcess()->GetID(), | 1611 return sync_compositor_->HandleInputEvent(input_event); |
1614 host_->GetRoutingID()); | |
1615 if (compositor) | |
1616 return compositor->HandleInputEvent(input_event); | |
1617 return INPUT_EVENT_ACK_STATE_NOT_CONSUMED; | 1612 return INPUT_EVENT_ACK_STATE_NOT_CONSUMED; |
1618 } | 1613 } |
1619 | 1614 |
1620 void RenderWidgetHostViewAndroid::OnSetNeedsFlushInput() { | 1615 void RenderWidgetHostViewAndroid::OnSetNeedsFlushInput() { |
1621 TRACE_EVENT0("input", "RenderWidgetHostViewAndroid::OnSetNeedsFlushInput"); | 1616 TRACE_EVENT0("input", "RenderWidgetHostViewAndroid::OnSetNeedsFlushInput"); |
1622 RequestVSyncUpdate(FLUSH_INPUT); | 1617 RequestVSyncUpdate(FLUSH_INPUT); |
1623 } | 1618 } |
1624 | 1619 |
1625 BrowserAccessibilityManager* | 1620 BrowserAccessibilityManager* |
1626 RenderWidgetHostViewAndroid::CreateBrowserAccessibilityManager( | 1621 RenderWidgetHostViewAndroid::CreateBrowserAccessibilityManager( |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1738 } | 1733 } |
1739 | 1734 |
1740 uint32_t RenderWidgetHostViewAndroid::GetSurfaceIdNamespace() { | 1735 uint32_t RenderWidgetHostViewAndroid::GetSurfaceIdNamespace() { |
1741 if (id_allocator_) | 1736 if (id_allocator_) |
1742 return id_allocator_->id_namespace(); | 1737 return id_allocator_->id_namespace(); |
1743 return 0; | 1738 return 0; |
1744 } | 1739 } |
1745 | 1740 |
1746 void RenderWidgetHostViewAndroid::SetContentViewCore( | 1741 void RenderWidgetHostViewAndroid::SetContentViewCore( |
1747 ContentViewCoreImpl* content_view_core) { | 1742 ContentViewCoreImpl* content_view_core) { |
1743 DCHECK(!content_view_core || !content_view_core_ || | |
1744 (content_view_core_ == content_view_core)); | |
1748 RemoveLayers(); | 1745 RemoveLayers(); |
1749 StopObservingRootWindow(); | 1746 StopObservingRootWindow(); |
1750 | 1747 |
1751 bool resize = false; | 1748 bool resize = false; |
1752 if (content_view_core != content_view_core_) { | 1749 if (content_view_core != content_view_core_) { |
1753 overscroll_controller_.reset(); | 1750 overscroll_controller_.reset(); |
1754 selection_controller_.reset(); | 1751 selection_controller_.reset(); |
1755 ReleaseLocksOnSurface(); | 1752 ReleaseLocksOnSurface(); |
1756 resize = true; | 1753 resize = true; |
1757 } | 1754 } |
1758 | 1755 |
1759 content_view_core_ = content_view_core; | 1756 content_view_core_ = content_view_core; |
1760 content_view_core_window_android_ = | 1757 content_view_core_window_android_ = |
1761 content_view_core_ ? content_view_core_->GetWindowAndroid() : nullptr; | 1758 content_view_core_ ? content_view_core_->GetWindowAndroid() : nullptr; |
1762 DCHECK_EQ(!!content_view_core_, !!content_view_core_window_android_); | 1759 DCHECK_EQ(!!content_view_core_, !!content_view_core_window_android_); |
1763 | 1760 |
1764 BrowserAccessibilityManager* manager = NULL; | 1761 BrowserAccessibilityManager* manager = NULL; |
1765 if (host_) | 1762 if (host_) |
1766 manager = host_->GetRootBrowserAccessibilityManager(); | 1763 manager = host_->GetRootBrowserAccessibilityManager(); |
1767 if (manager) { | 1764 if (manager) { |
1768 base::android::ScopedJavaLocalRef<jobject> obj; | 1765 base::android::ScopedJavaLocalRef<jobject> obj; |
1769 if (content_view_core_) | 1766 if (content_view_core_) |
1770 obj = content_view_core_->GetJavaObject(); | 1767 obj = content_view_core_->GetJavaObject(); |
1771 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj); | 1768 manager->ToBrowserAccessibilityManagerAndroid()->SetContentViewCore(obj); |
1772 } | 1769 } |
1773 | 1770 |
1774 AttachLayers(); | 1771 AttachLayers(); |
1775 | 1772 if (!content_view_core_) { |
1776 if (!content_view_core_) | 1773 sync_compositor_.reset(); |
1777 return; | 1774 return; |
1775 } | |
1778 | 1776 |
1779 if (is_showing_) | 1777 if (is_showing_) |
1780 StartObservingRootWindow(); | 1778 StartObservingRootWindow(); |
1781 | 1779 |
1782 if (resize) | 1780 if (resize) |
1783 WasResized(); | 1781 WasResized(); |
1784 | 1782 |
1785 if (!selection_controller_) | 1783 if (!selection_controller_) |
1786 selection_controller_ = CreateSelectionController(this, content_view_core_); | 1784 selection_controller_ = CreateSelectionController(this, content_view_core_); |
1787 | 1785 |
1788 if (!overscroll_controller_ && | 1786 if (!overscroll_controller_ && |
1789 content_view_core_window_android_->GetCompositor()) { | 1787 content_view_core_window_android_->GetCompositor()) { |
1790 overscroll_controller_ = CreateOverscrollController(content_view_core_); | 1788 overscroll_controller_ = CreateOverscrollController(content_view_core_); |
1791 } | 1789 } |
1790 | |
1791 if (!sync_compositor_) { | |
1792 sync_compositor_ = SynchronousCompositorImpl::Create( | |
1793 this, content_view_core_->GetWebContents()); | |
no sievers
2015/10/08 22:39:29
It's a bit ugly to see WebContents in RWHV. Really
boliu
2015/10/09 02:22:16
The practical argument: lots of code here already
| |
1794 } | |
1792 } | 1795 } |
1793 | 1796 |
1794 void RenderWidgetHostViewAndroid::RunAckCallbacks( | 1797 void RenderWidgetHostViewAndroid::RunAckCallbacks( |
1795 cc::SurfaceDrawStatus status) { | 1798 cc::SurfaceDrawStatus status) { |
1796 while (!ack_callbacks_.empty()) { | 1799 while (!ack_callbacks_.empty()) { |
1797 ack_callbacks_.front().Run(); | 1800 ack_callbacks_.front().Run(); |
1798 ack_callbacks_.pop(); | 1801 ack_callbacks_.pop(); |
1799 } | 1802 } |
1800 } | 1803 } |
1801 | 1804 |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2012 results->orientationAngle = display.RotationAsDegree(); | 2015 results->orientationAngle = display.RotationAsDegree(); |
2013 results->orientationType = | 2016 results->orientationType = |
2014 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); | 2017 RenderWidgetHostViewBase::GetOrientationTypeForMobile(display); |
2015 gfx::DeviceDisplayInfo info; | 2018 gfx::DeviceDisplayInfo info; |
2016 results->depth = info.GetBitsPerPixel(); | 2019 results->depth = info.GetBitsPerPixel(); |
2017 results->depthPerComponent = info.GetBitsPerComponent(); | 2020 results->depthPerComponent = info.GetBitsPerComponent(); |
2018 results->isMonochrome = (results->depthPerComponent == 0); | 2021 results->isMonochrome = (results->depthPerComponent == 0); |
2019 } | 2022 } |
2020 | 2023 |
2021 } // namespace content | 2024 } // namespace content |
OLD | NEW |