| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ppapi/cpp/dev/resource_array_dev.h" | |
| 6 | |
| 7 #include "ppapi/c/dev/ppb_resource_array_dev.h" | |
| 8 #include "ppapi/c/pp_errors.h" | |
| 9 #include "ppapi/cpp/instance_handle.h" | |
| 10 #include "ppapi/cpp/logging.h" | |
| 11 #include "ppapi/cpp/module.h" | |
| 12 #include "ppapi/cpp/module_impl.h" | |
| 13 | |
| 14 namespace pp { | |
| 15 | |
| 16 namespace { | |
| 17 | |
| 18 template <> const char* interface_name<PPB_ResourceArray_Dev>() { | |
| 19 return PPB_RESOURCEARRAY_DEV_INTERFACE; | |
| 20 } | |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 ResourceArray_Dev::ResourceArray_Dev() { | |
| 25 } | |
| 26 | |
| 27 ResourceArray_Dev::ResourceArray_Dev(PassRef, PP_Resource resource) | |
| 28 : Resource(PASS_REF, resource) { | |
| 29 } | |
| 30 | |
| 31 ResourceArray_Dev::ResourceArray_Dev(const ResourceArray_Dev& other) | |
| 32 : Resource(other) { | |
| 33 } | |
| 34 | |
| 35 ResourceArray_Dev::ResourceArray_Dev(const InstanceHandle& instance, | |
| 36 const PP_Resource elements[], | |
| 37 uint32_t size) { | |
| 38 if (has_interface<PPB_ResourceArray_Dev>()) { | |
| 39 PassRefFromConstructor(get_interface<PPB_ResourceArray_Dev>()->Create( | |
| 40 instance.pp_instance(), elements, size)); | |
| 41 } | |
| 42 } | |
| 43 | |
| 44 ResourceArray_Dev::~ResourceArray_Dev() { | |
| 45 } | |
| 46 | |
| 47 ResourceArray_Dev& ResourceArray_Dev::operator=( | |
| 48 const ResourceArray_Dev& other) { | |
| 49 Resource::operator=(other); | |
| 50 return *this; | |
| 51 } | |
| 52 | |
| 53 uint32_t ResourceArray_Dev::size() const { | |
| 54 if (!has_interface<PPB_ResourceArray_Dev>()) | |
| 55 return 0; | |
| 56 return get_interface<PPB_ResourceArray_Dev>()->GetSize(pp_resource()); | |
| 57 } | |
| 58 | |
| 59 PP_Resource ResourceArray_Dev::operator[](uint32_t index) const { | |
| 60 if (!has_interface<PPB_ResourceArray_Dev>()) | |
| 61 return 0; | |
| 62 return get_interface<PPB_ResourceArray_Dev>()->GetAt(pp_resource(), index); | |
| 63 } | |
| 64 | |
| 65 // static | |
| 66 void ResourceArray_Dev::ArrayOutputCallbackConverter(void* user_data, | |
| 67 int32_t result) { | |
| 68 ArrayOutputCallbackData* data = | |
| 69 static_cast<ArrayOutputCallbackData*>(user_data); | |
| 70 | |
| 71 // data->resource_array_output should remain 0 if the call failed. | |
| 72 ResourceArray_Dev resources(PASS_REF, data->resource_array_output); | |
| 73 PP_DCHECK(resources.is_null() || result == PP_OK); | |
| 74 | |
| 75 // Need to issue the "GetDataBuffer" even for error cases and when the number | |
| 76 // of items is 0. | |
| 77 PP_Resource* output_buf = static_cast<PP_Resource*>( | |
| 78 data->output.GetDataBuffer( | |
| 79 data->output.user_data, resources.is_null() ? 0 : resources.size(), | |
| 80 sizeof(PP_Resource))); | |
| 81 if (output_buf) { | |
| 82 for (uint32_t index = 0; index < resources.size(); ++index) { | |
| 83 output_buf[index] = resources[index]; | |
| 84 Module::Get()->core()->AddRefResource(output_buf[index]); | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 PP_RunCompletionCallback(&data->original_callback, result); | |
| 89 delete data; | |
| 90 } | |
| 91 | |
| 92 } // namespace pp | |
| OLD | NEW |