Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(539)

Side by Side Diff: ppapi/cpp/dev/var_array_buffer_dev.h

Issue 9169052: Tweaks to PPB_VarArrayBuffer in preperation for taking out of Dev. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes based on review comments Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 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_DEV_VAR_ARRAY_BUFFER_DEV_H_
6 #define PPAPI_CPP_DEV_VAR_ARRAY_BUFFER_DEV_H_ 6 #define PPAPI_CPP_DEV_VAR_ARRAY_BUFFER_DEV_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_Dev 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 /// VarArrayBuffer_Devs 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_Dev : public Var {
21 public: 21 public:
22 /// Contruct a VarArrayBuffer_Dev given a var for which is_array_buffer() is 22 /// Contruct a VarArrayBuffer_Dev given a var for which is_array_buffer() is
23 /// true. This will refer to the same buffer as var, but allows you to access 23 /// true. This will refer to the same ArrayBuffer as var, but allows you to
24 /// methods specific to VarArrayBuffer_Dev. 24 /// access methods specific to VarArrayBuffer_Dev.
25 /// 25 ///
26 /// @param[in] var An array buffer Var. 26 /// @param[in] var An ArrayBuffer Var.
27 explicit VarArrayBuffer_Dev(const Var& var); 27 explicit VarArrayBuffer_Dev(const Var& var);
28 28
29 /// Copy constructor.
29 VarArrayBuffer_Dev(const VarArrayBuffer_Dev& buffer) : Var(buffer) {} 30 VarArrayBuffer_Dev(const VarArrayBuffer_Dev& buffer) : Var(buffer) {}
30 31
32 virtual ~VarArrayBuffer_Dev() {}
33
34 /// This function assigns one VarArrayBuffer to another VarArrayBuffer.
35 ///
36 /// @param[in] other The VarArrayBuffer to be assigned.
37 ///
38 /// @return The resulting VarArrayBuffer.
39 VarArrayBuffer_Dev& operator=(const VarArrayBuffer_Dev& other);
40
31 /// Construct a new VarArrayBuffer_Dev which is size_in_bytes bytes long and 41 /// Construct a new VarArrayBuffer_Dev which is size_in_bytes bytes long and
32 /// initialized to zero. 42 /// initialized to zero.
33 /// 43 ///
34 /// @param[in] size_in_bytes The size of the constructed array in bytes. 44 /// @param[in] size_in_bytes The size of the constructed ArrayBuffer in bytes.
35 VarArrayBuffer_Dev(uint32_t size_in_bytes); 45 VarArrayBuffer_Dev(uint32_t size_in_bytes);
36 46
37 /// Return the length of the VarArrayBuffer_Dev in bytes. 47 /// Return the length of the VarArrayBuffer_Dev in bytes.
38 /// 48 ///
39 /// @return The length of the VarArrayBuffer_Dev in bytes. 49 /// @return The length of the VarArrayBuffer_Dev in bytes.
40 uint32_t ByteLength() const; 50 uint32_t ByteLength() const;
41 51
42 /// Return a pointer to the buffer associated with this VarArrayBuffer_Dev. 52 /// Maps the ArrayBuffer in to the module's address space and returns a
53 /// pointer to the internal buffer for this ArrayBuffer.
43 /// 54 ///
44 /// @return A pointer to the buffer associated with this VarArrayBuffer_Dev. 55 /// Note that calling Map() can be a relatively expensive operation. Use care
56 /// when calling it in performance-critical code. For example, you should call
57 /// it only once when looping over an ArrayBuffer:
58 ///
59 /// <code>
60 /// char* data = static_cast<char*>(array_buffer_var.Map());
61 /// uint32_t byte_length = array_buffer_var.ByteLength();
62 /// for (uint32_t i = 0; i < byte_length; ++i)
63 /// data[i] = 'A';
64 /// </code>
65 ///
66 /// @return A pointer to the internal buffer for this ArrayBuffer.
45 void* Map(); 67 void* Map();
46 const void* Map() const;
47 68
48 virtual ~VarArrayBuffer_Dev() {} 69 /// Unmaps this ArrayBuffer var from the module address space. Use this if
49 70 /// you want to save memory but might want to Map the buffer again later.
50 private: 71 void Unmap();
51 // We cache the buffer so that repeated calls to Map() are quick.
52 void* buffer_;
53 }; 72 };
54 73
55 } // namespace pp 74 } // namespace pp
56 75
57 #endif // PPAPI_CPP_DEV_VAR_ARRAY_BUFFER_DEV_H_ 76 #endif // PPAPI_CPP_DEV_VAR_ARRAY_BUFFER_DEV_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698