| 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_VAR_ARRAY_BUFFER_DEV_H_ | 5 #ifndef PPAPI_CPP_VAR_ARRAY_BUFFER_H_ |
| 6 #define PPAPI_CPP_DEV_VAR_ARRAY_BUFFER_DEV_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 an ArrayBuffer. | 11 /// This file defines the API for interacting with an ArrayBuffer. |
| 12 | 12 |
| 13 namespace pp { | 13 namespace pp { |
| 14 | 14 |
| 15 /// VarArrayBuffer_Dev provides a way to interact with JavaScript ArrayBuffers, | 15 /// VarArrayBuffer provides a way to interact with JavaScript ArrayBuffers, |
| 16 /// which represent a contiguous sequence of bytes. Note that | 16 /// which represent a contiguous sequence of bytes. Note that |
| 17 /// VarArrayBuffer_Devs are not part of the embedding page's DOM, and can only | 17 /// VarArrayBuffers are not part of the embedding page's DOM, and can only |
| 18 /// be shared with JavaScript via pp::Instance's PostMessage and HandleMessage | 18 /// be shared with JavaScript via pp::Instance's PostMessage and HandleMessage |
| 19 /// functions. | 19 /// functions. |
| 20 class VarArrayBuffer_Dev : public Var { | 20 class VarArrayBuffer : public Var { |
| 21 public: | 21 public: |
| 22 /// Contruct a VarArrayBuffer_Dev given a var for which is_array_buffer() is | 22 /// Contruct a VarArrayBuffer given a var for which is_array_buffer() is |
| 23 /// true. This will refer to the same ArrayBuffer as var, but allows you to | 23 /// true. This will refer to the same ArrayBuffer as var, but allows you to |
| 24 /// access methods specific to VarArrayBuffer_Dev. | 24 /// access methods specific to VarArrayBuffer. |
| 25 /// | 25 /// |
| 26 /// @param[in] var An ArrayBuffer Var. | 26 /// @param[in] var An ArrayBuffer Var. |
| 27 explicit VarArrayBuffer_Dev(const Var& var); | 27 explicit VarArrayBuffer(const Var& var); |
| 28 |
| 29 /// Construct a new VarArrayBuffer_Dev which is size_in_bytes bytes long and |
| 30 /// initialized to zero. |
| 31 /// |
| 32 /// @param[in] size_in_bytes The size of the constructed ArrayBuffer in bytes. |
| 33 explicit VarArrayBuffer(uint32_t size_in_bytes); |
| 28 | 34 |
| 29 /// Copy constructor. | 35 /// Copy constructor. |
| 30 VarArrayBuffer_Dev(const VarArrayBuffer_Dev& buffer) : Var(buffer) {} | 36 VarArrayBuffer(const VarArrayBuffer& buffer) : Var(buffer) {} |
| 31 | 37 |
| 32 virtual ~VarArrayBuffer_Dev() {} | 38 virtual ~VarArrayBuffer() {} |
| 33 | 39 |
| 34 /// This function assigns one VarArrayBuffer to another VarArrayBuffer. | 40 /// This function assigns one VarArrayBuffer to another VarArrayBuffer. |
| 35 /// | 41 /// |
| 36 /// @param[in] other The VarArrayBuffer to be assigned. | 42 /// @param[in] other The VarArrayBuffer to be assigned. |
| 37 /// | 43 /// |
| 38 /// @return The resulting VarArrayBuffer. | 44 /// @return The resulting VarArrayBuffer. |
| 39 VarArrayBuffer_Dev& operator=(const VarArrayBuffer_Dev& other); | 45 VarArrayBuffer& operator=(const VarArrayBuffer& other); |
| 40 | 46 |
| 41 /// This function assigns one VarArrayBuffer to another VarArrayBuffer. Var's | 47 /// This function assigns one VarArrayBuffer to another VarArrayBuffer. Var's |
| 42 /// assignment operator is overloaded here so that we can check for assigning | 48 /// assignment operator is overloaded here so that we can check for assigning |
| 43 /// a non-ArrayBuffer var to a VarArrayBuffer_Dev. | 49 /// a non-ArrayBuffer var to a VarArrayBuffer_Dev. |
| 44 /// | 50 /// |
| 45 /// @param[in] other The VarArrayBuffer to be assigned. | 51 /// @param[in] other The VarArrayBuffer to be assigned. |
| 46 /// | 52 /// |
| 47 /// @return The resulting VarArrayBuffer (as a Var&). | 53 /// @return The resulting VarArrayBuffer (as a Var&). |
| 48 virtual Var& operator=(const Var& other); | 54 virtual Var& operator=(const Var& other); |
| 49 | 55 |
| 50 /// Construct a new VarArrayBuffer_Dev which is size_in_bytes bytes long and | 56 /// Return the length of the VarArrayBuffer in bytes. |
| 51 /// initialized to zero. | |
| 52 /// | 57 /// |
| 53 /// @param[in] size_in_bytes The size of the constructed ArrayBuffer in bytes. | 58 /// @return The length of the VarArrayBuffer in bytes. |
| 54 VarArrayBuffer_Dev(uint32_t size_in_bytes); | |
| 55 | |
| 56 /// Return the length of the VarArrayBuffer_Dev in bytes. | |
| 57 /// | |
| 58 /// @return The length of the VarArrayBuffer_Dev in bytes. | |
| 59 uint32_t ByteLength() const; | 59 uint32_t ByteLength() const; |
| 60 | 60 |
| 61 /// Maps the ArrayBuffer in to the module's address space and returns a | 61 /// Maps the ArrayBuffer in to the module's address space and returns a |
| 62 /// pointer to the internal buffer for this ArrayBuffer. | 62 /// pointer to the internal buffer for this ArrayBuffer. |
| 63 /// | 63 /// |
| 64 /// Note that calling Map() can be a relatively expensive operation. Use care | 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 | 65 /// when calling it in performance-critical code. For example, you should call |
| 66 /// it only once when looping over an ArrayBuffer: | 66 /// it only once when looping over an ArrayBuffer: |
| 67 /// | 67 /// |
| 68 /// <code> | 68 /// <code> |
| 69 /// char* data = static_cast<char*>(array_buffer_var.Map()); | 69 /// char* data = static_cast<char*>(array_buffer_var.Map()); |
| 70 /// uint32_t byte_length = array_buffer_var.ByteLength(); | 70 /// uint32_t byte_length = array_buffer_var.ByteLength(); |
| 71 /// for (uint32_t i = 0; i < byte_length; ++i) | 71 /// for (uint32_t i = 0; i < byte_length; ++i) |
| 72 /// data[i] = 'A'; | 72 /// data[i] = 'A'; |
| 73 /// </code> | 73 /// </code> |
| 74 /// | 74 /// |
| 75 /// @return A pointer to the internal buffer for this ArrayBuffer. | 75 /// @return A pointer to the internal buffer for this ArrayBuffer. |
| 76 void* Map(); | 76 void* Map(); |
| 77 | 77 |
| 78 /// Unmaps this ArrayBuffer var from the module address space. Use this if | 78 /// Unmaps this ArrayBuffer var from the module address space. Use this if |
| 79 /// you want to save memory but might want to Map the buffer again later. | 79 /// you want to save memory but might want to Map the buffer again later. |
| 80 void Unmap(); | 80 void Unmap(); |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 } // namespace pp | 83 } // namespace pp |
| 84 | 84 |
| 85 #endif // PPAPI_CPP_DEV_VAR_ARRAY_BUFFER_DEV_H_ | 85 #endif // PPAPI_CPP_VAR_ARRAY_BUFFER_H_ |
| OLD | NEW |