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