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
3 // found in the LICENSE file.
5 #include "ppapi/cpp/var_array_buffer.h"
9 #include "ppapi/c/ppb_var_array_buffer.h"
10 #include "ppapi/cpp/logging.h"
11 #include "ppapi/cpp/module_impl.h"
17 template <> const char* interface_name
<PPB_VarArrayBuffer_1_0
>() {
18 return PPB_VAR_ARRAY_BUFFER_INTERFACE_1_0
;
23 VarArrayBuffer::VarArrayBuffer() {
27 VarArrayBuffer::VarArrayBuffer(const Var
& var
) : Var(var
) {
28 if (!var
.is_array_buffer()) {
34 VarArrayBuffer::VarArrayBuffer(uint32_t size_in_bytes
) {
35 ConstructWithSize(size_in_bytes
);
38 pp::VarArrayBuffer
& VarArrayBuffer::operator=(const VarArrayBuffer
& other
) {
39 Var::operator=(other
);
43 pp::Var
& VarArrayBuffer::operator=(const Var
& other
) {
44 if (other
.is_array_buffer()) {
45 return Var::operator=(other
);
52 uint32_t VarArrayBuffer::ByteLength() const {
53 uint32_t byte_length
= std::numeric_limits
<uint32_t>::max();
54 if (is_array_buffer() && has_interface
<PPB_VarArrayBuffer_1_0
>())
55 get_interface
<PPB_VarArrayBuffer_1_0
>()->ByteLength(var_
, &byte_length
);
61 void* VarArrayBuffer::Map() {
62 if (is_array_buffer() && has_interface
<PPB_VarArrayBuffer_1_0
>())
63 return get_interface
<PPB_VarArrayBuffer_1_0
>()->Map(var_
);
68 void VarArrayBuffer::Unmap() {
69 if (is_array_buffer() && has_interface
<PPB_VarArrayBuffer_1_0
>())
70 get_interface
<PPB_VarArrayBuffer_1_0
>()->Unmap(var_
);
76 void VarArrayBuffer::ConstructWithSize(uint32_t size_in_bytes
) {
77 PP_DCHECK(is_undefined());
79 if (has_interface
<PPB_VarArrayBuffer_1_0
>()) {
80 var_
= get_interface
<PPB_VarArrayBuffer_1_0
>()->Create(size_in_bytes
);