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

Unified Diff: content/browser/devtools/protocol/page_handler.cc

Issue 1463813003: DevTools: optimize screencast for slower devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/devtools/protocol/page_handler.cc
diff --git a/content/browser/devtools/protocol/page_handler.cc b/content/browser/devtools/protocol/page_handler.cc
index c4aac86bb98135ded08b06918c24c75a53e25e93..3bef87095d10029d55697a2081c5fe6b353a7c0a 100644
--- a/content/browser/devtools/protocol/page_handler.cc
+++ b/content/browser/devtools/protocol/page_handler.cc
@@ -96,11 +96,11 @@ PageHandler::PageHandler()
screencast_quality_(kDefaultScreenshotQuality),
screencast_max_width_(-1),
screencast_max_height_(-1),
+ capture_every_nth_frame_(1),
capture_retry_count_(0),
has_compositor_frame_metadata_(false),
screencast_frame_sent_(0),
screencast_frame_acked_(0),
- processing_screencast_frame_(false),
color_picker_(new ColorPicker(base::Bind(
&PageHandler::OnColorPicked, base::Unretained(this)))),
host_(nullptr),
@@ -288,7 +288,8 @@ Response PageHandler::CanScreencast(bool* result) {
Response PageHandler::StartScreencast(const std::string* format,
const int* quality,
const int* max_width,
- const int* max_height) {
+ const int* max_height,
+ const int* every_nth_frame) {
RenderWidgetHostImpl* widget_host =
host_ ? host_->GetRenderWidgetHost() : nullptr;
if (!widget_host)
@@ -301,6 +302,8 @@ Response PageHandler::StartScreencast(const std::string* format,
screencast_quality_ = kDefaultScreenshotQuality;
screencast_max_width_ = max_width ? *max_width : -1;
screencast_max_height_ = max_height ? *max_height : -1;
+ screencast_frame_acked_ = screencast_frame_sent_;
+ capture_every_nth_frame_ = every_nth_frame ? *every_nth_frame : 1;
bool visible = !widget_host->is_hidden();
NotifyScreencastVisibility(visible);
@@ -372,12 +375,16 @@ void PageHandler::NotifyScreencastVisibility(bool visible) {
}
void PageHandler::InnerSwapCompositorFrame() {
+ if (!host_ || !host_->GetView())
+ return;
+
if (screencast_frame_sent_ - screencast_frame_acked_ >
- kMaxScreencastFramesInFlight || processing_screencast_frame_) {
+ kMaxScreencastFramesInFlight) {
return;
}
- if (!host_ || !host_->GetView())
+ static int global_frame_counter = 0;
dgozman 2015/11/20 22:53:23 With two different screencasts active it may happe
pfeldman 2015/11/20 23:18:25 Yep.
+ if (++global_frame_counter % capture_every_nth_frame_)
return;
RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
@@ -412,24 +419,24 @@ void PageHandler::InnerSwapCompositorFrame() {
gfx::ScaleSize(viewport_size_dip, scale)));
if (snapshot_size_dip.width() > 0 && snapshot_size_dip.height() > 0) {
- processing_screencast_frame_ = true;
gfx::Rect viewport_bounds_dip(gfx::ToRoundedSize(viewport_size_dip));
view->CopyFromCompositingSurface(
viewport_bounds_dip,
snapshot_size_dip,
base::Bind(&PageHandler::ScreencastFrameCaptured,
weak_factory_.GetWeakPtr(),
- last_compositor_frame_metadata_),
+ last_compositor_frame_metadata_,
+ ++screencast_frame_sent_),
kN32_SkColorType);
}
}
void PageHandler::ScreencastFrameCaptured(
const cc::CompositorFrameMetadata& metadata,
+ int frame_number,
const SkBitmap& bitmap,
ReadbackResponse response) {
if (response != READBACK_SUCCESS) {
- processing_screencast_frame_ = false;
if (capture_retry_count_) {
--capture_retry_count_;
base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
@@ -437,6 +444,7 @@ void PageHandler::ScreencastFrameCaptured(
weak_factory_.GetWeakPtr()),
base::TimeDelta::FromMilliseconds(kFrameRetryDelayMs));
}
+ --screencast_frame_sent_;
dgozman 2015/11/20 22:53:23 This violates the assumption of increasing screenc
pfeldman 2015/11/20 23:18:25 Not really.
return;
}
base::PostTaskAndReplyWithResult(
@@ -445,23 +453,27 @@ void PageHandler::ScreencastFrameCaptured(
base::Bind(&EncodeScreencastFrame,
bitmap, screencast_format_, screencast_quality_),
base::Bind(&PageHandler::ScreencastFrameEncoded,
- weak_factory_.GetWeakPtr(), metadata, base::Time::Now()));
+ weak_factory_.GetWeakPtr(), metadata,
+ frame_number, base::Time::Now()));
}
void PageHandler::ScreencastFrameEncoded(
const cc::CompositorFrameMetadata& metadata,
+ int frame_number,
const base::Time& timestamp,
const std::string& data) {
- processing_screencast_frame_ = false;
-
// Consider metadata empty in case it has no device scale factor.
- if (metadata.device_scale_factor == 0 || !host_ || data.empty())
+ if (metadata.device_scale_factor == 0 || !host_ || data.empty()) {
+ --screencast_frame_sent_;
return;
+ }
RenderWidgetHostViewBase* view = static_cast<RenderWidgetHostViewBase*>(
host_->GetView());
- if (!view)
+ if (!view) {
+ --screencast_frame_sent_;
return;
+ }
gfx::SizeF screen_size_dip =
gfx::ScaleSize(gfx::SizeF(view->GetPhysicalBackingSize()),
@@ -478,7 +490,7 @@ void PageHandler::ScreencastFrameEncoded(
client_->ScreencastFrame(ScreencastFrameParams::Create()
->set_data(data)
->set_metadata(param_metadata)
- ->set_frame_number(++screencast_frame_sent_));
+ ->set_frame_number(frame_number));
}
void PageHandler::ScreenshotCaptured(DevToolsCommandId command_id,
« no previous file with comments | « content/browser/devtools/protocol/page_handler.h ('k') | third_party/WebKit/Source/core/inspector/InspectorPageAgent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698