blob: 0216768914d1c7a8a6ba5d1deb37b85a368f3c50 [file] [log] [blame]
jiayl@webrtc.org0e710702014-11-11 18:15:55 +00001/*
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
13namespace webrtc {
14
15// A DesktopFrame that is a sub-rect of another DesktopFrame.
16class CroppedDesktopFrame : public DesktopFrame {
17 public:
18 CroppedDesktopFrame(DesktopFrame* frame, const DesktopRect& rect);
19
20 private:
21 scoped_ptr<DesktopFrame> frame_;
22
23 DISALLOW_COPY_AND_ASSIGN(CroppedDesktopFrame);
24};
25
26DesktopFrame*
27CreateCroppedDesktopFrame(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
36CroppedDesktopFrame::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