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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 ignore_input_events_(false), | 185 ignore_input_events_(false), |
186 input_method_active_(false), | 186 input_method_active_(false), |
187 text_direction_updated_(false), | 187 text_direction_updated_(false), |
188 text_direction_(blink::WebTextDirectionLeftToRight), | 188 text_direction_(blink::WebTextDirectionLeftToRight), |
189 text_direction_canceled_(false), | 189 text_direction_canceled_(false), |
190 suppress_next_char_events_(false), | 190 suppress_next_char_events_(false), |
191 pending_mouse_lock_request_(false), | 191 pending_mouse_lock_request_(false), |
192 allow_privileged_mouse_lock_(false), | 192 allow_privileged_mouse_lock_(false), |
193 has_touch_handler_(false), | 193 has_touch_handler_(false), |
194 weak_factory_(this), | 194 weak_factory_(this), |
195 last_input_number_(static_cast<int64>(GetProcess()->GetID()) << 32) { | 195 last_input_number_(static_cast<int64>(GetProcess()->GetID()) << 32), |
| 196 next_browser_snapshot_id_(0) { |
196 CHECK(delegate_); | 197 CHECK(delegate_); |
197 if (routing_id_ == MSG_ROUTING_NONE) { | 198 if (routing_id_ == MSG_ROUTING_NONE) { |
198 routing_id_ = process_->GetNextRoutingID(); | 199 routing_id_ = process_->GetNextRoutingID(); |
199 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( | 200 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( |
200 process_->GetID(), | 201 process_->GetID(), |
201 routing_id_); | 202 routing_id_); |
202 } else { | 203 } else { |
203 // TODO(piman): This is a O(N) lookup, where we could forward the | 204 // TODO(piman): This is a O(N) lookup, where we could forward the |
204 // information from the RenderWidgetHelper. The problem is that doing so | 205 // information from the RenderWidgetHelper. The problem is that doing so |
205 // currently leaks outside of content all the way to chrome classes, and | 206 // currently leaks outside of content all the way to chrome classes, and |
(...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 // factor). | 1156 // factor). |
1156 InvalidateScreenInfo(); | 1157 InvalidateScreenInfo(); |
1157 WasResized(); | 1158 WasResized(); |
1158 } | 1159 } |
1159 | 1160 |
1160 void RenderWidgetHostImpl::InvalidateScreenInfo() { | 1161 void RenderWidgetHostImpl::InvalidateScreenInfo() { |
1161 screen_info_out_of_date_ = true; | 1162 screen_info_out_of_date_ = true; |
1162 screen_info_.reset(); | 1163 screen_info_.reset(); |
1163 } | 1164 } |
1164 | 1165 |
| 1166 void RenderWidgetHostImpl::GetSnapshotFromBrowser( |
| 1167 const base::Callback<void(const unsigned char*,size_t)> callback) { |
| 1168 int id = next_browser_snapshot_id_++; |
| 1169 pending_browser_snapshots_.insert(std::make_pair(id, callback)); |
| 1170 Send(new ViewMsg_ForceRedraw(GetRoutingID(), id)); |
| 1171 } |
| 1172 |
1165 void RenderWidgetHostImpl::OnSelectionChanged(const base::string16& text, | 1173 void RenderWidgetHostImpl::OnSelectionChanged(const base::string16& text, |
1166 size_t offset, | 1174 size_t offset, |
1167 const gfx::Range& range) { | 1175 const gfx::Range& range) { |
1168 if (view_) | 1176 if (view_) |
1169 view_->SelectionChanged(text, offset, range); | 1177 view_->SelectionChanged(text, offset, range); |
1170 } | 1178 } |
1171 | 1179 |
1172 void RenderWidgetHostImpl::OnSelectionBoundsChanged( | 1180 void RenderWidgetHostImpl::OnSelectionBoundsChanged( |
1173 const ViewHostMsg_SelectionBounds_Params& params) { | 1181 const ViewHostMsg_SelectionBounds_Params& params) { |
1174 if (view_) { | 1182 if (view_) { |
(...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2150 "Event.Latency.Browser.TouchAcked", | 2158 "Event.Latency.Browser.TouchAcked", |
2151 acked_delta.InMicroseconds(), | 2159 acked_delta.InMicroseconds(), |
2152 1, | 2160 1, |
2153 1000000, | 2161 1000000, |
2154 100); | 2162 100); |
2155 } | 2163 } |
2156 } | 2164 } |
2157 | 2165 |
2158 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { | 2166 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { |
2159 ui::LatencyInfo::LatencyComponent window_snapshot_component; | 2167 ui::LatencyInfo::LatencyComponent window_snapshot_component; |
| 2168 if (latency_info.FindLatency(ui::WINDOW_OLD_SNAPSHOT_FRAME_NUMBER_COMPONENT, |
| 2169 GetLatencyComponentId(), |
| 2170 &window_snapshot_component)) { |
| 2171 WindowOldSnapshotReachedScreen( |
| 2172 static_cast<int>(window_snapshot_component.sequence_number)); |
| 2173 } |
2160 if (latency_info.FindLatency(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, | 2174 if (latency_info.FindLatency(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, |
2161 GetLatencyComponentId(), | 2175 GetLatencyComponentId(), |
2162 &window_snapshot_component)) { | 2176 &window_snapshot_component)) { |
2163 WindowSnapshotReachedScreen( | 2177 WindowSnapshotReachedScreen( |
2164 static_cast<int>(window_snapshot_component.sequence_number)); | 2178 static_cast<int>(window_snapshot_component.sequence_number)); |
2165 } | 2179 } |
2166 | 2180 |
2167 ui::LatencyInfo::LatencyComponent rwh_component; | 2181 ui::LatencyInfo::LatencyComponent rwh_component; |
2168 ui::LatencyInfo::LatencyComponent swap_component; | 2182 ui::LatencyInfo::LatencyComponent swap_component; |
2169 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, | 2183 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2209 std::vector<unsigned char> png_vector; | 2223 std::vector<unsigned char> png_vector; |
2210 Send(new ViewMsg_WindowSnapshotCompleted( | 2224 Send(new ViewMsg_WindowSnapshotCompleted( |
2211 routing_id, snapshot_id, gfx::Size(), png_vector)); | 2225 routing_id, snapshot_id, gfx::Size(), png_vector)); |
2212 return; | 2226 return; |
2213 } | 2227 } |
2214 | 2228 |
2215 Send(new ViewMsg_WindowSnapshotCompleted( | 2229 Send(new ViewMsg_WindowSnapshotCompleted( |
2216 routing_id, snapshot_id, snapshot_size, png_data->data())); | 2230 routing_id, snapshot_id, snapshot_size, png_data->data())); |
2217 } | 2231 } |
2218 | 2232 |
2219 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { | 2233 void RenderWidgetHostImpl::WindowOldSnapshotReachedScreen(int snapshot_id) { |
2220 DCHECK(base::MessageLoopForUI::IsCurrent()); | 2234 DCHECK(base::MessageLoopForUI::IsCurrent()); |
2221 | 2235 |
2222 std::vector<unsigned char> png; | 2236 std::vector<unsigned char> png; |
2223 | 2237 |
2224 // This feature is behind the kEnableGpuBenchmarking command line switch | 2238 // This feature is behind the kEnableGpuBenchmarking command line switch |
2225 // because it poses security concerns and should only be used for testing. | 2239 // because it poses security concerns and should only be used for testing. |
2226 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 2240 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
2227 if (!command_line.HasSwitch(cc::switches::kEnableGpuBenchmarking)) { | 2241 if (!command_line.HasSwitch(cc::switches::kEnableGpuBenchmarking)) { |
2228 Send(new ViewMsg_WindowSnapshotCompleted( | 2242 Send(new ViewMsg_WindowSnapshotCompleted( |
2229 GetRoutingID(), snapshot_id, gfx::Size(), png)); | 2243 GetRoutingID(), snapshot_id, gfx::Size(), png)); |
(...skipping 15 matching lines...) Expand all Loading... |
2245 GetView()->GetNativeView(), | 2259 GetView()->GetNativeView(), |
2246 snapshot_bounds, | 2260 snapshot_bounds, |
2247 base::ThreadTaskRunnerHandle::Get(), | 2261 base::ThreadTaskRunnerHandle::Get(), |
2248 base::Bind(&RenderWidgetHostImpl::WindowSnapshotAsyncCallback, | 2262 base::Bind(&RenderWidgetHostImpl::WindowSnapshotAsyncCallback, |
2249 weak_factory_.GetWeakPtr(), | 2263 weak_factory_.GetWeakPtr(), |
2250 GetRoutingID(), | 2264 GetRoutingID(), |
2251 snapshot_id, | 2265 snapshot_id, |
2252 snapshot_size)); | 2266 snapshot_size)); |
2253 } | 2267 } |
2254 | 2268 |
| 2269 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { |
| 2270 DCHECK(base::MessageLoopForUI::IsCurrent()); |
| 2271 |
| 2272 gfx::Rect view_bounds = GetView()->GetViewBounds(); |
| 2273 gfx::Rect snapshot_bounds(view_bounds.size()); |
| 2274 |
| 2275 std::vector<unsigned char> png; |
| 2276 if (ui::GrabViewSnapshot( |
| 2277 GetView()->GetNativeView(), &png, snapshot_bounds)) { |
| 2278 OnSnapshotDataReceived(snapshot_id, &png.front(), png.size()); |
| 2279 return; |
| 2280 } |
| 2281 |
| 2282 ui::GrabViewSnapshotAsync( |
| 2283 GetView()->GetNativeView(), |
| 2284 snapshot_bounds, |
| 2285 base::ThreadTaskRunnerHandle::Get(), |
| 2286 base::Bind(&RenderWidgetHostImpl::OnSnapshotDataReceivedAsync, |
| 2287 weak_factory_.GetWeakPtr(), |
| 2288 snapshot_id)); |
| 2289 } |
| 2290 |
| 2291 void RenderWidgetHostImpl::OnSnapshotDataReceived(int snapshot_id, |
| 2292 const unsigned char* data, |
| 2293 size_t size) { |
| 2294 // Any pending snapshots with a lower ID than the one received are considered |
| 2295 // to be implicitly complete, and returned the same snapshot data. |
| 2296 PendingSnapshotMap::iterator it = pending_browser_snapshots_.begin(); |
| 2297 while(it != pending_browser_snapshots_.end()) { |
| 2298 if (it->first <= snapshot_id) { |
| 2299 it->second.Run(data, size); |
| 2300 pending_browser_snapshots_.erase(it++); |
| 2301 } else { |
| 2302 ++it; |
| 2303 } |
| 2304 } |
| 2305 } |
| 2306 |
| 2307 void RenderWidgetHostImpl::OnSnapshotDataReceivedAsync( |
| 2308 int snapshot_id, |
| 2309 scoped_refptr<base::RefCountedBytes> png_data) { |
| 2310 if (png_data) |
| 2311 OnSnapshotDataReceived(snapshot_id, png_data->front(), png_data->size()); |
| 2312 else |
| 2313 OnSnapshotDataReceived(snapshot_id, NULL, 0); |
| 2314 } |
| 2315 |
2255 // static | 2316 // static |
2256 void RenderWidgetHostImpl::CompositorFrameDrawn( | 2317 void RenderWidgetHostImpl::CompositorFrameDrawn( |
2257 const std::vector<ui::LatencyInfo>& latency_info) { | 2318 const std::vector<ui::LatencyInfo>& latency_info) { |
2258 for (size_t i = 0; i < latency_info.size(); i++) { | 2319 for (size_t i = 0; i < latency_info.size(); i++) { |
2259 std::set<RenderWidgetHostImpl*> rwhi_set; | 2320 std::set<RenderWidgetHostImpl*> rwhi_set; |
2260 for (ui::LatencyInfo::LatencyMap::const_iterator b = | 2321 for (ui::LatencyInfo::LatencyMap::const_iterator b = |
2261 latency_info[i].latency_components.begin(); | 2322 latency_info[i].latency_components.begin(); |
2262 b != latency_info[i].latency_components.end(); | 2323 b != latency_info[i].latency_components.end(); |
2263 ++b) { | 2324 ++b) { |
2264 if (b->first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || | 2325 if (b->first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || |
2265 b->first.first == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT) { | 2326 b->first.first == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT || |
| 2327 b->first.first == ui::WINDOW_OLD_SNAPSHOT_FRAME_NUMBER_COMPONENT) { |
2266 // Matches with GetLatencyComponentId | 2328 // Matches with GetLatencyComponentId |
2267 int routing_id = b->first.second & 0xffffffff; | 2329 int routing_id = b->first.second & 0xffffffff; |
2268 int process_id = (b->first.second >> 32) & 0xffffffff; | 2330 int process_id = (b->first.second >> 32) & 0xffffffff; |
2269 RenderWidgetHost* rwh = | 2331 RenderWidgetHost* rwh = |
2270 RenderWidgetHost::FromID(process_id, routing_id); | 2332 RenderWidgetHost::FromID(process_id, routing_id); |
2271 if (!rwh) { | 2333 if (!rwh) { |
2272 continue; | 2334 continue; |
2273 } | 2335 } |
2274 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); | 2336 RenderWidgetHostImpl* rwhi = RenderWidgetHostImpl::From(rwh); |
2275 if (rwhi_set.insert(rwhi).second) | 2337 if (rwhi_set.insert(rwhi).second) |
2276 rwhi->FrameSwapped(latency_info[i]); | 2338 rwhi->FrameSwapped(latency_info[i]); |
2277 } | 2339 } |
2278 } | 2340 } |
2279 } | 2341 } |
2280 } | 2342 } |
2281 | 2343 |
2282 void RenderWidgetHostImpl::AddLatencyInfoComponentIds( | 2344 void RenderWidgetHostImpl::AddLatencyInfoComponentIds( |
2283 ui::LatencyInfo* latency_info) { | 2345 ui::LatencyInfo* latency_info) { |
2284 ui::LatencyInfo::LatencyMap new_components; | 2346 ui::LatencyInfo::LatencyMap new_components; |
2285 ui::LatencyInfo::LatencyMap::iterator lc = | 2347 ui::LatencyInfo::LatencyMap::iterator lc = |
2286 latency_info->latency_components.begin(); | 2348 latency_info->latency_components.begin(); |
2287 while (lc != latency_info->latency_components.end()) { | 2349 while (lc != latency_info->latency_components.end()) { |
2288 ui::LatencyComponentType component_type = lc->first.first; | 2350 ui::LatencyComponentType component_type = lc->first.first; |
2289 if (component_type == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT) { | 2351 if (component_type == ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT || |
| 2352 component_type == ui::WINDOW_OLD_SNAPSHOT_FRAME_NUMBER_COMPONENT) { |
2290 // Generate a new component entry with the correct component ID | 2353 // Generate a new component entry with the correct component ID |
2291 ui::LatencyInfo::LatencyMap::key_type key = | 2354 ui::LatencyInfo::LatencyMap::key_type key = |
2292 std::make_pair(component_type, GetLatencyComponentId()); | 2355 std::make_pair(component_type, GetLatencyComponentId()); |
2293 new_components[key] = lc->second; | 2356 new_components[key] = lc->second; |
2294 | 2357 |
2295 // Remove the old entry | 2358 // Remove the old entry |
2296 latency_info->latency_components.erase(lc++); | 2359 latency_info->latency_components.erase(lc++); |
2297 } else { | 2360 } else { |
2298 ++lc; | 2361 ++lc; |
2299 } | 2362 } |
2300 } | 2363 } |
2301 | 2364 |
2302 // Add newly generated components into the latency info | 2365 // Add newly generated components into the latency info |
2303 for (lc = new_components.begin(); lc != new_components.end(); ++lc) { | 2366 for (lc = new_components.begin(); lc != new_components.end(); ++lc) { |
2304 latency_info->latency_components[lc->first] = lc->second; | 2367 latency_info->latency_components[lc->first] = lc->second; |
2305 } | 2368 } |
2306 } | 2369 } |
2307 | 2370 |
2308 SkBitmap::Config RenderWidgetHostImpl::PreferredReadbackFormat() { | 2371 SkBitmap::Config RenderWidgetHostImpl::PreferredReadbackFormat() { |
2309 if (view_) | 2372 if (view_) |
2310 return view_->PreferredReadbackFormat(); | 2373 return view_->PreferredReadbackFormat(); |
2311 return SkBitmap::kARGB_8888_Config; | 2374 return SkBitmap::kARGB_8888_Config; |
2312 } | 2375 } |
2313 | 2376 |
2314 } // namespace content | 2377 } // namespace content |
OLD | NEW |