From 9c0914f93801eb0c081ae733bd744290e17e5bef Mon Sep 17 00:00:00 2001 From: Zijie He Date: Wed, 26 Jul 2017 17:52:38 -0700 Subject: [PATCH] Do not crop DesktopFrame if the size won't change CreateCroppedDesktopFrame() does not need to create a CroppedDesktopFrame if the size won't change. Bug: webrtc:8039 Change-Id: Ie6789a4b473b69bced94c4a25a68f1da6bb3510e Reviewed-on: https://chromium-review.googlesource.com/587808 Commit-Queue: Zijie He Reviewed-by: Jamie Walch Cr-Commit-Position: refs/heads/master@{#19163} --- .../modules/desktop_capture/cropped_desktop_frame.cc | 10 +++++++++- webrtc/modules/desktop_capture/cropped_desktop_frame.h | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/webrtc/modules/desktop_capture/cropped_desktop_frame.cc b/webrtc/modules/desktop_capture/cropped_desktop_frame.cc index 9d4d123212..5aa1449447 100644 --- a/webrtc/modules/desktop_capture/cropped_desktop_frame.cc +++ b/webrtc/modules/desktop_capture/cropped_desktop_frame.cc @@ -12,6 +12,7 @@ #include "webrtc/modules/desktop_capture/cropped_desktop_frame.h" +#include "webrtc/rtc_base/checks.h" #include "webrtc/rtc_base/constructormagic.h" namespace webrtc { @@ -31,8 +32,15 @@ class CroppedDesktopFrame : public DesktopFrame { std::unique_ptr CreateCroppedDesktopFrame( std::unique_ptr frame, const DesktopRect& rect) { - if (!DesktopRect::MakeSize(frame->size()).ContainsRect(rect)) + RTC_DCHECK(frame); + + if (!DesktopRect::MakeSize(frame->size()).ContainsRect(rect)) { return nullptr; + } + + if (frame->size().equals(rect.size())) { + return frame; + } return std::unique_ptr( new CroppedDesktopFrame(std::move(frame), rect)); diff --git a/webrtc/modules/desktop_capture/cropped_desktop_frame.h b/webrtc/modules/desktop_capture/cropped_desktop_frame.h index 42ae587acb..107fe7f4ca 100644 --- a/webrtc/modules/desktop_capture/cropped_desktop_frame.h +++ b/webrtc/modules/desktop_capture/cropped_desktop_frame.h @@ -15,6 +15,10 @@ namespace webrtc { +// Creates a DesktopFrame to contain only the area of |rect| in the original +// |frame|. +// |frame| should not be nullptr. |rect| is in |frame| coordinate, i.e. +// |frame|->top_left() does not impact the area of |rect|. // Returns nullptr frame if |rect| is not contained by the bounds of |frame|. std::unique_ptr CreateCroppedDesktopFrame( std::unique_ptr frame,