Line data Source code
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 <memory>
12 :
13 : #include "webrtc/modules/desktop_capture/cropped_desktop_frame.h"
14 :
15 : #include "webrtc/base/constructormagic.h"
16 :
17 : namespace webrtc {
18 :
19 : // A DesktopFrame that is a sub-rect of another DesktopFrame.
20 0 : class CroppedDesktopFrame : public DesktopFrame {
21 : public:
22 : CroppedDesktopFrame(std::unique_ptr<DesktopFrame> frame,
23 : const DesktopRect& rect);
24 :
25 : private:
26 : std::unique_ptr<DesktopFrame> frame_;
27 :
28 : RTC_DISALLOW_COPY_AND_ASSIGN(CroppedDesktopFrame);
29 : };
30 :
31 0 : std::unique_ptr<DesktopFrame> CreateCroppedDesktopFrame(
32 : std::unique_ptr<DesktopFrame> frame,
33 : const DesktopRect& rect) {
34 0 : if (!DesktopRect::MakeSize(frame->size()).ContainsRect(rect))
35 0 : return nullptr;
36 :
37 : return std::unique_ptr<DesktopFrame>(
38 0 : new CroppedDesktopFrame(std::move(frame), rect));
39 : }
40 :
41 0 : CroppedDesktopFrame::CroppedDesktopFrame(std::unique_ptr<DesktopFrame> frame,
42 0 : const DesktopRect& rect)
43 : : DesktopFrame(rect.size(),
44 : frame->stride(),
45 0 : frame->GetFrameDataAtPos(rect.top_left()),
46 0 : frame->shared_memory()) {
47 0 : frame_ = std::move(frame);
48 0 : }
49 :
50 : } // namespace webrtc
|