blob: d9a521b0642d8a6c47d936acbfe97d8762a5f64d [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
kwiberg4485ffb2016-04-26 08:14:39 -070014#include "webrtc/base/constructormagic.h"
sergeyu5d910282016-06-07 16:41:58 -070015#include "webrtc/base/refcount.h"
Peter Boström26b08602015-06-04 15:18:17 +020016#include "webrtc/base/scoped_ref_ptr.h"
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000017#include "webrtc/modules/desktop_capture/desktop_frame.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:
25 virtual ~SharedDesktopFrame();
26
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
34 // Returns the underlying instance of DesktopFrame.
35 DesktopFrame* GetUnderlyingFrame();
36
37 // Creates a clone of this object.
sergeyu5d910282016-06-07 16:41:58 -070038 std::unique_ptr<SharedDesktopFrame> Share();
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000039
40 // Checks if the frame is currently shared. If it returns false it's
41 // guaranteed that there are no clones of the object.
42 bool IsShared();
43
44 private:
sergeyu5d910282016-06-07 16:41:58 -070045 typedef rtc::RefCountedObject<std::unique_ptr<DesktopFrame>> Core;
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000046
Peter Boström26b08602015-06-04 15:18:17 +020047 SharedDesktopFrame(rtc::scoped_refptr<Core> core);
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000048
Peter Boström26b08602015-06-04 15:18:17 +020049 rtc::scoped_refptr<Core> core_;
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000050
henrikg3c089d72015-09-16 05:37:44 -070051 RTC_DISALLOW_COPY_AND_ASSIGN(SharedDesktopFrame);
sergeyu@chromium.org3d34f662013-06-04 18:51:23 +000052};
53
54} // namespace webrtc
55
56#endif // WEBRTC_MODULES_DESKTOP_CAPTURE_SHARED_DESKTOP_FRAME_H_