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

Unified Diff: content/browser/media/capture/desktop_capture_device_aura.cc

Issue 965123002: Crash fix for desktop capture size calculations, and some minor things. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/media/capture/content_video_capture_device_core.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/media/capture/desktop_capture_device_aura.cc
diff --git a/content/browser/media/capture/desktop_capture_device_aura.cc b/content/browser/media/capture/desktop_capture_device_aura.cc
index 37979613dddf0572340bda84df472ae3df7c2033..de1a1093b38f828e7522573a7d7612a85c086d2b 100644
--- a/content/browser/media/capture/desktop_capture_device_aura.cc
+++ b/content/browser/media/capture/desktop_capture_device_aura.cc
@@ -145,7 +145,8 @@ class DesktopVideoCaptureMachine
scoped_ptr<cc::CopyOutputResult> result);
// Helper function to update cursor state.
- // |region_in_frame| defines the desktop bound in the captured frame.
+ // |region_in_frame| defines where the desktop is rendered in the captured
+ // frame.
// Returns the current cursor position in captured frame.
gfx::Point UpdateCursorState(const gfx::Rect& region_in_frame);
@@ -172,6 +173,7 @@ class DesktopVideoCaptureMachine
// Cursor state.
ui::Cursor last_cursor_;
+ gfx::Size desktop_size_when_cursor_last_updated_;
gfx::Point cursor_hot_point_;
SkBitmap scaled_cursor_bitmap_;
@@ -347,6 +349,7 @@ bool DesktopVideoCaptureMachine::ProcessCopyOutputResponse(
const ThreadSafeCaptureOracle::CaptureFrameCallback& capture_frame_cb,
scoped_ptr<cc::CopyOutputResult> result) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+
if (result->IsEmpty() || result->size().IsEmpty() || !desktop_window_)
return false;
@@ -368,6 +371,8 @@ bool DesktopVideoCaptureMachine::ProcessCopyOutputResponse(
base::TimeDelta(), false);
capture_frame_cb.Run(video_frame, start_time, true);
return true;
+ } else {
+ DCHECK(video_frame.get());
}
// Compute the dest size we want after the letterboxing resize. Make the
@@ -430,19 +435,33 @@ bool DesktopVideoCaptureMachine::ProcessCopyOutputResponse(
gfx::Point DesktopVideoCaptureMachine::UpdateCursorState(
const gfx::Rect& region_in_frame) {
const gfx::Rect desktop_bounds = desktop_window_->layer()->bounds();
+ if (desktop_bounds.IsEmpty()) {
+ // Return early to prevent divide-by-zero in calculations below.
+ ClearCursorState();
+ return gfx::Point();
+ }
+
gfx::NativeCursor cursor =
desktop_window_->GetHost()->last_cursor();
- if (last_cursor_ != cursor) {
+ if (last_cursor_ != cursor ||
+ desktop_size_when_cursor_last_updated_ != desktop_bounds.size()) {
SkBitmap cursor_bitmap;
if (ui::GetCursorBitmap(cursor, &cursor_bitmap, &cursor_hot_point_)) {
+ const int scaled_width = cursor_bitmap.width() *
+ region_in_frame.width() / desktop_bounds.width();
+ const int scaled_height = cursor_bitmap.height() *
+ region_in_frame.height() / desktop_bounds.height();
+ if (scaled_width <= 0 || scaled_height <= 0) {
+ ClearCursorState();
+ return gfx::Point();
+ }
scaled_cursor_bitmap_ = skia::ImageOperations::Resize(
cursor_bitmap,
skia::ImageOperations::RESIZE_BEST,
- cursor_bitmap.width() * region_in_frame.width() /
- desktop_bounds.width(),
- cursor_bitmap.height() * region_in_frame.height() /
- desktop_bounds.height());
+ scaled_width,
+ scaled_height);
last_cursor_ = cursor;
+ desktop_size_when_cursor_last_updated_ = desktop_bounds.size();
} else {
// Clear cursor state if ui::GetCursorBitmap failed so that we do not
// render cursor on the captured frame.
@@ -466,6 +485,7 @@ gfx::Point DesktopVideoCaptureMachine::UpdateCursorState(
void DesktopVideoCaptureMachine::ClearCursorState() {
last_cursor_ = ui::Cursor();
+ desktop_size_when_cursor_last_updated_ = gfx::Size();
cursor_hot_point_ = gfx::Point();
scaled_cursor_bitmap_.reset();
}
« no previous file with comments | « content/browser/media/capture/content_video_capture_device_core.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698