| 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 "ui/surface/transport_dib.h" | 5 #include "ui/surface/transport_dib.h" |
| 6 | 6 |
| 7 // Desktop GTK Linux builds use the old-style SYSV SHM based DIBs. | 7 // Desktop GTK Linux builds use the old-style SYSV SHM based DIBs. |
| 8 // Linux Aura and Chrome OS do too. This will change very soon. | 8 // Linux Aura and Chrome OS do too. This will change very soon. |
| 9 #if defined(TOOLKIT_GTK) || (defined(OS_LINUX) && defined(USE_AURA)) | 9 #if defined(TOOLKIT_GTK) || (defined(OS_LINUX) && defined(USE_AURA) && defined(U
SE_X11)) |
| 10 | 10 |
| 11 #include <errno.h> | 11 #include <errno.h> |
| 12 #include <stdlib.h> | 12 #include <stdlib.h> |
| 13 #include <sys/ipc.h> | 13 #include <sys/ipc.h> |
| 14 #include <sys/shm.h> | 14 #include <sys/shm.h> |
| 15 | 15 |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "skia/ext/platform_canvas.h" | 18 #include "skia/ext/platform_canvas.h" |
| 19 #include "ui/gfx/size.h" |
| 20 |
| 21 #if defined(USE_X11) |
| 19 #include "ui/base/x/x11_util.h" | 22 #include "ui/base/x/x11_util.h" |
| 20 #include "ui/gfx/size.h" | 23 #endif |
| 21 | 24 |
| 22 // The shmat system call uses this as it's invalid return address | 25 // The shmat system call uses this as it's invalid return address |
| 23 static void *const kInvalidAddress = (void*) -1; | 26 static void *const kInvalidAddress = (void*) -1; |
| 24 | 27 |
| 25 TransportDIB::TransportDIB() | 28 TransportDIB::TransportDIB() |
| 26 : address_(kInvalidAddress), | 29 : address_(kInvalidAddress), |
| 30 #if defined(USE_X11) |
| 27 x_shm_(0), | 31 x_shm_(0), |
| 28 display_(NULL), | 32 display_(NULL), |
| 33 #endif |
| 29 inflight_counter_(0), | 34 inflight_counter_(0), |
| 30 detached_(false), | 35 detached_(false), |
| 31 size_(0) { | 36 size_(0) { |
| 32 } | 37 } |
| 33 | 38 |
| 34 TransportDIB::~TransportDIB() { | 39 TransportDIB::~TransportDIB() { |
| 35 if (address_ != kInvalidAddress) { | 40 if (address_ != kInvalidAddress) { |
| 36 shmdt(address_); | 41 shmdt(address_); |
| 37 address_ = kInvalidAddress; | 42 address_ = kInvalidAddress; |
| 38 } | 43 } |
| 39 | 44 |
| 45 #if defined(USE_X11) |
| 40 if (x_shm_) { | 46 if (x_shm_) { |
| 41 DCHECK(display_); | 47 DCHECK(display_); |
| 42 ui::DetachSharedMemory(display_, x_shm_); | 48 ui::DetachSharedMemory(display_, x_shm_); |
| 43 } | 49 } |
| 50 #endif |
| 44 } | 51 } |
| 45 | 52 |
| 46 // static | 53 // static |
| 47 TransportDIB* TransportDIB::Create(size_t size, uint32 sequence_num) { | 54 TransportDIB* TransportDIB::Create(size_t size, uint32 sequence_num) { |
| 48 const int shmkey = shmget(IPC_PRIVATE, size, 0600); | 55 const int shmkey = shmget(IPC_PRIVATE, size, 0600); |
| 49 if (shmkey == -1) { | 56 if (shmkey == -1) { |
| 50 DLOG(ERROR) << "Failed to create SysV shared memory region" | 57 DLOG(ERROR) << "Failed to create SysV shared memory region" |
| 51 << " errno:" << errno; | 58 << " errno:" << errno; |
| 52 return NULL; | 59 return NULL; |
| 53 } else { | 60 } else { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 } | 135 } |
| 129 | 136 |
| 130 TransportDIB::Id TransportDIB::id() const { | 137 TransportDIB::Id TransportDIB::id() const { |
| 131 return key_; | 138 return key_; |
| 132 } | 139 } |
| 133 | 140 |
| 134 TransportDIB::Handle TransportDIB::handle() const { | 141 TransportDIB::Handle TransportDIB::handle() const { |
| 135 return key_.shmkey; | 142 return key_.shmkey; |
| 136 } | 143 } |
| 137 | 144 |
| 145 #if defined(USE_X11) |
| 138 XID TransportDIB::MapToX(Display* display) { | 146 XID TransportDIB::MapToX(Display* display) { |
| 139 if (!x_shm_) { | 147 if (!x_shm_) { |
| 140 x_shm_ = ui::AttachSharedMemory(display, key_.shmkey); | 148 x_shm_ = ui::AttachSharedMemory(display, key_.shmkey); |
| 141 display_ = display; | 149 display_ = display; |
| 142 } | 150 } |
| 143 | 151 |
| 144 return x_shm_; | 152 return x_shm_; |
| 145 } | 153 } |
| 154 #endif |
| 146 | 155 |
| 147 void TransportDIB::DecreaseInFlightCounter() { | 156 void TransportDIB::DecreaseInFlightCounter() { |
| 148 CHECK(inflight_counter_); | 157 CHECK(inflight_counter_); |
| 149 inflight_counter_--; | 158 inflight_counter_--; |
| 150 if (!inflight_counter_ && detached_) | 159 if (!inflight_counter_ && detached_) |
| 151 delete this; | 160 delete this; |
| 152 } | 161 } |
| 153 | 162 |
| 154 void TransportDIB::Detach() { | 163 void TransportDIB::Detach() { |
| 155 CHECK(!detached_); | 164 CHECK(!detached_); |
| 156 detached_ = true; | 165 detached_ = true; |
| 157 if (!inflight_counter_) | 166 if (!inflight_counter_) |
| 158 delete this; | 167 delete this; |
| 159 } | 168 } |
| 160 | 169 |
| 161 #endif | 170 #endif |
| 162 | 171 |
| OLD | NEW |