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