blob: 6b2fea099d8068983c802726b462b587879b6d9e [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
11#ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_SHARED_DESKTOP_FRAME_H_
12#define WEBRTC_MODULES_DESKTOP_CAPTURE_SHARED_DESKTOP_FRAME_H_
13
14#include "webrtc/modules/desktop_capture/desktop_frame.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020015#include "webrtc/rtc_base/constructormagic.h"
16#include "webrtc/rtc_base/refcount.h"
17#include "webrtc/rtc_base/scoped_ref_ptr.h"
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000018
19namespace webrtc {
20
21// SharedDesktopFrame is a DesktopFrame that may have multiple instances all
22// sharing the same buffer.
23class SharedDesktopFrame : public DesktopFrame {
24 public:
Sergey Ulanov58000a02016-10-20 09:33:52 -070025 ~SharedDesktopFrame() override;
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000026
sergeyu5d910282016-06-07 16:41:58 -070027 static std::unique_ptr<SharedDesktopFrame> Wrap(
28 std::unique_ptr<DesktopFrame> desktop_frame);
29
30 // Deprecated.
31 // TODO(sergeyu): remove this method.
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000032 static SharedDesktopFrame* Wrap(DesktopFrame* desktop_frame);
33
Zijie He5acd9d02017-08-24 12:41:53 -070034 // Deprecated. Clients do not need to know the underlying DesktopFrame
35 // instance.
36 // TODO(zijiehe): Remove this method.
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000037 // Returns the underlying instance of DesktopFrame.
38 DesktopFrame* GetUnderlyingFrame();
39
Zijie He5acd9d02017-08-24 12:41:53 -070040 // Returns whether |this| and |other| share the underlying DesktopFrame.
41 bool ShareFrameWith(const SharedDesktopFrame& other) const;
42
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000043 // Creates a clone of this object.
sergeyu5d910282016-06-07 16:41:58 -070044 std::unique_ptr<SharedDesktopFrame> Share();
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000045
46 // Checks if the frame is currently shared. If it returns false it's
47 // guaranteed that there are no clones of the object.
48 bool IsShared();
49
50 private:
sergeyu5d910282016-06-07 16:41:58 -070051 typedef rtc::RefCountedObject<std::unique_ptr<DesktopFrame>> Core;
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000052
Peter Boström26b08602015-06-04 15:18:17 +020053 SharedDesktopFrame(rtc::scoped_refptr<Core> core);
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000054
Zijie He5acd9d02017-08-24 12:41:53 -070055 const rtc::scoped_refptr<Core> core_;
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000056
henrikg3c089d72015-09-16 05:37:44 -070057 RTC_DISALLOW_COPY_AND_ASSIGN(SharedDesktopFrame);
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000058};
59
60} // namespace webrtc
61
62#endif // WEBRTC_MODULES_DESKTOP_CAPTURE_SHARED_DESKTOP_FRAME_H_