1 /* 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 MODULES_DESKTOP_CAPTURE_SHARED_DESKTOP_FRAME_H_ 12 #define MODULES_DESKTOP_CAPTURE_SHARED_DESKTOP_FRAME_H_ 13 14 #include <memory> 15 16 #include "api/scoped_refptr.h" 17 #include "modules/desktop_capture/desktop_frame.h" 18 #include "rtc_base/ref_counted_object.h" 19 #include "rtc_base/system/rtc_export.h" 20 21 namespace webrtc { 22 23 // SharedDesktopFrame is a DesktopFrame that may have multiple instances all 24 // sharing the same buffer. 25 class RTC_EXPORT SharedDesktopFrame final : public DesktopFrame { 26 public: 27 ~SharedDesktopFrame() override; 28 29 SharedDesktopFrame(const SharedDesktopFrame&) = delete; 30 SharedDesktopFrame& operator=(const SharedDesktopFrame&) = delete; 31 32 static std::unique_ptr<SharedDesktopFrame> Wrap( 33 std::unique_ptr<DesktopFrame> desktop_frame); 34 35 // Deprecated. 36 // TODO(sergeyu): remove this method. 37 static SharedDesktopFrame* Wrap(DesktopFrame* desktop_frame); 38 39 // Deprecated. Clients do not need to know the underlying DesktopFrame 40 // instance. 41 // TODO(zijiehe): Remove this method. 42 // Returns the underlying instance of DesktopFrame. 43 DesktopFrame* GetUnderlyingFrame(); 44 45 // Returns whether `this` and `other` share the underlying DesktopFrame. 46 bool ShareFrameWith(const SharedDesktopFrame& other) const; 47 48 // Creates a clone of this object. 49 std::unique_ptr<SharedDesktopFrame> Share(); 50 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: 56 typedef rtc::FinalRefCountedObject<std::unique_ptr<DesktopFrame>> Core; 57 58 SharedDesktopFrame(rtc::scoped_refptr<Core> core); 59 60 const rtc::scoped_refptr<Core> core_; 61 }; 62 63 } // namespace webrtc 64 65 #endif // MODULES_DESKTOP_CAPTURE_SHARED_DESKTOP_FRAME_H_ 66