blob: f70508cee15b6906c24e6d136632e3b3a524c0fd [file] [log] [blame]
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +00001/*
2 * Copyright (c) 2013 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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef MODULES_DESKTOP_CAPTURE_SHARED_DESKTOP_FRAME_H_
12#define MODULES_DESKTOP_CAPTURE_SHARED_DESKTOP_FRAME_H_
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000013
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020014#include "modules/desktop_capture/desktop_frame.h"
15#include "rtc_base/constructormagic.h"
16#include "rtc_base/refcount.h"
Niels Möller84255bb2017-10-06 13:43:23 +020017#include "rtc_base/refcountedobject.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "rtc_base/scoped_ref_ptr.h"
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000019
20namespace webrtc {
21
22// SharedDesktopFrame is a DesktopFrame that may have multiple instances all
23// sharing the same buffer.
24class SharedDesktopFrame : public DesktopFrame {
25 public:
Sergey Ulanov58000a02016-10-20 09:33:52 -070026 ~SharedDesktopFrame() override;
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000027
sergeyu5d910282016-06-07 16:41:58 -070028 static std::unique_ptr<SharedDesktopFrame> Wrap(
29 std::unique_ptr<DesktopFrame> desktop_frame);
30
31 // Deprecated.
32 // TODO(sergeyu): remove this method.
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000033 static SharedDesktopFrame* Wrap(DesktopFrame* desktop_frame);
34
Zijie He5acd9d02017-08-24 12:41:53 -070035 // Deprecated. Clients do not need to know the underlying DesktopFrame
36 // instance.
37 // TODO(zijiehe): Remove this method.
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000038 // Returns the underlying instance of DesktopFrame.
39 DesktopFrame* GetUnderlyingFrame();
40
Zijie He5acd9d02017-08-24 12:41:53 -070041 // Returns whether |this| and |other| share the underlying DesktopFrame.
42 bool ShareFrameWith(const SharedDesktopFrame& other) const;
43
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000044 // Creates a clone of this object.
sergeyu5d910282016-06-07 16:41:58 -070045 std::unique_ptr<SharedDesktopFrame> Share();
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000046
47 // Checks if the frame is currently shared. If it returns false it's
48 // guaranteed that there are no clones of the object.
49 bool IsShared();
50
51 private:
sergeyu5d910282016-06-07 16:41:58 -070052 typedef rtc::RefCountedObject<std::unique_ptr<DesktopFrame>> Core;
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000053
Peter Boström26b08602015-06-04 15:18:17 +020054 SharedDesktopFrame(rtc::scoped_refptr<Core> core);
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000055
Zijie He5acd9d02017-08-24 12:41:53 -070056 const rtc::scoped_refptr<Core> core_;
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000057
henrikg3c089d72015-09-16 05:37:44 -070058 RTC_DISALLOW_COPY_AND_ASSIGN(SharedDesktopFrame);
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000059};
60
61} // namespace webrtc
62
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020063#endif // MODULES_DESKTOP_CAPTURE_SHARED_DESKTOP_FRAME_H_