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 #include "modules/desktop_capture/shared_desktop_frame.h" 12 13 #include <memory> 14 #include <type_traits> 15 #include <utility> 16 17 namespace webrtc { 18 ~SharedDesktopFrame()19SharedDesktopFrame::~SharedDesktopFrame() {} 20 21 // static Wrap(std::unique_ptr<DesktopFrame> desktop_frame)22std::unique_ptr<SharedDesktopFrame> SharedDesktopFrame::Wrap( 23 std::unique_ptr<DesktopFrame> desktop_frame) { 24 return std::unique_ptr<SharedDesktopFrame>( 25 new SharedDesktopFrame(new Core(std::move(desktop_frame)))); 26 } 27 Wrap(DesktopFrame * desktop_frame)28SharedDesktopFrame* SharedDesktopFrame::Wrap(DesktopFrame* desktop_frame) { 29 return Wrap(std::unique_ptr<DesktopFrame>(desktop_frame)).release(); 30 } 31 GetUnderlyingFrame()32DesktopFrame* SharedDesktopFrame::GetUnderlyingFrame() { 33 return core_->get(); 34 } 35 ShareFrameWith(const SharedDesktopFrame & other) const36bool SharedDesktopFrame::ShareFrameWith(const SharedDesktopFrame& other) const { 37 return core_->get() == other.core_->get(); 38 } 39 Share()40std::unique_ptr<SharedDesktopFrame> SharedDesktopFrame::Share() { 41 std::unique_ptr<SharedDesktopFrame> result(new SharedDesktopFrame(core_)); 42 result->CopyFrameInfoFrom(*this); 43 return result; 44 } 45 IsShared()46bool SharedDesktopFrame::IsShared() { 47 return !core_->HasOneRef(); 48 } 49 SharedDesktopFrame(rtc::scoped_refptr<Core> core)50SharedDesktopFrame::SharedDesktopFrame(rtc::scoped_refptr<Core> core) 51 : DesktopFrame((*core)->size(), 52 (*core)->stride(), 53 (*core)->data(), 54 (*core)->shared_memory()), 55 core_(core) { 56 CopyFrameInfoFrom(*(core_->get())); 57 } 58 59 } // namespace webrtc 60