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.
5 #include "ppapi/cpp/dev/resource_array_dev.h"
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"
18 template <> const char* interface_name
<PPB_ResourceArray_Dev
>() {
19 return PPB_RESOURCEARRAY_DEV_INTERFACE
;
24 ResourceArray_Dev::ResourceArray_Dev() {
27 ResourceArray_Dev::ResourceArray_Dev(PassRef
, PP_Resource resource
)
28 : Resource(PASS_REF
, resource
) {
31 ResourceArray_Dev::ResourceArray_Dev(const ResourceArray_Dev
& other
)
35 ResourceArray_Dev::ResourceArray_Dev(const InstanceHandle
& instance
,
36 const PP_Resource elements
[],
38 if (has_interface
<PPB_ResourceArray_Dev
>()) {
39 PassRefFromConstructor(get_interface
<PPB_ResourceArray_Dev
>()->Create(
40 instance
.pp_instance(), elements
, size
));
44 ResourceArray_Dev::~ResourceArray_Dev() {
47 ResourceArray_Dev
& ResourceArray_Dev::operator=(
48 const ResourceArray_Dev
& other
) {
49 Resource::operator=(other
);
53 uint32_t ResourceArray_Dev::size() const {
54 if (!has_interface
<PPB_ResourceArray_Dev
>())
56 return get_interface
<PPB_ResourceArray_Dev
>()->GetSize(pp_resource());
59 PP_Resource
ResourceArray_Dev::operator[](uint32_t index
) const {
60 if (!has_interface
<PPB_ResourceArray_Dev
>())
62 return get_interface
<PPB_ResourceArray_Dev
>()->GetAt(pp_resource(), index
);
66 void ResourceArray_Dev::ArrayOutputCallbackConverter(void* user_data
,
68 ArrayOutputCallbackData
* data
=
69 static_cast<ArrayOutputCallbackData
*>(user_data
);
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
);
75 // Need to issue the "GetDataBuffer" even for error cases and when the number
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
)));
82 for (uint32_t index
= 0; index
< resources
.size(); ++index
) {
83 output_buf
[index
] = resources
[index
];
84 Module::Get()->core()->AddRefResource(output_buf
[index
]);
88 PP_RunCompletionCallback(&data
->original_callback
, result
);