Chromium Code Reviews| 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 1435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1446 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); | 1446 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE))); |
| 1447 } | 1447 } |
| 1448 #endif | 1448 #endif |
| 1449 pending_browser_snapshots_.insert(std::make_pair(id, callback)); | 1449 pending_browser_snapshots_.insert(std::make_pair(id, callback)); |
| 1450 ui::LatencyInfo latency_info; | 1450 ui::LatencyInfo latency_info; |
| 1451 latency_info.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, 0, | 1451 latency_info.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, 0, |
| 1452 id); | 1452 id); |
| 1453 Send(new ViewMsg_ForceRedraw(GetRoutingID(), latency_info)); | 1453 Send(new ViewMsg_ForceRedraw(GetRoutingID(), latency_info)); |
| 1454 } | 1454 } |
| 1455 | 1455 |
| 1456 void RenderWidgetHostImpl::GetSurfaceSnapshotFromBrowser( | |
| 1457 const GetSurfaceSnapshotFromBrowserCallback& callback) { | |
| 1458 int id = next_browser_snapshot_id_++; | |
| 1459 | |
| 1460 pending_surface_browser_snapshots_.insert(std::make_pair(id, callback)); | |
| 1461 ui::LatencyInfo latency_info; | |
| 1462 latency_info.AddLatencyNumber(ui::WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT, 0, | |
| 1463 id); | |
| 1464 Send(new ViewMsg_ForceRedraw(GetRoutingID(), latency_info)); | |
| 1465 } | |
| 1466 | |
| 1456 const NativeWebKeyboardEvent* | 1467 const NativeWebKeyboardEvent* |
| 1457 RenderWidgetHostImpl::GetLastKeyboardEvent() const { | 1468 RenderWidgetHostImpl::GetLastKeyboardEvent() const { |
| 1458 return input_router_->GetLastKeyboardEvent(); | 1469 return input_router_->GetLastKeyboardEvent(); |
| 1459 } | 1470 } |
| 1460 | 1471 |
| 1461 void RenderWidgetHostImpl::SelectionChanged(const base::string16& text, | 1472 void RenderWidgetHostImpl::SelectionChanged(const base::string16& text, |
| 1462 uint32_t offset, | 1473 uint32_t offset, |
| 1463 const gfx::Range& range) { | 1474 const gfx::Range& range) { |
| 1464 if (view_) | 1475 if (view_) |
| 1465 view_->SelectionChanged(text, static_cast<size_t>(offset), range); | 1476 view_->SelectionChanged(text, static_cast<size_t>(offset), range); |
| (...skipping 887 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2353 is_running_navigation_hint_task); | 2364 is_running_navigation_hint_task); |
| 2354 } | 2365 } |
| 2355 | 2366 |
| 2356 void RenderWidgetHostImpl::DidReceiveRendererFrame() { | 2367 void RenderWidgetHostImpl::DidReceiveRendererFrame() { |
| 2357 view_->DidReceiveRendererFrame(); | 2368 view_->DidReceiveRendererFrame(); |
| 2358 } | 2369 } |
| 2359 | 2370 |
| 2360 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { | 2371 void RenderWidgetHostImpl::WindowSnapshotReachedScreen(int snapshot_id) { |
| 2361 DCHECK(base::MessageLoopForUI::IsCurrent()); | 2372 DCHECK(base::MessageLoopForUI::IsCurrent()); |
| 2362 | 2373 |
| 2374 if (!pending_surface_browser_snapshots_.empty()) { | |
| 2375 GetView()->CopyFromSurface( | |
| 2376 gfx::Rect(), gfx::Size(), | |
| 2377 base::Bind(&RenderWidgetHostImpl::OnSnapshotFromSurfaceReceived, | |
| 2378 weak_factory_.GetWeakPtr(), snapshot_id, 0), | |
| 2379 kN32_SkColorType); | |
| 2380 } | |
| 2381 | |
| 2382 if (!pending_browser_snapshots_.empty()) { | |
| 2363 #if defined(OS_ANDROID) | 2383 #if defined(OS_ANDROID) |
| 2364 // On Android, call sites should pass in the bounds with correct offset | 2384 // On Android, call sites should pass in the bounds with correct offset |
| 2365 // to capture the intended content area. | 2385 // to capture the intended content area. |
| 2366 gfx::Rect snapshot_bounds(GetView()->GetViewBounds()); | 2386 gfx::Rect snapshot_bounds(GetView()->GetViewBounds()); |
| 2367 snapshot_bounds.Offset(0, GetView()->GetNativeView()->content_offset().y()); | 2387 snapshot_bounds.Offset(0, GetView()->GetNativeView()->content_offset().y()); |
| 2368 #else | 2388 #else |
| 2369 gfx::Rect snapshot_bounds(GetView()->GetViewBounds().size()); | 2389 gfx::Rect snapshot_bounds(GetView()->GetViewBounds().size()); |
| 2370 #endif | 2390 #endif |
| 2371 | 2391 |
| 2372 gfx::Image image; | 2392 gfx::Image image; |
| 2373 if (ui::GrabViewSnapshot(GetView()->GetNativeView(), snapshot_bounds, | 2393 if (ui::GrabViewSnapshot(GetView()->GetNativeView(), snapshot_bounds, |
| 2374 &image)) { | 2394 &image)) { |
| 2375 OnSnapshotReceived(snapshot_id, image); | 2395 OnSnapshotReceived(snapshot_id, image); |
| 2396 return; | |
| 2397 } | |
| 2398 | |
| 2399 ui::GrabViewSnapshotAsync( | |
| 2400 GetView()->GetNativeView(), snapshot_bounds, | |
| 2401 base::Bind(&RenderWidgetHostImpl::OnSnapshotReceived, | |
| 2402 weak_factory_.GetWeakPtr(), snapshot_id)); | |
| 2403 } | |
| 2404 } | |
| 2405 | |
| 2406 void RenderWidgetHostImpl::OnSnapshotFromSurfaceReceived( | |
| 2407 int snapshot_id, | |
| 2408 int retry_count, | |
| 2409 const SkBitmap& bitmap, | |
| 2410 ReadbackResponse response) { | |
| 2411 static const int kMaxRetries = 5; | |
|
dgozman
2017/03/08 19:21:36
Why do we need retries?
dvallet
2017/03/09 06:19:47
I copied this code from Eric's patch https://coder
Eric Seckler
2017/03/09 09:55:22
Yup, and it also mimics
https://cs.chromium.org/ch
| |
| 2412 if (response != READBACK_SUCCESS && retry_count < kMaxRetries) { | |
| 2413 GetView()->CopyFromSurface( | |
| 2414 gfx::Rect(), gfx::Size(), | |
| 2415 base::Bind(&RenderWidgetHostImpl::OnSnapshotFromSurfaceReceived, | |
| 2416 weak_factory_.GetWeakPtr(), snapshot_id, retry_count + 1), | |
| 2417 kN32_SkColorType); | |
| 2376 return; | 2418 return; |
| 2377 } | 2419 } |
| 2378 | 2420 // Any pending snapshots with a lower ID than the one received are considered |
| 2379 ui::GrabViewSnapshotAsync( | 2421 // to be implicitly complete, and returned the same snapshot data. |
| 2380 GetView()->GetNativeView(), snapshot_bounds, | 2422 PendingSnapshotFromSurfaceMap::iterator it = |
| 2381 base::Bind(&RenderWidgetHostImpl::OnSnapshotReceived, | 2423 pending_surface_browser_snapshots_.begin(); |
| 2382 weak_factory_.GetWeakPtr(), snapshot_id)); | 2424 while (it != pending_surface_browser_snapshots_.end()) { |
| 2425 if (it->first <= snapshot_id) { | |
| 2426 it->second.Run(bitmap); | |
| 2427 pending_surface_browser_snapshots_.erase(it++); | |
| 2428 } else { | |
| 2429 ++it; | |
| 2430 } | |
| 2431 } | |
| 2383 } | 2432 } |
| 2384 | 2433 |
| 2385 void RenderWidgetHostImpl::OnSnapshotReceived(int snapshot_id, | 2434 void RenderWidgetHostImpl::OnSnapshotReceived(int snapshot_id, |
| 2386 const gfx::Image& image) { | 2435 const gfx::Image& image) { |
| 2387 // Any pending snapshots with a lower ID than the one received are considered | 2436 // Any pending snapshots with a lower ID than the one received are considered |
| 2388 // to be implicitly complete, and returned the same snapshot data. | 2437 // to be implicitly complete, and returned the same snapshot data. |
| 2389 PendingSnapshotMap::iterator it = pending_browser_snapshots_.begin(); | 2438 PendingSnapshotMap::iterator it = pending_browser_snapshots_.begin(); |
| 2390 while (it != pending_browser_snapshots_.end()) { | 2439 while (it != pending_browser_snapshots_.end()) { |
| 2391 if (it->first <= snapshot_id) { | 2440 if (it->first <= snapshot_id) { |
| 2392 it->second.Run(image); | 2441 it->second.Run(image); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2514 // different from the receiver's. | 2563 // different from the receiver's. |
| 2515 file_system_file.url = | 2564 file_system_file.url = |
| 2516 GURL(storage::GetIsolatedFileSystemRootURIString( | 2565 GURL(storage::GetIsolatedFileSystemRootURIString( |
| 2517 file_system_url.origin(), filesystem_id, std::string()) | 2566 file_system_url.origin(), filesystem_id, std::string()) |
| 2518 .append(register_name)); | 2567 .append(register_name)); |
| 2519 file_system_file.filesystem_id = filesystem_id; | 2568 file_system_file.filesystem_id = filesystem_id; |
| 2520 } | 2569 } |
| 2521 } | 2570 } |
| 2522 | 2571 |
| 2523 } // namespace content | 2572 } // namespace content |
| OLD | NEW |