webrtc_m130/webrtc/modules/desktop_capture/shared_desktop_frame.cc
sergeyu b4c7b8365d Revert of Use std::unique_ptr<> to pass frame ownership in DesktopCapturer impls. (patchset #7 id:140001 of https://codereview.webrtc.org/1988783003/ )
Reason for revert:
Broke chromium builder

Original issue's description:
> Use std::unique_ptr<> to pass frame ownership in DesktopCapturer impls.
>
> Previously raw pointers were used for owned DesktopFrame instances.
> Updated all screen and window capturer implementations to use
> std::unique_ptr<>.
>
> Also includes some other cleanups in the capturers:
>  - s/NULL/nullptr
>  - moved default initializers to class definition.
>
> BUG=webrtc:5950
>
> Committed: https://crrev.com/4a627a8c13554d12412cabb8f751caee6e61ee32
> Cr-Commit-Position: refs/heads/master@{#13032}

TBR=wez@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=webrtc:5950

Review-Url: https://codereview.webrtc.org/2030333003
Cr-Commit-Position: refs/heads/master@{#13033}
2016-06-03 12:56:47 +00:00

82 lines
2.1 KiB
C++

/*
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "webrtc/modules/desktop_capture/shared_desktop_frame.h"
#include <memory>
#include "webrtc/base/constructormagic.h"
#include "webrtc/system_wrappers/include/atomic32.h"
namespace webrtc {
class SharedDesktopFrame::Core {
public:
Core(DesktopFrame* frame) : frame_(frame) {}
DesktopFrame* frame() { return frame_.get(); }
bool HasOneRef() { return ref_count_.Value() == 1; }
virtual int32_t AddRef() {
return ++ref_count_;
}
virtual int32_t Release() {
int32_t ref_count;
ref_count = --ref_count_;
if (ref_count == 0)
delete this;
return ref_count;
}
private:
virtual ~Core() {}
Atomic32 ref_count_;
std::unique_ptr<DesktopFrame> frame_;
RTC_DISALLOW_COPY_AND_ASSIGN(Core);
};
SharedDesktopFrame::~SharedDesktopFrame() {}
// static
SharedDesktopFrame* SharedDesktopFrame::Wrap(DesktopFrame* desktop_frame) {
rtc::scoped_refptr<Core> core(new Core(desktop_frame));
return new SharedDesktopFrame(core);
}
DesktopFrame* SharedDesktopFrame::GetUnderlyingFrame() {
return core_->frame();
}
SharedDesktopFrame* SharedDesktopFrame::Share() {
SharedDesktopFrame* result = new SharedDesktopFrame(core_);
result->set_dpi(dpi());
result->set_capture_time_ms(capture_time_ms());
*result->mutable_updated_region() = updated_region();
return result;
}
bool SharedDesktopFrame::IsShared() {
return !core_->HasOneRef();
}
SharedDesktopFrame::SharedDesktopFrame(rtc::scoped_refptr<Core> core)
: DesktopFrame(core->frame()->size(),
core->frame()->stride(),
core->frame()->data(),
core->frame()->shared_memory()),
core_(core) {
}
} // namespace webrtc