| Index: webrtc/modules/desktop_capture/screen_drawer_win.cc
|
| diff --git a/webrtc/modules/desktop_capture/screen_drawer_win.cc b/webrtc/modules/desktop_capture/screen_drawer_win.cc
|
| index 061a40539e1cb72091347bf1b743b2315982e99c..2b1a7cfdf7f09f99208da4c9cd127991d831b8aa 100644
|
| --- a/webrtc/modules/desktop_capture/screen_drawer_win.cc
|
| +++ b/webrtc/modules/desktop_capture/screen_drawer_win.cc
|
| @@ -13,6 +13,7 @@
|
| #include <memory>
|
|
|
| #include "webrtc/modules/desktop_capture/screen_drawer.h"
|
| +#include "webrtc/system_wrappers/include/sleep.h"
|
|
|
| namespace webrtc {
|
|
|
| @@ -34,6 +35,14 @@ HWND CreateDrawerWindow(DesktopRect rect) {
|
| return hwnd;
|
| }
|
|
|
| +COLORREF ColorToRef(uint32_t bgra) {
|
| + int b = (bgra & 0xff000000) >> 24;
|
| + int g = (bgra & 0xff0000) >> 16;
|
| + int r = (bgra & 0xff00) >> 8;
|
| + // Windows device context does not support Alpha.
|
| + return RGB(r, g, b);
|
| +}
|
| +
|
| // A ScreenDrawer implementation for Windows.
|
| class ScreenDrawerWin : public ScreenDrawer {
|
| public:
|
| @@ -42,10 +51,16 @@ class ScreenDrawerWin : public ScreenDrawer {
|
|
|
| // ScreenDrawer interface.
|
| DesktopRect DrawableRegion() override;
|
| - void DrawRectangle(DesktopRect rect, uint32_t rgba) override;
|
| - void Clear() override;
|
| + void DrawRectangle(DesktopRect rect, uint32_t bgra) override;
|
| + void WaitForPendingPaintings() override;
|
|
|
| private:
|
| + // Draw a line with |bgra| color.
|
| + void DrawLine(DesktopVector start, DesktopVector end, uint32_t bgra);
|
| +
|
| + // Draw a dot with |bgra| color.
|
| + void DrawDot(DesktopVector vect, uint32_t bgra);
|
| +
|
| const DesktopRect rect_;
|
| HWND window_;
|
| HDC hdc_;
|
| @@ -57,8 +72,12 @@ ScreenDrawerWin::ScreenDrawerWin()
|
| window_(CreateDrawerWindow(rect_)),
|
| hdc_(GetWindowDC(window_)) {
|
| // We do not need to handle any messages for the |window_|, so disable Windows
|
| - // process windows ghosting feature.
|
| + // from processing windows ghosting feature.
|
| DisableProcessWindowsGhosting();
|
| +
|
| + // Always use stock pen (DC_PEN) and brush (DC_BRUSH).
|
| + SelectObject(hdc_, GetStockObject(DC_PEN));
|
| + SelectObject(hdc_, GetStockObject(DC_BRUSH));
|
| }
|
|
|
| ScreenDrawerWin::~ScreenDrawerWin() {
|
| @@ -71,20 +90,44 @@ DesktopRect ScreenDrawerWin::DrawableRegion() {
|
| return rect_;
|
| }
|
|
|
| -void ScreenDrawerWin::DrawRectangle(DesktopRect rect, uint32_t rgba) {
|
| - int r = (rgba & 0xff00) >> 8;
|
| - int g = (rgba & 0xff0000) >> 16;
|
| - int b = (rgba & 0xff000000) >> 24;
|
| - // Windows device context does not support Alpha.
|
| - SelectObject(hdc_, GetStockObject(DC_PEN));
|
| - SelectObject(hdc_, GetStockObject(DC_BRUSH));
|
| - SetDCBrushColor(hdc_, RGB(r, g, b));
|
| - SetDCPenColor(hdc_, RGB(r, g, b));
|
| +void ScreenDrawerWin::DrawRectangle(DesktopRect rect, uint32_t bgra) {
|
| + if (rect.width() == 1 && rect.height() == 1) {
|
| + // Rectangle function cannot draw a 1 pixel rectangle.
|
| + DrawDot(rect.top_left(), bgra);
|
| + return;
|
| + }
|
| +
|
| + if (rect.width() == 1 || rect.height() == 1) {
|
| + // Rectangle function cannot draw a 1 pixel rectangle.
|
| + DrawLine(rect.top_left(), DesktopVector(rect.right(), rect.bottom()), bgra);
|
| + return;
|
| + }
|
| +
|
| + SetDCBrushColor(hdc_, ColorToRef(bgra));
|
| + SetDCPenColor(hdc_, ColorToRef(bgra));
|
| Rectangle(hdc_, rect.left(), rect.top(), rect.right(), rect.bottom());
|
| }
|
|
|
| -void ScreenDrawerWin::Clear() {
|
| - DrawRectangle(DrawableRegion(), 0);
|
| +// TODO(zijiehe): Find the right signal to indicate the finish of all pending
|
| +// paintings.
|
| +void ScreenDrawerWin::WaitForPendingPaintings() {
|
| + SleepMs(500);
|
| +}
|
| +
|
| +void ScreenDrawerWin::DrawLine(DesktopVector start,
|
| + DesktopVector end,
|
| + uint32_t bgra) {
|
| + POINT points[2];
|
| + points[0].x = start.x();
|
| + points[0].y = start.y();
|
| + points[1].x = end.x();
|
| + points[1].y = end.y();
|
| + SetDCPenColor(hdc_, ColorToRef(bgra));
|
| + Polyline(hdc_, points, 2);
|
| +}
|
| +
|
| +void ScreenDrawerWin::DrawDot(DesktopVector vect, uint32_t bgra) {
|
| + SetPixel(hdc_, vect.x(), vect.y(), ColorToRef(bgra));
|
| }
|
|
|
| } // namespace
|
|
|