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