1 /*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/modules/desktop_capture/cropped_desktop_frame.h"
12
13 namespace webrtc {
14
15 // A DesktopFrame that is a sub-rect of another DesktopFrame.
16 class CroppedDesktopFrame : public DesktopFrame {
17 public:
18 CroppedDesktopFrame(DesktopFrame* frame, const DesktopRect& rect);
19
20 private:
21 rtc::scoped_ptr<DesktopFrame> frame_;
22
23 RTC_DISALLOW_COPY_AND_ASSIGN(CroppedDesktopFrame);
24 };
25
26 DesktopFrame*
CreateCroppedDesktopFrame(DesktopFrame * frame,const DesktopRect & rect)27 CreateCroppedDesktopFrame(DesktopFrame* frame, const DesktopRect& rect) {
28 if (!DesktopRect::MakeSize(frame->size()).ContainsRect(rect)) {
29 delete frame;
30 return NULL;
31 }
32
33 return new CroppedDesktopFrame(frame, rect);
34 }
35
CroppedDesktopFrame(DesktopFrame * frame,const DesktopRect & rect)36 CroppedDesktopFrame::CroppedDesktopFrame(DesktopFrame* frame,
37 const DesktopRect& rect)
38 : DesktopFrame(rect.size(),
39 frame->stride(),
40 frame->GetFrameDataAtPos(rect.top_left()),
41 frame->shared_memory()),
42 frame_(frame) {
43 }
44
45 } // namespace webrtc
46