Fix cross-window focus in Chrome Frame.
[chromium-blink-merge.git] / ppapi / c / pp_array_output.h
blobadd873cf8d1b9f32052a271c3276edadd2ba7337
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 */
6 /* From pp_array_output.idl modified Thu Mar 28 11:07:53 2013. */
8 #ifndef PPAPI_C_PP_ARRAY_OUTPUT_H_
9 #define PPAPI_C_PP_ARRAY_OUTPUT_H_
11 #include "ppapi/c/pp_macros.h"
12 #include "ppapi/c/pp_stdint.h"
14 /**
15 * @file
16 * PP_ArrayOutput_GetDataBuffer is a callback function to allocate plugin
17 * memory for an array. It returns the allocated memory or null on failure.
19 * This function will be called reentrantly. This means that if you call a
20 * function PPB_Foo.GetData(&array_output), GetData will call your
21 * GetDataBuffer function before it returns.
23 * This function will be called even when returning 0-length arrays, so be sure
24 * your implementation can support that. You can return NULL for 0 length
25 * arrays and it will not be treated as a failure.
27 * You should not perform any processing in this callback, including calling
28 * other PPAPI functions, outside of allocating memory. You should not throw
29 * any exceptions. In C++, this means using "new (nothrow)" or being sure to
30 * catch any exceptions before returning.
32 * The C++ wrapper provides a convenient templatized implementation around
33 * std::vector which you should generally use instead of coding this
34 * specifically.
36 * @param user_data The pointer provided in the PP_ArrayOutput structure. This
37 * has no meaning to the browser, it is intended to be used by the
38 * implementation to figure out where to put the data.
40 * @param element_count The number of elements in the array. This will be 0
41 * if there is no data to return.
43 * @param element_size The size of each element in bytes.
45 * @return Returns a pointer to the allocated memory. On failure, returns null.
46 * You can also return null if the element_count is 0.
50 /**
51 * @addtogroup Typedefs
52 * @{
54 typedef void* (*PP_ArrayOutput_GetDataBuffer)(void* user_data,
55 uint32_t element_count,
56 uint32_t element_size);
57 /**
58 * @}
61 /**
62 * @addtogroup Structs
63 * @{
65 /**
66 * A structure that defines a way for the browser to return arrays of data
67 * to the plugin. The browser can not allocate memory on behalf of the plugin
68 * because the plugin and browser may have different allocators.
70 * Array output works by having the browser call to the plugin to allocate a
71 * buffer, and then the browser will copy the contents of the array into that
72 * buffer.
74 * In C, you would typically implement this as follows:
76 * @code
77 * struct MyArrayOutput {
78 * void* data;
79 * int element_count;
80 * };
81 * void* MyGetDataBuffer(void* user_data, uint32_t count, uint32_t size) {
82 * MyArrayOutput* output = (MyArrayOutput*)user_data;
83 * output->element_count = count;
84 * if (size) {
85 * output->data = malloc(count * size);
86 * if (!output->data) // Be careful to set size properly on malloc failure.
87 * output->element_count = 0;
88 * } else {
89 * output->data = NULL;
90 * }
91 * return output->data;
92 * }
93 * void MyFunction() {
94 * MyArrayOutput array = { NULL, 0 };
95 * PP_ArrayOutput output = { &MyGetDataBuffer, &array };
96 * ppb_foo->GetData(&output);
97 * }
98 * @endcode
100 struct PP_ArrayOutput {
102 * A pointer to the allocation function that the browser implements.
104 PP_ArrayOutput_GetDataBuffer GetDataBuffer;
106 * Data that is passed to the allocation function. Typically, this is used
107 * to communicate how the data should be stored.
109 void* user_data;
112 * @}
115 #endif /* PPAPI_C_PP_ARRAY_OUTPUT_H_ */