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.
7 * PP_ArrayOutput_GetDataBuffer is a callback function to allocate plugin
8 * memory for an array. It returns the allocated memory or null on failure.
10 * This function will be called reentrantly. This means that if you call a
11 * function PPB_Foo.GetData(&array_output), GetData will call your
12 * GetDataBuffer function before it returns.
14 * This function will be called even when returning 0-length arrays, so be sure
15 * your implementation can support that. You can return NULL for 0 length
16 * arrays and it will not be treated as a failure.
18 * You should not perform any processing in this callback, including calling
19 * other PPAPI functions, outside of allocating memory. You should not throw
20 * any exceptions. In C++, this means using "new (nothrow)" or being sure to
21 * catch any exceptions before returning.
23 * The C++ wrapper provides a convenient templatized implementation around
24 * std::vector which you should generally use instead of coding this
27 * @param user_data The pointer provided in the PP_ArrayOutput structure. This
28 * has no meaning to the browser, it is intended to be used by the
29 * implementation to figure out where to put the data.
31 * @param element_count The number of elements in the array. This will be 0
32 * if there is no data to return.
34 * @param element_size The size of each element in bytes.
36 * @return Returns a pointer to the allocated memory. On failure, returns null.
37 * You can also return null if the element_count is 0.
39 typedef mem_t PP_ArrayOutput_GetDataBuffer
([inout
] mem_t user_data
,
40 [in] uint32_t element_count
,
41 [in] uint32_t element_size
);
44 * A structure that defines a way for the browser to return arrays of data
45 * to the plugin. The browser can not allocate memory on behalf of the plugin
46 * becaues the plugin and browser may have different allocators.
48 * Array output works by having the browser call to the plugin to allocate a
49 * buffer, and then the browser will copy the contents of the array into that
52 * In C, you would typically implement this as follows:
55 * struct MyArrayOutput {
59 * void* MyGetDataBuffer(void* user_data, uint32_t count, uint32_t size) {
60 * MyArrayOutput* output = (MyArrayOutput*)user_data;
61 * output->element_count = count;
63 * output->data = malloc(count * size);
64 * if (!output->data) // Be careful to set size properly on malloc failure.
65 * output->element_count = 0;
67 * output->data = NULL;
69 * return output->data;
72 * MyArrayOutput array = { NULL, 0 };
73 * PP_ArrayOutput output = { &MyGetDataBuffer, &array };
74 * ppb_foo->GetData(&output);
79 struct PP_ArrayOutput
{
81 * A pointer to the allocation function that the browser implements.
83 PP_ArrayOutput_GetDataBuffer GetDataBuffer
;
86 * Data that is passed to the allocation function. Typically, this is used
87 * to communicate how the data should be stored.