blob: f48c19fee39521db9d38fc571fd71fdbee3aace0 [file] [log] [blame]
[email protected]256513872012-01-05 15:41:521/* Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]ddd61db2011-12-07 06:49:002 * 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]98d3e532012-02-17 17:24:567 * This file defines the <code>PPB_VarArrayBuffer</code> struct providing
8 * a way to interact with JavaScript ArrayBuffers.
[email protected]ddd61db2011-12-07 06:49:009 */
10
11label Chrome {
[email protected]9c6e0de2012-01-27 04:55:5512 M18 = 1.0
[email protected]ddd61db2011-12-07 06:49:0013};
14
15/**
[email protected]98d3e532012-02-17 17:24:5616 * The <code>PPB_VarArrayBuffer</code> interface provides a way to interact
17 * with JavaScript ArrayBuffers, which represent a contiguous sequence of
18 * bytes. Use <code>PPB_Var</code> to manage the reference count for a
19 * <code>VarArrayBuffer</code>. Note that these Vars are not part of the
20 * embedding page's DOM, and can only be shared with JavaScript using the
21 * <code>PostMessage</code> and <code>HandleMessage</code> functions of
22 * <code>pp::Instance</code>.
[email protected]ddd61db2011-12-07 06:49:0023 */
[email protected]9c6e0de2012-01-27 04:55:5524[macro="PPB_VAR_ARRAY_BUFFER_INTERFACE"]
25interface PPB_VarArrayBuffer {
[email protected]ddd61db2011-12-07 06:49:0026 /**
[email protected]98d3e532012-02-17 17:24:5627 * Create() creates a zero-initialized <code>VarArrayBuffer</code>.
[email protected]ddd61db2011-12-07 06:49:0028 *
[email protected]98d3e532012-02-17 17:24:5629 * @param[in] size_in_bytes The size of the <code>ArrayBuffer</code> to
30 * be created.
[email protected]ddd61db2011-12-07 06:49:0031 *
[email protected]98d3e532012-02-17 17:24:5632 * @return A <code>PP_Var</code> representing a <code>VarArrayBuffer</code>
33 * of the requested size and with a reference count of 1.
[email protected]ddd61db2011-12-07 06:49:0034 */
35 PP_Var Create([in] uint32_t size_in_bytes);
[email protected]47ef6142012-01-26 21:04:1036
[email protected]ddd61db2011-12-07 06:49:0037 /**
[email protected]98d3e532012-02-17 17:24:5638 * ByteLength() retrieves the length of the <code>VarArrayBuffer</code> in
39 * bytes. On success, <code>byte_length</code> is set to the length of the
40 * given <code>ArrayBuffer</code> var. On failure, <code>byte_length</code>
41 * is unchanged (this could happen, for instance, if the given
42 * <code>PP_Var</code> is not of type <code>PP_VARTYPE_ARRAY_BUFFER</code>).
43 * Note that ByteLength() will successfully retrieve the size of an
44 * <code>ArrayBuffer</code> even if the <code>ArrayBuffer</code> is not
45 * currently mapped.
[email protected]ddd61db2011-12-07 06:49:0046 *
[email protected]98d3e532012-02-17 17:24:5647 * @param[in] array The <code>ArrayBuffer</code> whose length should be
48 * returned.
[email protected]47ef6142012-01-26 21:04:1049 *
50 * @param[out] byte_length A variable which is set to the length of the given
[email protected]98d3e532012-02-17 17:24:5651 * <code>ArrayBuffer</code> on success.
[email protected]47ef6142012-01-26 21:04:1052 *
[email protected]98d3e532012-02-17 17:24:5653 * @return <code>PP_TRUE</code> on success, <code>PP_FALSE</code> on failure.
[email protected]ddd61db2011-12-07 06:49:0054 */
[email protected]47ef6142012-01-26 21:04:1055 PP_Bool ByteLength([in] PP_Var array, [out] uint32_t byte_length);
56
[email protected]ddd61db2011-12-07 06:49:0057 /**
[email protected]98d3e532012-02-17 17:24:5658 * Map() maps the <code>ArrayBuffer</code> in to the module's address space
59 * and returns a pointer to the beginning of the buffer for the given
[email protected]1decf6d2013-02-25 23:00:5060 * <code>ArrayBuffer PP_Var</code>. ArrayBuffers are copied when transmitted,
61 * so changes to the underlying memory are not automatically available to
[email protected]dddbff162013-02-28 20:26:3062 * the embedding page.
[email protected]1decf6d2013-02-25 23:00:5063 *
64 * Note that calling Map() can be a relatively expensive operation. Use care
65 * when calling it in performance-critical code. For example, you should call
66 * it only once when looping over an <code>ArrayBuffer</code>.
[email protected]ddd61db2011-12-07 06:49:0067 *
[email protected]98d3e532012-02-17 17:24:5668 * <strong>Example:</strong>
[email protected]ddd61db2011-12-07 06:49:0069 *
[email protected]98d3e532012-02-17 17:24:5670 * @code
71 * char* data = (char*)(array_buffer_if.Map(array_buffer_var));
72 * uint32_t byte_length = 0;
73 * PP_Bool ok = array_buffer_if.ByteLength(array_buffer_var, &byte_length);
74 * if (!ok)
75 * return DoSomethingBecauseMyVarIsNotAnArrayBuffer();
76 * for (uint32_t i = 0; i < byte_length; ++i)
77 * data[i] = 'A';
78 * @endcode
[email protected]47ef6142012-01-26 21:04:1079 *
[email protected]98d3e532012-02-17 17:24:5680 * @param[in] array The <code>ArrayBuffer</code> whose internal buffer should
81 * be returned.
82 *
83 * @return A pointer to the internal buffer for this
84 * <code>ArrayBuffer</code>. Returns <code>NULL</code>
85 * if the given <code>PP_Var</code> is not of type
86 * <code>PP_VARTYPE_ARRAY_BUFFER</code>.
[email protected]ddd61db2011-12-07 06:49:0087 */
88 mem_t Map([in] PP_Var array);
[email protected]47ef6142012-01-26 21:04:1089
90 /**
[email protected]98d3e532012-02-17 17:24:5691 * Unmap() unmaps the given <code>ArrayBuffer</code> var from the module
92 * address space. Use this if you want to save memory but might want to call
93 * Map() to map the buffer again later. The <code>PP_Var</code> remains valid
94 * and should still be released using <code>PPB_Var</code> when you are done
95 * with the <code>ArrayBuffer</code>.
[email protected]47ef6142012-01-26 21:04:1096 *
[email protected]98d3e532012-02-17 17:24:5697 * @param[in] array The <code>ArrayBuffer</code> to be released.
[email protected]47ef6142012-01-26 21:04:1098 */
99 void Unmap([in] PP_Var array);
[email protected]ddd61db2011-12-07 06:49:00100};
101