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

Unified Diff: webrtc/modules/desktop_capture/screen_drawer_linux.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
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..c745205df0d585adc52f569f5235be2181ab5dde 100644
--- a/webrtc/modules/desktop_capture/screen_drawer_linux.cc
+++ b/webrtc/modules/desktop_capture/screen_drawer_linux.cc
@@ -8,6 +8,11 @@
* be found in the AUTHORS file in the root of the source tree.
*/
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <semaphore.h>
+#include <string.h>
+
#include <memory>
#include "webrtc/base/checks.h"
@@ -19,6 +24,30 @@ namespace webrtc {
namespace {
+static constexpr char kSemaphoreName[] =
+ "/global-screen-drawer-linux-54fe5552-8047-11e6-a725-3f429a5b4fb4";
+
+class ScreenDrawerLockLinux : public ScreenDrawerLock {
+ public:
+ ScreenDrawerLockLinux();
+ ~ScreenDrawerLockLinux();
+
+ private:
+ sem_t* semaphore_;
+};
+
+ScreenDrawerLockLinux::ScreenDrawerLockLinux() {
+ semaphore_ =
+ sem_open(kSemaphoreName, O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO, 1);
+ sem_wait(semaphore_);
+}
+
+ScreenDrawerLockLinux::~ScreenDrawerLockLinux() {
+ sem_post(semaphore_);
+ sem_close(semaphore_);
+ // sem_unlink(kSemaphoreName);
+}
+
// A ScreenDrawer implementation for X11.
class ScreenDrawerLinux : public ScreenDrawer {
public:
@@ -30,8 +59,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 +114,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);
}
@@ -121,9 +156,40 @@ void ScreenDrawerLinux::WaitForPendingDraws() {
SleepMs(50);
}
+bool ScreenDrawerLinux::MayDrawIncompleteShapes() {
+ return true;
+}
+
+void ScreenDrawerLinux::BringToFront() {
+ Atom state_above = XInternAtom(display_->display(), "_NET_WM_STATE_ABOVE", 1);
+ Atom window_state = XInternAtom(display_->display(), "_NET_WM_STATE", 1);
+ if (state_above == None || window_state == None) {
+ // Fallback to use XRaiseWindow, it's not reliable if two windows are both
+ // raise itself to the top.
+ XRaiseWindow(display_->display(), window_);
+ return;
+ }
+
+ XEvent event;
+ memset(&event, 0, sizeof(event));
+ event.type = ClientMessage;
+ event.xclient.window = window_;
+ event.xclient.message_type = window_state;
+ event.xclient.format = 32;
+ event.xclient.data.l[0] = 1; // _NET_WM_STATE_ADD
+ event.xclient.data.l[1] = state_above;
+ XSendEvent(display_->display(), RootWindow(display_->display(), screen_num_),
+ False, SubstructureRedirectMask | SubstructureNotifyMask, &event);
+}
+
} // namespace
// static
+std::unique_ptr<ScreenDrawerLock> ScreenDrawerLock::Create() {
+ return std::unique_ptr<ScreenDrawerLock>(new ScreenDrawerLockLinux());
+}
+
+// static
std::unique_ptr<ScreenDrawer> ScreenDrawer::Create() {
if (SharedXDisplay::CreateDefault().get()) {
return std::unique_ptr<ScreenDrawer>(new ScreenDrawerLinux());
« no previous file with comments | « webrtc/modules/desktop_capture/screen_drawer.cc ('k') | webrtc/modules/desktop_capture/screen_drawer_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698