blob: c6f52247f4ba0c5560c51ec919dcdae18f566a53 [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/ref_counted_object.h"
Mirko Bonadeiac194142018-10-22 17:08:37 +020019#include "rtc_base/system/rtc_export.h"
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000020
21namespace webrtc {
22
23// SharedDesktopFrame is a DesktopFrame that may have multiple instances all
24// sharing the same buffer.
Tomas Gunnarssone249d192021-04-26 11:46:54 +020025class RTC_EXPORT SharedDesktopFrame final : public DesktopFrame {
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000026 public:
Sergey Ulanov58000a02016-10-20 09:33:52 -070027 ~SharedDesktopFrame() override;
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000028
Byoungchan Lee604fd2f2022-01-21 09:49:39 +090029 SharedDesktopFrame(const SharedDesktopFrame&) = delete;
30 SharedDesktopFrame& operator=(const SharedDesktopFrame&) = delete;
31
sergeyu5d910282016-06-07 16:41:58 -070032 static std::unique_ptr<SharedDesktopFrame> Wrap(
33 std::unique_ptr<DesktopFrame> desktop_frame);
34
35 // Deprecated.
36 // TODO(sergeyu): remove this method.
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000037 static SharedDesktopFrame* Wrap(DesktopFrame* desktop_frame);
38
Zijie He5acd9d02017-08-24 12:41:53 -070039 // Deprecated. Clients do not need to know the underlying DesktopFrame
40 // instance.
41 // TODO(zijiehe): Remove this method.
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000042 // Returns the underlying instance of DesktopFrame.
43 DesktopFrame* GetUnderlyingFrame();
44
Artem Titovcec43432021-07-28 23:35:39 +020045 // Returns whether `this` and `other` share the underlying DesktopFrame.
Zijie He5acd9d02017-08-24 12:41:53 -070046 bool ShareFrameWith(const SharedDesktopFrame& other) const;
47
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000048 // Creates a clone of this object.
sergeyu5d910282016-06-07 16:41:58 -070049 std::unique_ptr<SharedDesktopFrame> Share();
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000050
51 // Checks if the frame is currently shared. If it returns false it's
52 // guaranteed that there are no clones of the object.
53 bool IsShared();
54
55 private:
Tomas Gunnarssone249d192021-04-26 11:46:54 +020056 typedef rtc::FinalRefCountedObject<std::unique_ptr<DesktopFrame>> Core;
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000057
Peter Boström26b08602015-06-04 15:18:17 +020058 SharedDesktopFrame(rtc::scoped_refptr<Core> core);
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000059
Zijie He5acd9d02017-08-24 12:41:53 -070060 const rtc::scoped_refptr<Core> core_;
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_