From 679147eead574d186ebf3069647b4c23e8ccace6 Mon Sep 17 00:00:00 2001 From: Zeno Albisser Date: Thu, 15 Aug 2013 21:46:11 +0200 Subject: Initial import. --- chromium/ppapi/cpp/var_array_buffer.h | 104 ++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 chromium/ppapi/cpp/var_array_buffer.h (limited to 'chromium/ppapi/cpp/var_array_buffer.h') diff --git a/chromium/ppapi/cpp/var_array_buffer.h b/chromium/ppapi/cpp/var_array_buffer.h new file mode 100644 index 00000000000..7d1f9ad48c4 --- /dev/null +++ b/chromium/ppapi/cpp/var_array_buffer.h @@ -0,0 +1,104 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PPAPI_CPP_VAR_ARRAY_BUFFER_H_ +#define PPAPI_CPP_VAR_ARRAY_BUFFER_H_ + +#include "ppapi/cpp/var.h" + +/// @file +/// This file defines the API for interacting with a JavaScript ArrayBuffer. + +namespace pp { + +/// VarArrayBuffer provides a way to interact with JavaScript +/// ArrayBuffers, which represent a contiguous sequence of bytes. Note that +/// these vars are not part of the embedding page's DOM, and can only be +/// shared with JavaScript using the PostMessage and +/// HandleMessage functions of Instance. +class VarArrayBuffer : public Var { + public: + /// The default constructor constructs a VarArrayBuffer which is + /// 0 byte long. + VarArrayBuffer(); + + /// Construct a VarArrayBuffer given a var for which + /// is_array_buffer() is true. This will refer to the same + /// ArrayBuffer as var, but allows you to access methods + /// specific to VarArrayBuffer. + /// + /// @param[in] var An ArrayBuffer var. + explicit VarArrayBuffer(const Var& var); + + /// Construct a new VarArrayBuffer which is + /// size_in_bytes bytes long and initialized to zero. + /// + /// @param[in] size_in_bytes The size of the constructed + /// ArrayBuffer in bytes. + explicit VarArrayBuffer(uint32_t size_in_bytes); + + /// Copy constructor. + VarArrayBuffer(const VarArrayBuffer& buffer) : Var(buffer) {} + + virtual ~VarArrayBuffer() {} + + /// This function assigns one VarArrayBuffer to another + /// VarArrayBuffer. + /// + /// @param[in] other The VarArrayBuffer to be assigned. + /// + /// @return The resulting VarArrayBuffer. + VarArrayBuffer& operator=(const VarArrayBuffer& other); + + /// This function assigns one VarArrayBuffer to another + /// VarArrayBuffer. A Var's assignment operator is overloaded + /// here so that we can check for assigning a non-ArrayBuffer var to a + /// VarArrayBuffer. + /// + /// @param[in] other The VarArrayBuffer to be assigned. + /// + /// @return The resulting VarArrayBuffer (as a Var&). + virtual Var& operator=(const Var& other); + + /// ByteLength() retrieves the length of the VarArrayBuffer in + /// bytes. + /// + /// @return The length of the VarArrayBuffer in bytes. + uint32_t ByteLength() const; + + /// Map() maps the ArrayBuffer in to the module's address space + /// and returns a pointer to the beginning of the internal buffer for + /// this ArrayBuffer. ArrayBuffers are copied when transmitted, + /// so changes to the underlying memory are not automatically available to + /// the embedding page. + /// + /// Note that calling Map() can be a relatively expensive operation. Use care + /// when calling it in performance-critical code. For example, you should call + /// it only once when looping over an ArrayBuffer. + /// + /// Example: + /// + /// @code + /// char* data = static_cast(array_buffer_var.Map()); + /// uint32_t byte_length = array_buffer_var.ByteLength(); + /// for (uint32_t i = 0; i < byte_length; ++i) + /// data[i] = 'A'; + /// @endcode + /// + /// @return A pointer to the internal buffer for this + /// ArrayBuffer. + void* Map(); + + /// Unmap() unmaps this ArrayBuffer var from the module address + /// space. Use this if you want to save memory but might want to call Map() + /// to map the buffer again later. + void Unmap(); + + private: + void ConstructWithSize(uint32_t size_in_bytes); +}; + +} // namespace pp + +#endif // PPAPI_CPP_VAR_ARRAY_BUFFER_H_ -- cgit v1.2.1