| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <errno.h> | 5 #include <errno.h> |
| 6 #include <stdlib.h> | 6 #include <stdlib.h> |
| 7 #include <sys/ipc.h> | 7 #include <sys/ipc.h> |
| 8 #include <sys/shm.h> | 8 #include <sys/shm.h> |
| 9 | 9 |
| 10 #include "app/surface/transport_dib.h" | 10 #include "app/surface/transport_dib.h" |
| 11 #include "app/x11_util.h" | |
| 12 #include "base/logging.h" | 11 #include "base/logging.h" |
| 13 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 14 #include "gfx/size.h" | 13 #include "gfx/size.h" |
| 15 #include "skia/ext/platform_canvas.h" | 14 #include "skia/ext/platform_canvas.h" |
| 15 #include "ui/base/x/x11_util.h" |
| 16 | 16 |
| 17 // The shmat system call uses this as it's invalid return address | 17 // The shmat system call uses this as it's invalid return address |
| 18 static void *const kInvalidAddress = (void*) -1; | 18 static void *const kInvalidAddress = (void*) -1; |
| 19 | 19 |
| 20 TransportDIB::TransportDIB() | 20 TransportDIB::TransportDIB() |
| 21 : key_(-1), | 21 : key_(-1), |
| 22 address_(kInvalidAddress), | 22 address_(kInvalidAddress), |
| 23 x_shm_(0), | 23 x_shm_(0), |
| 24 display_(NULL), | 24 display_(NULL), |
| 25 size_(0) { | 25 size_(0) { |
| 26 } | 26 } |
| 27 | 27 |
| 28 TransportDIB::~TransportDIB() { | 28 TransportDIB::~TransportDIB() { |
| 29 if (address_ != kInvalidAddress) { | 29 if (address_ != kInvalidAddress) { |
| 30 shmdt(address_); | 30 shmdt(address_); |
| 31 address_ = kInvalidAddress; | 31 address_ = kInvalidAddress; |
| 32 } | 32 } |
| 33 | 33 |
| 34 if (x_shm_) { | 34 if (x_shm_) { |
| 35 DCHECK(display_); | 35 DCHECK(display_); |
| 36 x11_util::DetachSharedMemory(display_, x_shm_); | 36 ui::DetachSharedMemory(display_, x_shm_); |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 | 39 |
| 40 // static | 40 // static |
| 41 TransportDIB* TransportDIB::Create(size_t size, uint32 sequence_num) { | 41 TransportDIB* TransportDIB::Create(size_t size, uint32 sequence_num) { |
| 42 // We use a mode of 0666 since the X server won't attach to memory which is | 42 // We use a mode of 0666 since the X server won't attach to memory which is |
| 43 // 0600 since it can't know if it (as a root process) is being asked to map | 43 // 0600 since it can't know if it (as a root process) is being asked to map |
| 44 // someone else's private shared memory region. | 44 // someone else's private shared memory region. |
| 45 const int shmkey = shmget(IPC_PRIVATE, size, 0666); | 45 const int shmkey = shmget(IPC_PRIVATE, size, 0666); |
| 46 if (shmkey == -1) { | 46 if (shmkey == -1) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 TransportDIB::Id TransportDIB::id() const { | 121 TransportDIB::Id TransportDIB::id() const { |
| 122 return key_; | 122 return key_; |
| 123 } | 123 } |
| 124 | 124 |
| 125 TransportDIB::Handle TransportDIB::handle() const { | 125 TransportDIB::Handle TransportDIB::handle() const { |
| 126 return key_; | 126 return key_; |
| 127 } | 127 } |
| 128 | 128 |
| 129 XID TransportDIB::MapToX(Display* display) { | 129 XID TransportDIB::MapToX(Display* display) { |
| 130 if (!x_shm_) { | 130 if (!x_shm_) { |
| 131 x_shm_ = x11_util::AttachSharedMemory(display, key_); | 131 x_shm_ = ui::AttachSharedMemory(display, key_); |
| 132 display_ = display; | 132 display_ = display; |
| 133 } | 133 } |
| 134 | 134 |
| 135 return x_shm_; | 135 return x_shm_; |
| 136 } | 136 } |
| OLD | NEW |