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 "base/gfx/size.h" | 10 #include "base/gfx/size.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "chrome/common/transport_dib.h" | 12 #include "chrome/common/transport_dib.h" |
13 #include "chrome/common/x11_util.h" | 13 #include "chrome/common/x11_util.h" |
| 14 #include "skia/ext/platform_canvas.h" |
14 | 15 |
15 // The shmat system call uses this as it's invalid return address | 16 // The shmat system call uses this as it's invalid return address |
16 static void *const kInvalidAddress = (void*) -1; | 17 static void *const kInvalidAddress = (void*) -1; |
17 | 18 |
18 TransportDIB::TransportDIB() | 19 TransportDIB::TransportDIB() |
19 : key_(-1), | 20 : key_(-1), |
20 address_(kInvalidAddress), | 21 address_(kInvalidAddress), |
21 x_shm_(0), | 22 x_shm_(0), |
22 display_(NULL), | 23 display_(NULL), |
23 size_(0) { | 24 size_(0) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 return NULL; | 74 return NULL; |
74 | 75 |
75 TransportDIB* dib = new TransportDIB; | 76 TransportDIB* dib = new TransportDIB; |
76 | 77 |
77 dib->address_ = address; | 78 dib->address_ = address; |
78 dib->size_ = shmst.shm_segsz; | 79 dib->size_ = shmst.shm_segsz; |
79 dib->key_ = shmkey; | 80 dib->key_ = shmkey; |
80 return dib; | 81 return dib; |
81 } | 82 } |
82 | 83 |
| 84 skia::PlatformCanvas* TransportDIB::GetPlatformCanvas(int w, int h) { |
| 85 return new skia::PlatformCanvas(w, h, true, |
| 86 reinterpret_cast<uint8_t*>(memory())); |
| 87 } |
| 88 |
83 void* TransportDIB::memory() const { | 89 void* TransportDIB::memory() const { |
84 DCHECK_NE(address_, kInvalidAddress); | 90 DCHECK_NE(address_, kInvalidAddress); |
85 return address_; | 91 return address_; |
86 } | 92 } |
87 | 93 |
88 TransportDIB::Id TransportDIB::id() const { | 94 TransportDIB::Id TransportDIB::id() const { |
89 return key_; | 95 return key_; |
90 } | 96 } |
91 | 97 |
92 TransportDIB::Handle TransportDIB::handle() const { | 98 TransportDIB::Handle TransportDIB::handle() const { |
93 return key_; | 99 return key_; |
94 } | 100 } |
95 | 101 |
96 XID TransportDIB::MapToX(Display* display) { | 102 XID TransportDIB::MapToX(Display* display) { |
97 if (!x_shm_) { | 103 if (!x_shm_) { |
98 x_shm_ = x11_util::AttachSharedMemory(display, key_); | 104 x_shm_ = x11_util::AttachSharedMemory(display, key_); |
99 display_ = display; | 105 display_ = display; |
100 } | 106 } |
101 | 107 |
102 return x_shm_; | 108 return x_shm_; |
103 } | 109 } |
OLD | NEW |