Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1268)

Side by Side Diff: ui/surface/transport_dib_sysvipc.cc

Issue 13886018: Add a factory and defines for native Linux surfaces. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Get {base,ui,aura}_unittests working with native linux surface Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
OLDNEW
« build/common.gypi ('K') | « ui/surface/transport_dib.h ('k') | ui/ui.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698