blob: ea12c000f2a64528f5c08fc73c27d12e198bb91d [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"
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.
Mirko Bonadeiac194142018-10-22 17:08:37 +020025class RTC_EXPORT SharedDesktopFrame : 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
sergeyu5d910282016-06-07 16:41:58 -070029 static std::unique_ptr<SharedDesktopFrame> Wrap(
30 std::unique_ptr<DesktopFrame> desktop_frame);
31
32 // Deprecated.
33 // TODO(sergeyu): remove this method.
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000034 static SharedDesktopFrame* Wrap(DesktopFrame* desktop_frame);
35
Zijie He5acd9d02017-08-24 12:41:53 -070036 // Deprecated. Clients do not need to know the underlying DesktopFrame
37 // instance.
38 // TODO(zijiehe): Remove this method.
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000039 // Returns the underlying instance of DesktopFrame.
40 DesktopFrame* GetUnderlyingFrame();
41
Zijie He5acd9d02017-08-24 12:41:53 -070042 // Returns whether |this| and |other| share the underlying DesktopFrame.
43 bool ShareFrameWith(const SharedDesktopFrame& other) const;
44
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000045 // Creates a clone of this object.
sergeyu5d910282016-06-07 16:41:58 -070046 std::unique_ptr<SharedDesktopFrame> Share();
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000047
48 // Checks if the frame is currently shared. If it returns false it's
49 // guaranteed that there are no clones of the object.
50 bool IsShared();
51
52 private:
sergeyu5d910282016-06-07 16:41:58 -070053 typedef rtc::RefCountedObject<std::unique_ptr<DesktopFrame>> Core;
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000054
Peter Boström26b08602015-06-04 15:18:17 +020055 SharedDesktopFrame(rtc::scoped_refptr<Core> core);
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000056
Zijie He5acd9d02017-08-24 12:41:53 -070057 const rtc::scoped_refptr<Core> core_;
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000058
henrikg3c089d72015-09-16 05:37:44 -070059 RTC_DISALLOW_COPY_AND_ASSIGN(SharedDesktopFrame);
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000060};
61
62} // namespace webrtc
63
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020064#endif // MODULES_DESKTOP_CAPTURE_SHARED_DESKTOP_FRAME_H_