| 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_buffer_proxy.h" | 5 #include "ppapi/proxy/ppb_buffer_proxy.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 if (map_count_++ == 0) | 52 if (map_count_++ == 0) |
| 53 shm_.Map(size_); | 53 shm_.Map(size_); |
| 54 return shm_.memory(); | 54 return shm_.memory(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void Buffer::Unmap() { | 57 void Buffer::Unmap() { |
| 58 if (--map_count_ == 0) | 58 if (--map_count_ == 0) |
| 59 shm_.Unmap(); | 59 shm_.Unmap(); |
| 60 } | 60 } |
| 61 | 61 |
| 62 int32_t Buffer::GetSharedMemory(int* out_handle) { | 62 int32_t Buffer::GetSharedMemory(base::SharedMemory* out_handle) { |
| 63 NOTREACHED(); | 63 NOTREACHED(); |
| 64 return PP_ERROR_NOTSUPPORTED; | 64 return PP_ERROR_NOTSUPPORTED; |
| 65 } | 65 } |
| 66 | 66 |
| 67 PPB_Buffer_Proxy::PPB_Buffer_Proxy(Dispatcher* dispatcher) | 67 PPB_Buffer_Proxy::PPB_Buffer_Proxy(Dispatcher* dispatcher) |
| 68 : InterfaceProxy(dispatcher) { | 68 : InterfaceProxy(dispatcher) { |
| 69 } | 69 } |
| 70 | 70 |
| 71 PPB_Buffer_Proxy::~PPB_Buffer_Proxy() { | 71 PPB_Buffer_Proxy::~PPB_Buffer_Proxy() { |
| 72 } | 72 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 return; | 125 return; |
| 126 PP_Resource local_buffer_resource = enter.functions()->CreateBuffer(instance, | 126 PP_Resource local_buffer_resource = enter.functions()->CreateBuffer(instance, |
| 127 size); | 127 size); |
| 128 if (local_buffer_resource == 0) | 128 if (local_buffer_resource == 0) |
| 129 return; | 129 return; |
| 130 | 130 |
| 131 thunk::EnterResourceNoLock<thunk::PPB_Buffer_API> trusted_buffer( | 131 thunk::EnterResourceNoLock<thunk::PPB_Buffer_API> trusted_buffer( |
| 132 local_buffer_resource, false); | 132 local_buffer_resource, false); |
| 133 if (trusted_buffer.failed()) | 133 if (trusted_buffer.failed()) |
| 134 return; | 134 return; |
| 135 int local_fd; | 135 base::SharedMemory local_shm; |
| 136 if (trusted_buffer.object()->GetSharedMemory(&local_fd) != PP_OK) | 136 if (trusted_buffer.object()->GetSharedMemory(&local_shm) != PP_OK) |
| 137 return; | 137 return; |
| 138 | 138 |
| 139 result_resource->SetHostResource(instance, local_buffer_resource); | 139 result_resource->SetHostResource(instance, local_buffer_resource); |
| 140 | 140 |
| 141 // TODO(piman/brettw): Change trusted interface to return a PP_FileHandle, | |
| 142 // those casts are ugly. | |
| 143 base::PlatformFile platform_file = | |
| 144 #if defined(OS_WIN) | |
| 145 reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd)); | |
| 146 #elif defined(OS_POSIX) | |
| 147 local_fd; | |
| 148 #else | |
| 149 #error Not implemented. | |
| 150 #endif | |
| 151 result_shm_handle->set_shmem( | 141 result_shm_handle->set_shmem( |
| 152 dispatcher->ShareHandleWithRemote(platform_file, false), size); | 142 dispatcher->ShareSharedMemoryHandleWithRemote(local_shm.handle()), size); |
| 153 } | 143 } |
| 154 | 144 |
| 155 } // namespace proxy | 145 } // namespace proxy |
| 156 } // namespace ppapi | 146 } // namespace ppapi |
| OLD | NEW |