Chromium Code Reviews| 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 52 return image->bits_per_pixel == 32 && | 52 return image->bits_per_pixel == 32 && |
| 53 image->red_mask == 0xff0000 && | 53 image->red_mask == 0xff0000 && |
| 54 image->green_mask == 0xff00 && | 54 image->green_mask == 0xff00 && |
| 55 image->blue_mask == 0xff; | 55 image->blue_mask == 0xff; |
| 56 } | 56 } |
| 57 | 57 |
| 58 } // namespace | 58 } // namespace |
| 59 | 59 |
| 60 namespace webrtc { | 60 namespace webrtc { |
| 61 | 61 |
| 62 XServerPixelBuffer::XServerPixelBuffer() | 62 XServerPixelBuffer::XServerPixelBuffer() {} |
| 63 : display_(NULL), window_(0), | |
| 64 x_image_(NULL), | |
| 65 shm_segment_info_(NULL), shm_pixmap_(0), shm_gc_(NULL) { | |
| 66 } | |
| 67 | 63 |
| 68 XServerPixelBuffer::~XServerPixelBuffer() { | 64 XServerPixelBuffer::~XServerPixelBuffer() { |
| 69 Release(); | 65 Release(); |
| 70 } | 66 } |
| 71 | 67 |
| 72 void XServerPixelBuffer::Release() { | 68 void XServerPixelBuffer::Release() { |
| 73 if (x_image_) { | 69 if (x_image_) { |
| 74 XDestroyImage(x_image_); | 70 XDestroyImage(x_image_); |
| 75 x_image_ = NULL; | 71 x_image_ = NULL; |
| 76 } | 72 } |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 222 return false; | 218 return false; |
| 223 } | 219 } |
| 224 } | 220 } |
| 225 return true; | 221 return true; |
| 226 } | 222 } |
| 227 | 223 |
| 228 void XServerPixelBuffer::Synchronize() { | 224 void XServerPixelBuffer::Synchronize() { |
| 229 if (shm_segment_info_ && !shm_pixmap_) { | 225 if (shm_segment_info_ && !shm_pixmap_) { |
| 230 // XShmGetImage can fail if the display is being reconfigured. | 226 // XShmGetImage can fail if the display is being reconfigured. |
| 231 XErrorTrap error_trap(display_); | 227 XErrorTrap error_trap(display_); |
| 232 XShmGetImage(display_, window_, x_image_, 0, 0, AllPlanes); | 228 // XShmGetImage will return false if the window is partially out of screen. |
|
Sergey Ulanov
2016/06/10 23:35:58
s/will return false/fails/
| |
| 229 xshm_get_image_succeeded_ = | |
| 230 XShmGetImage(display_, window_, x_image_, 0, 0, AllPlanes); | |
| 233 } | 231 } |
| 234 } | 232 } |
| 235 | 233 |
| 236 void XServerPixelBuffer::CaptureRect(const DesktopRect& rect, | 234 void XServerPixelBuffer::CaptureRect(const DesktopRect& rect, |
| 237 DesktopFrame* frame) { | 235 DesktopFrame* frame) { |
| 238 assert(rect.right() <= window_size_.width()); | 236 assert(rect.right() <= window_size_.width()); |
| 239 assert(rect.bottom() <= window_size_.height()); | 237 assert(rect.bottom() <= window_size_.height()); |
| 240 | 238 |
| 241 uint8_t* data; | 239 uint8_t* data; |
| 242 | 240 |
| 243 if (shm_segment_info_) { | 241 if (shm_segment_info_ && (shm_pixmap_ || xshm_get_image_succeeded_)) { |
| 244 if (shm_pixmap_) { | 242 if (shm_pixmap_) { |
| 245 XCopyArea(display_, window_, shm_pixmap_, shm_gc_, | 243 XCopyArea(display_, window_, shm_pixmap_, shm_gc_, |
| 246 rect.left(), rect.top(), rect.width(), rect.height(), | 244 rect.left(), rect.top(), rect.width(), rect.height(), |
| 247 rect.left(), rect.top()); | 245 rect.left(), rect.top()); |
| 248 XSync(display_, False); | 246 XSync(display_, False); |
| 249 } | 247 } |
| 250 data = reinterpret_cast<uint8_t*>(x_image_->data) + | 248 data = reinterpret_cast<uint8_t*>(x_image_->data) + |
| 251 rect.top() * x_image_->bytes_per_line + | 249 rect.top() * x_image_->bytes_per_line + |
| 252 rect.left() * x_image_->bits_per_pixel / 8; | 250 rect.left() * x_image_->bits_per_pixel / 8; |
| 253 } else { | 251 } else { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 // Write as 32-bit RGB. | 326 // Write as 32-bit RGB. |
| 329 dst_pos_32[x] = ((r >> 8) & 0xff0000) | ((g >> 16) & 0xff00) | | 327 dst_pos_32[x] = ((r >> 8) & 0xff0000) | ((g >> 16) & 0xff00) | |
| 330 ((b >> 24) & 0xff); | 328 ((b >> 24) & 0xff); |
| 331 } | 329 } |
| 332 dst_pos += frame->stride(); | 330 dst_pos += frame->stride(); |
| 333 src_pos += src_stride; | 331 src_pos += src_stride; |
| 334 } | 332 } |
| 335 } | 333 } |
| 336 | 334 |
| 337 } // namespace webrtc | 335 } // namespace webrtc |
| OLD | NEW |