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 #include <set> | 8 #include <set> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 1982 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1993 | 1993 |
1994 OnRenderAutoResized(new_size); | 1994 OnRenderAutoResized(new_size); |
1995 } | 1995 } |
1996 | 1996 |
1997 void RenderWidgetHostImpl::DetachDelegate() { | 1997 void RenderWidgetHostImpl::DetachDelegate() { |
1998 delegate_ = NULL; | 1998 delegate_ = NULL; |
1999 } | 1999 } |
2000 | 2000 |
2001 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { | 2001 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { |
2002 ui::LatencyInfo::LatencyComponent window_snapshot_component; | 2002 ui::LatencyInfo::LatencyComponent window_snapshot_component; |
2003 if (latency_info.FindLatency(ui::WINDOW_OLD_SNAPSHOT_FRAME_NUMBER_COMPONENT, | |
2004 GetLatencyComponentId(), | |
2005 &window_snapshot_component)) { | |
2006 WindowOldSnapshotReachedScreen( | |
2007 static_cast<int>(window_snapshot_component.sequence_number)); | |
2008 } | |
2009 if (latency_info.FindLatency(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, | 2003 if (latency_info.FindLatency(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, |
2010 GetLatencyComponentId(), | 2004 GetLatencyComponentId(), |
2011 &window_snapshot_component)) { | 2005 &window_snapshot_component)) { |
2012 int sequence_number = static_cast<int>( | 2006 int sequence_number = static_cast<int>( |
2013 window_snapshot_component.sequence_number); | 2007 window_snapshot_component.sequence_number); |
2014 #if defined(OS_MACOSX) | 2008 #if defined(OS_MACOSX) |
2015 // On Mac, when using CoreAnmation, there is a delay between when content | 2009 // On Mac, when using CoreAnmation, there is a delay between when content |
2016 // is drawn to the screen, and when the snapshot will actually pick up | 2010 // is drawn to the screen, and when the snapshot will actually pick up |
2017 // that content. Insert a manual delay of 1/6th of a second (to simulate | 2011 // that content. Insert a manual delay of 1/6th of a second (to simulate |
2018 // 10 frames at 60 fps) before actually taking the snapshot. | 2012 // 10 frames at 60 fps) before actually taking the snapshot. |
2019 base::MessageLoop::current()->PostDelayedTask( | 2013 base::MessageLoop::current()->PostDelayedTask( |
2020 FROM_HERE, | 2014 FROM_HERE, |
2021 base::Bind(&RenderWidgetHostImpl::WindowSnapshotReachedScreen, | 2015 base::Bind(&RenderWidgetHostImpl::WindowSnapshotReachedScreen, |
2022 weak_factory_.GetWeakPtr(), | 2016 weak_factory_.GetWeakPtr(), |
2023 sequence_number), | 2017 sequence_number), |
2024 base::TimeDelta::FromSecondsD(1. / 6)); | 2018 base::TimeDelta::FromSecondsD(1. / 6)); |
2025 #else | 2019 #else |
2026 WindowSnapshotReachedScreen(sequence_number); | 2020 WindowSnapshotReachedScreen(sequence_number); |
2027 #endif | 2021 #endif |
2028 } | 2022 } |
2029 | 2023 |
2030 latency_tracker_.OnFrameSwapped(latency_info); | 2024 latency_tracker_.OnFrameSwapped(latency_info); |
2031 } | 2025 } |
2032 | 2026 |
2033 void RenderWidgetHostImpl::DidReceiveRendererFrame() { | 2027 void RenderWidgetHostImpl::DidReceiveRendererFrame() { |
2034 view_->DidReceiveRendererFrame(); | 2028 view_->DidReceiveRendererFrame(); |
2035 } | 2029 } |
2036 | 2030 |
2037 void RenderWidgetHostImpl::WindowSnapshotAsyncCallback( | |
2038 int routing_id, | |
2039 int snapshot_id, | |
2040 gfx::Size snapshot_size, | |
2041 scoped_refptr<base::RefCountedBytes> png_data) { | |
2042 if (!png_data.get()) { | |
2043 std::vector<unsigned char> png_vector; | |
2044 Send(new ViewMsg_WindowSnapshotCompleted( | |
2045 routing_id, snapshot_id, gfx::Size(), png_vector)); | |
2046 return; | |
2047 } | |
2048 | |
2049 Send(new ViewMsg_WindowSnapshotCompleted( | |
2050 routing_id, snapshot_id, snapshot_size, png_data->data())); | |
2051 } | |
2052 | |
2053 void RenderWidgetHostImpl::WindowOldSnapshotReachedScreen(int snapshot_id) { | |
2054 DCHECK(base::MessageLoopForUI::IsCurrent()); | |
2055 | |
2056 std::vector<unsigned char> png; | |
2057 | |
2058 // This feature is behind the kEnableGpuBenchmarking command line switch | |
2059 // because it poses security concerns and should only be used for testing. | |
2060 const base::CommandLine& command_line = | |
2061 *base::CommandLine::ForCurrentProcess(); | |
2062 if (!command_line.HasSwitch(cc::switches::kEnableGpuBenchmarking)) { | |
2063 Send(new ViewMsg_WindowSnapshotCompleted( | |
2064 GetRoutingID(), snapshot_id, gfx::Size(), png)); | |
2065 return; | |
2066 } | |
2067 | |
2068 gfx::Rect view_bounds = GetView()->GetViewBounds(); | |
2069 gfx::Rect snapshot_bounds(view_bounds.size()); | |
2070 gfx::Size snapshot_size = snapshot_bounds.size(); | |
2071 | |
2072 if (ui::GrabViewSnapshot( | |
2073 GetView()->GetNativeView(), &png, snapshot_bounds)) { | |
2074 Send(new ViewMsg_WindowSnapshotCompleted( | |
2075 GetRoutingID(), snapshot_id, snapshot_size, png)); | |
2076 return; | |
2077 } | |
2078 | |
2079 ui::GrabViewSnapshotAsync( | |
2080 GetView()->GetNativeView(), | |
2081 snapshot_bounds, | |
2082 base::ThreadTaskRunnerHandle::Get(), | |
2083 base::Bind(&RenderWidgetHostImpl::WindowSnapshotAsyncCallback, | |
2084 weak_factory_.GetWeakPtr(), | |
2085 GetRoutingID(), | |
2086 snapshot_id, | |
2087 snapshot_size)); | |
2088 } | |
2089 | |
2090 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { | 2031 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { |
2091 DCHECK(base::MessageLoopForUI::IsCurrent()); | 2032 DCHECK(base::MessageLoopForUI::IsCurrent()); |
2092 | 2033 |
2093 gfx::Rect view_bounds = GetView()->GetViewBounds(); | 2034 gfx::Rect view_bounds = GetView()->GetViewBounds(); |
2094 gfx::Rect snapshot_bounds(view_bounds.size()); | 2035 gfx::Rect snapshot_bounds(view_bounds.size()); |
2095 | 2036 |
2096 std::vector<unsigned char> png; | 2037 std::vector<unsigned char> png; |
2097 if (ui::GrabViewSnapshot( | 2038 if (ui::GrabViewSnapshot( |
2098 GetView()->GetNativeView(), &png, snapshot_bounds)) { | 2039 GetView()->GetNativeView(), &png, snapshot_bounds)) { |
2099 OnSnapshotDataReceived(snapshot_id, &png.front(), png.size()); | 2040 OnSnapshotDataReceived(snapshot_id, &png.front(), png.size()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2138 void RenderWidgetHostImpl::CompositorFrameDrawn( | 2079 void RenderWidgetHostImpl::CompositorFrameDrawn( |
2139 const std::vector<ui::LatencyInfo>& latency_info) { | 2080 const std::vector<ui::LatencyInfo>& latency_info) { |
2140 for (size_t i = 0; i < latency_info.size(); i++) { | 2081 for (size_t i = 0; i < latency_info.size(); i++) { |
2141 std::set<RenderWidgetHostImpl*> rwhi_set; | 2082 std::set<RenderWidgetHostImpl*> rwhi_set; |
2142 for (ui::LatencyInfo::LatencyMap::const_iterator b = | 2083 for (ui::LatencyInfo::LatencyMap::const_iterator b = |
2143 latency_info[i].latency_components.begin(); | 2084 latency_info[i].latency_components.begin(); |
2144 b != latency_info[i].latency_components.end(); | 2085 b != latency_info[i].latency_components.end(); |
2145 ++b) { | 2086 ++b) { |
2146 if (b->first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || | 2087 if (b->first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || |
2147 b->first.first == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT || | 2088 b->first.first == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT || |
2148 b->first.first == ui::WINDOW_OLD_SNAPSHOT_FRAME_NUMBER_COMPONENT || | |
2149 b->first.first == ui::TAB_SHOW_COMPONENT) { | 2089 b->first.first == ui::TAB_SHOW_COMPONENT) { |
2150 // Matches with GetLatencyComponentId | 2090 // Matches with GetLatencyComponentId |
2151 int routing_id = b->first.second & 0xffffffff; | 2091 int routing_id = b->first.second & 0xffffffff; |
2152 int process_id = (b->first.second >> 32) & 0xffffffff; | 2092 int process_id = (b->first.second >> 32) & 0xffffffff; |
2153 RenderWidgetHost* rwh = | 2093 RenderWidgetHost* rwh = |
2154 RenderWidgetHost::FromID(process_id, routing_id); | 2094 RenderWidgetHost::FromID(process_id, routing_id); |
2155 if (!rwh) { | 2095 if (!rwh) { |
2156 continue; | 2096 continue; |
2157 } | 2097 } |
2158 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); | 2098 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); |
(...skipping 26 matching lines...) Expand all Loading... |
2185 } | 2125 } |
2186 #endif | 2126 #endif |
2187 | 2127 |
2188 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() { | 2128 SkColorType RenderWidgetHostImpl::PreferredReadbackFormat() { |
2189 if (view_) | 2129 if (view_) |
2190 return view_->PreferredReadbackFormat(); | 2130 return view_->PreferredReadbackFormat(); |
2191 return kN32_SkColorType; | 2131 return kN32_SkColorType; |
2192 } | 2132 } |
2193 | 2133 |
2194 } // namespace content | 2134 } // namespace content |
OLD | NEW |