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

Side by Side Diff: webrtc/modules/desktop_capture/shared_desktop_frame.cc

Issue 1988783003: 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, 7 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 { 20 class SharedDesktopFrame::Core {
Wez 2016/05/18 01:29:50 nit: While you're here... couldn't this effectivel
Sergey Ulanov 2016/05/31 12:02:49 Done.
21 public: 21 public:
22 Core(DesktopFrame* frame) : frame_(frame) {} 22 Core(std::unique_ptr<DesktopFrame> frame) : frame_(std::move(frame)) {}
23 23
24 DesktopFrame* frame() { return frame_.get(); } 24 DesktopFrame* frame() { return frame_.get(); }
25 25
26 bool HasOneRef() { return ref_count_.Value() == 1; } 26 bool HasOneRef() { return ref_count_.Value() == 1; }
27 27
28 virtual int32_t AddRef() { 28 virtual int32_t AddRef() {
29 return ++ref_count_; 29 return ++ref_count_;
30 } 30 }
31 31
32 virtual int32_t Release() { 32 virtual int32_t Release() {
33 int32_t ref_count; 33 int32_t ref_count;
34 ref_count = --ref_count_; 34 ref_count = --ref_count_;
35 if (ref_count == 0) 35 if (ref_count == 0)
36 delete this; 36 delete this;
37 return ref_count; 37 return ref_count;
38 } 38 }
39 39
40 private: 40 private:
41 virtual ~Core() {} 41 virtual ~Core() {}
42 42
43 Atomic32 ref_count_; 43 Atomic32 ref_count_;
44 std::unique_ptr<DesktopFrame> frame_; 44 std::unique_ptr<DesktopFrame> frame_;
45 45
46 RTC_DISALLOW_COPY_AND_ASSIGN(Core); 46 RTC_DISALLOW_COPY_AND_ASSIGN(Core);
47 }; 47 };
48 48
49 SharedDesktopFrame::~SharedDesktopFrame() {} 49 SharedDesktopFrame::~SharedDesktopFrame() {}
50 50
51 // static 51 // static
52 std::unique_ptr<SharedDesktopFrame> SharedDesktopFrame::Wrap(
53 std::unique_ptr<DesktopFrame> desktop_frame) {
54 return std::unique_ptr<SharedDesktopFrame>(
55 new SharedDesktopFrame(new Core(std::move(desktop_frame))));
56 }
57
52 SharedDesktopFrame* SharedDesktopFrame::Wrap(DesktopFrame* desktop_frame) { 58 SharedDesktopFrame* SharedDesktopFrame::Wrap(DesktopFrame* desktop_frame) {
53 rtc::scoped_refptr<Core> core(new Core(desktop_frame)); 59 return Wrap(std::unique_ptr<DesktopFrame>(desktop_frame)).release();
54 return new SharedDesktopFrame(core);
55 } 60 }
56 61
57 DesktopFrame* SharedDesktopFrame::GetUnderlyingFrame() { 62 DesktopFrame* SharedDesktopFrame::GetUnderlyingFrame() {
58 return core_->frame(); 63 return core_->frame();
59 } 64 }
60 65
61 SharedDesktopFrame* SharedDesktopFrame::Share() { 66 std::unique_ptr<SharedDesktopFrame> SharedDesktopFrame::Share() {
62 SharedDesktopFrame* result = new SharedDesktopFrame(core_); 67 std::unique_ptr<SharedDesktopFrame> result(new SharedDesktopFrame(core_));
63 result->set_dpi(dpi()); 68 result->set_dpi(dpi());
64 result->set_capture_time_ms(capture_time_ms()); 69 result->set_capture_time_ms(capture_time_ms());
65 *result->mutable_updated_region() = updated_region(); 70 *result->mutable_updated_region() = updated_region();
66 return result; 71 return result;
67 } 72 }
68 73
69 bool SharedDesktopFrame::IsShared() { 74 bool SharedDesktopFrame::IsShared() {
70 return !core_->HasOneRef(); 75 return !core_->HasOneRef();
71 } 76 }
72 77
73 SharedDesktopFrame::SharedDesktopFrame(rtc::scoped_refptr<Core> core) 78 SharedDesktopFrame::SharedDesktopFrame(rtc::scoped_refptr<Core> core)
74 : DesktopFrame(core->frame()->size(), 79 : DesktopFrame(core->frame()->size(),
75 core->frame()->stride(), 80 core->frame()->stride(),
76 core->frame()->data(), 81 core->frame()->data(),
77 core->frame()->shared_memory()), 82 core->frame()->shared_memory()),
78 core_(core) { 83 core_(core) {
79 } 84 }
80 85
81 } // namespace webrtc 86 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698