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_image_data_proxy.h" | 5 #include "ppapi/proxy/ppb_image_data_proxy.h" |
6 | 6 |
7 #include <string.h> // For memcpy | 7 #include <string.h> // For memcpy |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 namespace { | 87 namespace { |
88 | 88 |
89 PP_ImageDataFormat GetNativeImageDataFormat() { | 89 PP_ImageDataFormat GetNativeImageDataFormat() { |
90 int32 format = 0; | 90 int32 format = 0; |
91 PluginDispatcher::Get()->Send( | 91 PluginDispatcher::Get()->Send( |
92 new PpapiHostMsg_PPBImageData_GetNativeImageDataFormat( | 92 new PpapiHostMsg_PPBImageData_GetNativeImageDataFormat( |
93 INTERFACE_ID_PPB_IMAGE_DATA, &format)); | 93 INTERFACE_ID_PPB_IMAGE_DATA, &format)); |
94 return static_cast<PP_ImageDataFormat>(format); | 94 return static_cast<PP_ImageDataFormat>(format); |
95 } | 95 } |
96 | 96 |
97 bool IsImageDataFormatSupported(PP_ImageDataFormat format) { | 97 PP_Bool IsImageDataFormatSupported(PP_ImageDataFormat format) { |
98 bool supported = false; | 98 PP_Bool supported = PP_FALSE; |
99 PluginDispatcher::Get()->Send( | 99 PluginDispatcher::Get()->Send( |
100 new PpapiHostMsg_PPBImageData_IsImageDataFormatSupported( | 100 new PpapiHostMsg_PPBImageData_IsImageDataFormatSupported( |
101 INTERFACE_ID_PPB_IMAGE_DATA, static_cast<int32_t>(format), | 101 INTERFACE_ID_PPB_IMAGE_DATA, static_cast<int32_t>(format), |
102 &supported)); | 102 &supported)); |
103 return supported; | 103 return supported; |
104 } | 104 } |
105 | 105 |
106 PP_Resource Create(PP_Module module_id, | 106 PP_Resource Create(PP_Module module_id, |
107 PP_ImageDataFormat format, | 107 PP_ImageDataFormat format, |
108 const PP_Size* size, | 108 const PP_Size* size, |
109 bool init_to_zero) { | 109 PP_Bool init_to_zero) { |
110 PP_Resource result = 0; | 110 PP_Resource result = 0; |
111 std::string image_data_desc; | 111 std::string image_data_desc; |
112 uint64_t shm_handle = -1; | 112 uint64_t shm_handle = -1; |
113 PluginDispatcher::Get()->Send( | 113 PluginDispatcher::Get()->Send( |
114 new PpapiHostMsg_PPBImageData_Create( | 114 new PpapiHostMsg_PPBImageData_Create( |
115 INTERFACE_ID_PPB_IMAGE_DATA, module_id, format, *size, init_to_zero, | 115 INTERFACE_ID_PPB_IMAGE_DATA, module_id, format, *size, init_to_zero, |
116 &result, &image_data_desc, &shm_handle)); | 116 &result, &image_data_desc, &shm_handle)); |
117 | 117 |
118 if (result && image_data_desc.size() == sizeof(PP_ImageDataDesc)) { | 118 if (result && image_data_desc.size() == sizeof(PP_ImageDataDesc)) { |
119 // We serialize the PP_ImageDataDesc just by copying to a string. | 119 // We serialize the PP_ImageDataDesc just by copying to a string. |
120 PP_ImageDataDesc desc; | 120 PP_ImageDataDesc desc; |
121 memcpy(&desc, image_data_desc.data(), sizeof(PP_ImageDataDesc)); | 121 memcpy(&desc, image_data_desc.data(), sizeof(PP_ImageDataDesc)); |
122 | 122 |
123 linked_ptr<ImageData> object( | 123 linked_ptr<ImageData> object( |
124 new ImageData(desc, shm_handle)); | 124 new ImageData(desc, shm_handle)); |
125 PluginDispatcher::Get()->plugin_resource_tracker()->AddResource( | 125 PluginDispatcher::Get()->plugin_resource_tracker()->AddResource( |
126 result, object); | 126 result, object); |
127 } | 127 } |
128 return result; | 128 return result; |
129 } | 129 } |
130 | 130 |
131 bool IsImageData(PP_Resource resource) { | 131 PP_Bool IsImageData(PP_Resource resource) { |
132 ImageData* object = PluginResource::GetAs<ImageData>(resource); | 132 ImageData* object = PluginResource::GetAs<ImageData>(resource); |
133 return !!object; | 133 return BoolToPPBool(!!object); |
134 } | 134 } |
135 | 135 |
136 bool Describe(PP_Resource resource, PP_ImageDataDesc* desc) { | 136 PP_Bool Describe(PP_Resource resource, PP_ImageDataDesc* desc) { |
137 ImageData* object = PluginResource::GetAs<ImageData>(resource); | 137 ImageData* object = PluginResource::GetAs<ImageData>(resource); |
138 if (!object) | 138 if (!object) |
139 return false; | 139 return PP_FALSE; |
140 memcpy(desc, &object->desc(), sizeof(PP_ImageDataDesc)); | 140 memcpy(desc, &object->desc(), sizeof(PP_ImageDataDesc)); |
141 return true; | 141 return PP_TRUE; |
142 } | 142 } |
143 | 143 |
144 void* Map(PP_Resource resource) { | 144 void* Map(PP_Resource resource) { |
145 ImageData* object = PluginResource::GetAs<ImageData>(resource); | 145 ImageData* object = PluginResource::GetAs<ImageData>(resource); |
146 if (!object) | 146 if (!object) |
147 return NULL; | 147 return NULL; |
148 return object->Map(); | 148 return object->Map(); |
149 } | 149 } |
150 | 150 |
151 void Unmap(PP_Resource resource) { | 151 void Unmap(PP_Resource resource) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_Create, OnMsgCreate) | 191 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBImageData_Create, OnMsgCreate) |
192 IPC_END_MESSAGE_MAP() | 192 IPC_END_MESSAGE_MAP() |
193 // FIXME(brettw) handle bad messages! | 193 // FIXME(brettw) handle bad messages! |
194 } | 194 } |
195 | 195 |
196 void PPB_ImageData_Proxy::OnMsgGetNativeImageDataFormat(int32* result) { | 196 void PPB_ImageData_Proxy::OnMsgGetNativeImageDataFormat(int32* result) { |
197 *result = ppb_image_data_target()->GetNativeImageDataFormat(); | 197 *result = ppb_image_data_target()->GetNativeImageDataFormat(); |
198 } | 198 } |
199 | 199 |
200 void PPB_ImageData_Proxy::OnMsgIsImageDataFormatSupported(int32 format, | 200 void PPB_ImageData_Proxy::OnMsgIsImageDataFormatSupported(int32 format, |
201 bool* result) { | 201 PP_Bool* result) { |
202 *result = ppb_image_data_target()->IsImageDataFormatSupported( | 202 *result = ppb_image_data_target()->IsImageDataFormatSupported( |
203 static_cast<PP_ImageDataFormat>(format)); | 203 static_cast<PP_ImageDataFormat>(format)); |
204 } | 204 } |
205 | 205 |
206 void PPB_ImageData_Proxy::OnMsgCreate(PP_Module module, | 206 void PPB_ImageData_Proxy::OnMsgCreate(PP_Module module, |
207 int32_t format, | 207 int32_t format, |
208 const PP_Size& size, | 208 const PP_Size& size, |
209 bool init_to_zero, | 209 PP_Bool init_to_zero, |
210 PP_Resource* result, | 210 PP_Resource* result, |
211 std::string* image_data_desc, | 211 std::string* image_data_desc, |
212 uint64_t* result_shm_handle) { | 212 uint64_t* result_shm_handle) { |
213 *result = ppb_image_data_target()->Create( | 213 *result = ppb_image_data_target()->Create( |
214 module, static_cast<PP_ImageDataFormat>(format), &size, init_to_zero); | 214 module, static_cast<PP_ImageDataFormat>(format), &size, init_to_zero); |
215 *result_shm_handle = 0; | 215 *result_shm_handle = 0; |
216 if (*result) { | 216 if (*result) { |
217 // The ImageDesc is just serialized as a string. | 217 // The ImageDesc is just serialized as a string. |
218 PP_ImageDataDesc desc; | 218 PP_ImageDataDesc desc; |
219 if (ppb_image_data_target()->Describe(*result, &desc)) { | 219 if (ppb_image_data_target()->Describe(*result, &desc)) { |
220 image_data_desc->resize(sizeof(PP_ImageDataDesc)); | 220 image_data_desc->resize(sizeof(PP_ImageDataDesc)); |
221 memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc)); | 221 memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc)); |
222 } | 222 } |
223 | 223 |
224 // Get the shared memory handle. | 224 // Get the shared memory handle. |
225 const PPB_ImageDataTrusted* trusted = | 225 const PPB_ImageDataTrusted* trusted = |
226 reinterpret_cast<const PPB_ImageDataTrusted*>( | 226 reinterpret_cast<const PPB_ImageDataTrusted*>( |
227 dispatcher()->GetLocalInterface(PPB_IMAGEDATA_TRUSTED_INTERFACE)); | 227 dispatcher()->GetLocalInterface(PPB_IMAGEDATA_TRUSTED_INTERFACE)); |
228 if (trusted) | 228 if (trusted) |
229 *result_shm_handle = trusted->GetNativeMemoryHandle(*result); | 229 *result_shm_handle = trusted->GetNativeMemoryHandle(*result); |
230 } | 230 } |
231 } | 231 } |
232 | 232 |
233 } // namespace proxy | 233 } // namespace proxy |
234 } // namespace pp | 234 } // namespace pp |
OLD | NEW |