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_VAR_ARRAY_BUFFER_H_ | 5 #ifndef PPAPI_CPP_VAR_ARRAY_BUFFER_H_ |
6 #define PPAPI_CPP_VAR_ARRAY_BUFFER_H_ | 6 #define PPAPI_CPP_VAR_ARRAY_BUFFER_H_ |
7 | 7 |
8 #include "ppapi/cpp/var.h" | 8 #include "ppapi/cpp/var.h" |
9 | 9 |
10 /// @file | 10 /// @file |
11 /// This file defines the API for interacting with a JavaScript ArrayBuffer. | 11 /// This file defines the API for interacting with a JavaScript ArrayBuffer. |
12 | 12 |
13 namespace pp { | 13 namespace pp { |
14 | 14 |
15 /// <code>VarArrayBuffer</code> provides a way to interact with JavaScript | 15 /// <code>VarArrayBuffer</code> provides a way to interact with JavaScript |
16 /// ArrayBuffers, which represent a contiguous sequence of bytes. Note that | 16 /// ArrayBuffers, which represent a contiguous sequence of bytes. Note that |
17 /// these vars are not part of the embedding page's DOM, and can only be | 17 /// these vars are not part of the embedding page's DOM, and can only be |
18 /// shared with JavaScript using the <code>PostMessage</code> and | 18 /// shared with JavaScript using the <code>PostMessage</code> and |
19 /// <code>HandleMessage</code> functions of <code>Instance</code>. | 19 /// <code>HandleMessage</code> functions of <code>Instance</code>. |
20 class VarArrayBuffer : public Var { | 20 class VarArrayBuffer : public Var { |
21 public: | 21 public: |
| 22 /// The default constructor constructs a <code>VarArrayBuffer</code> which is |
| 23 /// 0 byte long. |
| 24 VarArrayBuffer(); |
| 25 |
22 /// Construct a <code>VarArrayBuffer</code> given a var for which | 26 /// Construct a <code>VarArrayBuffer</code> given a var for which |
23 /// is_array_buffer() is true. This will refer to the same | 27 /// is_array_buffer() is true. This will refer to the same |
24 /// <code>ArrayBuffer</code> as var, but allows you to access methods | 28 /// <code>ArrayBuffer</code> as var, but allows you to access methods |
25 /// specific to <code>VarArrayBuffer</code>. | 29 /// specific to <code>VarArrayBuffer</code>. |
26 /// | 30 /// |
27 /// @param[in] var An <code>ArrayBuffer</code> var. | 31 /// @param[in] var An <code>ArrayBuffer</code> var. |
28 explicit VarArrayBuffer(const Var& var); | 32 explicit VarArrayBuffer(const Var& var); |
29 | 33 |
30 /// Construct a new <code>VarArrayBuffer_Dev</code> which is | 34 /// Construct a new <code>VarArrayBuffer</code> which is |
31 /// <code>size_in_bytes</code> bytes long and initialized to zero. | 35 /// <code>size_in_bytes</code> bytes long and initialized to zero. |
32 /// | 36 /// |
33 /// @param[in] size_in_bytes The size of the constructed | 37 /// @param[in] size_in_bytes The size of the constructed |
34 /// <code>ArrayBuffer</code> in bytes. | 38 /// <code>ArrayBuffer</code> in bytes. |
35 explicit VarArrayBuffer(uint32_t size_in_bytes); | 39 explicit VarArrayBuffer(uint32_t size_in_bytes); |
36 | 40 |
37 /// Copy constructor. | 41 /// Copy constructor. |
38 VarArrayBuffer(const VarArrayBuffer& buffer) : Var(buffer) {} | 42 VarArrayBuffer(const VarArrayBuffer& buffer) : Var(buffer) {} |
39 | 43 |
40 virtual ~VarArrayBuffer() {} | 44 virtual ~VarArrayBuffer() {} |
41 | 45 |
42 /// This function assigns one <code>VarArrayBuffer</code> to another | 46 /// This function assigns one <code>VarArrayBuffer</code> to another |
43 /// <code>VarArrayBuffer</code>. | 47 /// <code>VarArrayBuffer</code>. |
44 /// | 48 /// |
45 /// @param[in] other The <code>VarArrayBuffer</code> to be assigned. | 49 /// @param[in] other The <code>VarArrayBuffer</code> to be assigned. |
46 /// | 50 /// |
47 /// @return The resulting <code>VarArrayBuffer</code>. | 51 /// @return The resulting <code>VarArrayBuffer</code>. |
48 VarArrayBuffer& operator=(const VarArrayBuffer& other); | 52 VarArrayBuffer& operator=(const VarArrayBuffer& other); |
49 | 53 |
50 /// This function assigns one <code>VarArrayBuffer</code> to another | 54 /// This function assigns one <code>VarArrayBuffer</code> to another |
51 /// <code>VarArrayBuffer</code>. A Var's assignment operator is overloaded | 55 /// <code>VarArrayBuffer</code>. A Var's assignment operator is overloaded |
52 /// here so that we can check for assigning a non-ArrayBuffer var to a | 56 /// here so that we can check for assigning a non-ArrayBuffer var to a |
53 /// <code>VarArrayBuffer_Dev</code>. | 57 /// <code>VarArrayBuffer</code>. |
54 /// | 58 /// |
55 /// @param[in] other The <code>VarArrayBuffer</code> to be assigned. | 59 /// @param[in] other The <code>VarArrayBuffer</code> to be assigned. |
56 /// | 60 /// |
57 /// @return The resulting <code>VarArrayBuffer</code> (as a Var&). | 61 /// @return The resulting <code>VarArrayBuffer</code> (as a Var&). |
58 virtual Var& operator=(const Var& other); | 62 virtual Var& operator=(const Var& other); |
59 | 63 |
60 /// ByteLength() retrieves the length of the <code>VarArrayBuffer</code> in | 64 /// ByteLength() retrieves the length of the <code>VarArrayBuffer</code> in |
61 /// bytes. | 65 /// bytes. |
62 /// | 66 /// |
63 /// @return The length of the <code>VarArrayBuffer</code> in bytes. | 67 /// @return The length of the <code>VarArrayBuffer</code> in bytes. |
(...skipping 19 matching lines...) Expand all Loading... |
83 /// @endcode | 87 /// @endcode |
84 /// | 88 /// |
85 /// @return A pointer to the internal buffer for this | 89 /// @return A pointer to the internal buffer for this |
86 /// <code>ArrayBuffer</code>. | 90 /// <code>ArrayBuffer</code>. |
87 void* Map(); | 91 void* Map(); |
88 | 92 |
89 /// Unmap() unmaps this <code>ArrayBuffer</code> var from the module address | 93 /// Unmap() unmaps this <code>ArrayBuffer</code> var from the module address |
90 /// space. Use this if you want to save memory but might want to call Map() | 94 /// space. Use this if you want to save memory but might want to call Map() |
91 /// to map the buffer again later. | 95 /// to map the buffer again later. |
92 void Unmap(); | 96 void Unmap(); |
| 97 |
| 98 private: |
| 99 void ConstructWithSize(uint32_t size_in_bytes); |
93 }; | 100 }; |
94 | 101 |
95 } // namespace pp | 102 } // namespace pp |
96 | 103 |
97 #endif // PPAPI_CPP_VAR_ARRAY_BUFFER_H_ | 104 #endif // PPAPI_CPP_VAR_ARRAY_BUFFER_H_ |
OLD | NEW |