blob: cde9a2e50ea92f07711e4ec969b1d95596239e2c [file] [log] [blame]
zijiehe49c01d72016-08-16 17:33:55 -07001/*
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
zijiehe0f49dac2016-09-07 11:52:25 -070018#include "webrtc/modules/desktop_capture/rgba_color.h"
zijiehe49c01d72016-08-16 17:33:55 -070019#include "webrtc/modules/desktop_capture/desktop_geometry.h"
20
21namespace webrtc {
22
zijiehe6a4607e2016-10-18 18:22:18 -070023// A cross-process lock to ensure only one ScreenDrawer can be used at a certain
24// time.
25class ScreenDrawerLock {
26 public:
27 virtual ~ScreenDrawerLock();
28
29 static std::unique_ptr<ScreenDrawerLock> Create();
30
31 protected:
32 ScreenDrawerLock();
33};
34
zijiehe0f49dac2016-09-07 11:52:25 -070035// A set of basic platform dependent functions to draw various shapes on the
36// screen.
zijiehe49c01d72016-08-16 17:33:55 -070037class ScreenDrawer {
38 public:
zijiehe0f49dac2016-09-07 11:52:25 -070039 // Creates a ScreenDrawer for the current platform, returns nullptr if no
40 // ScreenDrawer implementation available.
zijiehe6a4607e2016-10-18 18:22:18 -070041 // 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.
zijiehe49c01d72016-08-16 17:33:55 -070044 static std::unique_ptr<ScreenDrawer> Create();
45
zijiehe6a4607e2016-10-18 18:22:18 -070046 ScreenDrawer();
47 virtual ~ScreenDrawer();
zijiehe49c01d72016-08-16 17:33:55 -070048
zijiehe0f49dac2016-09-07 11:52:25 -070049 // 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.
zijiehe49c01d72016-08-16 17:33:55 -070053 virtual DesktopRect DrawableRegion() = 0;
54
zijiehe0f49dac2016-09-07 11:52:25 -070055 // 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;
zijiehe49c01d72016-08-16 17:33:55 -070059
zijiehe0f49dac2016-09-07 11:52:25 -070060 // Clears all content on the screen by filling the area with black.
zijiehe49c01d72016-08-16 17:33:55 -070061 virtual void Clear() = 0;
zijiehe0f49dac2016-09-07 11:52:25 -070062
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;
zijiehe6a4607e2016-10-18 18:22:18 -070067
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;
zijiehe49c01d72016-08-16 17:33:55 -070073};
74
75} // namespace webrtc
76
77#endif // WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_DRAWER_H_