| 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_impl.h" | 5 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 6 | 6 |
| 7 #include <math.h> | 7 #include <math.h> |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <tuple> | 10 #include <tuple> |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 | 98 |
| 99 #if defined(OS_ANDROID) | 99 #if defined(OS_ANDROID) |
| 100 #include "ui/android/view_android.h" | 100 #include "ui/android/view_android.h" |
| 101 #else | 101 #else |
| 102 #include "content/browser/compositor/image_transport_factory.h" | 102 #include "content/browser/compositor/image_transport_factory.h" |
| 103 // nogncheck as dependency of "ui/compositor" is on non-Android platforms only. | 103 // nogncheck as dependency of "ui/compositor" is on non-Android platforms only. |
| 104 #include "ui/compositor/compositor.h" // nogncheck | 104 #include "ui/compositor/compositor.h" // nogncheck |
| 105 #endif | 105 #endif |
| 106 | 106 |
| 107 #if defined(OS_MACOSX) | 107 #if defined(OS_MACOSX) |
| 108 #include "device/power_save_blocker/power_save_blocker.h" | 108 #include "content/public/common/service_manager_connection.h" |
| 109 #include "device/wake_lock/public/interfaces/wake_lock_provider.mojom.h" |
| 110 #include "services/device/public/interfaces/constants.mojom.h" |
| 111 #include "services/service_manager/public/cpp/connector.h" |
| 109 #include "ui/accelerated_widget_mac/window_resize_helper_mac.h" | 112 #include "ui/accelerated_widget_mac/window_resize_helper_mac.h" |
| 110 #endif | 113 #endif |
| 111 | 114 |
| 112 using base::Time; | 115 using base::Time; |
| 113 using base::TimeDelta; | 116 using base::TimeDelta; |
| 114 using base::TimeTicks; | 117 using base::TimeTicks; |
| 115 using blink::WebDragOperation; | 118 using blink::WebDragOperation; |
| 116 using blink::WebDragOperationsMask; | 119 using blink::WebDragOperationsMask; |
| 117 using blink::WebGestureEvent; | 120 using blink::WebGestureEvent; |
| 118 using blink::WebInputEvent; | 121 using blink::WebInputEvent; |
| (...skipping 1389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1508 latency_info.AddLatencyNumber(ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT, | 1511 latency_info.AddLatencyNumber(ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT, |
| 1509 0, id); | 1512 0, id); |
| 1510 Send(new ViewMsg_ForceRedraw(GetRoutingID(), latency_info)); | 1513 Send(new ViewMsg_ForceRedraw(GetRoutingID(), latency_info)); |
| 1511 return; | 1514 return; |
| 1512 } | 1515 } |
| 1513 | 1516 |
| 1514 #if defined(OS_MACOSX) | 1517 #if defined(OS_MACOSX) |
| 1515 // MacOS version of underlying GrabViewSnapshot() blocks while | 1518 // MacOS version of underlying GrabViewSnapshot() blocks while |
| 1516 // display/GPU are in a power-saving mode, so make sure display | 1519 // display/GPU are in a power-saving mode, so make sure display |
| 1517 // does not go to sleep for the duration of reading a snapshot. | 1520 // does not go to sleep for the duration of reading a snapshot. |
| 1518 if (pending_browser_snapshots_.empty()) { | 1521 if (pending_browser_snapshots_.empty()) |
| 1519 DCHECK(!power_save_blocker_); | 1522 GetWakeLockService()->RequestWakeLock(); |
| 1520 power_save_blocker_.reset(new device::PowerSaveBlocker( | |
| 1521 device::PowerSaveBlocker::kPowerSaveBlockPreventDisplaySleep, | |
| 1522 device::PowerSaveBlocker::kReasonOther, "GetSnapshot", | |
| 1523 BrowserThread::GetTaskRunnerForThread(BrowserThread::UI), | |
| 1524 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); | |
| 1525 } | |
| 1526 #endif | 1523 #endif |
| 1527 pending_browser_snapshots_.insert(std::make_pair(id, callback)); | 1524 pending_browser_snapshots_.insert(std::make_pair(id, callback)); |
| 1528 ui::LatencyInfo latency_info; | 1525 ui::LatencyInfo latency_info; |
| 1529 latency_info.AddLatencyNumber(ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT, 0, | 1526 latency_info.AddLatencyNumber(ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT, 0, |
| 1530 id); | 1527 id); |
| 1531 Send(new ViewMsg_ForceRedraw(GetRoutingID(), latency_info)); | 1528 Send(new ViewMsg_ForceRedraw(GetRoutingID(), latency_info)); |
| 1532 } | 1529 } |
| 1533 | 1530 |
| 1534 const NativeWebKeyboardEvent* | 1531 const NativeWebKeyboardEvent* |
| 1535 RenderWidgetHostImpl::GetLastKeyboardEvent() const { | 1532 RenderWidgetHostImpl::GetLastKeyboardEvent() const { |
| (...skipping 936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2472 while (it != pending_browser_snapshots_.end()) { | 2469 while (it != pending_browser_snapshots_.end()) { |
| 2473 if (it->first <= snapshot_id) { | 2470 if (it->first <= snapshot_id) { |
| 2474 it->second.Run(image); | 2471 it->second.Run(image); |
| 2475 pending_browser_snapshots_.erase(it++); | 2472 pending_browser_snapshots_.erase(it++); |
| 2476 } else { | 2473 } else { |
| 2477 ++it; | 2474 ++it; |
| 2478 } | 2475 } |
| 2479 } | 2476 } |
| 2480 #if defined(OS_MACOSX) | 2477 #if defined(OS_MACOSX) |
| 2481 if (pending_browser_snapshots_.empty()) | 2478 if (pending_browser_snapshots_.empty()) |
| 2482 power_save_blocker_.reset(); | 2479 GetWakeLockService()->CancelWakeLock(); |
| 2483 #endif | 2480 #endif |
| 2484 } | 2481 } |
| 2485 | 2482 |
| 2486 // static | 2483 // static |
| 2487 void RenderWidgetHostImpl::OnGpuSwapBuffersCompleted( | 2484 void RenderWidgetHostImpl::OnGpuSwapBuffersCompleted( |
| 2488 const std::vector<ui::LatencyInfo>& latency_info) { | 2485 const std::vector<ui::LatencyInfo>& latency_info) { |
| 2489 for (size_t i = 0; i < latency_info.size(); i++) { | 2486 for (size_t i = 0; i < latency_info.size(); i++) { |
| 2490 std::set<RenderWidgetHostImpl*> rwhi_set; | 2487 std::set<RenderWidgetHostImpl*> rwhi_set; |
| 2491 for (const auto& lc : latency_info[i].latency_components()) { | 2488 for (const auto& lc : latency_info[i].latency_components()) { |
| 2492 if (lc.first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || | 2489 if (lc.first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2642 std::vector<IPC::Message> messages) { | 2639 std::vector<IPC::Message> messages) { |
| 2643 RenderProcessHost* rph = GetProcess(); | 2640 RenderProcessHost* rph = GetProcess(); |
| 2644 for (std::vector<IPC::Message>::const_iterator i = messages.begin(); | 2641 for (std::vector<IPC::Message>::const_iterator i = messages.begin(); |
| 2645 i != messages.end(); ++i) { | 2642 i != messages.end(); ++i) { |
| 2646 rph->OnMessageReceived(*i); | 2643 rph->OnMessageReceived(*i); |
| 2647 if (i->dispatch_error()) | 2644 if (i->dispatch_error()) |
| 2648 rph->OnBadMessageReceived(*i); | 2645 rph->OnBadMessageReceived(*i); |
| 2649 } | 2646 } |
| 2650 } | 2647 } |
| 2651 | 2648 |
| 2649 #if defined(OS_MACOSX) |
| 2650 device::mojom::WakeLockService* RenderWidgetHostImpl::GetWakeLockService() { |
| 2651 // Here is a lazy binding, and will not reconnect after connection error. |
| 2652 if (!wake_lock_) { |
| 2653 device::mojom::WakeLockServiceRequest request = |
| 2654 mojo::MakeRequest(&wake_lock_); |
| 2655 // In some testing contexts, the service manager connection isn't |
| 2656 // initialized. |
| 2657 if (ServiceManagerConnection::GetForProcess()) { |
| 2658 service_manager::Connector* connector = |
| 2659 ServiceManagerConnection::GetForProcess()->GetConnector(); |
| 2660 DCHECK(connector); |
| 2661 device::mojom::WakeLockProviderPtr wake_lock_provider; |
| 2662 connector->BindInterface(device::mojom::kServiceName, |
| 2663 mojo::MakeRequest(&wake_lock_provider)); |
| 2664 wake_lock_provider->GetWakeLockWithoutContext( |
| 2665 device::mojom::WakeLockType::PreventDisplaySleep, |
| 2666 device::mojom::WakeLockReason::ReasonOther, "GetSnapshot", |
| 2667 std::move(request)); |
| 2668 } |
| 2669 } |
| 2670 return wake_lock_.get(); |
| 2671 } |
| 2672 #endif |
| 2673 |
| 2652 } // namespace content | 2674 } // namespace content |
| OLD | NEW |