screen_capturer_helper.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  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. #ifndef MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_HELPER_H_
  11. #define MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_HELPER_H_
  12. #include <memory>
  13. #include "modules/desktop_capture/desktop_geometry.h"
  14. #include "modules/desktop_capture/desktop_region.h"
  15. #include "rtc_base/constructor_magic.h"
  16. #include "rtc_base/synchronization/rw_lock_wrapper.h"
  17. namespace webrtc {
  18. // ScreenCapturerHelper is intended to be used by an implementation of the
  19. // ScreenCapturer interface. It maintains a thread-safe invalid region, and
  20. // the size of the most recently captured screen, on behalf of the
  21. // ScreenCapturer that owns it.
  22. class ScreenCapturerHelper {
  23. public:
  24. ScreenCapturerHelper();
  25. ~ScreenCapturerHelper();
  26. // Clear out the invalid region.
  27. void ClearInvalidRegion();
  28. // Invalidate the specified region.
  29. void InvalidateRegion(const DesktopRegion& invalid_region);
  30. // Invalidate the entire screen, of a given size.
  31. void InvalidateScreen(const DesktopSize& size);
  32. // Copies current invalid region to |invalid_region| clears invalid region
  33. // storage for the next frame.
  34. void TakeInvalidRegion(DesktopRegion* invalid_region);
  35. // Access the size of the most recently captured screen.
  36. const DesktopSize& size_most_recent() const;
  37. void set_size_most_recent(const DesktopSize& size);
  38. // Lossy compression can result in color values leaking between pixels in one
  39. // block. If part of a block changes, then unchanged parts of that block can
  40. // be changed in the compressed output. So we need to re-render an entire
  41. // block whenever part of the block changes.
  42. //
  43. // If |log_grid_size| is >= 1, then this function makes TakeInvalidRegion()
  44. // produce an invalid region expanded so that its vertices lie on a grid of
  45. // size 2 ^ |log_grid_size|. The expanded region is then clipped to the size
  46. // of the most recently captured screen, as previously set by
  47. // set_size_most_recent().
  48. // If |log_grid_size| is <= 0, then the invalid region is not expanded.
  49. void SetLogGridSize(int log_grid_size);
  50. // Expands a region so that its vertices all lie on a grid.
  51. // The grid size must be >= 2, so |log_grid_size| must be >= 1.
  52. static void ExpandToGrid(const DesktopRegion& region,
  53. int log_grid_size,
  54. DesktopRegion* result);
  55. private:
  56. // A region that has been manually invalidated (through InvalidateRegion).
  57. // These will be returned as dirty_region in the capture data during the next
  58. // capture.
  59. DesktopRegion invalid_region_;
  60. // A lock protecting |invalid_region_| across threads.
  61. std::unique_ptr<RWLockWrapper> invalid_region_lock_;
  62. // The size of the most recently captured screen.
  63. DesktopSize size_most_recent_;
  64. // The log (base 2) of the size of the grid to which the invalid region is
  65. // expanded.
  66. // If the value is <= 0, then the invalid region is not expanded to a grid.
  67. int log_grid_size_;
  68. RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCapturerHelper);
  69. };
  70. } // namespace webrtc
  71. #endif // MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_HELPER_H_