[email protected] | 25651387 | 2012-01-05 15:41:52 | [diff] [blame] | 1 | /* Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | ddd61db | 2011-12-07 06:49:00 | [diff] [blame] | 2 | * Use of this source code is governed by a BSD-style license that can be |
| 3 | * found in the LICENSE file. |
| 4 | */ |
| 5 | |
| 6 | /** |
[email protected] | 9c6e0de | 2012-01-27 04:55:55 | [diff] [blame] | 7 | * This file defines the <code>PPB_VarArrayBuffer</code> struct. |
[email protected] | ddd61db | 2011-12-07 06:49:00 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | label Chrome { |
[email protected] | 9c6e0de | 2012-01-27 04:55:55 | [diff] [blame] | 11 | M18 = 1.0 |
[email protected] | ddd61db | 2011-12-07 06:49:00 | [diff] [blame] | 12 | }; |
| 13 | |
| 14 | /** |
[email protected] | 9c6e0de | 2012-01-27 04:55:55 | [diff] [blame] | 15 | * PPB_VarArrayBuffer API. This provides a way to interact with JavaScript |
[email protected] | ddd61db | 2011-12-07 06:49:00 | [diff] [blame] | 16 | * ArrayBuffers, which represent a contiguous sequence of bytes. To manage the |
| 17 | * reference count for a VarArrayBuffer, please see PPB_Var. Note that |
| 18 | * these Vars are not part of the embedding page's DOM, and can only be shared |
| 19 | * with JavaScript via pp::Instance's PostMessage and HandleMessage functions. |
| 20 | */ |
[email protected] | 9c6e0de | 2012-01-27 04:55:55 | [diff] [blame] | 21 | [macro="PPB_VAR_ARRAY_BUFFER_INTERFACE"] |
| 22 | interface PPB_VarArrayBuffer { |
[email protected] | ddd61db | 2011-12-07 06:49:00 | [diff] [blame] | 23 | /** |
| 24 | * Create a zero-initialized VarArrayBuffer. |
| 25 | * |
[email protected] | 47ef614 | 2012-01-26 21:04:10 | [diff] [blame] | 26 | * @param[in] size_in_bytes The size of the ArrayBuffer that will be created. |
[email protected] | ddd61db | 2011-12-07 06:49:00 | [diff] [blame] | 27 | * |
[email protected] | 47ef614 | 2012-01-26 21:04:10 | [diff] [blame] | 28 | * @return A PP_Var which represents a VarArrayBuffer of the requested size |
[email protected] | ddd61db | 2011-12-07 06:49:00 | [diff] [blame] | 29 | * with a reference count of 1. |
| 30 | */ |
| 31 | PP_Var Create([in] uint32_t size_in_bytes); |
[email protected] | 47ef614 | 2012-01-26 21:04:10 | [diff] [blame] | 32 | |
[email protected] | ddd61db | 2011-12-07 06:49:00 | [diff] [blame] | 33 | /** |
[email protected] | 47ef614 | 2012-01-26 21:04:10 | [diff] [blame] | 34 | * Retrieves the length of the VarArrayBuffer in bytes. On success, |
| 35 | * byte_length is set to the length of the given ArrayBuffer var. On failure, |
| 36 | * byte_length is unchanged (this could happen, for instance, if the given |
| 37 | * PP_Var is not of type PP_VARTYPE_ARRAY_BUFFER). Note that ByteLength() will |
| 38 | * successfully retrieve the the size of an ArrayBuffer even if the |
| 39 | * ArrayBuffer is not currently mapped. |
[email protected] | ddd61db | 2011-12-07 06:49:00 | [diff] [blame] | 40 | * |
[email protected] | 47ef614 | 2012-01-26 21:04:10 | [diff] [blame] | 41 | * @param[in] array The ArrayBuffer whose length should be returned. |
| 42 | * |
| 43 | * @param[out] byte_length A variable which is set to the length of the given |
| 44 | * ArrayBuffer on success. |
| 45 | * |
| 46 | * @return PP_TRUE on success, PP_FALSE on failure. |
[email protected] | ddd61db | 2011-12-07 06:49:00 | [diff] [blame] | 47 | */ |
[email protected] | 47ef614 | 2012-01-26 21:04:10 | [diff] [blame] | 48 | PP_Bool ByteLength([in] PP_Var array, [out] uint32_t byte_length); |
| 49 | |
[email protected] | ddd61db | 2011-12-07 06:49:00 | [diff] [blame] | 50 | /** |
[email protected] | 47ef614 | 2012-01-26 21:04:10 | [diff] [blame] | 51 | * Maps the ArrayBuffer in to the module's address space and returns a pointer |
| 52 | * to the beginning of the buffer for the given ArrayBuffer PP_Var. Note that |
| 53 | * calling Map() can be a relatively expensive operation. Use care when |
| 54 | * calling it in performance-critical code. For example, you should call it |
| 55 | * only once when looping over an ArrayBuffer: |
[email protected] | ddd61db | 2011-12-07 06:49:00 | [diff] [blame] | 56 | * |
[email protected] | 47ef614 | 2012-01-26 21:04:10 | [diff] [blame] | 57 | * <code> |
| 58 | * char* data = (char*)(array_buffer_if.Map(array_buffer_var)); |
| 59 | * uint32_t byte_length = 0; |
| 60 | * PP_Bool ok = array_buffer_if.ByteLength(array_buffer_var, &byte_length); |
| 61 | * if (!ok) |
| 62 | * return DoSomethingBecauseMyVarIsNotAnArrayBuffer(); |
| 63 | * for (uint32_t i = 0; i < byte_length; ++i) |
| 64 | * data[i] = 'A'; |
| 65 | * </code> |
[email protected] | ddd61db | 2011-12-07 06:49:00 | [diff] [blame] | 66 | * |
[email protected] | 47ef614 | 2012-01-26 21:04:10 | [diff] [blame] | 67 | * @param[in] array The ArrayBuffer whose internal buffer should be returned. |
| 68 | * |
| 69 | * @return A pointer to the internal buffer for this ArrayBuffer. Returns NULL |
| 70 | * if the given PP_Var is not of type PP_VARTYPE_ARRAY_BUFFER. |
[email protected] | ddd61db | 2011-12-07 06:49:00 | [diff] [blame] | 71 | */ |
| 72 | mem_t Map([in] PP_Var array); |
[email protected] | 47ef614 | 2012-01-26 21:04:10 | [diff] [blame] | 73 | |
| 74 | /** |
| 75 | * Unmaps the given ArrayBuffer var from the module address space. Use this if |
| 76 | * you want to save memory but might want to Map the buffer again later. The |
| 77 | * PP_Var remains valid and should still be released using PPB_Var when you |
| 78 | * are done with the ArrayBuffer. |
| 79 | * |
| 80 | * @param[in] array The ArrayBuffer which should be released. |
| 81 | */ |
| 82 | void Unmap([in] PP_Var array); |
[email protected] | ddd61db | 2011-12-07 06:49:00 | [diff] [blame] | 83 | }; |
| 84 | |