| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/video/capture/screen/x11/x_server_pixel_buffer.h" | 5 #include "media/video/capture/screen/x11/x_server_pixel_buffer.h" |
| 6 | 6 |
| 7 #include <sys/shm.h> | 7 #include <sys/shm.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 | 10 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 } | 53 } |
| 54 | 54 |
| 55 #endif // !defined(TOOLKIT_GTK) | 55 #endif // !defined(TOOLKIT_GTK) |
| 56 | 56 |
| 57 } // namespace | 57 } // namespace |
| 58 | 58 |
| 59 namespace media { | 59 namespace media { |
| 60 | 60 |
| 61 XServerPixelBuffer::XServerPixelBuffer() | 61 XServerPixelBuffer::XServerPixelBuffer() |
| 62 : display_(NULL), root_window_(0), | 62 : display_(NULL), root_window_(0), |
| 63 root_window_size_(SkISize::Make(0, 0)), x_image_(NULL), | 63 x_image_(NULL), |
| 64 shm_segment_info_(NULL), shm_pixmap_(0), shm_gc_(NULL) { | 64 shm_segment_info_(NULL), shm_pixmap_(0), shm_gc_(NULL) { |
| 65 } | 65 } |
| 66 | 66 |
| 67 XServerPixelBuffer::~XServerPixelBuffer() { | 67 XServerPixelBuffer::~XServerPixelBuffer() { |
| 68 Release(); | 68 Release(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void XServerPixelBuffer::Release() { | 71 void XServerPixelBuffer::Release() { |
| 72 if (x_image_) { | 72 if (x_image_) { |
| 73 XDestroyImage(x_image_); | 73 XDestroyImage(x_image_); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 85 if (shm_segment_info_->shmaddr != reinterpret_cast<char*>(-1)) | 85 if (shm_segment_info_->shmaddr != reinterpret_cast<char*>(-1)) |
| 86 shmdt(shm_segment_info_->shmaddr); | 86 shmdt(shm_segment_info_->shmaddr); |
| 87 if (shm_segment_info_->shmid != -1) | 87 if (shm_segment_info_->shmid != -1) |
| 88 shmctl(shm_segment_info_->shmid, IPC_RMID, 0); | 88 shmctl(shm_segment_info_->shmid, IPC_RMID, 0); |
| 89 delete shm_segment_info_; | 89 delete shm_segment_info_; |
| 90 shm_segment_info_ = NULL; | 90 shm_segment_info_ = NULL; |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 void XServerPixelBuffer::Init(Display* display, | 94 void XServerPixelBuffer::Init(Display* display, |
| 95 const SkISize& screen_size) { | 95 const webrtc::DesktopSize& screen_size) { |
| 96 Release(); | 96 Release(); |
| 97 display_ = display; | 97 display_ = display; |
| 98 root_window_size_ = screen_size; | 98 root_window_size_ = screen_size; |
| 99 int default_screen = DefaultScreen(display_); | 99 int default_screen = DefaultScreen(display_); |
| 100 root_window_ = RootWindow(display_, default_screen); | 100 root_window_ = RootWindow(display_, default_screen); |
| 101 InitShm(default_screen); | 101 InitShm(default_screen); |
| 102 } | 102 } |
| 103 | 103 |
| 104 // static | 104 // static |
| 105 SkISize XServerPixelBuffer::GetRootWindowSize(Display* display) { | 105 webrtc::DesktopSize XServerPixelBuffer::GetRootWindowSize(Display* display) { |
| 106 XWindowAttributes root_attr; | 106 XWindowAttributes root_attr; |
| 107 XGetWindowAttributes(display, DefaultRootWindow(display), &root_attr); | 107 XGetWindowAttributes(display, DefaultRootWindow(display), &root_attr); |
| 108 return SkISize::Make(root_attr.width, root_attr.height); | 108 return webrtc::DesktopSize(root_attr.width, root_attr.height); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void XServerPixelBuffer::InitShm(int screen) { | 111 void XServerPixelBuffer::InitShm(int screen) { |
| 112 Visual* default_visual = DefaultVisual(display_, screen); | 112 Visual* default_visual = DefaultVisual(display_, screen); |
| 113 int default_depth = DefaultDepth(display_, screen); | 113 int default_depth = DefaultDepth(display_, screen); |
| 114 | 114 |
| 115 int major, minor; | 115 int major, minor; |
| 116 Bool havePixmaps; | 116 Bool havePixmaps; |
| 117 if (!XShmQueryVersion(display_, &major, &minor, &havePixmaps)) | 117 if (!XShmQueryVersion(display_, &major, &minor, &havePixmaps)) |
| 118 // Shared memory not supported. CaptureRect will use the XImage API instead. | 118 // Shared memory not supported. CaptureRect will use the XImage API instead. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 204 |
| 205 void XServerPixelBuffer::Synchronize() { | 205 void XServerPixelBuffer::Synchronize() { |
| 206 if (shm_segment_info_ && !shm_pixmap_) { | 206 if (shm_segment_info_ && !shm_pixmap_) { |
| 207 // XShmGetImage can fail if the display is being reconfigured. | 207 // XShmGetImage can fail if the display is being reconfigured. |
| 208 EnableXServerErrorTrap(); | 208 EnableXServerErrorTrap(); |
| 209 XShmGetImage(display_, root_window_, x_image_, 0, 0, AllPlanes); | 209 XShmGetImage(display_, root_window_, x_image_, 0, 0, AllPlanes); |
| 210 GetLastXServerError(); | 210 GetLastXServerError(); |
| 211 } | 211 } |
| 212 } | 212 } |
| 213 | 213 |
| 214 uint8* XServerPixelBuffer::CaptureRect(const SkIRect& rect) { | 214 uint8* XServerPixelBuffer::CaptureRect(const webrtc::DesktopRect& rect) { |
| 215 DCHECK(SkIRect::MakeSize(root_window_size_).contains(rect)); | 215 DCHECK_LE(rect.right(), root_window_size_.width()); |
| 216 DCHECK_LE(rect.bottom(), root_window_size_.height()); |
| 217 |
| 216 if (shm_segment_info_) { | 218 if (shm_segment_info_) { |
| 217 if (shm_pixmap_) { | 219 if (shm_pixmap_) { |
| 218 XCopyArea(display_, root_window_, shm_pixmap_, shm_gc_, | 220 XCopyArea(display_, root_window_, shm_pixmap_, shm_gc_, |
| 219 rect.fLeft, rect.fTop, rect.width(), rect.height(), | 221 rect.left(), rect.top(), rect.width(), rect.height(), |
| 220 rect.fLeft, rect.fTop); | 222 rect.left(), rect.top()); |
| 221 XSync(display_, False); | 223 XSync(display_, False); |
| 222 } | 224 } |
| 223 return reinterpret_cast<uint8*>(x_image_->data) + | 225 return reinterpret_cast<uint8*>(x_image_->data) + |
| 224 rect.fTop * x_image_->bytes_per_line + | 226 rect.top() * x_image_->bytes_per_line + |
| 225 rect.fLeft * x_image_->bits_per_pixel / 8; | 227 rect.left() * x_image_->bits_per_pixel / 8; |
| 226 } else { | 228 } else { |
| 227 if (x_image_) | 229 if (x_image_) |
| 228 XDestroyImage(x_image_); | 230 XDestroyImage(x_image_); |
| 229 x_image_ = XGetImage(display_, root_window_, rect.fLeft, rect.fTop, | 231 x_image_ = XGetImage(display_, root_window_, rect.left(), rect.top(), |
| 230 rect.width(), rect.height(), AllPlanes, ZPixmap); | 232 rect.width(), rect.height(), AllPlanes, ZPixmap); |
| 231 return reinterpret_cast<uint8*>(x_image_->data); | 233 return reinterpret_cast<uint8*>(x_image_->data); |
| 232 } | 234 } |
| 233 } | 235 } |
| 234 | 236 |
| 235 int XServerPixelBuffer::GetStride() const { | 237 int XServerPixelBuffer::GetStride() const { |
| 236 return x_image_->bytes_per_line; | 238 return x_image_->bytes_per_line; |
| 237 } | 239 } |
| 238 | 240 |
| 239 int XServerPixelBuffer::GetDepth() const { | 241 int XServerPixelBuffer::GetDepth() const { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 250 | 252 |
| 251 int XServerPixelBuffer::GetBlueMask() const { | 253 int XServerPixelBuffer::GetBlueMask() const { |
| 252 return x_image_->blue_mask; | 254 return x_image_->blue_mask; |
| 253 } | 255 } |
| 254 | 256 |
| 255 int XServerPixelBuffer::GetGreenMask() const { | 257 int XServerPixelBuffer::GetGreenMask() const { |
| 256 return x_image_->green_mask; | 258 return x_image_->green_mask; |
| 257 } | 259 } |
| 258 | 260 |
| 259 } // namespace media | 261 } // namespace media |
| OLD | NEW |