Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/devtools/protocol/page_handler.h" | 5 #include "content/browser/devtools/protocol/page_handler.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 463 | 463 |
| 464 if (frames_in_flight_ > kMaxScreencastFramesInFlight) | 464 if (frames_in_flight_ > kMaxScreencastFramesInFlight) |
| 465 return; | 465 return; |
| 466 | 466 |
| 467 if (++frame_counter_ % capture_every_nth_frame_) | 467 if (++frame_counter_ % capture_every_nth_frame_) |
| 468 return; | 468 return; |
| 469 | 469 |
| 470 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( | 470 RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>( |
| 471 host_->GetView()); | 471 host_->GetView()); |
| 472 // TODO(vkuzkokov): do not use previous frame metadata. | 472 // TODO(vkuzkokov): do not use previous frame metadata. |
| 473 // TODO(miu): RWHV to provide an API to provide actual rendering size. | |
|
dgozman
2017/02/28 19:13:52
I think that would help in devtools_frame_trace_re
miu
2017/03/01 01:17:02
Acknowledged.
| |
| 474 // http://crbug.com/73362 | |
| 473 cc::CompositorFrameMetadata& metadata = last_compositor_frame_metadata_; | 475 cc::CompositorFrameMetadata& metadata = last_compositor_frame_metadata_; |
| 474 | 476 |
| 475 gfx::SizeF viewport_size_dip = gfx::ScaleSize( | 477 gfx::SizeF viewport_size_dip = gfx::ScaleSize( |
| 476 metadata.scrollable_viewport_size, metadata.page_scale_factor); | 478 metadata.scrollable_viewport_size, metadata.page_scale_factor); |
| 477 gfx::SizeF screen_size_dip = | 479 gfx::SizeF screen_size_dip = |
| 478 gfx::ScaleSize(gfx::SizeF(view->GetPhysicalBackingSize()), | 480 gfx::ScaleSize(gfx::SizeF(view->GetPhysicalBackingSize()), |
| 479 1 / metadata.device_scale_factor); | 481 1 / metadata.device_scale_factor); |
| 480 | 482 |
| 481 content::ScreenInfo screen_info; | 483 content::ScreenInfo screen_info; |
| 482 GetWebContents()->GetView()->GetScreenInfo(&screen_info); | 484 GetWebContents()->GetView()->GetScreenInfo(&screen_info); |
| 483 double device_scale_factor = screen_info.device_scale_factor; | 485 double device_scale_factor = screen_info.device_scale_factor; |
| 484 double scale = 1; | 486 double scale = 1; |
| 485 | 487 |
| 486 if (screencast_max_width_ > 0) { | 488 if (screencast_max_width_ > 0) { |
| 487 double max_width_dip = screencast_max_width_ / device_scale_factor; | 489 double max_width_dip = screencast_max_width_ / device_scale_factor; |
| 488 scale = std::min(scale, max_width_dip / screen_size_dip.width()); | 490 scale = std::min(scale, max_width_dip / screen_size_dip.width()); |
| 489 } | 491 } |
| 490 if (screencast_max_height_ > 0) { | 492 if (screencast_max_height_ > 0) { |
| 491 double max_height_dip = screencast_max_height_ / device_scale_factor; | 493 double max_height_dip = screencast_max_height_ / device_scale_factor; |
| 492 scale = std::min(scale, max_height_dip / screen_size_dip.height()); | 494 scale = std::min(scale, max_height_dip / screen_size_dip.height()); |
| 493 } | 495 } |
| 494 | 496 |
| 495 if (scale <= 0) | 497 if (scale <= 0) |
| 496 scale = 0.1; | 498 scale = 0.1; |
| 497 | 499 |
| 498 gfx::Size snapshot_size_dip(gfx::ToRoundedSize( | 500 gfx::Size snapshot_size_dip(gfx::ToRoundedSize( |
| 499 gfx::ScaleSize(viewport_size_dip, scale))); | 501 gfx::ScaleSize(viewport_size_dip, scale))); |
| 500 | 502 |
| 501 if (snapshot_size_dip.width() > 0 && snapshot_size_dip.height() > 0) { | 503 if (snapshot_size_dip.width() > 0 && snapshot_size_dip.height() > 0) { |
| 502 gfx::Rect viewport_bounds_dip(gfx::ToRoundedSize(viewport_size_dip)); | 504 view->CopyFromSurface( |
| 503 view->CopyFromCompositingSurface( | 505 gfx::Rect(), snapshot_size_dip, |
| 504 viewport_bounds_dip, snapshot_size_dip, | |
| 505 base::Bind(&PageHandler::ScreencastFrameCaptured, | 506 base::Bind(&PageHandler::ScreencastFrameCaptured, |
| 506 weak_factory_.GetWeakPtr(), | 507 weak_factory_.GetWeakPtr(), |
| 507 base::Passed(last_compositor_frame_metadata_.Clone())), | 508 base::Passed(last_compositor_frame_metadata_.Clone())), |
| 508 kN32_SkColorType); | 509 kN32_SkColorType); |
| 509 frames_in_flight_++; | 510 frames_in_flight_++; |
| 510 } | 511 } |
| 511 } | 512 } |
| 512 | 513 |
| 513 void PageHandler::ScreencastFrameCaptured(cc::CompositorFrameMetadata metadata, | 514 void PageHandler::ScreencastFrameCaptured(cc::CompositorFrameMetadata metadata, |
| 514 const SkBitmap& bitmap, | 515 const SkBitmap& bitmap, |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 588 Response PageHandler::StopLoading() { | 589 Response PageHandler::StopLoading() { |
| 589 WebContentsImpl* web_contents = GetWebContents(); | 590 WebContentsImpl* web_contents = GetWebContents(); |
| 590 if (!web_contents) | 591 if (!web_contents) |
| 591 return Response::InternalError(); | 592 return Response::InternalError(); |
| 592 web_contents->Stop(); | 593 web_contents->Stop(); |
| 593 return Response::OK(); | 594 return Response::OK(); |
| 594 } | 595 } |
| 595 | 596 |
| 596 } // namespace protocol | 597 } // namespace protocol |
| 597 } // namespace content | 598 } // namespace content |
| OLD | NEW |