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

Unified Diff: webrtc/modules/desktop_capture/screen_drawer_win.cc

Issue 2337073007: Deflaky ScreenCapturerTest (Closed)
Patch Set: Resolve review comments 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
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..f8e0796ca74fed36eb5f26694f226e2e6613787e 100644
--- a/webrtc/modules/desktop_capture/screen_drawer_win.cc
+++ b/webrtc/modules/desktop_capture/screen_drawer_win.cc
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ * Copyright 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
@@ -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() {
@@ -114,9 +150,14 @@ void ScreenDrawerWin::Clear() {
// TODO(zijiehe): Find the right signal to indicate the finish of all pending
// paintings.
void ScreenDrawerWin::WaitForPendingDraws() {
+ BringToFront();
SleepMs(50);
}
+bool ScreenDrawerWin::MayDrawIncompleteShapes() {
+ return true;
+}
+
void ScreenDrawerWin::DrawLine(DesktopVector start,
DesktopVector end,
RgbaColor color) {
@@ -133,9 +174,18 @@ void ScreenDrawerWin::DrawDot(DesktopVector vect, RgbaColor color) {
SetPixel(hdc_, vect.x(), vect.y(), ColorToRef(color));
}
+void ScreenDrawerWin::BringToFront() {
+ 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());
}

Powered by Google App Engine
This is Rietveld 408576698