Chromium Code Reviews| Index: ppapi/native_client/src/shared/ppapi_proxy/array_buffer_proxy_var.h |
| diff --git a/ppapi/native_client/src/shared/ppapi_proxy/array_buffer_proxy_var.h b/ppapi/native_client/src/shared/ppapi_proxy/array_buffer_proxy_var.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..cc06ce5a29de8933c8e8c93da2b75d929e8aaebe |
| --- /dev/null |
| +++ b/ppapi/native_client/src/shared/ppapi_proxy/array_buffer_proxy_var.h |
| @@ -0,0 +1,47 @@ |
| +// Copyright (c) 2011 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 NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_ARRAY_BUFFER_PROXY_VAR_H_ |
| +#define NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_ARRAY_BUFFER_PROXY_VAR_H_ |
| + |
| +#include "native_client/src/include/nacl_memory.h" |
| +#include "native_client/src/shared/ppapi_proxy/proxy_var.h" |
| + |
| +#include <vector> |
| + |
| +namespace ppapi_proxy { |
| + |
| +// Subclass of ProxyVar that handles ArrayBuffer objects. |
| +class ArrayBufferProxyVar : public ProxyVar { |
| + public: |
| + explicit ArrayBufferProxyVar(uint32_t size_in_bytes) |
| + : ProxyVar(PP_VARTYPE_ARRAY_BUFFER), buffer_(size_in_bytes, 0) {} |
| + |
| + void* buffer() { return buffer_.empty() ? NULL : &buffer_[0]; } |
| + uint32_t buffer_length() const { return buffer_.size(); } |
| + |
| + // Convenience function to do type checking and down-casting. This returns a |
| + // scoped_refptr<>, so you don't have to down-cast the raw pointer. |
| + static scoped_refptr<ArrayBufferProxyVar> CastFromProxyVar( |
| + SharedProxyVar proxy_var) { |
| + if (proxy_var == NULL || |
| + proxy_var->pp_var_type() != PP_VARTYPE_ARRAY_BUFFER) { |
| + scoped_refptr<ArrayBufferProxyVar> null_ptr; |
| + return null_ptr; |
| + } |
| + return scoped_refptr<ArrayBufferProxyVar>( |
| + static_cast<ArrayBufferProxyVar*>(proxy_var.get())); |
| + } |
| + |
| + private: |
| + std::vector<uint8_t> buffer_; |
| + |
| + ArrayBufferProxyVar(); // Not implemented, do not use. |
|
brettw
2011/12/28 20:05:14
Are you sure you need this to prevent the empty co
|
| +}; |
| + |
| +typedef scoped_refptr<ArrayBufferProxyVar> SharedArrayBufferProxyVar; |
| + |
| +} // namespace ppapi_proxy |
| + |
| +#endif // NATIVE_CLIENT_SRC_SHARED_PPAPI_PROXY_ARRAY_BUFFER_PROXY_VAR_H_ |