| 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" |
| 11 #include "ppapi/c/pp_completion_callback.h" | 11 #include "ppapi/c/pp_completion_callback.h" |
| 12 #include "ppapi/c/pp_errors.h" | 12 #include "ppapi/c/pp_errors.h" |
| 13 #include "ppapi/c/pp_resource.h" | 13 #include "ppapi/c/pp_resource.h" |
| 14 #include "ppapi/c/dev/ppb_buffer_dev.h" | 14 #include "ppapi/c/dev/ppb_buffer_dev.h" |
| 15 #include "ppapi/proxy/host_dispatcher.h" | 15 #include "ppapi/proxy/host_dispatcher.h" |
| 16 #include "ppapi/proxy/plugin_dispatcher.h" | 16 #include "ppapi/proxy/plugin_dispatcher.h" |
| 17 #include "ppapi/proxy/ppapi_messages.h" | 17 #include "ppapi/proxy/ppapi_messages.h" |
| 18 #include "ppapi/thunk/enter.h" | 18 #include "ppapi/thunk/enter.h" |
| 19 #include "ppapi/thunk/ppb_buffer_trusted_api.h" | |
| 20 #include "ppapi/thunk/resource_creation_api.h" | 19 #include "ppapi/thunk/resource_creation_api.h" |
| 21 #include "ppapi/thunk/thunk.h" | 20 #include "ppapi/thunk/thunk.h" |
| 22 | 21 |
| 23 namespace ppapi { | 22 namespace ppapi { |
| 24 namespace proxy { | 23 namespace proxy { |
| 25 | 24 |
| 26 Buffer::Buffer(const HostResource& resource, | 25 Buffer::Buffer(const HostResource& resource, |
| 27 const base::SharedMemoryHandle& shm_handle, | 26 const base::SharedMemoryHandle& shm_handle, |
| 28 uint32_t size) | 27 uint32_t size) |
| 29 : Resource(OBJECT_IS_PROXY, resource), | 28 : Resource(OBJECT_IS_PROXY, resource), |
| (...skipping 23 matching lines...) Expand all Loading... |
| 53 if (map_count_++ == 0) | 52 if (map_count_++ == 0) |
| 54 shm_.Map(size_); | 53 shm_.Map(size_); |
| 55 return shm_.memory(); | 54 return shm_.memory(); |
| 56 } | 55 } |
| 57 | 56 |
| 58 void Buffer::Unmap() { | 57 void Buffer::Unmap() { |
| 59 if (--map_count_ == 0) | 58 if (--map_count_ == 0) |
| 60 shm_.Unmap(); | 59 shm_.Unmap(); |
| 61 } | 60 } |
| 62 | 61 |
| 62 int32_t Buffer::GetSharedMemory(int* out_handle) { |
| 63 NOTREACHED(); |
| 64 return PP_ERROR_NOTSUPPORTED; |
| 65 } |
| 66 |
| 63 PPB_Buffer_Proxy::PPB_Buffer_Proxy(Dispatcher* dispatcher) | 67 PPB_Buffer_Proxy::PPB_Buffer_Proxy(Dispatcher* dispatcher) |
| 64 : InterfaceProxy(dispatcher) { | 68 : InterfaceProxy(dispatcher) { |
| 65 } | 69 } |
| 66 | 70 |
| 67 PPB_Buffer_Proxy::~PPB_Buffer_Proxy() { | 71 PPB_Buffer_Proxy::~PPB_Buffer_Proxy() { |
| 68 } | 72 } |
| 69 | 73 |
| 70 // static | 74 // static |
| 71 PP_Resource PPB_Buffer_Proxy::CreateProxyResource(PP_Instance instance, | 75 PP_Resource PPB_Buffer_Proxy::CreateProxyResource(PP_Instance instance, |
| 72 uint32_t size) { | 76 uint32_t size) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 return; | 121 return; |
| 118 | 122 |
| 119 thunk::EnterResourceCreation enter(instance); | 123 thunk::EnterResourceCreation enter(instance); |
| 120 if (enter.failed()) | 124 if (enter.failed()) |
| 121 return; | 125 return; |
| 122 PP_Resource local_buffer_resource = enter.functions()->CreateBuffer(instance, | 126 PP_Resource local_buffer_resource = enter.functions()->CreateBuffer(instance, |
| 123 size); | 127 size); |
| 124 if (local_buffer_resource == 0) | 128 if (local_buffer_resource == 0) |
| 125 return; | 129 return; |
| 126 | 130 |
| 127 thunk::EnterResourceNoLock<thunk::PPB_BufferTrusted_API> trusted_buffer( | 131 thunk::EnterResourceNoLock<thunk::PPB_Buffer_API> trusted_buffer( |
| 128 local_buffer_resource, false); | 132 local_buffer_resource, false); |
| 129 if (trusted_buffer.failed()) | 133 if (trusted_buffer.failed()) |
| 130 return; | 134 return; |
| 131 int local_fd; | 135 int local_fd; |
| 132 if (trusted_buffer.object()->GetSharedMemory(&local_fd) != PP_OK) | 136 if (trusted_buffer.object()->GetSharedMemory(&local_fd) != PP_OK) |
| 133 return; | 137 return; |
| 134 | 138 |
| 135 result_resource->SetHostResource(instance, local_buffer_resource); | 139 result_resource->SetHostResource(instance, local_buffer_resource); |
| 136 | 140 |
| 137 // TODO(piman/brettw): Change trusted interface to return a PP_FileHandle, | 141 // TODO(piman/brettw): Change trusted interface to return a PP_FileHandle, |
| 138 // those casts are ugly. | 142 // those casts are ugly. |
| 139 base::PlatformFile platform_file = | 143 base::PlatformFile platform_file = |
| 140 #if defined(OS_WIN) | 144 #if defined(OS_WIN) |
| 141 reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd)); | 145 reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd)); |
| 142 #elif defined(OS_POSIX) | 146 #elif defined(OS_POSIX) |
| 143 local_fd; | 147 local_fd; |
| 144 #else | 148 #else |
| 145 #error Not implemented. | 149 #error Not implemented. |
| 146 #endif | 150 #endif |
| 147 result_shm_handle->set_shmem( | 151 result_shm_handle->set_shmem( |
| 148 dispatcher->ShareHandleWithRemote(platform_file, false), size); | 152 dispatcher->ShareHandleWithRemote(platform_file, false), size); |
| 149 } | 153 } |
| 150 | 154 |
| 151 } // namespace proxy | 155 } // namespace proxy |
| 152 } // namespace ppapi | 156 } // namespace ppapi |
| OLD | NEW |