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

Side by Side 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" 11 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h"
12 12
13 #include <memory> 13 #include <memory>
14 14
15 #include "webrtc/base/constructormagic.h" 15 #include "webrtc/base/constructormagic.h"
16 #include "webrtc/system_wrappers/include/atomic32.h" 16 #include "webrtc/system_wrappers/include/atomic32.h"
17 17
18 namespace webrtc { 18 namespace webrtc {
19 19
20 class SharedDesktopFrame::Core {
21 public:
22 Core(DesktopFrame* frame) : frame_(frame) {}
23
24 DesktopFrame* frame() { return frame_.get(); }
25
26 bool HasOneRef() { return ref_count_.Value() == 1; }
27
28 virtual int32_t AddRef() {
29 return ++ref_count_;
30 }
31
32 virtual int32_t Release() {
33 int32_t ref_count;
34 ref_count = --ref_count_;
35 if (ref_count == 0)
36 delete this;
37 return ref_count;
38 }
39
40 private:
41 virtual ~Core() {}
42
43 Atomic32 ref_count_;
44 std::unique_ptr<DesktopFrame> frame_;
45
46 RTC_DISALLOW_COPY_AND_ASSIGN(Core);
47 };
48
20 SharedDesktopFrame::~SharedDesktopFrame() {} 49 SharedDesktopFrame::~SharedDesktopFrame() {}
21 50
22 // static 51 // static
23 std::unique_ptr<SharedDesktopFrame> SharedDesktopFrame::Wrap(
24 std::unique_ptr<DesktopFrame> desktop_frame) {
25 return std::unique_ptr<SharedDesktopFrame>(
26 new SharedDesktopFrame(new Core(desktop_frame.release())));
27 }
28
29 SharedDesktopFrame* SharedDesktopFrame::Wrap(DesktopFrame* desktop_frame) { 52 SharedDesktopFrame* SharedDesktopFrame::Wrap(DesktopFrame* desktop_frame) {
30 return Wrap(std::unique_ptr<DesktopFrame>(desktop_frame)).release(); 53 rtc::scoped_refptr<Core> core(new Core(desktop_frame));
54 return new SharedDesktopFrame(core);
31 } 55 }
32 56
33 DesktopFrame* SharedDesktopFrame::GetUnderlyingFrame() { 57 DesktopFrame* SharedDesktopFrame::GetUnderlyingFrame() {
34 return core_->get(); 58 return core_->frame();
35 } 59 }
36 60
37 std::unique_ptr<SharedDesktopFrame> SharedDesktopFrame::Share() { 61 SharedDesktopFrame* SharedDesktopFrame::Share() {
38 std::unique_ptr<SharedDesktopFrame> result(new SharedDesktopFrame(core_)); 62 SharedDesktopFrame* result = new SharedDesktopFrame(core_);
39 result->set_dpi(dpi()); 63 result->set_dpi(dpi());
40 result->set_capture_time_ms(capture_time_ms()); 64 result->set_capture_time_ms(capture_time_ms());
41 *result->mutable_updated_region() = updated_region(); 65 *result->mutable_updated_region() = updated_region();
42 return result; 66 return result;
43 } 67 }
44 68
45 bool SharedDesktopFrame::IsShared() { 69 bool SharedDesktopFrame::IsShared() {
46 return !core_->HasOneRef(); 70 return !core_->HasOneRef();
47 } 71 }
48 72
49 SharedDesktopFrame::SharedDesktopFrame(rtc::scoped_refptr<Core> core) 73 SharedDesktopFrame::SharedDesktopFrame(rtc::scoped_refptr<Core> core)
50 : DesktopFrame((*core)->size(), 74 : DesktopFrame(core->frame()->size(),
51 (*core)->stride(), 75 core->frame()->stride(),
52 (*core)->data(), 76 core->frame()->data(),
53 (*core)->shared_memory()), 77 core->frame()->shared_memory()),
54 core_(core) {} 78 core_(core) {
79 }
55 80
56 } // namespace webrtc 81 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698