OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_resource.h" | 12 #include "ppapi/c/pp_resource.h" |
13 #include "ppapi/c/dev/ppb_buffer_dev.h" | 13 #include "ppapi/c/dev/ppb_buffer_dev.h" |
14 #include "ppapi/proxy/plugin_dispatcher.h" | 14 #include "ppapi/proxy/plugin_dispatcher.h" |
15 #include "ppapi/proxy/plugin_resource.h" | 15 #include "ppapi/proxy/plugin_resource.h" |
16 #include "ppapi/proxy/ppapi_messages.h" | 16 #include "ppapi/proxy/ppapi_messages.h" |
17 | 17 |
18 namespace pp { | 18 namespace pp { |
19 namespace proxy { | 19 namespace proxy { |
20 | 20 |
21 class Buffer : public PluginResource { | 21 class Buffer : public PluginResource { |
22 public: | 22 public: |
23 Buffer(PP_Instance instance, int memory_handle, uint32_t size); | 23 Buffer(const HostResource& resource, |
| 24 int memory_handle, |
| 25 uint32_t size); |
24 virtual ~Buffer(); | 26 virtual ~Buffer(); |
25 | 27 |
26 // Resource overrides. | 28 // Resource overrides. |
27 virtual Buffer* AsBuffer() { return this; } | 29 virtual Buffer* AsBuffer() { return this; } |
28 | 30 |
29 uint32_t size() const { return size_; } | 31 uint32_t size() const { return size_; } |
30 | 32 |
31 void* Map(); | 33 void* Map(); |
32 void Unmap(); | 34 void Unmap(); |
33 | 35 |
34 private: | 36 private: |
35 int memory_handle_; | 37 int memory_handle_; |
36 uint32_t size_; | 38 uint32_t size_; |
37 | 39 |
38 void* mapped_data_; | 40 void* mapped_data_; |
39 | 41 |
40 DISALLOW_COPY_AND_ASSIGN(Buffer); | 42 DISALLOW_COPY_AND_ASSIGN(Buffer); |
41 }; | 43 }; |
42 | 44 |
43 Buffer::Buffer(PP_Instance instance, int memory_handle, uint32_t size) | 45 Buffer::Buffer(const HostResource& resource, |
44 : PluginResource(instance), | 46 int memory_handle, |
| 47 uint32_t size) |
| 48 : PluginResource(resource), |
45 memory_handle_(memory_handle), | 49 memory_handle_(memory_handle), |
46 size_(size), | 50 size_(size), |
47 mapped_data_(NULL) { | 51 mapped_data_(NULL) { |
48 } | 52 } |
49 | 53 |
50 Buffer::~Buffer() { | 54 Buffer::~Buffer() { |
51 Unmap(); | 55 Unmap(); |
52 } | 56 } |
53 | 57 |
54 void* Buffer::Map() { | 58 void* Buffer::Map() { |
55 // TODO(brettw) implement this. | 59 // TODO(brettw) implement this. |
56 return mapped_data_; | 60 return mapped_data_; |
57 } | 61 } |
58 | 62 |
59 void Buffer::Unmap() { | 63 void Buffer::Unmap() { |
60 // TODO(brettw) implement this. | 64 // TODO(brettw) implement this. |
61 } | 65 } |
62 | 66 |
63 namespace { | 67 namespace { |
64 | 68 |
65 PP_Resource Create(PP_Instance instance, uint32_t size) { | 69 PP_Resource Create(PP_Instance instance, uint32_t size) { |
66 PP_Resource result = 0; | 70 HostResource result; |
67 int32_t shm_handle = -1; | 71 int32_t shm_handle = -1; |
68 PluginDispatcher::GetForInstance(instance)->Send( | 72 PluginDispatcher::GetForInstance(instance)->Send( |
69 new PpapiHostMsg_PPBBuffer_Create( | 73 new PpapiHostMsg_PPBBuffer_Create( |
70 INTERFACE_ID_PPB_BUFFER, instance, size, | 74 INTERFACE_ID_PPB_BUFFER, instance, size, |
71 &result, &shm_handle)); | 75 &result, &shm_handle)); |
72 if (!result) | 76 if (result.is_null()) |
73 return 0; | 77 return 0; |
74 | 78 |
75 linked_ptr<Buffer> object(new Buffer(instance, static_cast<int>(shm_handle), | 79 linked_ptr<Buffer> object(new Buffer(result, |
76 size)); | 80 static_cast<int>(shm_handle), size)); |
77 PluginResourceTracker::GetInstance()->AddResource(result, object); | 81 return PluginResourceTracker::GetInstance()->AddResource(object); |
78 return result; | |
79 } | 82 } |
80 | 83 |
81 PP_Bool IsBuffer(PP_Resource resource) { | 84 PP_Bool IsBuffer(PP_Resource resource) { |
82 Buffer* object = PluginResource::GetAs<Buffer>(resource); | 85 Buffer* object = PluginResource::GetAs<Buffer>(resource); |
83 return BoolToPPBool(!!object); | 86 return BoolToPPBool(!!object); |
84 } | 87 } |
85 | 88 |
86 PP_Bool Describe(PP_Resource resource, uint32_t* size_in_bytes) { | 89 PP_Bool Describe(PP_Resource resource, uint32_t* size_in_bytes) { |
87 Buffer* object = PluginResource::GetAs<Buffer>(resource); | 90 Buffer* object = PluginResource::GetAs<Buffer>(resource); |
88 if (!object) { | 91 if (!object) { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 IPC_BEGIN_MESSAGE_MAP(PPB_Buffer_Proxy, msg) | 140 IPC_BEGIN_MESSAGE_MAP(PPB_Buffer_Proxy, msg) |
138 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBBuffer_Create, OnMsgCreate) | 141 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBBuffer_Create, OnMsgCreate) |
139 IPC_MESSAGE_UNHANDLED(handled = false) | 142 IPC_MESSAGE_UNHANDLED(handled = false) |
140 IPC_END_MESSAGE_MAP() | 143 IPC_END_MESSAGE_MAP() |
141 // TODO(brettw) handle bad messages! | 144 // TODO(brettw) handle bad messages! |
142 return handled; | 145 return handled; |
143 } | 146 } |
144 | 147 |
145 void PPB_Buffer_Proxy::OnMsgCreate(PP_Instance instance, | 148 void PPB_Buffer_Proxy::OnMsgCreate(PP_Instance instance, |
146 uint32_t size, | 149 uint32_t size, |
147 PP_Resource* result_resource, | 150 HostResource* result_resource, |
148 int* result_shm_handle) { | 151 int* result_shm_handle) { |
149 *result_resource = ppb_buffer_target()->Create(instance, size); | 152 result_resource->SetHostResource( |
| 153 instance, |
| 154 ppb_buffer_target()->Create(instance, size)); |
150 // TODO(brettw) set the shm handle from a trusted interface. | 155 // TODO(brettw) set the shm handle from a trusted interface. |
151 *result_shm_handle = 0; | 156 *result_shm_handle = 0; |
152 } | 157 } |
153 | 158 |
154 } // namespace proxy | 159 } // namespace proxy |
155 } // namespace pp | 160 } // namespace pp |
OLD | NEW |