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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/modules/desktop_capture/screen_drawer_mac.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 48b770d14b6ea64ad8e9e4861fa1c382009fb9ce..0b669916479c876366ac0237557745e693f37a3a 100644
--- a/webrtc/modules/desktop_capture/screen_drawer_win.cc
+++ b/webrtc/modules/desktop_capture/screen_drawer_win.cc
@@ -19,6 +19,36 @@ namespace webrtc {
namespace {
+static constexpr TCHAR kMutexName[] =
+ TEXT("Local\\ScreenDrawerWin-da834f82-8044-11e6-ac81-73dcdd1c1869");
+
+class ScreenDrawerLockWin : public ScreenDrawerLock {
+ public:
+ ScreenDrawerLockWin();
+ ~ScreenDrawerLockWin();
+
+ private:
+ HANDLE mutex_;
+};
+
+ScreenDrawerLockWin::ScreenDrawerLockWin() {
+ while (true) {
+ mutex_ = CreateMutex(NULL, FALSE, kMutexName);
+ if (GetLastError() != ERROR_ALREADY_EXISTS && mutex_ != NULL) {
+ break;
+ } else {
+ if (mutex_) {
+ CloseHandle(mutex_);
+ }
+ SleepMs(1000);
+ }
+ }
+}
+
+ScreenDrawerLockWin::~ScreenDrawerLockWin() {
+ CloseHandle(mutex_);
+}
+
DesktopRect GetScreenRect() {
HDC hdc = GetDC(NULL);
DesktopRect rect = DesktopRect::MakeWH(GetDeviceCaps(hdc, HORZRES),
@@ -51,8 +81,13 @@ class ScreenDrawerWin : public ScreenDrawer {
void DrawRectangle(DesktopRect rect, RgbaColor color) override;
void Clear() override;
void WaitForPendingDraws() override;
+ bool MayDrawIncompleteShapes() override;
private:
+ // Bring the window to the front, this can help to avoid the impact from other
+ // windows or shadow effects.
+ void BringToFront();
+
// Draw a line with |color|.
void DrawLine(DesktopVector start, DesktopVector end, RgbaColor color);
@@ -76,6 +111,7 @@ ScreenDrawerWin::ScreenDrawerWin()
// Always use stock pen (DC_PEN) and brush (DC_BRUSH).
SelectObject(hdc_, GetStockObject(DC_PEN));
SelectObject(hdc_, GetStockObject(DC_BRUSH));
+ BringToFront();
}
ScreenDrawerWin::~ScreenDrawerWin() {
@@ -117,6 +153,10 @@ void ScreenDrawerWin::WaitForPendingDraws() {
SleepMs(50);
}
+bool ScreenDrawerWin::MayDrawIncompleteShapes() {
+ return true;
+}
+
void ScreenDrawerWin::DrawLine(DesktopVector start,
DesktopVector end,
RgbaColor color) {
@@ -133,9 +173,29 @@ void ScreenDrawerWin::DrawDot(DesktopVector vect, RgbaColor color) {
SetPixel(hdc_, vect.x(), vect.y(), ColorToRef(color));
}
+void ScreenDrawerWin::BringToFront() {
+ if (SUCCEEDED(SetWindowPos(
+ window_, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE))) {
+ return;
+ }
+
+ long ex_style = GetWindowLong(window_, GWL_EXSTYLE);
+ ex_style |= WS_EX_TOPMOST;
+ if (SetWindowLong(window_, GWL_EXSTYLE, ex_style) != 0) {
+ return;
+ }
+
+ BringWindowToTop(window_);
+}
+
} // namespace
// static
+std::unique_ptr<ScreenDrawerLock> ScreenDrawerLock::Create() {
+ return std::unique_ptr<ScreenDrawerLock>(new ScreenDrawerLockWin());
+}
+
+// static
std::unique_ptr<ScreenDrawer> ScreenDrawer::Create() {
return std::unique_ptr<ScreenDrawer>(new ScreenDrawerWin());
}
« 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