Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: content/browser/renderer_host/render_widget_host_impl.cc

Issue 190693002: Migrate Telemetry from beginWindowSnapshotPNG to Page.captureScreenshot (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Aligned with the existing API Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 ignore_input_events_(false), 202 ignore_input_events_(false),
203 input_method_active_(false), 203 input_method_active_(false),
204 text_direction_updated_(false), 204 text_direction_updated_(false),
205 text_direction_(blink::WebTextDirectionLeftToRight), 205 text_direction_(blink::WebTextDirectionLeftToRight),
206 text_direction_canceled_(false), 206 text_direction_canceled_(false),
207 suppress_next_char_events_(false), 207 suppress_next_char_events_(false),
208 pending_mouse_lock_request_(false), 208 pending_mouse_lock_request_(false),
209 allow_privileged_mouse_lock_(false), 209 allow_privileged_mouse_lock_(false),
210 has_touch_handler_(false), 210 has_touch_handler_(false),
211 weak_factory_(this), 211 weak_factory_(this),
212 last_input_number_(static_cast<int64>(GetProcess()->GetID()) << 32) { 212 last_input_number_(static_cast<int64>(GetProcess()->GetID()) << 32),
213 next_browser_snapshot_id_(0) {
213 CHECK(delegate_); 214 CHECK(delegate_);
214 if (routing_id_ == MSG_ROUTING_NONE) { 215 if (routing_id_ == MSG_ROUTING_NONE) {
215 routing_id_ = process_->GetNextRoutingID(); 216 routing_id_ = process_->GetNextRoutingID();
216 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer( 217 surface_id_ = GpuSurfaceTracker::Get()->AddSurfaceForRenderer(
217 process_->GetID(), 218 process_->GetID(),
218 routing_id_); 219 routing_id_);
219 } else { 220 } else {
220 // TODO(piman): This is a O(N) lookup, where we could forward the 221 // TODO(piman): This is a O(N) lookup, where we could forward the
221 // information from the RenderWidgetHelper. The problem is that doing so 222 // information from the RenderWidgetHelper. The problem is that doing so
222 // currently leaks outside of content all the way to chrome classes, and 223 // currently leaks outside of content all the way to chrome classes, and
(...skipping 995 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 1219
1219 pending_snapshots_.push(callback); 1220 pending_snapshots_.push(callback);
1220 1221
1221 gfx::Rect copy_rect = src_subrect.IsEmpty() ? 1222 gfx::Rect copy_rect = src_subrect.IsEmpty() ?
1222 gfx::Rect(view_->GetViewBounds().size()) : src_subrect; 1223 gfx::Rect(view_->GetViewBounds().size()) : src_subrect;
1223 1224
1224 gfx::Rect copy_rect_in_pixel = ConvertViewRectToPixel(view_, copy_rect); 1225 gfx::Rect copy_rect_in_pixel = ConvertViewRectToPixel(view_, copy_rect);
1225 Send(new ViewMsg_Snapshot(GetRoutingID(), copy_rect_in_pixel)); 1226 Send(new ViewMsg_Snapshot(GetRoutingID(), copy_rect_in_pixel));
1226 } 1227 }
1227 1228
1229 void RenderWidgetHostImpl::GetSnapshotFromBrowser(
1230 const base::Callback<void(const unsigned char*,size_t)> callback) {
1231 int id = next_browser_snapshot_id_++;
1232 pending_browser_snapshots_.insert(std::make_pair(id, callback));
1233 Send(new ViewMsg_ForceRedraw(GetRoutingID(), id));
1234 }
1235
1228 void RenderWidgetHostImpl::OnSnapshot(bool success, 1236 void RenderWidgetHostImpl::OnSnapshot(bool success,
1229 const SkBitmap& bitmap) { 1237 const SkBitmap& bitmap) {
1230 if (pending_snapshots_.size() == 0) { 1238 if (pending_snapshots_.size() == 0) {
1231 LOG(ERROR) << "RenderWidgetHostImpl::OnSnapshot: " 1239 LOG(ERROR) << "RenderWidgetHostImpl::OnSnapshot: "
1232 "Received a snapshot that was not requested."; 1240 "Received a snapshot that was not requested.";
1233 return; 1241 return;
1234 } 1242 }
1235 1243
1236 base::Callback<void(bool, const SkBitmap&)> callback = 1244 base::Callback<void(bool, const SkBitmap&)> callback =
1237 pending_snapshots_.front(); 1245 pending_snapshots_.front();
(...skipping 1142 matching lines...) Expand 10 before | Expand all | Expand 10 after
2380 1000000, 2388 1000000,
2381 100); 2389 100);
2382 } 2390 }
2383 } 2391 }
2384 2392
2385 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { 2393 void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) {
2386 ui::LatencyInfo::LatencyComponent window_snapshot_component; 2394 ui::LatencyInfo::LatencyComponent window_snapshot_component;
2387 if (latency_info.FindLatency(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, 2395 if (latency_info.FindLatency(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT,
2388 GetLatencyComponentId(), 2396 GetLatencyComponentId(),
2389 &window_snapshot_component)) { 2397 &window_snapshot_component)) {
2390 WindowSnapshotReachedScreen( 2398 // While GpuBenchmarking V8 extension coexists with Page.captureScreenshot
2391 static_cast<int>(window_snapshot_component.sequence_number)); 2399 // they share the same LatencyComponentType. To avoid confusion only one
2400 // of the two methods should be used when testing a specific renderer.
Ken Russell (switch to Gerrit) 2014/03/11 18:22:29 That's a non-intuitive restriction that leaves the
Vladislav Kaznacheev 2014/03/12 09:24:24 Fair enough. I will try and remove the old GPU ben
2401 // TODO(kaznacheev): Remove this method when GpuBenchmarking V8 extension is
2402 // retired.
2403 int id = static_cast<int>(window_snapshot_component.sequence_number);
2404 if (pending_browser_snapshots_.count(id))
2405 WindowSnapshotReachedScreen(id);
2406 else
2407 WindowSnapshotReachedScreenUnsafe(id);
2392 } 2408 }
2393 2409
2394 ui::LatencyInfo::LatencyComponent rwh_component; 2410 ui::LatencyInfo::LatencyComponent rwh_component;
2395 ui::LatencyInfo::LatencyComponent swap_component; 2411 ui::LatencyInfo::LatencyComponent swap_component;
2396 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 2412 if (!latency_info.FindLatency(ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
2397 GetLatencyComponentId(), 2413 GetLatencyComponentId(),
2398 &rwh_component) || 2414 &rwh_component) ||
2399 !latency_info.FindLatency( 2415 !latency_info.FindLatency(
2400 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 2416 ui::INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT,
2401 0, &swap_component)) { 2417 0, &swap_component)) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2436 std::vector<unsigned char> png_vector; 2452 std::vector<unsigned char> png_vector;
2437 Send(new ViewMsg_WindowSnapshotCompleted( 2453 Send(new ViewMsg_WindowSnapshotCompleted(
2438 routing_id, snapshot_id, gfx::Size(), png_vector)); 2454 routing_id, snapshot_id, gfx::Size(), png_vector));
2439 return; 2455 return;
2440 } 2456 }
2441 2457
2442 Send(new ViewMsg_WindowSnapshotCompleted( 2458 Send(new ViewMsg_WindowSnapshotCompleted(
2443 routing_id, snapshot_id, snapshot_size, png_data->data())); 2459 routing_id, snapshot_id, snapshot_size, png_data->data()));
2444 } 2460 }
2445 2461
2446 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { 2462 void RenderWidgetHostImpl::WindowSnapshotReachedScreenUnsafe(int snapshot_id) {
2447 DCHECK(base::MessageLoopForUI::IsCurrent()); 2463 DCHECK(base::MessageLoopForUI::IsCurrent());
2448 2464
2449 std::vector<unsigned char> png; 2465 std::vector<unsigned char> png;
2450 2466
2451 // This feature is behind the kEnableGpuBenchmarking command line switch 2467 // This feature is behind the kEnableGpuBenchmarking command line switch
2452 // because it poses security concerns and should only be used for testing. 2468 // because it poses security concerns and should only be used for testing.
2453 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 2469 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
2454 if (!command_line.HasSwitch(cc::switches::kEnableGpuBenchmarking)) { 2470 if (!command_line.HasSwitch(cc::switches::kEnableGpuBenchmarking)) {
2455 Send(new ViewMsg_WindowSnapshotCompleted( 2471 Send(new ViewMsg_WindowSnapshotCompleted(
2456 GetRoutingID(), snapshot_id, gfx::Size(), png)); 2472 GetRoutingID(), snapshot_id, gfx::Size(), png));
(...skipping 15 matching lines...) Expand all
2472 GetView()->GetNativeView(), 2488 GetView()->GetNativeView(),
2473 snapshot_bounds, 2489 snapshot_bounds,
2474 base::ThreadTaskRunnerHandle::Get(), 2490 base::ThreadTaskRunnerHandle::Get(),
2475 base::Bind(&RenderWidgetHostImpl::WindowSnapshotAsyncCallback, 2491 base::Bind(&RenderWidgetHostImpl::WindowSnapshotAsyncCallback,
2476 weak_factory_.GetWeakPtr(), 2492 weak_factory_.GetWeakPtr(),
2477 GetRoutingID(), 2493 GetRoutingID(),
2478 snapshot_id, 2494 snapshot_id,
2479 snapshot_size)); 2495 snapshot_size));
2480 } 2496 }
2481 2497
2498 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) {
2499 DCHECK(base::MessageLoopForUI::IsCurrent());
2500
2501 gfx::Rect view_bounds = GetView()->GetViewBounds();
2502 gfx::Rect snapshot_bounds(view_bounds.size());
2503
2504 std::vector<unsigned char> png;
2505 if (ui::GrabViewSnapshot(
2506 GetView()->GetNativeView(), &png, snapshot_bounds)) {
2507 OnSnapshotDataReceived(snapshot_id, &png.front(), png.size());
2508 return;
2509 }
2510
2511 ui::GrabViewSnapshotAsync(
2512 GetView()->GetNativeView(),
2513 snapshot_bounds,
2514 base::ThreadTaskRunnerHandle::Get(),
2515 base::Bind(&RenderWidgetHostImpl::OnSnapshotDataReceivedAsync,
2516 weak_factory_.GetWeakPtr(),
2517 snapshot_id));
2518 }
2519
2520 void RenderWidgetHostImpl::OnSnapshotDataReceived(int snapshot_id,
2521 const unsigned char* data,
2522 size_t size) {
2523 // Any pending snapshots with a lower ID than the one received are considered
2524 // to be implicitly complete, and returned the same snapshot data.
2525 PendingSnapshotMap::iterator it = pending_browser_snapshots_.begin();
2526 while(it != pending_browser_snapshots_.end()) {
2527 if (it->first <= snapshot_id) {
2528 it->second.Run(data, size);
2529 pending_browser_snapshots_.erase(it++);
2530 } else {
2531 ++it;
2532 }
2533 }
2534 }
2535
2536 void RenderWidgetHostImpl::OnSnapshotDataReceivedAsync(
2537 int snapshot_id,
2538 scoped_refptr<base::RefCountedBytes> png_data) {
2539 if (png_data)
2540 OnSnapshotDataReceived(snapshot_id, png_data->front(), png_data->size());
2541 else
2542 OnSnapshotDataReceived(snapshot_id, NULL, 0);
2543 }
2544
2482 // static 2545 // static
2483 void RenderWidgetHostImpl::CompositorFrameDrawn( 2546 void RenderWidgetHostImpl::CompositorFrameDrawn(
2484 const std::vector<ui::LatencyInfo>& latency_info) { 2547 const std::vector<ui::LatencyInfo>& latency_info) {
2485 for (size_t i = 0; i < latency_info.size(); i++) { 2548 for (size_t i = 0; i < latency_info.size(); i++) {
2486 std::set<RenderWidgetHostImpl*> rwhi_set; 2549 std::set<RenderWidgetHostImpl*> rwhi_set;
2487 for (ui::LatencyInfo::LatencyMap::const_iterator b = 2550 for (ui::LatencyInfo::LatencyMap::const_iterator b =
2488 latency_info[i].latency_components.begin(); 2551 latency_info[i].latency_components.begin();
2489 b != latency_info[i].latency_components.end(); 2552 b != latency_info[i].latency_components.end();
2490 ++b) { 2553 ++b) {
2491 if (b->first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || 2554 if (b->first.first == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT ||
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2526 } 2589 }
2527 } 2590 }
2528 2591
2529 // Add newly generated components into the latency info 2592 // Add newly generated components into the latency info
2530 for (lc = new_components.begin(); lc != new_components.end(); ++lc) { 2593 for (lc = new_components.begin(); lc != new_components.end(); ++lc) {
2531 latency_info->latency_components[lc->first] = lc->second; 2594 latency_info->latency_components[lc->first] = lc->second;
2532 } 2595 }
2533 } 2596 }
2534 2597
2535 } // namespace content 2598 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698