OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 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 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 124 |
125 MouseCursorMonitorX11::~MouseCursorMonitorX11() { | 125 MouseCursorMonitorX11::~MouseCursorMonitorX11() { |
126 if (have_xfixes_) { | 126 if (have_xfixes_) { |
127 x_display_->RemoveEventHandler(xfixes_event_base_ + XFixesCursorNotify, | 127 x_display_->RemoveEventHandler(xfixes_event_base_ + XFixesCursorNotify, |
128 this); | 128 this); |
129 } | 129 } |
130 } | 130 } |
131 | 131 |
132 void MouseCursorMonitorX11::Init(Callback* callback, Mode mode) { | 132 void MouseCursorMonitorX11::Init(Callback* callback, Mode mode) { |
133 // Init can be called only once per instance of MouseCursorMonitor. | 133 // Init can be called only once per instance of MouseCursorMonitor. |
134 assert(!callback_); | 134 RTC_DCHECK(!callback_); |
135 assert(callback); | 135 RTC_DCHECK(callback); |
136 | 136 |
137 callback_ = callback; | 137 callback_ = callback; |
138 mode_ = mode; | 138 mode_ = mode; |
139 | 139 |
140 have_xfixes_ = | 140 have_xfixes_ = |
141 XFixesQueryExtension(display(), &xfixes_event_base_, &xfixes_error_base_); | 141 XFixesQueryExtension(display(), &xfixes_event_base_, &xfixes_error_base_); |
142 | 142 |
143 if (have_xfixes_) { | 143 if (have_xfixes_) { |
144 // Register for changes to the cursor shape. | 144 // Register for changes to the cursor shape. |
145 XFixesSelectCursorInput(display(), window_, XFixesDisplayCursorNotifyMask); | 145 XFixesSelectCursorInput(display(), window_, XFixesDisplayCursorNotifyMask); |
146 x_display_->AddEventHandler(xfixes_event_base_ + XFixesCursorNotify, this); | 146 x_display_->AddEventHandler(xfixes_event_base_ + XFixesCursorNotify, this); |
147 | 147 |
148 CaptureCursor(); | 148 CaptureCursor(); |
149 } else { | 149 } else { |
150 LOG(LS_INFO) << "X server does not support XFixes."; | 150 LOG(LS_INFO) << "X server does not support XFixes."; |
151 } | 151 } |
152 } | 152 } |
153 | 153 |
154 void MouseCursorMonitorX11::Capture() { | 154 void MouseCursorMonitorX11::Capture() { |
155 assert(callback_); | 155 RTC_DCHECK(callback_); |
156 | 156 |
157 // Process X11 events in case XFixes has sent cursor notification. | 157 // Process X11 events in case XFixes has sent cursor notification. |
158 x_display_->ProcessPendingXEvents(); | 158 x_display_->ProcessPendingXEvents(); |
159 | 159 |
160 // cursor_shape_| is set only if we were notified of a cursor shape change. | 160 // cursor_shape_| is set only if we were notified of a cursor shape change. |
161 if (cursor_shape_.get()) | 161 if (cursor_shape_.get()) |
162 callback_->OnMouseCursor(cursor_shape_.release()); | 162 callback_->OnMouseCursor(cursor_shape_.release()); |
163 | 163 |
164 // Get cursor position if necessary. | 164 // Get cursor position if necessary. |
165 if (mode_ == SHAPE_AND_POSITION) { | 165 if (mode_ == SHAPE_AND_POSITION) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 if (cursor_event->subtype == XFixesDisplayCursorNotify) { | 197 if (cursor_event->subtype == XFixesDisplayCursorNotify) { |
198 CaptureCursor(); | 198 CaptureCursor(); |
199 } | 199 } |
200 // Return false, even if the event has been handled, because there might be | 200 // Return false, even if the event has been handled, because there might be |
201 // other listeners for cursor notifications. | 201 // other listeners for cursor notifications. |
202 } | 202 } |
203 return false; | 203 return false; |
204 } | 204 } |
205 | 205 |
206 void MouseCursorMonitorX11::CaptureCursor() { | 206 void MouseCursorMonitorX11::CaptureCursor() { |
207 assert(have_xfixes_); | 207 RTC_DCHECK(have_xfixes_); |
208 | 208 |
209 XFixesCursorImage* img; | 209 XFixesCursorImage* img; |
210 { | 210 { |
211 XErrorTrap error_trap(display()); | 211 XErrorTrap error_trap(display()); |
212 img = XFixesGetCursorImage(display()); | 212 img = XFixesGetCursorImage(display()); |
213 if (!img || error_trap.GetLastErrorAndDisable() != 0) | 213 if (!img || error_trap.GetLastErrorAndDisable() != 0) |
214 return; | 214 return; |
215 } | 215 } |
216 | 216 |
217 std::unique_ptr<DesktopFrame> image( | 217 std::unique_ptr<DesktopFrame> image( |
(...skipping 29 matching lines...) Expand all Loading... |
247 MouseCursorMonitor* MouseCursorMonitor::CreateForScreen( | 247 MouseCursorMonitor* MouseCursorMonitor::CreateForScreen( |
248 const DesktopCaptureOptions& options, | 248 const DesktopCaptureOptions& options, |
249 ScreenId screen) { | 249 ScreenId screen) { |
250 if (!options.x_display()) | 250 if (!options.x_display()) |
251 return NULL; | 251 return NULL; |
252 return new MouseCursorMonitorX11( | 252 return new MouseCursorMonitorX11( |
253 options, DefaultRootWindow(options.x_display()->display())); | 253 options, DefaultRootWindow(options.x_display()->display())); |
254 } | 254 } |
255 | 255 |
256 } // namespace webrtc | 256 } // namespace webrtc |
OLD | NEW |