1*d9f75844SAndroid Build Coastguard Worker /* 2*d9f75844SAndroid Build Coastguard Worker * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3*d9f75844SAndroid Build Coastguard Worker * 4*d9f75844SAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license 5*d9f75844SAndroid Build Coastguard Worker * that can be found in the LICENSE file in the root of the source 6*d9f75844SAndroid Build Coastguard Worker * tree. An additional intellectual property rights grant can be found 7*d9f75844SAndroid Build Coastguard Worker * in the file PATENTS. All contributing project authors may 8*d9f75844SAndroid Build Coastguard Worker * be found in the AUTHORS file in the root of the source tree. 9*d9f75844SAndroid Build Coastguard Worker */ 10*d9f75844SAndroid Build Coastguard Worker 11*d9f75844SAndroid Build Coastguard Worker #ifndef MODULES_DESKTOP_CAPTURE_SCREEN_DRAWER_H_ 12*d9f75844SAndroid Build Coastguard Worker #define MODULES_DESKTOP_CAPTURE_SCREEN_DRAWER_H_ 13*d9f75844SAndroid Build Coastguard Worker 14*d9f75844SAndroid Build Coastguard Worker #include "modules/desktop_capture/desktop_capture_types.h" 15*d9f75844SAndroid Build Coastguard Worker #include "modules/desktop_capture/desktop_geometry.h" 16*d9f75844SAndroid Build Coastguard Worker #include "modules/desktop_capture/rgba_color.h" 17*d9f75844SAndroid Build Coastguard Worker 18*d9f75844SAndroid Build Coastguard Worker namespace webrtc { 19*d9f75844SAndroid Build Coastguard Worker 20*d9f75844SAndroid Build Coastguard Worker // A cross-process lock to ensure only one ScreenDrawer can be used at a certain 21*d9f75844SAndroid Build Coastguard Worker // time. 22*d9f75844SAndroid Build Coastguard Worker class ScreenDrawerLock { 23*d9f75844SAndroid Build Coastguard Worker public: 24*d9f75844SAndroid Build Coastguard Worker virtual ~ScreenDrawerLock(); 25*d9f75844SAndroid Build Coastguard Worker 26*d9f75844SAndroid Build Coastguard Worker static std::unique_ptr<ScreenDrawerLock> Create(); 27*d9f75844SAndroid Build Coastguard Worker 28*d9f75844SAndroid Build Coastguard Worker protected: 29*d9f75844SAndroid Build Coastguard Worker ScreenDrawerLock(); 30*d9f75844SAndroid Build Coastguard Worker }; 31*d9f75844SAndroid Build Coastguard Worker 32*d9f75844SAndroid Build Coastguard Worker // A set of basic platform dependent functions to draw various shapes on the 33*d9f75844SAndroid Build Coastguard Worker // screen. 34*d9f75844SAndroid Build Coastguard Worker class ScreenDrawer { 35*d9f75844SAndroid Build Coastguard Worker public: 36*d9f75844SAndroid Build Coastguard Worker // Creates a ScreenDrawer for the current platform, returns nullptr if no 37*d9f75844SAndroid Build Coastguard Worker // ScreenDrawer implementation available. 38*d9f75844SAndroid Build Coastguard Worker // If the implementation cannot guarantee two ScreenDrawer instances won't 39*d9f75844SAndroid Build Coastguard Worker // impact each other, this function may block current thread until another 40*d9f75844SAndroid Build Coastguard Worker // ScreenDrawer has been destroyed. 41*d9f75844SAndroid Build Coastguard Worker static std::unique_ptr<ScreenDrawer> Create(); 42*d9f75844SAndroid Build Coastguard Worker 43*d9f75844SAndroid Build Coastguard Worker ScreenDrawer(); 44*d9f75844SAndroid Build Coastguard Worker virtual ~ScreenDrawer(); 45*d9f75844SAndroid Build Coastguard Worker 46*d9f75844SAndroid Build Coastguard Worker // Returns the region inside which DrawRectangle() function are expected to 47*d9f75844SAndroid Build Coastguard Worker // work, in capturer coordinates (assuming ScreenCapturer::SelectScreen has 48*d9f75844SAndroid Build Coastguard Worker // not been called). This region may exclude regions of the screen reserved by 49*d9f75844SAndroid Build Coastguard Worker // the OS for things like menu bars or app launchers. The DesktopRect is in 50*d9f75844SAndroid Build Coastguard Worker // system coordinate, i.e. the primary monitor always starts from (0, 0). 51*d9f75844SAndroid Build Coastguard Worker virtual DesktopRect DrawableRegion() = 0; 52*d9f75844SAndroid Build Coastguard Worker 53*d9f75844SAndroid Build Coastguard Worker // Draws a rectangle to cover `rect` with `color`. Note, rect.bottom() and 54*d9f75844SAndroid Build Coastguard Worker // rect.right() two lines are not included. The part of `rect` which is out of 55*d9f75844SAndroid Build Coastguard Worker // DrawableRegion() will be ignored. 56*d9f75844SAndroid Build Coastguard Worker virtual void DrawRectangle(DesktopRect rect, RgbaColor color) = 0; 57*d9f75844SAndroid Build Coastguard Worker 58*d9f75844SAndroid Build Coastguard Worker // Clears all content on the screen by filling the area with black. 59*d9f75844SAndroid Build Coastguard Worker virtual void Clear() = 0; 60*d9f75844SAndroid Build Coastguard Worker 61*d9f75844SAndroid Build Coastguard Worker // Blocks current thread until OS finishes previous DrawRectangle() actions. 62*d9f75844SAndroid Build Coastguard Worker // ScreenCapturer should be able to capture the changes after this function 63*d9f75844SAndroid Build Coastguard Worker // finish. 64*d9f75844SAndroid Build Coastguard Worker virtual void WaitForPendingDraws() = 0; 65*d9f75844SAndroid Build Coastguard Worker 66*d9f75844SAndroid Build Coastguard Worker // Returns true if incomplete shapes previous actions required may be drawn on 67*d9f75844SAndroid Build Coastguard Worker // the screen after a WaitForPendingDraws() call. i.e. Though the complete 68*d9f75844SAndroid Build Coastguard Worker // shapes will eventually be drawn on the screen, due to some OS limitations, 69*d9f75844SAndroid Build Coastguard Worker // these shapes may be partially appeared sometimes. 70*d9f75844SAndroid Build Coastguard Worker virtual bool MayDrawIncompleteShapes() = 0; 71*d9f75844SAndroid Build Coastguard Worker 72*d9f75844SAndroid Build Coastguard Worker // Returns the id of the drawer window. This function returns kNullWindowId if 73*d9f75844SAndroid Build Coastguard Worker // the implementation does not draw on a window of the system. 74*d9f75844SAndroid Build Coastguard Worker virtual WindowId window_id() const = 0; 75*d9f75844SAndroid Build Coastguard Worker }; 76*d9f75844SAndroid Build Coastguard Worker 77*d9f75844SAndroid Build Coastguard Worker } // namespace webrtc 78*d9f75844SAndroid Build Coastguard Worker 79*d9f75844SAndroid Build Coastguard Worker #endif // MODULES_DESKTOP_CAPTURE_SCREEN_DRAWER_H_ 80