Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: webrtc/modules/desktop_capture/screen_drawer_win.cc

Issue 2337073007: Deflaky ScreenCapturerTest (Closed)
Patch Set: Still disable real screen capturer tests Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/modules/desktop_capture/screen_drawer_mac.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <windows.h> 11 #include <windows.h>
12 12
13 #include <memory> 13 #include <memory>
14 14
15 #include "webrtc/modules/desktop_capture/screen_drawer.h" 15 #include "webrtc/modules/desktop_capture/screen_drawer.h"
16 #include "webrtc/system_wrappers/include/sleep.h" 16 #include "webrtc/system_wrappers/include/sleep.h"
17 17
18 namespace webrtc { 18 namespace webrtc {
19 19
20 namespace { 20 namespace {
21 21
22 static constexpr TCHAR kMutexName[] =
23 TEXT("Local\\ScreenDrawerWin-da834f82-8044-11e6-ac81-73dcdd1c1869");
24
25 class ScreenDrawerLockWin : public ScreenDrawerLock {
26 public:
27 ScreenDrawerLockWin();
28 ~ScreenDrawerLockWin();
29
30 private:
31 HANDLE mutex_;
32 };
33
34 ScreenDrawerLockWin::ScreenDrawerLockWin() {
35 while (true) {
36 mutex_ = CreateMutex(NULL, FALSE, kMutexName);
37 if (GetLastError() != ERROR_ALREADY_EXISTS && mutex_ != NULL) {
38 break;
39 } else {
40 if (mutex_) {
41 CloseHandle(mutex_);
42 }
43 SleepMs(1000);
44 }
45 }
46 }
47
48 ScreenDrawerLockWin::~ScreenDrawerLockWin() {
49 CloseHandle(mutex_);
50 }
51
22 DesktopRect GetScreenRect() { 52 DesktopRect GetScreenRect() {
23 HDC hdc = GetDC(NULL); 53 HDC hdc = GetDC(NULL);
24 DesktopRect rect = DesktopRect::MakeWH(GetDeviceCaps(hdc, HORZRES), 54 DesktopRect rect = DesktopRect::MakeWH(GetDeviceCaps(hdc, HORZRES),
25 GetDeviceCaps(hdc, VERTRES)); 55 GetDeviceCaps(hdc, VERTRES));
26 ReleaseDC(NULL, hdc); 56 ReleaseDC(NULL, hdc);
27 return rect; 57 return rect;
28 } 58 }
29 59
30 HWND CreateDrawerWindow(DesktopRect rect) { 60 HWND CreateDrawerWindow(DesktopRect rect) {
31 HWND hwnd = CreateWindowA( 61 HWND hwnd = CreateWindowA(
(...skipping 12 matching lines...) Expand all
44 class ScreenDrawerWin : public ScreenDrawer { 74 class ScreenDrawerWin : public ScreenDrawer {
45 public: 75 public:
46 ScreenDrawerWin(); 76 ScreenDrawerWin();
47 ~ScreenDrawerWin() override; 77 ~ScreenDrawerWin() override;
48 78
49 // ScreenDrawer interface. 79 // ScreenDrawer interface.
50 DesktopRect DrawableRegion() override; 80 DesktopRect DrawableRegion() override;
51 void DrawRectangle(DesktopRect rect, RgbaColor color) override; 81 void DrawRectangle(DesktopRect rect, RgbaColor color) override;
52 void Clear() override; 82 void Clear() override;
53 void WaitForPendingDraws() override; 83 void WaitForPendingDraws() override;
84 bool MayDrawIncompleteShapes() override;
54 85
55 private: 86 private:
87 // Bring the window to the front, this can help to avoid the impact from other
88 // windows or shadow effects.
89 void BringToFront();
90
56 // Draw a line with |color|. 91 // Draw a line with |color|.
57 void DrawLine(DesktopVector start, DesktopVector end, RgbaColor color); 92 void DrawLine(DesktopVector start, DesktopVector end, RgbaColor color);
58 93
59 // Draw a dot with |color|. 94 // Draw a dot with |color|.
60 void DrawDot(DesktopVector vect, RgbaColor color); 95 void DrawDot(DesktopVector vect, RgbaColor color);
61 96
62 const DesktopRect rect_; 97 const DesktopRect rect_;
63 HWND window_; 98 HWND window_;
64 HDC hdc_; 99 HDC hdc_;
65 }; 100 };
66 101
67 ScreenDrawerWin::ScreenDrawerWin() 102 ScreenDrawerWin::ScreenDrawerWin()
68 : ScreenDrawer(), 103 : ScreenDrawer(),
69 rect_(GetScreenRect()), 104 rect_(GetScreenRect()),
70 window_(CreateDrawerWindow(rect_)), 105 window_(CreateDrawerWindow(rect_)),
71 hdc_(GetWindowDC(window_)) { 106 hdc_(GetWindowDC(window_)) {
72 // We do not need to handle any messages for the |window_|, so disable Windows 107 // We do not need to handle any messages for the |window_|, so disable Windows
73 // from processing windows ghosting feature. 108 // from processing windows ghosting feature.
74 DisableProcessWindowsGhosting(); 109 DisableProcessWindowsGhosting();
75 110
76 // Always use stock pen (DC_PEN) and brush (DC_BRUSH). 111 // Always use stock pen (DC_PEN) and brush (DC_BRUSH).
77 SelectObject(hdc_, GetStockObject(DC_PEN)); 112 SelectObject(hdc_, GetStockObject(DC_PEN));
78 SelectObject(hdc_, GetStockObject(DC_BRUSH)); 113 SelectObject(hdc_, GetStockObject(DC_BRUSH));
114 BringToFront();
79 } 115 }
80 116
81 ScreenDrawerWin::~ScreenDrawerWin() { 117 ScreenDrawerWin::~ScreenDrawerWin() {
82 ReleaseDC(NULL, hdc_); 118 ReleaseDC(NULL, hdc_);
83 DestroyWindow(window_); 119 DestroyWindow(window_);
84 // Unfortunately there is no EnableProcessWindowsGhosting() API. 120 // Unfortunately there is no EnableProcessWindowsGhosting() API.
85 } 121 }
86 122
87 DesktopRect ScreenDrawerWin::DrawableRegion() { 123 DesktopRect ScreenDrawerWin::DrawableRegion() {
88 return rect_; 124 return rect_;
(...skipping 21 matching lines...) Expand all
110 void ScreenDrawerWin::Clear() { 146 void ScreenDrawerWin::Clear() {
111 DrawRectangle(rect_, RgbaColor(0, 0, 0)); 147 DrawRectangle(rect_, RgbaColor(0, 0, 0));
112 } 148 }
113 149
114 // TODO(zijiehe): Find the right signal to indicate the finish of all pending 150 // TODO(zijiehe): Find the right signal to indicate the finish of all pending
115 // paintings. 151 // paintings.
116 void ScreenDrawerWin::WaitForPendingDraws() { 152 void ScreenDrawerWin::WaitForPendingDraws() {
117 SleepMs(50); 153 SleepMs(50);
118 } 154 }
119 155
156 bool ScreenDrawerWin::MayDrawIncompleteShapes() {
157 return true;
158 }
159
120 void ScreenDrawerWin::DrawLine(DesktopVector start, 160 void ScreenDrawerWin::DrawLine(DesktopVector start,
121 DesktopVector end, 161 DesktopVector end,
122 RgbaColor color) { 162 RgbaColor color) {
123 POINT points[2]; 163 POINT points[2];
124 points[0].x = start.x(); 164 points[0].x = start.x();
125 points[0].y = start.y(); 165 points[0].y = start.y();
126 points[1].x = end.x(); 166 points[1].x = end.x();
127 points[1].y = end.y(); 167 points[1].y = end.y();
128 SetDCPenColor(hdc_, ColorToRef(color)); 168 SetDCPenColor(hdc_, ColorToRef(color));
129 Polyline(hdc_, points, 2); 169 Polyline(hdc_, points, 2);
130 } 170 }
131 171
132 void ScreenDrawerWin::DrawDot(DesktopVector vect, RgbaColor color) { 172 void ScreenDrawerWin::DrawDot(DesktopVector vect, RgbaColor color) {
133 SetPixel(hdc_, vect.x(), vect.y(), ColorToRef(color)); 173 SetPixel(hdc_, vect.x(), vect.y(), ColorToRef(color));
134 } 174 }
135 175
176 void ScreenDrawerWin::BringToFront() {
177 if (SUCCEEDED(SetWindowPos(
178 window_, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE))) {
179 return;
180 }
181
182 long ex_style = GetWindowLong(window_, GWL_EXSTYLE);
183 ex_style |= WS_EX_TOPMOST;
184 if (SetWindowLong(window_, GWL_EXSTYLE, ex_style) != 0) {
185 return;
186 }
187
188 BringWindowToTop(window_);
189 }
190
136 } // namespace 191 } // namespace
137 192
138 // static 193 // static
194 std::unique_ptr<ScreenDrawerLock> ScreenDrawerLock::Create() {
195 return std::unique_ptr<ScreenDrawerLock>(new ScreenDrawerLockWin());
196 }
197
198 // static
139 std::unique_ptr<ScreenDrawer> ScreenDrawer::Create() { 199 std::unique_ptr<ScreenDrawer> ScreenDrawer::Create() {
140 return std::unique_ptr<ScreenDrawer>(new ScreenDrawerWin()); 200 return std::unique_ptr<ScreenDrawer>(new ScreenDrawerWin());
141 } 201 }
142 202
143 } // namespace webrtc 203 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/desktop_capture/screen_drawer_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698