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

Side by Side Diff: webrtc/modules/desktop_capture/desktop_and_cursor_composer.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, 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
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 src += src_stride; 50 src += src_stride;
51 dest += dest_stride; 51 dest += dest_stride;
52 } 52 }
53 } 53 }
54 54
55 // DesktopFrame wrapper that draws mouse on a frame and restores original 55 // DesktopFrame wrapper that draws mouse on a frame and restores original
56 // content before releasing the underlying frame. 56 // content before releasing the underlying frame.
57 class DesktopFrameWithCursor : public DesktopFrame { 57 class DesktopFrameWithCursor : public DesktopFrame {
58 public: 58 public:
59 // Takes ownership of |frame|. 59 // Takes ownership of |frame|.
60 DesktopFrameWithCursor(DesktopFrame* frame, 60 DesktopFrameWithCursor(std::unique_ptr<DesktopFrame> frame,
61 const MouseCursor& cursor, 61 const MouseCursor& cursor,
62 const DesktopVector& position); 62 const DesktopVector& position);
63 virtual ~DesktopFrameWithCursor(); 63 virtual ~DesktopFrameWithCursor();
64 64
65 private: 65 private:
66 std::unique_ptr<DesktopFrame> original_frame_; 66 std::unique_ptr<DesktopFrame> original_frame_;
67 67
68 DesktopVector restore_position_; 68 DesktopVector restore_position_;
69 std::unique_ptr<DesktopFrame> restore_frame_; 69 std::unique_ptr<DesktopFrame> restore_frame_;
70 70
71 RTC_DISALLOW_COPY_AND_ASSIGN(DesktopFrameWithCursor); 71 RTC_DISALLOW_COPY_AND_ASSIGN(DesktopFrameWithCursor);
72 }; 72 };
73 73
74 DesktopFrameWithCursor::DesktopFrameWithCursor(DesktopFrame* frame, 74 DesktopFrameWithCursor::DesktopFrameWithCursor(
75 const MouseCursor& cursor, 75 std::unique_ptr<DesktopFrame> frame,
76 const DesktopVector& position) 76 const MouseCursor& cursor,
77 : DesktopFrame(frame->size(), frame->stride(), 77 const DesktopVector& position)
78 frame->data(), frame->shared_memory()), 78 : DesktopFrame(frame->size(),
79 original_frame_(frame) { 79 frame->stride(),
80 frame->data(),
81 frame->shared_memory()) {
80 set_dpi(frame->dpi()); 82 set_dpi(frame->dpi());
81 set_capture_time_ms(frame->capture_time_ms()); 83 set_capture_time_ms(frame->capture_time_ms());
82 mutable_updated_region()->Swap(frame->mutable_updated_region()); 84 mutable_updated_region()->Swap(frame->mutable_updated_region());
85 original_frame_ = std::move(frame);
83 86
84 DesktopVector image_pos = position.subtract(cursor.hotspot()); 87 DesktopVector image_pos = position.subtract(cursor.hotspot());
85 DesktopRect target_rect = DesktopRect::MakeSize(cursor.image()->size()); 88 DesktopRect target_rect = DesktopRect::MakeSize(cursor.image()->size());
86 target_rect.Translate(image_pos); 89 target_rect.Translate(image_pos);
87 DesktopVector target_origin = target_rect.top_left(); 90 DesktopVector target_origin = target_rect.top_left();
88 target_rect.IntersectWith(DesktopRect::MakeSize(size())); 91 target_rect.IntersectWith(DesktopRect::MakeSize(size()));
89 92
90 if (target_rect.is_empty()) 93 if (target_rect.is_empty())
91 return; 94 return;
92 95
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 void DesktopAndCursorComposer::Capture(const DesktopRegion& region) { 148 void DesktopAndCursorComposer::Capture(const DesktopRegion& region) {
146 if (mouse_monitor_.get()) 149 if (mouse_monitor_.get())
147 mouse_monitor_->Capture(); 150 mouse_monitor_->Capture();
148 desktop_capturer_->Capture(region); 151 desktop_capturer_->Capture(region);
149 } 152 }
150 153
151 void DesktopAndCursorComposer::SetExcludedWindow(WindowId window) { 154 void DesktopAndCursorComposer::SetExcludedWindow(WindowId window) {
152 desktop_capturer_->SetExcludedWindow(window); 155 desktop_capturer_->SetExcludedWindow(window);
153 } 156 }
154 157
155 void DesktopAndCursorComposer::OnCaptureCompleted(DesktopFrame* frame) { 158 void DesktopAndCursorComposer::OnCaptureResult(
156 if (frame && cursor_.get() && cursor_state_ == MouseCursorMonitor::INSIDE) { 159 DesktopCapturer::Result result,
157 DesktopFrameWithCursor* frame_with_cursor = 160 std::unique_ptr<DesktopFrame> frame) {
158 new DesktopFrameWithCursor(frame, *cursor_, cursor_position_); 161 if (frame && cursor_ && cursor_state_ == MouseCursorMonitor::INSIDE) {
159 frame = frame_with_cursor; 162 frame = std::unique_ptr<DesktopFrameWithCursor>(new DesktopFrameWithCursor(
163 std::move(frame), *cursor_, cursor_position_));
160 } 164 }
161 165
162 callback_->OnCaptureCompleted(frame); 166 callback_->OnCaptureResult(result, std::move(frame));
163 } 167 }
164 168
165 void DesktopAndCursorComposer::OnMouseCursor(MouseCursor* cursor) { 169 void DesktopAndCursorComposer::OnMouseCursor(MouseCursor* cursor) {
166 cursor_.reset(cursor); 170 cursor_.reset(cursor);
167 } 171 }
168 172
169 void DesktopAndCursorComposer::OnMouseCursorPosition( 173 void DesktopAndCursorComposer::OnMouseCursorPosition(
170 MouseCursorMonitor::CursorState state, 174 MouseCursorMonitor::CursorState state,
171 const DesktopVector& position) { 175 const DesktopVector& position) {
172 cursor_state_ = state; 176 cursor_state_ = state;
173 cursor_position_ = position; 177 cursor_position_ = position;
174 } 178 }
175 179
176 } // namespace webrtc 180 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698