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

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

Issue 2348803003: Remove differ from ScreenCapturer implementations (Closed)
Patch Set: Resolve review comments Created 4 years, 3 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/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
40 // A class to perform video frame capturing for Linux. 39 // A class to perform video frame capturing for Linux.
40 //
41 // This class does not detect DesktopFrame::updated_region(), the field is
42 // always set to the entire frame rectangle. ScreenCapturerDifferWrapper should
Sergey Ulanov 2016/09/24 00:09:15 This is not correct. updated_region() may or may n
Hzj_jie 2016/09/24 00:12:38 Updated.
43 // be used if that functionality is necessary.
41 class ScreenCapturerLinux : public ScreenCapturer, 44 class ScreenCapturerLinux : public ScreenCapturer,
42 public SharedXDisplay::XEventHandler { 45 public SharedXDisplay::XEventHandler {
43 public: 46 public:
44 ScreenCapturerLinux(); 47 ScreenCapturerLinux();
45 virtual ~ScreenCapturerLinux(); 48 virtual ~ScreenCapturerLinux();
46 49
47 // TODO(ajwong): Do we really want this to be synchronous? 50 // TODO(ajwong): Do we really want this to be synchronous?
48 bool Init(const DesktopCaptureOptions& options); 51 bool Init(const DesktopCaptureOptions& options);
49 52
50 // DesktopCapturer interface. 53 // DesktopCapturer interface.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 // recently captured screen. 112 // recently captured screen.
110 ScreenCapturerHelper helper_; 113 ScreenCapturerHelper helper_;
111 114
112 // Queue of the frames buffers. 115 // Queue of the frames buffers.
113 ScreenCaptureFrameQueue<SharedDesktopFrame> queue_; 116 ScreenCaptureFrameQueue<SharedDesktopFrame> queue_;
114 117
115 // Invalid region from the previous capture. This is used to synchronize the 118 // Invalid region from the previous capture. This is used to synchronize the
116 // current with the last buffer used. 119 // current with the last buffer used.
117 DesktopRegion last_invalid_region_; 120 DesktopRegion last_invalid_region_;
118 121
119 // |Differ| for use when polling for changes.
120 std::unique_ptr<Differ> differ_;
121
122 RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCapturerLinux); 122 RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCapturerLinux);
123 }; 123 };
124 124
125 ScreenCapturerLinux::ScreenCapturerLinux() { 125 ScreenCapturerLinux::ScreenCapturerLinux() {
126 helper_.SetLogGridSize(4); 126 helper_.SetLogGridSize(4);
127 } 127 }
128 128
129 ScreenCapturerLinux::~ScreenCapturerLinux() { 129 ScreenCapturerLinux::~ScreenCapturerLinux() {
130 options_.x_display()->RemoveEventHandler(ConfigureNotify, this); 130 options_.x_display()->RemoveEventHandler(ConfigureNotify, this);
131 if (use_damage_) { 131 if (use_damage_) {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 246
247 // If the current frame is from an older generation then allocate a new one. 247 // 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 248 // Note that we can't reallocate other buffers at this point, since the caller
249 // may still be reading from them. 249 // may still be reading from them.
250 if (!queue_.current_frame()) { 250 if (!queue_.current_frame()) {
251 queue_.ReplaceCurrentFrame( 251 queue_.ReplaceCurrentFrame(
252 SharedDesktopFrame::Wrap(std::unique_ptr<DesktopFrame>( 252 SharedDesktopFrame::Wrap(std::unique_ptr<DesktopFrame>(
253 new BasicDesktopFrame(x_server_pixel_buffer_.window_size())))); 253 new BasicDesktopFrame(x_server_pixel_buffer_.window_size()))));
254 } 254 }
255 255
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(); 256 std::unique_ptr<DesktopFrame> result = CaptureScreen();
267 last_invalid_region_ = result->updated_region(); 257 last_invalid_region_ = result->updated_region();
268 result->set_capture_time_ms((rtc::TimeNanos() - capture_start_time_nanos) / 258 result->set_capture_time_ms((rtc::TimeNanos() - capture_start_time_nanos) /
269 rtc::kNumNanosecsPerMillisec); 259 rtc::kNumNanosecsPerMillisec);
270 callback_->OnCaptureResult(Result::SUCCESS, std::move(result)); 260 callback_->OnCaptureResult(Result::SUCCESS, std::move(result));
271 } 261 }
272 262
273 bool ScreenCapturerLinux::GetScreenList(ScreenList* screens) { 263 bool ScreenCapturerLinux::GetScreenList(ScreenList* screens) {
274 RTC_DCHECK(screens->size() == 0); 264 RTC_DCHECK(screens->size() == 0);
275 // TODO(jiayl): implement screen enumeration. 265 // TODO(jiayl): implement screen enumeration.
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 332
343 for (DesktopRegion::Iterator it(*updated_region); 333 for (DesktopRegion::Iterator it(*updated_region);
344 !it.IsAtEnd(); it.Advance()) { 334 !it.IsAtEnd(); it.Advance()) {
345 x_server_pixel_buffer_.CaptureRect(it.rect(), frame.get()); 335 x_server_pixel_buffer_.CaptureRect(it.rect(), frame.get());
346 } 336 }
347 } else { 337 } else {
348 // Doing full-screen polling, or this is the first capture after a 338 // Doing full-screen polling, or this is the first capture after a
349 // screen-resolution change. In either case, need a full-screen capture. 339 // screen-resolution change. In either case, need a full-screen capture.
350 DesktopRect screen_rect = DesktopRect::MakeSize(frame->size()); 340 DesktopRect screen_rect = DesktopRect::MakeSize(frame->size());
351 x_server_pixel_buffer_.CaptureRect(screen_rect, frame.get()); 341 x_server_pixel_buffer_.CaptureRect(screen_rect, frame.get());
352 342 updated_region->SetRect(screen_rect);
353 if (queue_.previous_frame()) {
354 // Full-screen polling, so calculate the invalid rects here, based on the
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 } 343 }
368 344
369 return std::move(frame); 345 return std::move(frame);
370 } 346 }
371 347
372 void ScreenCapturerLinux::ScreenConfigurationChanged() { 348 void ScreenCapturerLinux::ScreenConfigurationChanged() {
373 // Make sure the frame buffers will be reallocated. 349 // Make sure the frame buffers will be reallocated.
374 queue_.Reset(); 350 queue_.Reset();
375 351
376 helper_.ClearInvalidRegion(); 352 helper_.ClearInvalidRegion();
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 } 410 }
435 411
436 if (options.detect_updated_region()) { 412 if (options.detect_updated_region()) {
437 capturer.reset(new ScreenCapturerDifferWrapper(std::move(capturer))); 413 capturer.reset(new ScreenCapturerDifferWrapper(std::move(capturer)));
438 } 414 }
439 415
440 return capturer.release(); 416 return capturer.release();
441 } 417 }
442 418
443 } // namespace webrtc 419 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/desktop_capture/differ_unittest.cc ('k') | webrtc/modules/desktop_capture/win/screen_capturer_win_gdi.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698