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 #ifndef PPAPI_PPB_BUFFER_PROXY_H_ | 5 #ifndef PPAPI_PPB_BUFFER_PROXY_H_ |
6 #define PPAPI_PPB_BUFFER_PROXY_H_ | 6 #define PPAPI_PPB_BUFFER_PROXY_H_ |
7 | 7 |
8 #include "base/shared_memory.h" | 8 #include "base/shared_memory.h" |
9 #include "ppapi/c/pp_instance.h" | 9 #include "ppapi/c/pp_instance.h" |
10 #include "ppapi/proxy/interface_proxy.h" | 10 #include "ppapi/proxy/interface_proxy.h" |
| 11 #include "ppapi/proxy/plugin_resource.h" |
| 12 #include "ppapi/thunk/ppb_buffer_api.h" |
11 | 13 |
12 struct PPB_Buffer_Dev; | 14 struct PPB_Buffer_Dev; |
13 | 15 |
14 namespace pp { | 16 namespace pp { |
15 namespace proxy { | 17 namespace proxy { |
16 | 18 |
17 class HostResource; | 19 class HostResource; |
18 | 20 |
| 21 class Buffer : public ppapi::thunk::PPB_Buffer_API, |
| 22 public PluginResource { |
| 23 public: |
| 24 Buffer(const HostResource& resource, |
| 25 const base::SharedMemoryHandle& shm_handle, |
| 26 uint32_t size); |
| 27 virtual ~Buffer(); |
| 28 |
| 29 // Resource overrides. |
| 30 virtual Buffer* AsBuffer() OVERRIDE; |
| 31 |
| 32 // ResourceObjectBase overrides. |
| 33 virtual ppapi::thunk::PPB_Buffer_API* AsPPB_Buffer_API() OVERRIDE; |
| 34 |
| 35 // PPB_Buffer_API implementation. |
| 36 virtual PP_Bool Describe(uint32_t* size_in_bytes) OVERRIDE; |
| 37 virtual PP_Bool IsMapped() OVERRIDE; |
| 38 virtual void* Map() OVERRIDE; |
| 39 virtual void Unmap() OVERRIDE; |
| 40 |
| 41 private: |
| 42 base::SharedMemory shm_; |
| 43 uint32_t size_; |
| 44 void* mapped_data_; |
| 45 int map_count_; |
| 46 |
| 47 DISALLOW_COPY_AND_ASSIGN(Buffer); |
| 48 }; |
| 49 |
19 class PPB_Buffer_Proxy : public InterfaceProxy { | 50 class PPB_Buffer_Proxy : public InterfaceProxy { |
20 public: | 51 public: |
21 PPB_Buffer_Proxy(Dispatcher* dispatcher, const void* target_interface); | 52 PPB_Buffer_Proxy(Dispatcher* dispatcher, const void* target_interface); |
22 virtual ~PPB_Buffer_Proxy(); | 53 virtual ~PPB_Buffer_Proxy(); |
23 | 54 |
24 static const Info* GetInfo(); | 55 static const Info* GetInfo(); |
25 | 56 |
26 static PP_Resource CreateProxyResource(PP_Instance instance, | 57 static PP_Resource CreateProxyResource(PP_Instance instance, |
27 uint32_t size); | 58 uint32_t size); |
28 | 59 |
29 const PPB_Buffer_Dev* ppb_buffer_target() const { | 60 const PPB_Buffer_Dev* ppb_buffer_target() const { |
30 return static_cast<const PPB_Buffer_Dev*>(target_interface()); | 61 return static_cast<const PPB_Buffer_Dev*>(target_interface()); |
31 } | 62 } |
32 | 63 |
33 // InterfaceProxy implementation. | 64 // InterfaceProxy implementation. |
34 virtual bool OnMessageReceived(const IPC::Message& msg); | 65 virtual bool OnMessageReceived(const IPC::Message& msg); |
35 | 66 |
36 private: | 67 private: |
37 // Message handlers. | 68 // Message handlers. |
38 void OnMsgCreate(PP_Instance instance, | 69 void OnMsgCreate(PP_Instance instance, |
39 uint32_t size, | 70 uint32_t size, |
40 HostResource* result_resource, | 71 HostResource* result_resource, |
41 base::SharedMemoryHandle* result_shm_handle); | 72 base::SharedMemoryHandle* result_shm_handle); |
42 }; | 73 }; |
43 | 74 |
44 } // namespace proxy | 75 } // namespace proxy |
45 } // namespace pp | 76 } // namespace pp |
46 | 77 |
47 #endif // PPAPI_PPB_BUFFER_PROXY_H_ | 78 #endif // PPAPI_PPB_BUFFER_PROXY_H_ |
OLD | NEW |