| 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  224 void XServerPixelBuffer::Synchronize() { |  224 void XServerPixelBuffer::Synchronize() { | 
|  225   if (shm_segment_info_ && !shm_pixmap_) { |  225   if (shm_segment_info_ && !shm_pixmap_) { | 
|  226     // XShmGetImage can fail if the display is being reconfigured. |  226     // XShmGetImage can fail if the display is being reconfigured. | 
|  227     XErrorTrap error_trap(display_); |  227     XErrorTrap error_trap(display_); | 
|  228     // XShmGetImage fails if the window is partially out of screen. |  228     // XShmGetImage fails if the window is partially out of screen. | 
|  229     xshm_get_image_succeeded_ = |  229     xshm_get_image_succeeded_ = | 
|  230         XShmGetImage(display_, window_, x_image_, 0, 0, AllPlanes); |  230         XShmGetImage(display_, window_, x_image_, 0, 0, AllPlanes); | 
|  231   } |  231   } | 
|  232 } |  232 } | 
|  233  |  233  | 
|  234 void XServerPixelBuffer::CaptureRect(const DesktopRect& rect, |  234 bool XServerPixelBuffer::CaptureRect(const DesktopRect& rect, | 
|  235                                      DesktopFrame* frame) { |  235                                      DesktopFrame* frame) { | 
|  236   assert(rect.right() <= window_size_.width()); |  236   assert(rect.right() <= window_size_.width()); | 
|  237   assert(rect.bottom() <= window_size_.height()); |  237   assert(rect.bottom() <= window_size_.height()); | 
|  238  |  238  | 
|  239   uint8_t* data; |  239   uint8_t* data; | 
|  240  |  240  | 
|  241   if (shm_segment_info_ && (shm_pixmap_ || xshm_get_image_succeeded_)) { |  241   if (shm_segment_info_ && (shm_pixmap_ || xshm_get_image_succeeded_)) { | 
|  242     if (shm_pixmap_) { |  242     if (shm_pixmap_) { | 
|  243       XCopyArea(display_, window_, shm_pixmap_, shm_gc_, |  243       XCopyArea(display_, window_, shm_pixmap_, shm_gc_, | 
|  244                 rect.left(), rect.top(), rect.width(), rect.height(), |  244                 rect.left(), rect.top(), rect.width(), rect.height(), | 
|  245                 rect.left(), rect.top()); |  245                 rect.left(), rect.top()); | 
|  246       XSync(display_, False); |  246       XSync(display_, False); | 
|  247     } |  247     } | 
|  248     data = reinterpret_cast<uint8_t*>(x_image_->data) + |  248     data = reinterpret_cast<uint8_t*>(x_image_->data) + | 
|  249         rect.top() * x_image_->bytes_per_line + |  249         rect.top() * x_image_->bytes_per_line + | 
|  250         rect.left() * x_image_->bits_per_pixel / 8; |  250         rect.left() * x_image_->bits_per_pixel / 8; | 
|  251   } else { |  251   } else { | 
|  252     if (x_image_) |  252     if (x_image_) | 
|  253       XDestroyImage(x_image_); |  253       XDestroyImage(x_image_); | 
|  254     x_image_ = XGetImage(display_, window_, rect.left(), rect.top(), |  254     x_image_ = XGetImage(display_, window_, rect.left(), rect.top(), | 
|  255                          rect.width(), rect.height(), AllPlanes, ZPixmap); |  255                          rect.width(), rect.height(), AllPlanes, ZPixmap); | 
 |  256     if (!x_image_) | 
 |  257       return false; | 
 |  258  | 
|  256     data = reinterpret_cast<uint8_t*>(x_image_->data); |  259     data = reinterpret_cast<uint8_t*>(x_image_->data); | 
|  257   } |  260   } | 
|  258  |  261  | 
|  259   if (IsXImageRGBFormat(x_image_)) { |  262   if (IsXImageRGBFormat(x_image_)) { | 
|  260     FastBlit(data, rect, frame); |  263     FastBlit(data, rect, frame); | 
|  261   } else { |  264   } else { | 
|  262     SlowBlit(data, rect, frame); |  265     SlowBlit(data, rect, frame); | 
|  263   } |  266   } | 
 |  267  | 
 |  268   return true; | 
|  264 } |  269 } | 
|  265  |  270  | 
|  266 void XServerPixelBuffer::FastBlit(uint8_t* image, |  271 void XServerPixelBuffer::FastBlit(uint8_t* image, | 
|  267                                   const DesktopRect& rect, |  272                                   const DesktopRect& rect, | 
|  268                                   DesktopFrame* frame) { |  273                                   DesktopFrame* frame) { | 
|  269   uint8_t* src_pos = image; |  274   uint8_t* src_pos = image; | 
|  270   int src_stride = x_image_->bytes_per_line; |  275   int src_stride = x_image_->bytes_per_line; | 
|  271   int dst_x = rect.left(), dst_y = rect.top(); |  276   int dst_x = rect.left(), dst_y = rect.top(); | 
|  272  |  277  | 
|  273   uint8_t* dst_pos = frame->data() + frame->stride() * dst_y; |  278   uint8_t* dst_pos = frame->data() + frame->stride() * dst_y; | 
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  326       // Write as 32-bit RGB. |  331       // Write as 32-bit RGB. | 
|  327       dst_pos_32[x] = ((r >> 8) & 0xff0000) | ((g >> 16) & 0xff00) | |  332       dst_pos_32[x] = ((r >> 8) & 0xff0000) | ((g >> 16) & 0xff00) | | 
|  328           ((b >> 24) & 0xff); |  333           ((b >> 24) & 0xff); | 
|  329     } |  334     } | 
|  330     dst_pos += frame->stride(); |  335     dst_pos += frame->stride(); | 
|  331     src_pos += src_stride; |  336     src_pos += src_stride; | 
|  332   } |  337   } | 
|  333 } |  338 } | 
|  334  |  339  | 
|  335 }  // namespace webrtc |  340 }  // namespace webrtc | 
| OLD | NEW |