| 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 "remoting/host/x_server_pixel_buffer.h" | 5 #include "remoting/host/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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 bool using_shm = false; | 114 bool using_shm = false; |
| 115 shm_segment_info_ = new XShmSegmentInfo; | 115 shm_segment_info_ = new XShmSegmentInfo; |
| 116 shm_segment_info_->shmid = -1; | 116 shm_segment_info_->shmid = -1; |
| 117 shm_segment_info_->shmaddr = reinterpret_cast<char*>(-1); | 117 shm_segment_info_->shmaddr = reinterpret_cast<char*>(-1); |
| 118 shm_segment_info_->readOnly = False; | 118 shm_segment_info_->readOnly = False; |
| 119 x_image_ = XShmCreateImage(display_, default_visual, default_depth, ZPixmap, | 119 x_image_ = XShmCreateImage(display_, default_visual, default_depth, ZPixmap, |
| 120 0, shm_segment_info_, width, height); | 120 0, shm_segment_info_, width, height); |
| 121 if (x_image_) { | 121 if (x_image_) { |
| 122 shm_segment_info_->shmid = shmget( | 122 shm_segment_info_->shmid = shmget( |
| 123 IPC_PRIVATE, x_image_->bytes_per_line * x_image_->height, | 123 IPC_PRIVATE, x_image_->bytes_per_line * x_image_->height, |
| 124 IPC_CREAT | 0666); | 124 IPC_CREAT | 0600); |
| 125 if (shm_segment_info_->shmid != -1) { | 125 if (shm_segment_info_->shmid != -1) { |
| 126 shm_segment_info_->shmaddr = x_image_->data = | 126 shm_segment_info_->shmaddr = x_image_->data = |
| 127 reinterpret_cast<char*>(shmat(shm_segment_info_->shmid, 0, 0)); | 127 reinterpret_cast<char*>(shmat(shm_segment_info_->shmid, 0, 0)); |
| 128 if (x_image_->data != reinterpret_cast<char*>(-1)) { | 128 if (x_image_->data != reinterpret_cast<char*>(-1)) { |
| 129 EnableXServerErrorTrap(); | 129 EnableXServerErrorTrap(); |
| 130 using_shm = XShmAttach(display_, shm_segment_info_); | 130 using_shm = XShmAttach(display_, shm_segment_info_); |
| 131 XSync(display_, False); | 131 XSync(display_, False); |
| 132 if (GetLastXServerError() != 0) | 132 if (GetLastXServerError() != 0) |
| 133 using_shm = false; | 133 using_shm = false; |
| 134 if (using_shm) { |
| 135 VLOG(1) << "Using X shared memory segment " |
| 136 << shm_segment_info_->shmid; |
| 137 } |
| 134 } | 138 } |
| 139 } else { |
| 140 LOG(WARNING) << "Failed to get shared memory segment. " |
| 141 "Performance may be degraded."; |
| 135 } | 142 } |
| 136 } | 143 } |
| 137 | 144 |
| 138 if (!using_shm) { | 145 if (!using_shm) { |
| 139 VLOG(1) << "Not using shared memory."; | 146 LOG(WARNING) << "Not using shared memory. Performance may be degraded."; |
| 140 Release(); | 147 Release(); |
| 141 return; | 148 return; |
| 142 } | 149 } |
| 143 | 150 |
| 144 if (havePixmaps) | 151 if (havePixmaps) |
| 145 havePixmaps = InitPixmaps(width, height, default_depth); | 152 havePixmaps = InitPixmaps(width, height, default_depth); |
| 146 | 153 |
| 147 shmctl(shm_segment_info_->shmid, IPC_RMID, 0); | 154 shmctl(shm_segment_info_->shmid, IPC_RMID, 0); |
| 148 shm_segment_info_->shmid = -1; | 155 shm_segment_info_->shmid = -1; |
| 149 | 156 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 | 256 |
| 250 int XServerPixelBuffer::GetGreenShift() const { | 257 int XServerPixelBuffer::GetGreenShift() const { |
| 251 return ffs(x_image_->green_mask) - 1; | 258 return ffs(x_image_->green_mask) - 1; |
| 252 } | 259 } |
| 253 | 260 |
| 254 bool XServerPixelBuffer::IsRgb() const { | 261 bool XServerPixelBuffer::IsRgb() const { |
| 255 return GetRedShift() == 16 && GetGreenShift() == 8 && GetBlueShift() == 0; | 262 return GetRedShift() == 16 && GetGreenShift() == 8 && GetBlueShift() == 0; |
| 256 } | 263 } |
| 257 | 264 |
| 258 } // namespace remoting | 265 } // namespace remoting |
| OLD | NEW |