blob: cd7fa689c0cabe06d3d26d0b20d08b73d7779092 [file] [log] [blame]
sergeyu@chromium.org3d34f662013-06-04 18:51:231/*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
Mirko Bonadei92ea95e2017-09-15 04:47:3111#ifndef MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_HELPER_H_
12#define MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_HELPER_H_
sergeyu@chromium.org3d34f662013-06-04 18:51:2313
kwiberg2bb3afa2016-03-16 22:58:0814#include <memory>
15
Mirko Bonadei92ea95e2017-09-15 04:47:3116#include "modules/desktop_capture/desktop_geometry.h"
17#include "modules/desktop_capture/desktop_region.h"
Niels Möllerb0d83cd2020-10-28 14:18:5618#include "rtc_base/synchronization/mutex.h"
19#include "rtc_base/thread_annotations.h"
sergeyu@chromium.org3d34f662013-06-04 18:51:2320
21namespace webrtc {
22
23// ScreenCapturerHelper is intended to be used by an implementation of the
24// ScreenCapturer interface. It maintains a thread-safe invalid region, and
25// the size of the most recently captured screen, on behalf of the
26// ScreenCapturer that owns it.
27class ScreenCapturerHelper {
28 public:
Niels Möllerb0d83cd2020-10-28 14:18:5629 ScreenCapturerHelper() = default;
30 ~ScreenCapturerHelper() = default;
sergeyu@chromium.org3d34f662013-06-04 18:51:2331
Byoungchan Lee604fd2f2022-01-21 00:49:3932 ScreenCapturerHelper(const ScreenCapturerHelper&) = delete;
33 ScreenCapturerHelper& operator=(const ScreenCapturerHelper&) = delete;
34
sergeyu@chromium.org3d34f662013-06-04 18:51:2335 // Clear out the invalid region.
36 void ClearInvalidRegion();
37
38 // Invalidate the specified region.
39 void InvalidateRegion(const DesktopRegion& invalid_region);
40
41 // Invalidate the entire screen, of a given size.
42 void InvalidateScreen(const DesktopSize& size);
43
Artem Titovcec43432021-07-28 21:35:3944 // Copies current invalid region to `invalid_region` clears invalid region
sergeyu@chromium.org3d34f662013-06-04 18:51:2345 // storage for the next frame.
46 void TakeInvalidRegion(DesktopRegion* invalid_region);
47
48 // Access the size of the most recently captured screen.
49 const DesktopSize& size_most_recent() const;
50 void set_size_most_recent(const DesktopSize& size);
51
52 // Lossy compression can result in color values leaking between pixels in one
53 // block. If part of a block changes, then unchanged parts of that block can
54 // be changed in the compressed output. So we need to re-render an entire
55 // block whenever part of the block changes.
56 //
Artem Titovcec43432021-07-28 21:35:3957 // If `log_grid_size` is >= 1, then this function makes TakeInvalidRegion()
sergeyu@chromium.org3d34f662013-06-04 18:51:2358 // produce an invalid region expanded so that its vertices lie on a grid of
Artem Titovcec43432021-07-28 21:35:3959 // size 2 ^ `log_grid_size`. The expanded region is then clipped to the size
sergeyu@chromium.org3d34f662013-06-04 18:51:2360 // of the most recently captured screen, as previously set by
61 // set_size_most_recent().
Artem Titovcec43432021-07-28 21:35:3962 // If `log_grid_size` is <= 0, then the invalid region is not expanded.
sergeyu@chromium.org3d34f662013-06-04 18:51:2363 void SetLogGridSize(int log_grid_size);
64
65 // Expands a region so that its vertices all lie on a grid.
Artem Titovcec43432021-07-28 21:35:3966 // The grid size must be >= 2, so `log_grid_size` must be >= 1.
sergeyu@chromium.org3d34f662013-06-04 18:51:2367 static void ExpandToGrid(const DesktopRegion& region,
68 int log_grid_size,
69 DesktopRegion* result);
70
71 private:
72 // A region that has been manually invalidated (through InvalidateRegion).
73 // These will be returned as dirty_region in the capture data during the next
74 // capture.
Niels Möllerb0d83cd2020-10-28 14:18:5675 DesktopRegion invalid_region_ RTC_GUARDED_BY(invalid_region_mutex_);
sergeyu@chromium.org3d34f662013-06-04 18:51:2376
Artem Titovcec43432021-07-28 21:35:3977 // A lock protecting `invalid_region_` across threads.
Niels Möllerb0d83cd2020-10-28 14:18:5678 Mutex invalid_region_mutex_;
sergeyu@chromium.org3d34f662013-06-04 18:51:2379
80 // The size of the most recently captured screen.
81 DesktopSize size_most_recent_;
82
83 // The log (base 2) of the size of the grid to which the invalid region is
84 // expanded.
85 // If the value is <= 0, then the invalid region is not expanded to a grid.
Niels Möllerb0d83cd2020-10-28 14:18:5686 int log_grid_size_ = 0;
sergeyu@chromium.org3d34f662013-06-04 18:51:2387};
88
89} // namespace webrtc
90
Mirko Bonadei92ea95e2017-09-15 04:47:3191#endif // MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_HELPER_H_