screen_drawer.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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_SCREEN_DRAWER_H_
  11. #define MODULES_DESKTOP_CAPTURE_SCREEN_DRAWER_H_
  12. #include "modules/desktop_capture/desktop_capture_types.h"
  13. #include "modules/desktop_capture/desktop_geometry.h"
  14. #include "modules/desktop_capture/rgba_color.h"
  15. namespace webrtc {
  16. // A cross-process lock to ensure only one ScreenDrawer can be used at a certain
  17. // time.
  18. class ScreenDrawerLock {
  19. public:
  20. virtual ~ScreenDrawerLock();
  21. static std::unique_ptr<ScreenDrawerLock> Create();
  22. protected:
  23. ScreenDrawerLock();
  24. };
  25. // A set of basic platform dependent functions to draw various shapes on the
  26. // screen.
  27. class ScreenDrawer {
  28. public:
  29. // Creates a ScreenDrawer for the current platform, returns nullptr if no
  30. // ScreenDrawer implementation available.
  31. // If the implementation cannot guarantee two ScreenDrawer instances won't
  32. // impact each other, this function may block current thread until another
  33. // ScreenDrawer has been destroyed.
  34. static std::unique_ptr<ScreenDrawer> Create();
  35. ScreenDrawer();
  36. virtual ~ScreenDrawer();
  37. // Returns the region inside which DrawRectangle() function are expected to
  38. // work, in capturer coordinates (assuming ScreenCapturer::SelectScreen has
  39. // not been called). This region may exclude regions of the screen reserved by
  40. // the OS for things like menu bars or app launchers. The DesktopRect is in
  41. // system coordinate, i.e. the primary monitor always starts from (0, 0).
  42. virtual DesktopRect DrawableRegion() = 0;
  43. // Draws a rectangle to cover |rect| with |color|. Note, rect.bottom() and
  44. // rect.right() two lines are not included. The part of |rect| which is out of
  45. // DrawableRegion() will be ignored.
  46. virtual void DrawRectangle(DesktopRect rect, RgbaColor color) = 0;
  47. // Clears all content on the screen by filling the area with black.
  48. virtual void Clear() = 0;
  49. // Blocks current thread until OS finishes previous DrawRectangle() actions.
  50. // ScreenCapturer should be able to capture the changes after this function
  51. // finish.
  52. virtual void WaitForPendingDraws() = 0;
  53. // Returns true if incomplete shapes previous actions required may be drawn on
  54. // the screen after a WaitForPendingDraws() call. i.e. Though the complete
  55. // shapes will eventually be drawn on the screen, due to some OS limitations,
  56. // these shapes may be partially appeared sometimes.
  57. virtual bool MayDrawIncompleteShapes() = 0;
  58. // Returns the id of the drawer window. This function returns kNullWindowId if
  59. // the implementation does not draw on a window of the system.
  60. virtual WindowId window_id() const = 0;
  61. };
  62. } // namespace webrtc
  63. #endif // MODULES_DESKTOP_CAPTURE_SCREEN_DRAWER_H_