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