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,