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 #ifndef PPAPI_CPP_DEV_RESOURCE_ARRAY_DEV_H_ | 5 #ifndef PPAPI_CPP_DEV_RESOURCE_ARRAY_DEV_H_ |
6 #define PPAPI_CPP_DEV_RESOURCE_ARRAY_DEV_H_ | 6 #define PPAPI_CPP_DEV_RESOURCE_ARRAY_DEV_H_ |
7 | 7 |
| 8 #include "ppapi/c/pp_array_output.h" |
| 9 #include "ppapi/c/pp_completion_callback.h" |
8 #include "ppapi/c/pp_stdint.h" | 10 #include "ppapi/c/pp_stdint.h" |
9 #include "ppapi/cpp/resource.h" | 11 #include "ppapi/cpp/resource.h" |
10 | 12 |
11 namespace pp { | 13 namespace pp { |
12 | 14 |
13 class InstanceHandle; | 15 class InstanceHandle; |
14 | 16 |
15 class ResourceArray_Dev : public Resource { | 17 class ResourceArray_Dev : public Resource { |
16 public: | 18 public: |
| 19 // Heap-allocated data passed to ArrayOutputCallbackConverter(). Please see |
| 20 // the comment of ArrayOutputCallbackConverter() for more details. |
| 21 struct ArrayOutputCallbackData { |
| 22 ArrayOutputCallbackData(const PP_ArrayOutput& array_output, |
| 23 const PP_CompletionCallback& callback) |
| 24 : resource_array_output(0), |
| 25 output(array_output), |
| 26 original_callback(callback) { |
| 27 } |
| 28 |
| 29 PP_Resource resource_array_output; |
| 30 PP_ArrayOutput output; |
| 31 PP_CompletionCallback original_callback; |
| 32 }; |
| 33 |
17 ResourceArray_Dev(); | 34 ResourceArray_Dev(); |
18 | 35 |
19 ResourceArray_Dev(PassRef, PP_Resource resource); | 36 ResourceArray_Dev(PassRef, PP_Resource resource); |
20 | 37 |
21 ResourceArray_Dev(const ResourceArray_Dev& other); | 38 ResourceArray_Dev(const ResourceArray_Dev& other); |
22 | 39 |
23 ResourceArray_Dev(const InstanceHandle& instance, | 40 ResourceArray_Dev(const InstanceHandle& instance, |
24 const PP_Resource elements[], | 41 const PP_Resource elements[], |
25 uint32_t size); | 42 uint32_t size); |
26 | 43 |
27 virtual ~ResourceArray_Dev(); | 44 virtual ~ResourceArray_Dev(); |
28 | 45 |
29 ResourceArray_Dev& operator=(const ResourceArray_Dev& other); | 46 ResourceArray_Dev& operator=(const ResourceArray_Dev& other); |
30 | 47 |
31 uint32_t size() const; | 48 uint32_t size() const; |
32 | 49 |
33 PP_Resource operator[](uint32_t index) const; | 50 PP_Resource operator[](uint32_t index) const; |
| 51 |
| 52 // This is an adapter for backward compatibility. It works with those APIs |
| 53 // which take a PPB_ResourceArray_Dev resource as output parameter, and |
| 54 // returns results using PP_ArrayOutput. For example: |
| 55 // |
| 56 // ResourceArray_Dev::ArrayOutputCallbackData* data = |
| 57 // new ResourceArray_Dev::ArrayOutputCallbackData( |
| 58 // pp_array_output, callback); |
| 59 // ppb_foo->Bar( |
| 60 // foo_resource, &data->resource_array_output, |
| 61 // PP_MakeCompletionCallback( |
| 62 // &ResourceArray_Dev::ArrayOutputCallbackConverter, data)); |
| 63 // |
| 64 // It takes a heap-allocated ArrayOutputCallbackData struct passed as the user |
| 65 // data, and deletes it when the call completes. |
| 66 static void ArrayOutputCallbackConverter(void* user_data, int32_t result); |
34 }; | 67 }; |
35 | 68 |
36 } // namespace pp | 69 } // namespace pp |
37 | 70 |
38 #endif // PPAPI_CPP_DEV_RESOURCE_ARRAY_DEV_H_ | 71 #endif // PPAPI_CPP_DEV_RESOURCE_ARRAY_DEV_H_ |
OLD | NEW |