screen_drawer.h (3111B)
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 MODULES_DESKTOP_CAPTURE_SCREEN_DRAWER_H_ 12 #define MODULES_DESKTOP_CAPTURE_SCREEN_DRAWER_H_ 13 14 #include <memory> 15 16 #include "modules/desktop_capture/desktop_capture_types.h" 17 #include "modules/desktop_capture/desktop_geometry.h" 18 #include "modules/desktop_capture/rgba_color.h" 19 20 namespace webrtc { 21 22 // A cross-process lock to ensure only one ScreenDrawer can be used at a certain 23 // time. 24 class ScreenDrawerLock { 25 public: 26 virtual ~ScreenDrawerLock(); 27 28 static std::unique_ptr<ScreenDrawerLock> Create(); 29 30 protected: 31 ScreenDrawerLock(); 32 }; 33 34 // A set of basic platform dependent functions to draw various shapes on the 35 // screen. 36 class ScreenDrawer { 37 public: 38 // Creates a ScreenDrawer for the current platform, returns nullptr if no 39 // ScreenDrawer implementation available. 40 // If the implementation cannot guarantee two ScreenDrawer instances won't 41 // impact each other, this function may block current thread until another 42 // ScreenDrawer has been destroyed. 43 static std::unique_ptr<ScreenDrawer> Create(); 44 45 ScreenDrawer(); 46 virtual ~ScreenDrawer(); 47 48 // Returns the region inside which DrawRectangle() function are expected to 49 // work, in capturer coordinates (assuming ScreenCapturer::SelectScreen has 50 // not been called). This region may exclude regions of the screen reserved by 51 // the OS for things like menu bars or app launchers. The DesktopRect is in 52 // system coordinate, i.e. the primary monitor always starts from (0, 0). 53 virtual DesktopRect DrawableRegion() = 0; 54 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; 59 60 // Clears all content on the screen by filling the area with black. 61 virtual void Clear() = 0; 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; 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; 73 74 // Returns the id of the drawer window. This function returns kNullWindowId if 75 // the implementation does not draw on a window of the system. 76 virtual WindowId window_id() const = 0; 77 }; 78 79 } // namespace webrtc 80 81 #endif // MODULES_DESKTOP_CAPTURE_SCREEN_DRAWER_H_