OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "ppapi/proxy/ppb_image_data_proxy.h" | 5 #include "ppapi/proxy/ppb_image_data_proxy.h" |
6 | 6 |
7 #include <string.h> // For memcpy | 7 #include <string.h> // For memcpy |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
13 #include "ppapi/c/pp_completion_callback.h" | 13 #include "ppapi/c/pp_completion_callback.h" |
| 14 #include "ppapi/c/pp_errors.h" |
14 #include "ppapi/c/pp_resource.h" | 15 #include "ppapi/c/pp_resource.h" |
15 #include "ppapi/c/ppb_image_data.h" | 16 #include "ppapi/c/ppb_image_data.h" |
16 #include "ppapi/c/trusted/ppb_image_data_trusted.h" | 17 #include "ppapi/c/trusted/ppb_image_data_trusted.h" |
17 #include "ppapi/proxy/plugin_dispatcher.h" | 18 #include "ppapi/proxy/plugin_dispatcher.h" |
18 #include "ppapi/proxy/plugin_resource.h" | 19 #include "ppapi/proxy/plugin_resource.h" |
19 #include "ppapi/proxy/ppapi_messages.h" | 20 #include "ppapi/proxy/ppapi_messages.h" |
20 | 21 |
21 #if defined(OS_LINUX) | 22 #if defined(OS_LINUX) |
22 #include <sys/shm.h> | 23 #include <sys/shm.h> |
23 #endif | 24 #endif |
24 | 25 |
25 namespace pp { | 26 namespace pp { |
26 namespace proxy { | 27 namespace proxy { |
27 | 28 |
28 class ImageData : public PluginResource { | 29 class ImageData : public PluginResource { |
29 public: | 30 public: |
30 ImageData(const PP_ImageDataDesc& desc, uint64_t memory_handle); | 31 ImageData(const PP_ImageDataDesc& desc, int memory_handle); |
31 virtual ~ImageData(); | 32 virtual ~ImageData(); |
32 | 33 |
33 // Resource overrides. | 34 // Resource overrides. |
34 virtual ImageData* AsImageData() { return this; } | 35 virtual ImageData* AsImageData() { return this; } |
35 | 36 |
36 void* Map(); | 37 void* Map(); |
37 void Unmap(); | 38 void Unmap(); |
38 | 39 |
39 const PP_ImageDataDesc& desc() const { return desc_; } | 40 const PP_ImageDataDesc& desc() const { return desc_; } |
40 | 41 |
41 private: | 42 private: |
42 PP_ImageDataDesc desc_; | 43 PP_ImageDataDesc desc_; |
43 uint64_t memory_handle_; | 44 int memory_handle_; |
44 | 45 |
45 void* mapped_data_; | 46 void* mapped_data_; |
46 | 47 |
47 DISALLOW_COPY_AND_ASSIGN(ImageData); | 48 DISALLOW_COPY_AND_ASSIGN(ImageData); |
48 }; | 49 }; |
49 | 50 |
50 ImageData::ImageData(const PP_ImageDataDesc& desc, | 51 ImageData::ImageData(const PP_ImageDataDesc& desc, |
51 uint64_t memory_handle) | 52 int memory_handle) |
52 : desc_(desc), | 53 : desc_(desc), |
53 memory_handle_(memory_handle), | 54 memory_handle_(memory_handle), |
54 mapped_data_(NULL) { | 55 mapped_data_(NULL) { |
55 } | 56 } |
56 | 57 |
57 ImageData::~ImageData() { | 58 ImageData::~ImageData() { |
58 Unmap(); | 59 Unmap(); |
59 } | 60 } |
60 | 61 |
61 void* ImageData::Map() { | 62 void* ImageData::Map() { |
62 #if defined(OS_LINUX) | 63 #if defined(OS_LINUX) |
63 // On linux, the memory handle is a SysV shared memory segment. | 64 // On linux, the memory handle is a SysV shared memory segment. |
64 int shmkey = static_cast<int>(memory_handle_); | 65 int shmkey = memory_handle_; |
65 void* address = shmat(shmkey, NULL, 0); | 66 void* address = shmat(shmkey, NULL, 0); |
66 // Mark for deletion in case we crash so the kernel will clean it up. | 67 // Mark for deletion in case we crash so the kernel will clean it up. |
67 shmctl(shmkey, IPC_RMID, 0); | 68 shmctl(shmkey, IPC_RMID, 0); |
68 if (address == (void*)-1) | 69 if (address == (void*)-1) |
69 return NULL; | 70 return NULL; |
70 mapped_data_ = address; | 71 mapped_data_ = address; |
71 return address; | 72 return address; |
72 #else | 73 #else |
73 NOTIMPLEMENTED(); | 74 NOTIMPLEMENTED(); |
74 return NULL; | 75 return NULL; |
(...skipping 28 matching lines...) Expand all Loading... |
103 &supported)); | 104 &supported)); |
104 return supported; | 105 return supported; |
105 } | 106 } |
106 | 107 |
107 PP_Resource Create(PP_Module module_id, | 108 PP_Resource Create(PP_Module module_id, |
108 PP_ImageDataFormat format, | 109 PP_ImageDataFormat format, |
109 const PP_Size* size, | 110 const PP_Size* size, |
110 PP_Bool init_to_zero) { | 111 PP_Bool init_to_zero) { |
111 PP_Resource result = 0; | 112 PP_Resource result = 0; |
112 std::string image_data_desc; | 113 std::string image_data_desc; |
113 uint64_t shm_handle = -1; | 114 int shm_handle = -1; |
114 PluginDispatcher::Get()->Send( | 115 PluginDispatcher::Get()->Send( |
115 new PpapiHostMsg_PPBImageData_Create( | 116 new PpapiHostMsg_PPBImageData_Create( |
116 INTERFACE_ID_PPB_IMAGE_DATA, module_id, format, *size, init_to_zero, | 117 INTERFACE_ID_PPB_IMAGE_DATA, module_id, format, *size, init_to_zero, |
117 &result, &image_data_desc, &shm_handle)); | 118 &result, &image_data_desc, &shm_handle)); |
118 | 119 |
119 if (result && image_data_desc.size() == sizeof(PP_ImageDataDesc)) { | 120 if (result && image_data_desc.size() == sizeof(PP_ImageDataDesc)) { |
120 // We serialize the PP_ImageDataDesc just by copying to a string. | 121 // We serialize the PP_ImageDataDesc just by copying to a string. |
121 PP_ImageDataDesc desc; | 122 PP_ImageDataDesc desc; |
122 memcpy(&desc, image_data_desc.data(), sizeof(PP_ImageDataDesc)); | 123 memcpy(&desc, image_data_desc.data(), sizeof(PP_ImageDataDesc)); |
123 | 124 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 *result = ppb_image_data_target()->IsImageDataFormatSupported( | 204 *result = ppb_image_data_target()->IsImageDataFormatSupported( |
204 static_cast<PP_ImageDataFormat>(format)); | 205 static_cast<PP_ImageDataFormat>(format)); |
205 } | 206 } |
206 | 207 |
207 void PPB_ImageData_Proxy::OnMsgCreate(PP_Module module, | 208 void PPB_ImageData_Proxy::OnMsgCreate(PP_Module module, |
208 int32_t format, | 209 int32_t format, |
209 const PP_Size& size, | 210 const PP_Size& size, |
210 PP_Bool init_to_zero, | 211 PP_Bool init_to_zero, |
211 PP_Resource* result, | 212 PP_Resource* result, |
212 std::string* image_data_desc, | 213 std::string* image_data_desc, |
213 uint64_t* result_shm_handle) { | 214 int* result_shm_handle) { |
214 *result = ppb_image_data_target()->Create( | 215 *result = ppb_image_data_target()->Create( |
215 module, static_cast<PP_ImageDataFormat>(format), &size, init_to_zero); | 216 module, static_cast<PP_ImageDataFormat>(format), &size, init_to_zero); |
216 *result_shm_handle = 0; | 217 *result_shm_handle = 0; |
217 if (*result) { | 218 if (*result) { |
218 // The ImageDesc is just serialized as a string. | 219 // The ImageDesc is just serialized as a string. |
219 PP_ImageDataDesc desc; | 220 PP_ImageDataDesc desc; |
220 if (ppb_image_data_target()->Describe(*result, &desc)) { | 221 if (ppb_image_data_target()->Describe(*result, &desc)) { |
221 image_data_desc->resize(sizeof(PP_ImageDataDesc)); | 222 image_data_desc->resize(sizeof(PP_ImageDataDesc)); |
222 memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc)); | 223 memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc)); |
223 } | 224 } |
224 | 225 |
225 // Get the shared memory handle. | 226 // Get the shared memory handle. |
226 const PPB_ImageDataTrusted* trusted = | 227 const PPB_ImageDataTrusted* trusted = |
227 reinterpret_cast<const PPB_ImageDataTrusted*>( | 228 reinterpret_cast<const PPB_ImageDataTrusted*>( |
228 dispatcher()->GetLocalInterface(PPB_IMAGEDATA_TRUSTED_INTERFACE)); | 229 dispatcher()->GetLocalInterface(PPB_IMAGEDATA_TRUSTED_INTERFACE)); |
229 uint32_t byte_count = 0; | 230 uint32_t byte_count = 0; |
230 if (trusted) | 231 if (trusted) { |
231 *result_shm_handle = trusted->GetNativeMemoryHandle(*result, &byte_count); | 232 int32_t handle; |
| 233 if (trusted->GetSharedMemory(*result, &handle, &byte_count) == PP_OK) |
| 234 *result_shm_handle = static_cast<int>(handle); |
| 235 } |
232 } | 236 } |
233 } | 237 } |
234 | 238 |
235 } // namespace proxy | 239 } // namespace proxy |
236 } // namespace pp | 240 } // namespace pp |
OLD | NEW |