Commit 564e0673 authored by Dana Fried's avatar Dana Fried Committed by Commit Bot

Avoid capture thrash due to Windows focus flicker on video capture.

Unfortunately, a side-effect of the capture code we're currently using
is that it triggers an instantaneous loss and then regaining of mouse
hover over the current controls; this results in capture starting and
stopping again in a tight loop.

This change allows existing capture to continue until the first time a
result comes in and either (a) the page is done loading [which is
existing behavior] or (b) we've stopped observing the thumbnail. It
prevents a momentary shakeup in whehter the thumbnail is being observed
from locking the browser into the tight loop described above.

We still want to follow up and determine *why* (and on what platforms -
it might just be Windows) starting capture causes mouse hover to be lost;
if we can't fix the signal we may have to debounce it in the hover card
system to prevent unintended visual results.

Bug: 1019303
Change-Id: Iec0cba64398891d589d3cbe6d7abeab0e1e230b1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1891142
Commit-Queue: Dana Fried <dfried@chromium.org>
Commit-Queue: Collin Baker <collinbaker@chromium.org>
Reviewed-by: default avatarCollin Baker <collinbaker@chromium.org>
Auto-Submit: Dana Fried <dfried@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711008}
parent fb5abd41
......@@ -37,15 +37,17 @@ ThumbnailTabHelper::~ThumbnailTabHelper() {
void ThumbnailTabHelper::ThumbnailImageBeingObservedChanged(
bool is_being_observed) {
if (is_being_observed) {
if (!captured_loaded_thumbnail_since_tab_hidden_)
if (is_being_observed_ != is_being_observed) {
is_being_observed_ = is_being_observed;
if (is_being_observed && !captured_loaded_thumbnail_since_tab_hidden_)
StartVideoCapture();
} else {
StopVideoCapture();
}
}
bool ThumbnailTabHelper::ShouldKeepUpdatingThumbnail() const {
if (!is_being_observed_)
return false;
auto* tab_load_tracker = resource_coordinator::TabLoadTracker::Get();
if (tab_load_tracker &&
tab_load_tracker->GetLoadingState(web_contents()) !=
......@@ -99,29 +101,19 @@ void ThumbnailTabHelper::StoreThumbnail(const SkBitmap& bitmap) {
}
void ThumbnailTabHelper::StartVideoCapture() {
bool was_capturing = false;
if (video_capturer_) {
// Already capturing: We're already forcing rendering. Clear the capturer.
was_capturing = true;
video_capturer_->Stop();
video_capturer_.reset();
}
if (video_capturer_)
return;
// Get the WebContents' main view.
content::RenderWidgetHostView* const source_view = GetView();
if (!source_view) {
if (was_capturing)
web_contents()->DecrementCapturerCount();
if (!source_view)
return;
}
// Get the source size and scale.
const float scale_factor = source_view->GetDeviceScaleFactor();
const gfx::Size source_size = source_view->GetViewBounds().size();
if (source_size.IsEmpty()) {
web_contents()->DecrementCapturerCount();
if (source_size.IsEmpty())
return;
}
// Figure out how large we want the capture target to be.
last_frame_capture_info_ =
......@@ -129,9 +121,7 @@ void ThumbnailTabHelper::StartVideoCapture() {
/* include_scrollbars_in_capture */ true);
const gfx::Size& target_size = last_frame_capture_info_.target_size;
if (!was_capturing)
web_contents()->IncrementCapturerCount(target_size);
constexpr int kMaxFrameRate = 5;
video_capturer_ = source_view->CreateVideoCapturer();
video_capturer_->SetResolutionConstraints(target_size, target_size, false);
......
......@@ -108,6 +108,9 @@ class ThumbnailTabHelper
// The last known visibility WebContents visibility.
content::Visibility last_visibility_;
// Is the thumbnail being observed?
bool is_being_observed_ = false;
// Whether a thumbnail was captured while the tab was loaded, since the tab
// was last hidden.
bool captured_loaded_thumbnail_since_tab_hidden_ = false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment