Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Unified Diff: webrtc/modules/desktop_capture/shared_desktop_frame.cc

Issue 2030333003: Revert of Use std::unique_ptr<> to pass frame ownership in DesktopCapturer impls. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/desktop_capture/shared_desktop_frame.cc
diff --git a/webrtc/modules/desktop_capture/shared_desktop_frame.cc b/webrtc/modules/desktop_capture/shared_desktop_frame.cc
index e069a54d0284eabc3b005774569dcbdb2018606a..8d10827e29cc2b78d472e8c28beaeb90064f1b81 100644
--- a/webrtc/modules/desktop_capture/shared_desktop_frame.cc
+++ b/webrtc/modules/desktop_capture/shared_desktop_frame.cc
@@ -17,25 +17,49 @@
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
-std::unique_ptr<SharedDesktopFrame> SharedDesktopFrame::Wrap(
- std::unique_ptr<DesktopFrame> desktop_frame) {
- return std::unique_ptr<SharedDesktopFrame>(
- new SharedDesktopFrame(new Core(desktop_frame.release())));
-}
-
SharedDesktopFrame* SharedDesktopFrame::Wrap(DesktopFrame* desktop_frame) {
- return Wrap(std::unique_ptr<DesktopFrame>(desktop_frame)).release();
+ rtc::scoped_refptr<Core> core(new Core(desktop_frame));
+ return new SharedDesktopFrame(core);
}
DesktopFrame* SharedDesktopFrame::GetUnderlyingFrame() {
- return core_->get();
+ return core_->frame();
}
-std::unique_ptr<SharedDesktopFrame> SharedDesktopFrame::Share() {
- std::unique_ptr<SharedDesktopFrame> result(new SharedDesktopFrame(core_));
+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();
@@ -47,10 +71,11 @@
}
SharedDesktopFrame::SharedDesktopFrame(rtc::scoped_refptr<Core> core)
- : DesktopFrame((*core)->size(),
- (*core)->stride(),
- (*core)->data(),
- (*core)->shared_memory()),
- core_(core) {}
+ : DesktopFrame(core->frame()->size(),
+ core->frame()->stride(),
+ core->frame()->data(),
+ core->frame()->shared_memory()),
+ core_(core) {
+}
} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698