blob: fd862d7f2135e692e06adffbbd9935218ee07ca3 [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
Yves Gerey3e707812018-11-28 16:47:49 +010014#include <memory>
15
Mirko Bonadeid9708072019-01-25 20:26:48 +010016#include "api/scoped_refptr.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "modules/desktop_capture/desktop_frame.h"
Steve Anton10542f22019-01-11 09:11:00 -080018#include "rtc_base/constructor_magic.h"
19#include "rtc_base/ref_counted_object.h"
Mirko Bonadeiac194142018-10-22 17:08:37 +020020#include "rtc_base/system/rtc_export.h"
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000021
22namespace webrtc {
23
24// SharedDesktopFrame is a DesktopFrame that may have multiple instances all
25// sharing the same buffer.
Mirko Bonadeiac194142018-10-22 17:08:37 +020026class RTC_EXPORT SharedDesktopFrame : public DesktopFrame {
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000027 public:
Sergey Ulanov58000a02016-10-20 09:33:52 -070028 ~SharedDesktopFrame() override;
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000029
sergeyu5d910282016-06-07 16:41:58 -070030 static std::unique_ptr<SharedDesktopFrame> Wrap(
31 std::unique_ptr<DesktopFrame> desktop_frame);
32
33 // Deprecated.
34 // TODO(sergeyu): remove this method.
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000035 static SharedDesktopFrame* Wrap(DesktopFrame* desktop_frame);
36
Zijie He5acd9d02017-08-24 12:41:53 -070037 // Deprecated. Clients do not need to know the underlying DesktopFrame
38 // instance.
39 // TODO(zijiehe): Remove this method.
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000040 // Returns the underlying instance of DesktopFrame.
41 DesktopFrame* GetUnderlyingFrame();
42
Zijie He5acd9d02017-08-24 12:41:53 -070043 // Returns whether |this| and |other| share the underlying DesktopFrame.
44 bool ShareFrameWith(const SharedDesktopFrame& other) const;
45
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000046 // Creates a clone of this object.
sergeyu5d910282016-06-07 16:41:58 -070047 std::unique_ptr<SharedDesktopFrame> Share();
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000048
49 // Checks if the frame is currently shared. If it returns false it's
50 // guaranteed that there are no clones of the object.
51 bool IsShared();
52
53 private:
sergeyu5d910282016-06-07 16:41:58 -070054 typedef rtc::RefCountedObject<std::unique_ptr<DesktopFrame>> Core;
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000055
Peter Boström26b08602015-06-04 15:18:17 +020056 SharedDesktopFrame(rtc::scoped_refptr<Core> core);
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000057
Zijie He5acd9d02017-08-24 12:41:53 -070058 const rtc::scoped_refptr<Core> core_;
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000059
henrikg3c089d72015-09-16 05:37:44 -070060 RTC_DISALLOW_COPY_AND_ASSIGN(SharedDesktopFrame);
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000061};
62
63} // namespace webrtc
64
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020065#endif // MODULES_DESKTOP_CAPTURE_SHARED_DESKTOP_FRAME_H_