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