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 "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 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 | 46 |
47 ImageData::ImageData(const HostResource& resource, | 47 ImageData::ImageData(const HostResource& resource, |
48 const PP_ImageDataDesc& desc, | 48 const PP_ImageDataDesc& desc, |
49 const base::SharedMemoryHandle& handle) | 49 const base::SharedMemoryHandle& handle) |
50 : Resource(OBJECT_IS_PROXY, resource), | 50 : Resource(OBJECT_IS_PROXY, resource), |
51 desc_(desc), | 51 desc_(desc), |
52 shm_(handle, false /* read_only */), | 52 shm_(handle, false /* read_only */), |
53 size_(desc.size.width * desc.size.height * 4), | 53 size_(desc.size.width * desc.size.height * 4), |
54 map_count_(0) { | 54 map_count_(0) { |
55 } | 55 } |
56 #endif // !defined(OS_NACL) | 56 #endif // else, !defined(OS_NACL) |
57 | 57 |
58 ImageData::~ImageData() { | 58 ImageData::~ImageData() { |
59 } | 59 } |
60 | 60 |
61 thunk::PPB_ImageData_API* ImageData::AsPPB_ImageData_API() { | 61 thunk::PPB_ImageData_API* ImageData::AsPPB_ImageData_API() { |
62 return this; | 62 return this; |
63 } | 63 } |
64 | 64 |
65 PP_Bool ImageData::Describe(PP_ImageDataDesc* desc) { | 65 PP_Bool ImageData::Describe(PP_ImageDataDesc* desc) { |
66 memcpy(desc, &desc_, sizeof(PP_ImageDataDesc)); | 66 memcpy(desc, &desc_, sizeof(PP_ImageDataDesc)); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 PP_ImageDataFormat format, | 156 PP_ImageDataFormat format, |
157 const PP_Size& size, | 157 const PP_Size& size, |
158 PP_Bool init_to_zero) { | 158 PP_Bool init_to_zero) { |
159 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 159 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
160 if (!dispatcher) | 160 if (!dispatcher) |
161 return 0; | 161 return 0; |
162 | 162 |
163 HostResource result; | 163 HostResource result; |
164 std::string image_data_desc; | 164 std::string image_data_desc; |
165 #if defined(OS_NACL) | 165 #if defined(OS_NACL) |
166 base::SharedMemoryHandle image_handle = base::SharedMemory::NULLHandle(); | 166 ppapi::proxy::SerializedHandle image_handle_wrapper; |
167 dispatcher->Send(new PpapiHostMsg_PPBImageData_CreateNaCl( | 167 dispatcher->Send(new PpapiHostMsg_PPBImageData_CreateNaCl( |
168 kApiID, instance, format, size, init_to_zero, | 168 kApiID, instance, format, size, init_to_zero, |
169 &result, &image_data_desc, &image_handle)); | 169 &result, &image_data_desc, &image_handle_wrapper)); |
| 170 if (!image_handle_wrapper.is_shmem()) |
| 171 return 0; |
| 172 base::SharedMemoryHandle image_handle = image_handle_wrapper.shmem(); |
170 #else | 173 #else |
171 ImageHandle image_handle = ImageData::NullHandle(); | 174 ImageHandle image_handle = ImageData::NullHandle(); |
172 dispatcher->Send(new PpapiHostMsg_PPBImageData_Create( | 175 dispatcher->Send(new PpapiHostMsg_PPBImageData_Create( |
173 kApiID, instance, format, size, init_to_zero, | 176 kApiID, instance, format, size, init_to_zero, |
174 &result, &image_data_desc, &image_handle)); | 177 &result, &image_data_desc, &image_handle)); |
175 #endif | 178 #endif |
176 | 179 |
177 if (result.is_null() || image_data_desc.size() != sizeof(PP_ImageDataDesc)) | 180 if (result.is_null() || image_data_desc.size() != sizeof(PP_ImageDataDesc)) |
178 return 0; | 181 return 0; |
179 | 182 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 #endif // defined(OS_NACL) | 245 #endif // defined(OS_NACL) |
243 } | 246 } |
244 | 247 |
245 void PPB_ImageData_Proxy::OnHostMsgCreateNaCl( | 248 void PPB_ImageData_Proxy::OnHostMsgCreateNaCl( |
246 PP_Instance instance, | 249 PP_Instance instance, |
247 int32_t format, | 250 int32_t format, |
248 const PP_Size& size, | 251 const PP_Size& size, |
249 PP_Bool init_to_zero, | 252 PP_Bool init_to_zero, |
250 HostResource* result, | 253 HostResource* result, |
251 std::string* image_data_desc, | 254 std::string* image_data_desc, |
252 base::SharedMemoryHandle* result_image_handle) { | 255 ppapi::proxy::SerializedHandle* result_image_handle) { |
253 #if defined(OS_NACL) | 256 #if defined(OS_NACL) |
254 // This message should never be received in untrusted code. To minimize the | 257 // This message should never be received in untrusted code. To minimize the |
255 // size of the IRT, we just don't handle it. | 258 // size of the IRT, we just don't handle it. |
256 return; | 259 return; |
257 #else | 260 #else |
258 *result_image_handle = base::SharedMemory::NULLHandle(); | 261 result_image_handle->set_null_shmem(); |
259 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 262 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
260 if (!dispatcher) | 263 if (!dispatcher) |
261 return; | 264 return; |
262 | 265 |
263 thunk::EnterResourceCreation enter(instance); | 266 thunk::EnterResourceCreation enter(instance); |
264 if (enter.failed()) | 267 if (enter.failed()) |
265 return; | 268 return; |
266 | 269 |
267 PP_Resource resource = enter.functions()->CreateImageDataNaCl( | 270 PP_Resource resource = enter.functions()->CreateImageDataNaCl( |
268 instance, static_cast<PP_ImageDataFormat>(format), size, init_to_zero); | 271 instance, static_cast<PP_ImageDataFormat>(format), size, init_to_zero); |
269 if (!resource) | 272 if (!resource) |
270 return; | 273 return; |
271 result->SetHostResource(instance, resource); | 274 result->SetHostResource(instance, resource); |
272 | 275 |
273 // Get the description, it's just serialized as a string. | 276 // Get the description, it's just serialized as a string. |
274 thunk::EnterResourceNoLock<thunk::PPB_ImageData_API> enter_resource( | 277 thunk::EnterResourceNoLock<thunk::PPB_ImageData_API> enter_resource( |
275 resource, false); | 278 resource, false); |
276 if (enter_resource.failed()) | 279 if (enter_resource.failed()) |
277 return; | 280 return; |
278 PP_ImageDataDesc desc; | 281 PP_ImageDataDesc desc; |
279 if (enter_resource.object()->Describe(&desc) == PP_TRUE) { | 282 if (enter_resource.object()->Describe(&desc) == PP_TRUE) { |
280 image_data_desc->resize(sizeof(PP_ImageDataDesc)); | 283 image_data_desc->resize(sizeof(PP_ImageDataDesc)); |
281 memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc)); | 284 memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc)); |
282 } | 285 } |
283 int local_fd; | 286 int local_fd; |
284 uint32_t byte_count; | 287 uint32_t byte_count; |
285 if (enter_resource.object()->GetSharedMemory(&local_fd, &byte_count) != PP_OK) | 288 if (enter_resource.object()->GetSharedMemory(&local_fd, &byte_count) != PP_OK) |
286 return; | 289 return; |
287 | |
288 // TODO(dmichael): Change trusted interface to return a PP_FileHandle, those | 290 // TODO(dmichael): Change trusted interface to return a PP_FileHandle, those |
289 // casts are ugly. | 291 // casts are ugly. |
290 base::PlatformFile platform_file = | 292 base::PlatformFile platform_file = |
291 #if defined(OS_WIN) | 293 #if defined(OS_WIN) |
292 reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd)); | 294 reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd)); |
293 #elif defined(OS_POSIX) | 295 #elif defined(OS_POSIX) |
294 local_fd; | 296 local_fd; |
295 #else | 297 #else |
296 #error Not implemented. | 298 #error Not implemented. |
297 #endif // defined(OS_WIN) | 299 #endif // defined(OS_WIN) |
298 *result_image_handle = | 300 result_image_handle->set_shmem( |
299 dispatcher->ShareHandleWithRemote(platform_file, false); | 301 dispatcher->ShareHandleWithRemote(platform_file, false), |
| 302 byte_count); |
300 #endif // defined(OS_NACL) | 303 #endif // defined(OS_NACL) |
301 } | 304 } |
302 | 305 |
303 } // namespace proxy | 306 } // namespace proxy |
304 } // namespace ppapi | 307 } // namespace ppapi |
OLD | NEW |