Index: ppapi/cpp/var_array_buffer.cc |
diff --git a/ppapi/cpp/var_array_buffer.cc b/ppapi/cpp/var_array_buffer.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a4104fd228e3a651e3e2188781df5b660d2293f4 |
--- /dev/null |
+++ b/ppapi/cpp/var_array_buffer.cc |
@@ -0,0 +1,77 @@ |
+// 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. |
+ |
+#include "ppapi/cpp/var_array_buffer.h" |
+ |
+#include <limits> |
+ |
+#include "ppapi/c/ppb_var_array_buffer.h" |
+#include "ppapi/cpp/logging.h" |
+#include "ppapi/cpp/module_impl.h" |
+ |
+namespace pp { |
+ |
+namespace { |
+ |
+template <> const char* interface_name<PPB_VarArrayBuffer>() { |
+ return PPB_VAR_ARRAY_BUFFER_INTERFACE; |
+} |
+ |
+} // namespace |
+ |
+VarArrayBuffer::VarArrayBuffer(const Var& var) : Var(var) { |
+ if (!var.is_array_buffer()) { |
+ PP_NOTREACHED(); |
+ var_ = PP_MakeNull(); |
+ } |
+} |
+ |
+VarArrayBuffer::VarArrayBuffer(uint32_t size_in_bytes) { |
+ if (has_interface<PPB_VarArrayBuffer>()) { |
+ var_ = get_interface<PPB_VarArrayBuffer>()->Create(size_in_bytes); |
+ needs_release_ = true; |
+ } else { |
+ PP_NOTREACHED(); |
+ var_ = PP_MakeNull(); |
+ } |
+} |
+ |
+pp::VarArrayBuffer& VarArrayBuffer::operator=(const VarArrayBuffer& other) { |
+ Var::operator=(other); |
+ return *this; |
+} |
+ |
+pp::Var& VarArrayBuffer::operator=(const Var& other) { |
+ if (other.is_array_buffer()) { |
+ return Var::operator=(other); |
+ } else { |
+ PP_NOTREACHED(); |
+ return *this; |
+ } |
+} |
+ |
+uint32_t VarArrayBuffer::ByteLength() const { |
+ uint32_t byte_length = std::numeric_limits<uint32_t>::max(); |
+ if (is_array_buffer() && has_interface<PPB_VarArrayBuffer>()) |
+ get_interface<PPB_VarArrayBuffer>()->ByteLength(var_, &byte_length); |
+ else |
+ PP_NOTREACHED(); |
+ return byte_length; |
+} |
+ |
+void* VarArrayBuffer::Map() { |
+ if (is_array_buffer() && has_interface<PPB_VarArrayBuffer>()) |
+ return get_interface<PPB_VarArrayBuffer>()->Map(var_); |
+ PP_NOTREACHED(); |
+ return NULL; |
+} |
+ |
+void VarArrayBuffer::Unmap() { |
+ if (is_array_buffer() && has_interface<PPB_VarArrayBuffer>()) |
+ get_interface<PPB_VarArrayBuffer>()->Unmap(var_); |
+ else |
+ PP_NOTREACHED(); |
+} |
+ |
+} // namespace pp |