| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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" | 19 #include "ppapi/thunk/ppb_buffer_trusted_api.h" |
| 20 #include "ppapi/thunk/resource_creation_api.h" |
| 20 #include "ppapi/thunk/thunk.h" | 21 #include "ppapi/thunk/thunk.h" |
| 21 | 22 |
| 22 namespace ppapi { | 23 namespace ppapi { |
| 23 namespace proxy { | 24 namespace proxy { |
| 24 | 25 |
| 25 namespace { | |
| 26 | |
| 27 InterfaceProxy* CreateBufferProxy(Dispatcher* dispatcher, | |
| 28 const void* target_interface) { | |
| 29 return new PPB_Buffer_Proxy(dispatcher, target_interface); | |
| 30 } | |
| 31 | |
| 32 } // namespace | |
| 33 | |
| 34 Buffer::Buffer(const HostResource& resource, | 26 Buffer::Buffer(const HostResource& resource, |
| 35 const base::SharedMemoryHandle& shm_handle, | 27 const base::SharedMemoryHandle& shm_handle, |
| 36 uint32_t size) | 28 uint32_t size) |
| 37 : Resource(resource), | 29 : Resource(resource), |
| 38 shm_(shm_handle, false), | 30 shm_(shm_handle, false), |
| 39 size_(size), | 31 size_(size), |
| 40 mapped_data_(NULL), | 32 mapped_data_(NULL), |
| 41 map_count_(0) { | 33 map_count_(0) { |
| 42 } | 34 } |
| 43 | 35 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 62 if (map_count_++ == 0) | 54 if (map_count_++ == 0) |
| 63 shm_.Map(size_); | 55 shm_.Map(size_); |
| 64 return shm_.memory(); | 56 return shm_.memory(); |
| 65 } | 57 } |
| 66 | 58 |
| 67 void Buffer::Unmap() { | 59 void Buffer::Unmap() { |
| 68 if (--map_count_ == 0) | 60 if (--map_count_ == 0) |
| 69 shm_.Unmap(); | 61 shm_.Unmap(); |
| 70 } | 62 } |
| 71 | 63 |
| 72 PPB_Buffer_Proxy::PPB_Buffer_Proxy(Dispatcher* dispatcher, | 64 PPB_Buffer_Proxy::PPB_Buffer_Proxy(Dispatcher* dispatcher) |
| 73 const void* target_interface) | 65 : InterfaceProxy(dispatcher) { |
| 74 : InterfaceProxy(dispatcher, target_interface) { | |
| 75 } | 66 } |
| 76 | 67 |
| 77 PPB_Buffer_Proxy::~PPB_Buffer_Proxy() { | 68 PPB_Buffer_Proxy::~PPB_Buffer_Proxy() { |
| 78 } | 69 } |
| 79 | 70 |
| 80 // static | 71 // static |
| 81 const InterfaceProxy::Info* PPB_Buffer_Proxy::GetInfo() { | |
| 82 static const Info info = { | |
| 83 thunk::GetPPB_Buffer_Thunk(), | |
| 84 PPB_BUFFER_DEV_INTERFACE, | |
| 85 INTERFACE_ID_PPB_BUFFER, | |
| 86 false, | |
| 87 &CreateBufferProxy, | |
| 88 }; | |
| 89 return &info; | |
| 90 } | |
| 91 | |
| 92 // static | |
| 93 PP_Resource PPB_Buffer_Proxy::CreateProxyResource(PP_Instance instance, | 72 PP_Resource PPB_Buffer_Proxy::CreateProxyResource(PP_Instance instance, |
| 94 uint32_t size) { | 73 uint32_t size) { |
| 95 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 74 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 96 if (!dispatcher) | 75 if (!dispatcher) |
| 97 return 0; | 76 return 0; |
| 98 | 77 |
| 99 HostResource result; | 78 HostResource result; |
| 100 base::SharedMemoryHandle shm_handle = base::SharedMemory::NULLHandle(); | 79 base::SharedMemoryHandle shm_handle = base::SharedMemory::NULLHandle(); |
| 101 dispatcher->Send(new PpapiHostMsg_PPBBuffer_Create( | 80 dispatcher->Send(new PpapiHostMsg_PPBBuffer_Create( |
| 102 INTERFACE_ID_PPB_BUFFER, instance, size, | 81 INTERFACE_ID_PPB_BUFFER, instance, size, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 128 void PPB_Buffer_Proxy::OnMsgCreate( | 107 void PPB_Buffer_Proxy::OnMsgCreate( |
| 129 PP_Instance instance, | 108 PP_Instance instance, |
| 130 uint32_t size, | 109 uint32_t size, |
| 131 HostResource* result_resource, | 110 HostResource* result_resource, |
| 132 base::SharedMemoryHandle* result_shm_handle) { | 111 base::SharedMemoryHandle* result_shm_handle) { |
| 133 // Overwritten below on success. | 112 // Overwritten below on success. |
| 134 *result_shm_handle = base::SharedMemory::NULLHandle(); | 113 *result_shm_handle = base::SharedMemory::NULLHandle(); |
| 135 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 114 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
| 136 if (!dispatcher) | 115 if (!dispatcher) |
| 137 return; | 116 return; |
| 138 PP_Resource local_buffer_resource = | 117 |
| 139 ppb_buffer_target()->Create(instance, size); | 118 thunk::EnterResourceCreation enter(instance); |
| 119 if (enter.failed()) |
| 120 return; |
| 121 PP_Resource local_buffer_resource = enter.functions()->CreateBuffer(instance, |
| 122 size); |
| 140 if (local_buffer_resource == 0) | 123 if (local_buffer_resource == 0) |
| 141 return; | 124 return; |
| 125 |
| 142 thunk::EnterResourceNoLock<thunk::PPB_BufferTrusted_API> trusted_buffer( | 126 thunk::EnterResourceNoLock<thunk::PPB_BufferTrusted_API> trusted_buffer( |
| 143 local_buffer_resource, false); | 127 local_buffer_resource, false); |
| 144 if (trusted_buffer.failed()) | 128 if (trusted_buffer.failed()) |
| 145 return; | 129 return; |
| 146 int local_fd; | 130 int local_fd; |
| 147 if (trusted_buffer.object()->GetSharedMemory(&local_fd) != PP_OK) | 131 if (trusted_buffer.object()->GetSharedMemory(&local_fd) != PP_OK) |
| 148 return; | 132 return; |
| 149 | 133 |
| 150 result_resource->SetHostResource(instance, local_buffer_resource); | 134 result_resource->SetHostResource(instance, local_buffer_resource); |
| 151 | 135 |
| 152 // TODO(piman/brettw): Change trusted interface to return a PP_FileHandle, | 136 // TODO(piman/brettw): Change trusted interface to return a PP_FileHandle, |
| 153 // those casts are ugly. | 137 // those casts are ugly. |
| 154 base::PlatformFile platform_file = | 138 base::PlatformFile platform_file = |
| 155 #if defined(OS_WIN) | 139 #if defined(OS_WIN) |
| 156 reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd)); | 140 reinterpret_cast<HANDLE>(static_cast<intptr_t>(local_fd)); |
| 157 #elif defined(OS_POSIX) | 141 #elif defined(OS_POSIX) |
| 158 local_fd; | 142 local_fd; |
| 159 #else | 143 #else |
| 160 #error Not implemented. | 144 #error Not implemented. |
| 161 #endif | 145 #endif |
| 162 *result_shm_handle = dispatcher->ShareHandleWithRemote(platform_file, false); | 146 *result_shm_handle = dispatcher->ShareHandleWithRemote(platform_file, false); |
| 163 } | 147 } |
| 164 | 148 |
| 165 } // namespace proxy | 149 } // namespace proxy |
| 166 } // namespace ppapi | 150 } // namespace ppapi |
| OLD | NEW |