| 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_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 22 matching lines...) Expand all Loading... |
| 33 } | 33 } |
| 34 | 34 |
| 35 PP_Resource Create(PP_Instance instance, | 35 PP_Resource Create(PP_Instance instance, |
| 36 PP_ImageDataFormat format, | 36 PP_ImageDataFormat format, |
| 37 const PP_Size* size, | 37 const PP_Size* size, |
| 38 PP_Bool init_to_zero) { | 38 PP_Bool init_to_zero) { |
| 39 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 39 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 40 if (!dispatcher) | 40 if (!dispatcher) |
| 41 return PP_ERROR_BADARGUMENT; | 41 return PP_ERROR_BADARGUMENT; |
| 42 | 42 |
| 43 PP_Resource result = 0; | 43 SerializedResource result; |
| 44 std::string image_data_desc; | 44 std::string image_data_desc; |
| 45 ImageHandle image_handle = ImageData::NullHandle; | 45 ImageHandle image_handle = ImageData::NullHandle; |
| 46 dispatcher->Send(new PpapiHostMsg_PPBImageData_Create( | 46 dispatcher->Send(new PpapiHostMsg_PPBImageData_Create( |
| 47 INTERFACE_ID_PPB_IMAGE_DATA, instance, format, *size, init_to_zero, | 47 INTERFACE_ID_PPB_IMAGE_DATA, instance, format, *size, init_to_zero, |
| 48 &result, &image_data_desc, &image_handle)); | 48 &result, &image_data_desc, &image_handle)); |
| 49 | 49 |
| 50 if (result && image_data_desc.size() == sizeof(PP_ImageDataDesc)) { | 50 if (result.is_null() || image_data_desc.size() != sizeof(PP_ImageDataDesc)) |
| 51 // We serialize the PP_ImageDataDesc just by copying to a string. | 51 return 0; |
| 52 PP_ImageDataDesc desc; | |
| 53 memcpy(&desc, image_data_desc.data(), sizeof(PP_ImageDataDesc)); | |
| 54 | 52 |
| 55 linked_ptr<ImageData> object(new ImageData(instance, desc, image_handle)); | 53 // We serialize the PP_ImageDataDesc just by copying to a string. |
| 56 PluginResourceTracker::GetInstance()->AddResource(result, object); | 54 PP_ImageDataDesc desc; |
| 57 } | 55 memcpy(&desc, image_data_desc.data(), sizeof(PP_ImageDataDesc)); |
| 58 return result; | 56 |
| 57 linked_ptr<ImageData> object(new ImageData(instance, result, desc, |
| 58 image_handle)); |
| 59 return PluginResourceTracker::GetInstance()->AddResource(object); |
| 59 } | 60 } |
| 60 | 61 |
| 61 PP_Bool IsImageData(PP_Resource resource) { | 62 PP_Bool IsImageData(PP_Resource resource) { |
| 62 ImageData* object = PluginResource::GetAs<ImageData>(resource); | 63 ImageData* object = PluginResource::GetAs<ImageData>(resource); |
| 63 return BoolToPPBool(!!object); | 64 return BoolToPPBool(!!object); |
| 64 } | 65 } |
| 65 | 66 |
| 66 PP_Bool Describe(PP_Resource resource, PP_ImageDataDesc* desc) { | 67 PP_Bool Describe(PP_Resource resource, PP_ImageDataDesc* desc) { |
| 67 ImageData* object = PluginResource::GetAs<ImageData>(resource); | 68 ImageData* object = PluginResource::GetAs<ImageData>(resource); |
| 68 if (!object) | 69 if (!object) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 IPC_MESSAGE_UNHANDLED(handled = false) | 120 IPC_MESSAGE_UNHANDLED(handled = false) |
| 120 IPC_END_MESSAGE_MAP() | 121 IPC_END_MESSAGE_MAP() |
| 121 // FIXME(brettw) handle bad messages! | 122 // FIXME(brettw) handle bad messages! |
| 122 return handled; | 123 return handled; |
| 123 } | 124 } |
| 124 | 125 |
| 125 void PPB_ImageData_Proxy::OnMsgCreate(PP_Instance instance, | 126 void PPB_ImageData_Proxy::OnMsgCreate(PP_Instance instance, |
| 126 int32_t format, | 127 int32_t format, |
| 127 const PP_Size& size, | 128 const PP_Size& size, |
| 128 PP_Bool init_to_zero, | 129 PP_Bool init_to_zero, |
| 129 PP_Resource* result, | 130 SerializedResource* result, |
| 130 std::string* image_data_desc, | 131 std::string* image_data_desc, |
| 131 ImageHandle* result_image_handle) { | 132 ImageHandle* result_image_handle) { |
| 132 *result = ppb_image_data_target()->Create( | 133 PP_Resource resource = ppb_image_data_target()->Create( |
| 133 instance, static_cast<PP_ImageDataFormat>(format), &size, init_to_zero); | 134 instance, static_cast<PP_ImageDataFormat>(format), &size, init_to_zero); |
| 134 *result_image_handle = ImageData::NullHandle; | 135 *result_image_handle = ImageData::NullHandle; |
| 135 if (*result) { | 136 if (resource) { |
| 136 // The ImageDesc is just serialized as a string. | 137 // The ImageDesc is just serialized as a string. |
| 137 PP_ImageDataDesc desc; | 138 PP_ImageDataDesc desc; |
| 138 if (ppb_image_data_target()->Describe(*result, &desc)) { | 139 if (ppb_image_data_target()->Describe(resource, &desc)) { |
| 139 image_data_desc->resize(sizeof(PP_ImageDataDesc)); | 140 image_data_desc->resize(sizeof(PP_ImageDataDesc)); |
| 140 memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc)); | 141 memcpy(&(*image_data_desc)[0], &desc, sizeof(PP_ImageDataDesc)); |
| 141 } | 142 } |
| 142 | 143 |
| 143 // Get the shared memory handle. | 144 // Get the shared memory handle. |
| 144 const PPB_ImageDataTrusted* trusted = | 145 const PPB_ImageDataTrusted* trusted = |
| 145 reinterpret_cast<const PPB_ImageDataTrusted*>( | 146 reinterpret_cast<const PPB_ImageDataTrusted*>( |
| 146 dispatcher()->GetLocalInterface(PPB_IMAGEDATA_TRUSTED_INTERFACE)); | 147 dispatcher()->GetLocalInterface(PPB_IMAGEDATA_TRUSTED_INTERFACE)); |
| 147 uint32_t byte_count = 0; | 148 uint32_t byte_count = 0; |
| 148 if (trusted) { | 149 if (trusted) { |
| 149 int32_t handle; | 150 int32_t handle; |
| 150 if (trusted->GetSharedMemory(*result, &handle, &byte_count) == PP_OK) | 151 if (trusted->GetSharedMemory(resource, &handle, &byte_count) == PP_OK) |
| 151 *result_image_handle = ImageData::HandleFromInt(handle); | 152 *result_image_handle = ImageData::HandleFromInt(handle); |
| 152 } | 153 } |
| 154 |
| 155 result->set_host_resource(resource); |
| 153 } | 156 } |
| 154 } | 157 } |
| 155 | 158 |
| 156 } // namespace proxy | 159 } // namespace proxy |
| 157 } // namespace pp | 160 } // namespace pp |
| OLD | NEW |