Chromium Code Reviews| Index: webrtc/modules/desktop_capture/screen_painter.h |
| diff --git a/webrtc/modules/desktop_capture/screen_painter.h b/webrtc/modules/desktop_capture/screen_painter.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e5807175f8ce10a9ade30f4a2da5be22bc8b1b60 |
| --- /dev/null |
| +++ b/webrtc/modules/desktop_capture/screen_painter.h |
| @@ -0,0 +1,145 @@ |
| +/* |
| + * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_PAINTER_H_ |
| +#define WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_PAINTER_H_ |
| + |
| +#include <stdint.h> |
| + |
| +#include <memory> |
| +#include <vector> |
| + |
| +#include "webrtc/modules/desktop_capture/desktop_frame.h" |
| +#include "webrtc/modules/desktop_capture/desktop_geometry.h" |
| +#include "webrtc/modules/desktop_capture/screen_drawer.h" |
| + |
| +namespace webrtc { |
| + |
| +// A set of platform independent functions to draw various shapes on the screen. |
| +// This class provides more convenient functions to draw more complex shapes by |
| +// using a ScreenDrawer for a certain platform. This class is for testing |
| +// ScreenCapturer* implementations only, and should not be used in production |
| +// logic. |
| +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.
|
| + public: |
| + // Creates a ScreenPainter for the current platform, returns nullptr if no |
| + // ScreenDrawer implementation available. |
| + static std::unique_ptr<ScreenPainter> Create(); |
| + |
| + ~ScreenPainter(); |
| + |
| + // A four bytes structure to store a color in BGRA format, which can be safely |
| + // cast into uint8_t* to compare with DesktopFrame::data(). |
| + struct Color final { |
| + // Creates a white Color. |
| + 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.
|
| + |
| + // Creates a random Color. |
| + 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.
|
| + |
| + // Returns true if |bgra| four bytes in BGRA order represents a same color |
| + // as |this|. |
| + bool operator==(const uint8_t* const bgra) const; |
| + |
| + // Returns true if |bgra| four bytes in BGRA order represents a different |
| + // color as |this|. |
| + bool operator!=(const uint8_t* const bgra) const; |
| + |
| + // Returns true if |this| and |right| is the same color. |
| + bool operator==(const Color right) const; |
| + |
| + // Returns true if |this| and |right| are different colors. |
| + bool operator!=(const Color right) const; |
| + |
| + // Returns true if the pixels represent by |right| are equal to |left|. |
| + static bool PixelsMatch(const std::vector<Color>& left, |
| + const uint8_t* right); |
| + |
| + // Converts current Color into its uint format in RGBA order for |
| + // ScreenDrawer to draw shapes. |
| + uint32_t ToUInt32() const; |
| + |
| + uint8_t bgra[DesktopFrame::kBytesPerPixel]; |
| + }; |
| + static_assert(sizeof(Color) == sizeof(Color::bgra) && |
| + sizeof(Color) == DesktopFrame::kBytesPerPixel, |
| + "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.
|
| + |
| + // Returns ScreenDrawer::DrawableRegion(). |
| + DesktopRect DrawableRegion(); |
| + |
| + // Draws a rectangle by calling ScreenDrawer::DrawRectangle. |rect| will be |
| + // intersected with DrawableRegion(), so if it's out of DrawableRegion(), this |
| + // function takes no effect. If part of |rect| is out of DrawableRegion(), |
| + // this function draws less area. |
| + void DrawRectangle(DesktopRect rect, Color color); |
| + |
| + // Calls ScreenDrawer::WaitForPendingPaintings(). |
| + void WaitForPendingPaintings(); |
| + |
| + // Draws a black (RGBA 0 0 0 0) rectangle to cover entire DrawableRegion(). |
| + void Clear(); |
| + |
| + // Draws a dot at |vect| with color |color|. If |vect| is out of |
| + // DrawableRegion(), this function takes no effect. |
| + void DrawDot(DesktopVector vect, Color color); |
| + |
| + // Draws a dot with random color at |vect| and returns the color. If |vect| is |
| + // out of DrawableRegion(), this function takes no effect, but still returns a |
| + // color. |
| + Color DrawRandomColorDot(DesktopVector vect); |
| + |
| + // Draws a serial of dots with random colors between |start| and |end|, and |
| + // stores the colors in |colors|. Returns the number of dots rendered, which |
| + // equals to |
| + // std::max(std::abs(end.y() - start.y()), std::abs(end.x() - start.x())). |
| + // The dot at |end| is ignored, and if |start| == |end|, this function does |
| + // not take effect. If |start| or |end| is out of DrawableRegion(), the |
| + // visible dots may be less than the value returned. |
| + int DrawColorfulLine(DesktopVector start, |
| + DesktopVector end, |
| + std::vector<Color>* colors); |
| + |
| + // Draws a colorful horizontal line starting from |start|, with length |len|, |
| + // stores the colors in |colors|. If |len| is less than zero, the line will be |
| + // drawn to left. If |len| is zero, this function does not take effect. If |
| + // |start| or |start|.x() + |len| is out of DrawableRegion(), this function |
| + // may draw less dots than |len|. |
| + void DrawColorfulHorizontalLine(DesktopVector start, |
| + int len, |
| + std::vector<Color>* colors); |
| + |
| + // Draws a colorful horizontal line starting from |start|, with length |
| + // |colors|.size(). This function draws each dot with one color in |colors| |
| + // sequentially. |
| + void DrawColorfulHorizontalLine(DesktopVector start, |
| + const std::vector<Color>& colors); |
| + |
| + // Draws a random color rectangle at |rect|, returns the color. |rect| will |
| + // be intersected with DrawableRegion(), so if it's out of DrawableRegion(), |
| + // this function takes no effect. If part of |rect| is out of |
| + // DrawableRegion(), this function draws less area. |
| + Color DrawRandomColorRectangle(DesktopRect rect); |
| + |
| + // Draws a random color rectangle with random size in the range of |range|, |
| + // and sets |color| and |rect| with the color, position and size. |
| + void DrawRandomColorRectangleIn(DesktopSize range, |
| + Color* color, |
| + DesktopRect* rect); |
| + |
| + private: |
| + explicit ScreenPainter(std::unique_ptr<ScreenDrawer> drawer); |
| + |
| + std::unique_ptr<ScreenDrawer> drawer_; |
| +}; |
| + |
| +} // namespace webrtc |
| + |
| +#endif // WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_PAINTER_H_ |