desktop_frame_generator.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright (c) 2016 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_DESKTOP_FRAME_GENERATOR_H_
  11. #define MODULES_DESKTOP_CAPTURE_DESKTOP_FRAME_GENERATOR_H_
  12. #include <memory>
  13. #include "modules/desktop_capture/desktop_frame.h"
  14. #include "modules/desktop_capture/desktop_geometry.h"
  15. #include "modules/desktop_capture/desktop_region.h"
  16. #include "modules/desktop_capture/shared_memory.h"
  17. namespace webrtc {
  18. // An interface to generate a DesktopFrame.
  19. class DesktopFrameGenerator {
  20. public:
  21. DesktopFrameGenerator();
  22. virtual ~DesktopFrameGenerator();
  23. virtual std::unique_ptr<DesktopFrame> GetNextFrame(
  24. SharedMemoryFactory* factory) = 0;
  25. };
  26. // An interface to paint a DesktopFrame. This interface is used by
  27. // PainterDesktopFrameGenerator.
  28. class DesktopFramePainter {
  29. public:
  30. DesktopFramePainter();
  31. virtual ~DesktopFramePainter();
  32. virtual bool Paint(DesktopFrame* frame, DesktopRegion* updated_region) = 0;
  33. };
  34. // An implementation of DesktopFrameGenerator to take care about the
  35. // DesktopFrame size, filling updated_region(), etc, but leaves the real
  36. // painting work to a DesktopFramePainter implementation.
  37. class PainterDesktopFrameGenerator final : public DesktopFrameGenerator {
  38. public:
  39. PainterDesktopFrameGenerator();
  40. ~PainterDesktopFrameGenerator() override;
  41. std::unique_ptr<DesktopFrame> GetNextFrame(
  42. SharedMemoryFactory* factory) override;
  43. // Sets the size of the frame which will be returned in next GetNextFrame()
  44. // call.
  45. DesktopSize* size();
  46. // Decides whether BaseDesktopFrameGenerator returns a frame in next Capture()
  47. // callback. If return_frame_ is true, BaseDesktopFrameGenerator will create a
  48. // frame according to both size_ and SharedMemoryFactory input, and uses
  49. // Paint() function to paint it.
  50. void set_return_frame(bool return_frame);
  51. // Decides whether MockScreenCapturer returns a frame with updated regions.
  52. // MockScreenCapturer will keep DesktopFrame::updated_region() empty if this
  53. // field is false.
  54. void set_provide_updated_region_hints(bool provide_updated_region_hints);
  55. // Decides whether MockScreenCapturer randomly enlarges updated regions in the
  56. // DesktopFrame. Set this field to true to simulate an inaccurate updated
  57. // regions' return from OS APIs.
  58. void set_enlarge_updated_region(bool enlarge_updated_region);
  59. // The range to enlarge a updated region if |enlarge_updated_region_| is true.
  60. // If this field is less than zero, it will be treated as zero, and
  61. // |enlarge_updated_region_| will be ignored.
  62. void set_enlarge_range(int enlarge_range);
  63. // Decides whether BaseDesktopFrameGenerator randomly add some updated regions
  64. // in the DesktopFrame. Set this field to true to simulate an inaccurate
  65. // updated regions' return from OS APIs.
  66. void set_add_random_updated_region(bool add_random_updated_region);
  67. // Sets the painter object to do the real painting work, if no |painter_| has
  68. // been set to this instance, the DesktopFrame returned by GetNextFrame()
  69. // function will keep in an undefined but valid state.
  70. // PainterDesktopFrameGenerator does not take ownership of the |painter|.
  71. void set_desktop_frame_painter(DesktopFramePainter* painter);
  72. private:
  73. DesktopSize size_;
  74. bool return_frame_;
  75. bool provide_updated_region_hints_;
  76. bool enlarge_updated_region_;
  77. int enlarge_range_;
  78. bool add_random_updated_region_;
  79. DesktopFramePainter* painter_;
  80. };
  81. // An implementation of DesktopFramePainter to paint black on
  82. // mutable_updated_region(), and white elsewhere.
  83. class BlackWhiteDesktopFramePainter final : public DesktopFramePainter {
  84. public:
  85. BlackWhiteDesktopFramePainter();
  86. ~BlackWhiteDesktopFramePainter() override;
  87. // The black regions of the frame which will be returned in next Paint()
  88. // call. BlackWhiteDesktopFramePainter will draw a white frame, with black
  89. // in the updated_region_. Each Paint() call will consume updated_region_.
  90. DesktopRegion* updated_region();
  91. // DesktopFramePainter interface.
  92. bool Paint(DesktopFrame* frame, DesktopRegion* updated_region) override;
  93. private:
  94. DesktopRegion updated_region_;
  95. };
  96. } // namespace webrtc
  97. #endif // MODULES_DESKTOP_CAPTURE_DESKTOP_FRAME_GENERATOR_H_