OLD | NEW |
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/screen_capturer.h" | 11 #include "webrtc/modules/desktop_capture/screen_capturer.h" |
12 | 12 |
13 #include <string.h> | 13 #include <string.h> |
14 | 14 |
15 #include <memory> | 15 #include <memory> |
16 #include <set> | 16 #include <set> |
17 #include <utility> | 17 #include <utility> |
18 | 18 |
19 #include <X11/extensions/Xdamage.h> | 19 #include <X11/extensions/Xdamage.h> |
20 #include <X11/extensions/Xfixes.h> | 20 #include <X11/extensions/Xfixes.h> |
21 #include <X11/Xlib.h> | 21 #include <X11/Xlib.h> |
22 #include <X11/Xutil.h> | 22 #include <X11/Xutil.h> |
23 | 23 |
24 #include "webrtc/base/checks.h" | 24 #include "webrtc/base/checks.h" |
25 #include "webrtc/base/constructormagic.h" | 25 #include "webrtc/base/constructormagic.h" |
26 #include "webrtc/base/timeutils.h" | 26 #include "webrtc/base/timeutils.h" |
27 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" | 27 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" |
28 #include "webrtc/modules/desktop_capture/desktop_frame.h" | 28 #include "webrtc/modules/desktop_capture/desktop_frame.h" |
29 #include "webrtc/modules/desktop_capture/differ.h" | |
30 #include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h" | 29 #include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h" |
31 #include "webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.h" | 30 #include "webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.h" |
32 #include "webrtc/modules/desktop_capture/screen_capturer_helper.h" | 31 #include "webrtc/modules/desktop_capture/screen_capturer_helper.h" |
33 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" | 32 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" |
34 #include "webrtc/modules/desktop_capture/x11/x_server_pixel_buffer.h" | 33 #include "webrtc/modules/desktop_capture/x11/x_server_pixel_buffer.h" |
35 #include "webrtc/system_wrappers/include/logging.h" | 34 #include "webrtc/system_wrappers/include/logging.h" |
36 | 35 |
37 namespace webrtc { | 36 namespace webrtc { |
38 namespace { | 37 namespace { |
39 | 38 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 // recently captured screen. | 108 // recently captured screen. |
110 ScreenCapturerHelper helper_; | 109 ScreenCapturerHelper helper_; |
111 | 110 |
112 // Queue of the frames buffers. | 111 // Queue of the frames buffers. |
113 ScreenCaptureFrameQueue<SharedDesktopFrame> queue_; | 112 ScreenCaptureFrameQueue<SharedDesktopFrame> queue_; |
114 | 113 |
115 // Invalid region from the previous capture. This is used to synchronize the | 114 // Invalid region from the previous capture. This is used to synchronize the |
116 // current with the last buffer used. | 115 // current with the last buffer used. |
117 DesktopRegion last_invalid_region_; | 116 DesktopRegion last_invalid_region_; |
118 | 117 |
119 // |Differ| for use when polling for changes. | |
120 std::unique_ptr<Differ> differ_; | |
121 | |
122 RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCapturerLinux); | 118 RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCapturerLinux); |
123 }; | 119 }; |
124 | 120 |
125 ScreenCapturerLinux::ScreenCapturerLinux() { | 121 ScreenCapturerLinux::ScreenCapturerLinux() { |
126 helper_.SetLogGridSize(4); | 122 helper_.SetLogGridSize(4); |
127 } | 123 } |
128 | 124 |
129 ScreenCapturerLinux::~ScreenCapturerLinux() { | 125 ScreenCapturerLinux::~ScreenCapturerLinux() { |
130 options_.x_display()->RemoveEventHandler(ConfigureNotify, this); | 126 options_.x_display()->RemoveEventHandler(ConfigureNotify, this); |
131 if (use_damage_) { | 127 if (use_damage_) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 | 242 |
247 // If the current frame is from an older generation then allocate a new one. | 243 // If the current frame is from an older generation then allocate a new one. |
248 // Note that we can't reallocate other buffers at this point, since the caller | 244 // Note that we can't reallocate other buffers at this point, since the caller |
249 // may still be reading from them. | 245 // may still be reading from them. |
250 if (!queue_.current_frame()) { | 246 if (!queue_.current_frame()) { |
251 queue_.ReplaceCurrentFrame( | 247 queue_.ReplaceCurrentFrame( |
252 SharedDesktopFrame::Wrap(std::unique_ptr<DesktopFrame>( | 248 SharedDesktopFrame::Wrap(std::unique_ptr<DesktopFrame>( |
253 new BasicDesktopFrame(x_server_pixel_buffer_.window_size())))); | 249 new BasicDesktopFrame(x_server_pixel_buffer_.window_size())))); |
254 } | 250 } |
255 | 251 |
256 // Refresh the Differ helper used by CaptureFrame(), if needed. | |
257 DesktopFrame* frame = queue_.current_frame(); | |
258 if (!use_damage_ && | |
259 (!differ_ || (differ_->width() != frame->size().width()) || | |
260 (differ_->height() != frame->size().height()) || | |
261 (differ_->bytes_per_row() != frame->stride()))) { | |
262 differ_.reset(new Differ(frame->size().width(), frame->size().height(), | |
263 DesktopFrame::kBytesPerPixel, frame->stride())); | |
264 } | |
265 | |
266 std::unique_ptr<DesktopFrame> result = CaptureScreen(); | 252 std::unique_ptr<DesktopFrame> result = CaptureScreen(); |
267 last_invalid_region_ = result->updated_region(); | 253 last_invalid_region_ = result->updated_region(); |
268 result->set_capture_time_ms((rtc::TimeNanos() - capture_start_time_nanos) / | 254 result->set_capture_time_ms((rtc::TimeNanos() - capture_start_time_nanos) / |
269 rtc::kNumNanosecsPerMillisec); | 255 rtc::kNumNanosecsPerMillisec); |
270 callback_->OnCaptureResult(Result::SUCCESS, std::move(result)); | 256 callback_->OnCaptureResult(Result::SUCCESS, std::move(result)); |
271 } | 257 } |
272 | 258 |
273 bool ScreenCapturerLinux::GetScreenList(ScreenList* screens) { | 259 bool ScreenCapturerLinux::GetScreenList(ScreenList* screens) { |
274 RTC_DCHECK(screens->size() == 0); | 260 RTC_DCHECK(screens->size() == 0); |
275 // TODO(jiayl): implement screen enumeration. | 261 // TODO(jiayl): implement screen enumeration. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 | 328 |
343 for (DesktopRegion::Iterator it(*updated_region); | 329 for (DesktopRegion::Iterator it(*updated_region); |
344 !it.IsAtEnd(); it.Advance()) { | 330 !it.IsAtEnd(); it.Advance()) { |
345 x_server_pixel_buffer_.CaptureRect(it.rect(), frame.get()); | 331 x_server_pixel_buffer_.CaptureRect(it.rect(), frame.get()); |
346 } | 332 } |
347 } else { | 333 } else { |
348 // Doing full-screen polling, or this is the first capture after a | 334 // Doing full-screen polling, or this is the first capture after a |
349 // screen-resolution change. In either case, need a full-screen capture. | 335 // screen-resolution change. In either case, need a full-screen capture. |
350 DesktopRect screen_rect = DesktopRect::MakeSize(frame->size()); | 336 DesktopRect screen_rect = DesktopRect::MakeSize(frame->size()); |
351 x_server_pixel_buffer_.CaptureRect(screen_rect, frame.get()); | 337 x_server_pixel_buffer_.CaptureRect(screen_rect, frame.get()); |
352 | 338 // ScreenCapturerDifferWrapper will help to detect the updated region if |
353 if (queue_.previous_frame()) { | 339 // needed. |
354 // Full-screen polling, so calculate the invalid rects here, based on the | 340 updated_region->SetRect(screen_rect); |
355 // changed pixels between current and previous buffers. | |
356 RTC_DCHECK(differ_); | |
357 RTC_DCHECK(queue_.previous_frame()->data()); | |
358 differ_->CalcDirtyRegion(queue_.previous_frame()->data(), | |
359 frame->data(), updated_region); | |
360 } else { | |
361 // No previous buffer, so always invalidate the whole screen, whether | |
362 // or not DAMAGE is being used. DAMAGE doesn't necessarily send a | |
363 // full-screen notification after a screen-resolution change, so | |
364 // this is done here. | |
365 updated_region->SetRect(screen_rect); | |
366 } | |
367 } | 341 } |
368 | 342 |
369 return std::move(frame); | 343 return std::move(frame); |
370 } | 344 } |
371 | 345 |
372 void ScreenCapturerLinux::ScreenConfigurationChanged() { | 346 void ScreenCapturerLinux::ScreenConfigurationChanged() { |
373 // Make sure the frame buffers will be reallocated. | 347 // Make sure the frame buffers will be reallocated. |
374 queue_.Reset(); | 348 queue_.Reset(); |
375 | 349 |
376 helper_.ClearInvalidRegion(); | 350 helper_.ClearInvalidRegion(); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 } | 408 } |
435 | 409 |
436 if (options.detect_updated_region()) { | 410 if (options.detect_updated_region()) { |
437 capturer.reset(new ScreenCapturerDifferWrapper(std::move(capturer))); | 411 capturer.reset(new ScreenCapturerDifferWrapper(std::move(capturer))); |
438 } | 412 } |
439 | 413 |
440 return capturer.release(); | 414 return capturer.release(); |
441 } | 415 } |
442 | 416 |
443 } // namespace webrtc | 417 } // namespace webrtc |
OLD | NEW |