OLD | NEW |
---|---|
(Empty) | |
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_PAINTER_H_ | |
12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_PAINTER_H_ | |
13 | |
14 #include <stdint.h> | |
15 | |
16 #include <memory> | |
17 #include <vector> | |
18 | |
19 #include "webrtc/modules/desktop_capture/desktop_frame.h" | |
20 #include "webrtc/modules/desktop_capture/desktop_geometry.h" | |
21 #include "webrtc/modules/desktop_capture/screen_drawer.h" | |
22 | |
23 namespace webrtc { | |
24 | |
25 // A set of platform independent functions to draw various shapes on the screen. | |
26 // This class provides more convenient functions to draw more complex shapes by | |
27 // using a ScreenDrawer for a certain platform. This class is for testing | |
28 // ScreenCapturer* implementations only, and should not be used in production | |
29 // logic. | |
30 class ScreenPainter final { | |
Jamie
2016/08/23 18:50:54
I suggest removing this class. Other than randomiz
Hzj_jie
2016/08/26 00:06:49
After talked offline with Joe, I will remove rando
Hzj_jie
2016/08/26 02:05:24
Sorry, my bad, I forgot to update this comment.
| |
31 public: | |
32 // Creates a ScreenPainter for the current platform, returns nullptr if no | |
33 // ScreenDrawer implementation available. | |
34 static std::unique_ptr<ScreenPainter> Create(); | |
35 | |
36 ~ScreenPainter(); | |
37 | |
38 // A four bytes structure to store a color in BGRA format, which can be safely | |
39 // cast into uint8_t* to compare with DesktopFrame::data(). | |
40 struct Color final { | |
41 // Creates a white Color. | |
42 static Color White(); | |
Jamie
2016/08/23 18:50:53
I don't think you need this ctor either if you sup
Hzj_jie
2016/08/26 00:06:49
Done.
| |
43 | |
44 // Creates a random Color. | |
45 static Color Random(); | |
Jamie
2016/08/23 18:50:53
I don't think this file should contain any functio
Hzj_jie
2016/08/26 00:06:49
Done.
| |
46 | |
47 // Returns true if |bgra| four bytes in BGRA order represents a same color | |
48 // as |this|. | |
49 bool operator==(const uint8_t* const bgra) const; | |
50 | |
51 // Returns true if |bgra| four bytes in BGRA order represents a different | |
52 // color as |this|. | |
53 bool operator!=(const uint8_t* const bgra) const; | |
54 | |
55 // Returns true if |this| and |right| is the same color. | |
56 bool operator==(const Color right) const; | |
57 | |
58 // Returns true if |this| and |right| are different colors. | |
59 bool operator!=(const Color right) const; | |
60 | |
61 // Returns true if the pixels represent by |right| are equal to |left|. | |
62 static bool PixelsMatch(const std::vector<Color>& left, | |
63 const uint8_t* right); | |
64 | |
65 // Converts current Color into its uint format in RGBA order for | |
66 // ScreenDrawer to draw shapes. | |
67 uint32_t ToUInt32() const; | |
68 | |
69 uint8_t bgra[DesktopFrame::kBytesPerPixel]; | |
70 }; | |
71 static_assert(sizeof(Color) == sizeof(Color::bgra) && | |
72 sizeof(Color) == DesktopFrame::kBytesPerPixel, | |
73 "No extra fields should be added to Color structure."); | |
Jamie
2016/08/23 18:50:53
You won't need this if you get rid of the memset/m
Hzj_jie
2016/08/26 00:06:49
Done.
| |
74 | |
75 // Returns ScreenDrawer::DrawableRegion(). | |
76 DesktopRect DrawableRegion(); | |
77 | |
78 // Draws a rectangle by calling ScreenDrawer::DrawRectangle. |rect| will be | |
79 // intersected with DrawableRegion(), so if it's out of DrawableRegion(), this | |
80 // function takes no effect. If part of |rect| is out of DrawableRegion(), | |
81 // this function draws less area. | |
82 void DrawRectangle(DesktopRect rect, Color color); | |
83 | |
84 // Calls ScreenDrawer::WaitForPendingPaintings(). | |
85 void WaitForPendingPaintings(); | |
86 | |
87 // Draws a black (RGBA 0 0 0 0) rectangle to cover entire DrawableRegion(). | |
88 void Clear(); | |
89 | |
90 // Draws a dot at |vect| with color |color|. If |vect| is out of | |
91 // DrawableRegion(), this function takes no effect. | |
92 void DrawDot(DesktopVector vect, Color color); | |
93 | |
94 // Draws a dot with random color at |vect| and returns the color. If |vect| is | |
95 // out of DrawableRegion(), this function takes no effect, but still returns a | |
96 // color. | |
97 Color DrawRandomColorDot(DesktopVector vect); | |
98 | |
99 // Draws a serial of dots with random colors between |start| and |end|, and | |
100 // stores the colors in |colors|. Returns the number of dots rendered, which | |
101 // equals to | |
102 // std::max(std::abs(end.y() - start.y()), std::abs(end.x() - start.x())). | |
103 // The dot at |end| is ignored, and if |start| == |end|, this function does | |
104 // not take effect. If |start| or |end| is out of DrawableRegion(), the | |
105 // visible dots may be less than the value returned. | |
106 int DrawColorfulLine(DesktopVector start, | |
107 DesktopVector end, | |
108 std::vector<Color>* colors); | |
109 | |
110 // Draws a colorful horizontal line starting from |start|, with length |len|, | |
111 // stores the colors in |colors|. If |len| is less than zero, the line will be | |
112 // drawn to left. If |len| is zero, this function does not take effect. If | |
113 // |start| or |start|.x() + |len| is out of DrawableRegion(), this function | |
114 // may draw less dots than |len|. | |
115 void DrawColorfulHorizontalLine(DesktopVector start, | |
116 int len, | |
117 std::vector<Color>* colors); | |
118 | |
119 // Draws a colorful horizontal line starting from |start|, with length | |
120 // |colors|.size(). This function draws each dot with one color in |colors| | |
121 // sequentially. | |
122 void DrawColorfulHorizontalLine(DesktopVector start, | |
123 const std::vector<Color>& colors); | |
124 | |
125 // Draws a random color rectangle at |rect|, returns the color. |rect| will | |
126 // be intersected with DrawableRegion(), so if it's out of DrawableRegion(), | |
127 // this function takes no effect. If part of |rect| is out of | |
128 // DrawableRegion(), this function draws less area. | |
129 Color DrawRandomColorRectangle(DesktopRect rect); | |
130 | |
131 // Draws a random color rectangle with random size in the range of |range|, | |
132 // and sets |color| and |rect| with the color, position and size. | |
133 void DrawRandomColorRectangleIn(DesktopSize range, | |
134 Color* color, | |
135 DesktopRect* rect); | |
136 | |
137 private: | |
138 explicit ScreenPainter(std::unique_ptr<ScreenDrawer> drawer); | |
139 | |
140 std::unique_ptr<ScreenDrawer> drawer_; | |
141 }; | |
142 | |
143 } // namespace webrtc | |
144 | |
145 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_PAINTER_H_ | |
OLD | NEW |