OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/cpp/dev/resource_array_dev.h" | 5 #include "ppapi/cpp/dev/resource_array_dev.h" |
6 | 6 |
7 #include "ppapi/c/dev/ppb_resource_array_dev.h" | 7 #include "ppapi/c/dev/ppb_resource_array_dev.h" |
| 8 #include "ppapi/c/pp_errors.h" |
8 #include "ppapi/cpp/instance_handle.h" | 9 #include "ppapi/cpp/instance_handle.h" |
| 10 #include "ppapi/cpp/logging.h" |
| 11 #include "ppapi/cpp/module.h" |
9 #include "ppapi/cpp/module_impl.h" | 12 #include "ppapi/cpp/module_impl.h" |
10 | 13 |
11 namespace pp { | 14 namespace pp { |
12 | 15 |
13 namespace { | 16 namespace { |
14 | 17 |
15 template <> const char* interface_name<PPB_ResourceArray_Dev>() { | 18 template <> const char* interface_name<PPB_ResourceArray_Dev>() { |
16 return PPB_RESOURCEARRAY_DEV_INTERFACE; | 19 return PPB_RESOURCEARRAY_DEV_INTERFACE; |
17 } | 20 } |
18 | 21 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 return 0; | 55 return 0; |
53 return get_interface<PPB_ResourceArray_Dev>()->GetSize(pp_resource()); | 56 return get_interface<PPB_ResourceArray_Dev>()->GetSize(pp_resource()); |
54 } | 57 } |
55 | 58 |
56 PP_Resource ResourceArray_Dev::operator[](uint32_t index) const { | 59 PP_Resource ResourceArray_Dev::operator[](uint32_t index) const { |
57 if (!has_interface<PPB_ResourceArray_Dev>()) | 60 if (!has_interface<PPB_ResourceArray_Dev>()) |
58 return 0; | 61 return 0; |
59 return get_interface<PPB_ResourceArray_Dev>()->GetAt(pp_resource(), index); | 62 return get_interface<PPB_ResourceArray_Dev>()->GetAt(pp_resource(), index); |
60 } | 63 } |
61 | 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 |
62 } // namespace pp | 92 } // namespace pp |
OLD | NEW |