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

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

Issue 2337073007: Deflaky ScreenCapturerTest (Closed)
Patch Set: The DISABLED_ prefixes will be added back 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_linux.cc
diff --git a/webrtc/modules/desktop_capture/screen_drawer_linux.cc b/webrtc/modules/desktop_capture/screen_drawer_linux.cc
index 08d8195b42dd66601351d02d138e081137e8220d..1d5d993144536420d8dd84bbc5b31a97734dfdc2 100644
--- a/webrtc/modules/desktop_capture/screen_drawer_linux.cc
+++ b/webrtc/modules/desktop_capture/screen_drawer_linux.cc
@@ -8,6 +8,10 @@
* be found in the AUTHORS file in the root of the source tree.
*/
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <semaphore.h>
+
#include <memory>
#include "webrtc/base/checks.h"
@@ -19,6 +23,35 @@ namespace webrtc {
namespace {
+static constexpr char kSemaphoreName[] =
+ "/global-screen-drawer-linux-54fe5552-8047-11e6-a725-3f429a5b4fb4";
+
+// A cross application lock to ensure only one ScreenDrawerLinux can be used at
+// a certain time.
+struct ScreenDrawerLock {
+ // Blocks current thread until a global lock is acquired.
+ ScreenDrawerLock();
+ // Releases the global lock acquired.
+ ~ScreenDrawerLock();
+
+ private:
+ sem_t* semaphore_;
+};
+
+ScreenDrawerLock::ScreenDrawerLock() {
+ semaphore_ =
+ sem_open(kSemaphoreName, O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO, 1);
+ sem_wait(semaphore_);
+}
+
+ScreenDrawerLock::~ScreenDrawerLock() {
+ sem_post(semaphore_);
+ sem_close(semaphore_);
+ // sem_unlink(kSemaphoreName);
+}
+
+std::unique_ptr<ScreenDrawerLock> g_screen_drawer_lock;
+
// A ScreenDrawer implementation for X11.
class ScreenDrawerLinux : public ScreenDrawer {
public:
@@ -30,8 +63,13 @@ class ScreenDrawerLinux : 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 effect.
+ void BringToFront();
+
rtc::scoped_refptr<SharedXDisplay> display_;
int screen_num_;
DesktopRect rect_;
@@ -80,6 +118,7 @@ ScreenDrawerLinux::ScreenDrawerLinux() {
root_attributes.height);
context_ = DefaultGC(display_->display(), screen_num_);
colormap_ = DefaultColormap(display_->display(), screen_num_);
+ BringToFront();
// Wait for window animations.
SleepMs(200);
}
@@ -87,6 +126,7 @@ ScreenDrawerLinux::ScreenDrawerLinux() {
ScreenDrawerLinux::~ScreenDrawerLinux() {
XUnmapWindow(display_->display(), window_);
XDestroyWindow(display_->display(), window_);
+ g_screen_drawer_lock.reset();
}
DesktopRect ScreenDrawerLinux::DrawableRegion() {
@@ -118,14 +158,24 @@ void ScreenDrawerLinux::Clear() {
// TODO(zijiehe): Find the right signal from X11 to indicate the finish of all
// pending paintings.
void ScreenDrawerLinux::WaitForPendingDraws() {
+ BringToFront();
SleepMs(50);
}
+bool ScreenDrawerLinux::MayDrawIncompleteShapes() {
+ return true;
+}
+
+void ScreenDrawerLinux::BringToFront() {
+ XRaiseWindow(display_->display(), window_);
+}
+
} // namespace
// static
std::unique_ptr<ScreenDrawer> ScreenDrawer::Create() {
if (SharedXDisplay::CreateDefault().get()) {
+ g_screen_drawer_lock.reset(new ScreenDrawerLock());
return std::unique_ptr<ScreenDrawer>(new ScreenDrawerLinux());
}
return nullptr;

Powered by Google App Engine
This is Rietveld 408576698