Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <fcntl.h> | |
| 12 #include <sys/stat.h> | |
| 13 #include <semaphore.h> | |
| 14 | |
| 11 #include <memory> | 15 #include <memory> |
| 12 | 16 |
| 13 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
| 14 #include "webrtc/modules/desktop_capture/screen_drawer.h" | 18 #include "webrtc/modules/desktop_capture/screen_drawer.h" |
| 15 #include "webrtc/modules/desktop_capture/x11/shared_x_display.h" | 19 #include "webrtc/modules/desktop_capture/x11/shared_x_display.h" |
| 16 #include "webrtc/system_wrappers/include/sleep.h" | 20 #include "webrtc/system_wrappers/include/sleep.h" |
| 17 | 21 |
| 18 namespace webrtc { | 22 namespace webrtc { |
| 19 | 23 |
| 20 namespace { | 24 namespace { |
| 21 | 25 |
| 26 static constexpr char kSemaphoreName[] = | |
| 27 "/global-screen-drawer-linux-54fe5552-8047-11e6-a725-3f429a5b4fb4"; | |
| 28 | |
| 29 class ScreenDrawerLockLinux : public ScreenDrawerLock { | |
| 30 public: | |
| 31 ScreenDrawerLockLinux(); | |
| 32 ~ScreenDrawerLockLinux(); | |
| 33 | |
| 34 private: | |
| 35 sem_t* semaphore_; | |
| 36 }; | |
| 37 | |
| 38 ScreenDrawerLockLinux::ScreenDrawerLockLinux() { | |
| 39 semaphore_ = | |
| 40 sem_open(kSemaphoreName, O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO, 1); | |
| 41 sem_wait(semaphore_); | |
| 42 } | |
| 43 | |
| 44 ScreenDrawerLockLinux::~ScreenDrawerLockLinux() { | |
| 45 sem_post(semaphore_); | |
| 46 sem_close(semaphore_); | |
| 47 // sem_unlink(kSemaphoreName); | |
| 48 } | |
| 49 | |
| 22 // A ScreenDrawer implementation for X11. | 50 // A ScreenDrawer implementation for X11. |
| 23 class ScreenDrawerLinux : public ScreenDrawer { | 51 class ScreenDrawerLinux : public ScreenDrawer { |
| 24 public: | 52 public: |
| 25 ScreenDrawerLinux(); | 53 ScreenDrawerLinux(); |
| 26 ~ScreenDrawerLinux() override; | 54 ~ScreenDrawerLinux() override; |
| 27 | 55 |
| 28 // ScreenDrawer interface. | 56 // ScreenDrawer interface. |
| 29 DesktopRect DrawableRegion() override; | 57 DesktopRect DrawableRegion() override; |
| 30 void DrawRectangle(DesktopRect rect, RgbaColor color) override; | 58 void DrawRectangle(DesktopRect rect, RgbaColor color) override; |
| 31 void Clear() override; | 59 void Clear() override; |
| 32 void WaitForPendingDraws() override; | 60 void WaitForPendingDraws() override; |
| 61 bool MayDrawIncompleteShapes() override; | |
| 33 | 62 |
| 34 private: | 63 private: |
| 64 // Bring the window to the front, this can help to avoid the impact from other | |
| 65 // windows or shadow effect. | |
| 66 void BringToFront(); | |
| 67 | |
| 35 rtc::scoped_refptr<SharedXDisplay> display_; | 68 rtc::scoped_refptr<SharedXDisplay> display_; |
| 36 int screen_num_; | 69 int screen_num_; |
| 37 DesktopRect rect_; | 70 DesktopRect rect_; |
| 38 Window window_; | 71 Window window_; |
| 39 GC context_; | 72 GC context_; |
| 40 Colormap colormap_; | 73 Colormap colormap_; |
| 41 }; | 74 }; |
| 42 | 75 |
| 43 ScreenDrawerLinux::ScreenDrawerLinux() { | 76 ScreenDrawerLinux::ScreenDrawerLinux() { |
| 44 display_ = SharedXDisplay::CreateDefault(); | 77 display_ = SharedXDisplay::CreateDefault(); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 73 RTC_DCHECK(false) << "Failed to get window position."; | 106 RTC_DCHECK(false) << "Failed to get window position."; |
| 74 } | 107 } |
| 75 // Some window manager does not allow a window to cover two or more monitors. | 108 // Some window manager does not allow a window to cover two or more monitors. |
| 76 // So if the window is on the first monitor of a two-monitor system, the | 109 // So if the window is on the first monitor of a two-monitor system, the |
| 77 // second half won't be able to show up without changing configurations of WM, | 110 // second half won't be able to show up without changing configurations of WM, |
| 78 // and its DrawableRegion() is not accurate. | 111 // and its DrawableRegion() is not accurate. |
| 79 rect_ = DesktopRect::MakeLTRB(x, y, root_attributes.width, | 112 rect_ = DesktopRect::MakeLTRB(x, y, root_attributes.width, |
| 80 root_attributes.height); | 113 root_attributes.height); |
| 81 context_ = DefaultGC(display_->display(), screen_num_); | 114 context_ = DefaultGC(display_->display(), screen_num_); |
| 82 colormap_ = DefaultColormap(display_->display(), screen_num_); | 115 colormap_ = DefaultColormap(display_->display(), screen_num_); |
| 116 BringToFront(); | |
| 83 // Wait for window animations. | 117 // Wait for window animations. |
| 84 SleepMs(200); | 118 SleepMs(200); |
| 85 } | 119 } |
| 86 | 120 |
| 87 ScreenDrawerLinux::~ScreenDrawerLinux() { | 121 ScreenDrawerLinux::~ScreenDrawerLinux() { |
| 88 XUnmapWindow(display_->display(), window_); | 122 XUnmapWindow(display_->display(), window_); |
| 89 XDestroyWindow(display_->display(), window_); | 123 XDestroyWindow(display_->display(), window_); |
| 90 } | 124 } |
| 91 | 125 |
| 92 DesktopRect ScreenDrawerLinux::DrawableRegion() { | 126 DesktopRect ScreenDrawerLinux::DrawableRegion() { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 111 XFlush(display_->display()); | 145 XFlush(display_->display()); |
| 112 } | 146 } |
| 113 | 147 |
| 114 void ScreenDrawerLinux::Clear() { | 148 void ScreenDrawerLinux::Clear() { |
| 115 DrawRectangle(rect_, RgbaColor(0, 0, 0)); | 149 DrawRectangle(rect_, RgbaColor(0, 0, 0)); |
| 116 } | 150 } |
| 117 | 151 |
| 118 // TODO(zijiehe): Find the right signal from X11 to indicate the finish of all | 152 // TODO(zijiehe): Find the right signal from X11 to indicate the finish of all |
| 119 // pending paintings. | 153 // pending paintings. |
| 120 void ScreenDrawerLinux::WaitForPendingDraws() { | 154 void ScreenDrawerLinux::WaitForPendingDraws() { |
| 155 BringToFront(); | |
| 121 SleepMs(50); | 156 SleepMs(50); |
| 122 } | 157 } |
| 123 | 158 |
| 159 bool ScreenDrawerLinux::MayDrawIncompleteShapes() { | |
| 160 return true; | |
| 161 } | |
| 162 | |
| 163 void ScreenDrawerLinux::BringToFront() { | |
| 164 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
| |
| 165 } | |
| 166 | |
| 124 } // namespace | 167 } // namespace |
| 125 | 168 |
| 126 // static | 169 // static |
| 170 std::unique_ptr<ScreenDrawerLock> ScreenDrawerLock::Create() { | |
| 171 return std::unique_ptr<ScreenDrawerLock>(new ScreenDrawerLockLinux()); | |
| 172 } | |
| 173 | |
| 174 // static | |
| 127 std::unique_ptr<ScreenDrawer> ScreenDrawer::Create() { | 175 std::unique_ptr<ScreenDrawer> ScreenDrawer::Create() { |
| 128 if (SharedXDisplay::CreateDefault().get()) { | 176 if (SharedXDisplay::CreateDefault().get()) { |
| 129 return std::unique_ptr<ScreenDrawer>(new ScreenDrawerLinux()); | 177 return std::unique_ptr<ScreenDrawer>(new ScreenDrawerLinux()); |
| 130 } | 178 } |
| 131 return nullptr; | 179 return nullptr; |
| 132 } | 180 } |
| 133 | 181 |
| 134 } // namespace webrtc | 182 } // namespace webrtc |
| OLD | NEW |