Chromium Code Reviews| 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..68571bc9a62dbbde7a05c9c25a65437c377d969a 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,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 +58,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 +113,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); |
| } |
| @@ -118,12 +152,26 @@ 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_); |
|
Sergey Ulanov
2016/10/18 03:26:56
If there is another test running in parallel it ma
Hzj_jie
2016/10/19 00:46:47
Another window can do exactly the same thing, but
|
| +} |
| + |
| } // 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()); |