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

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

Issue 8502030: Draft of a PPAPI interface for ArrayBuffer and typed arrays. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 9 years 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
« no previous file with comments | « ppapi/cpp/dev/var_array_buffer_dev.h ('k') | ppapi/cpp/var.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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.
4
5 #include "ppapi/cpp/dev/var_array_buffer_dev.h"
6
7 #include "ppapi/c/dev/ppb_var_array_buffer_dev.h"
8 #include "ppapi/cpp/logging.h"
9 #include "ppapi/cpp/module_impl.h"
10
11 namespace pp {
12
13 namespace {
14
15 template <> const char* interface_name<PPB_VarArrayBuffer_Dev>() {
16 return PPB_VAR_ARRAY_BUFFER_DEV_INTERFACE;
17 }
18
19 } // namespace
20
21 VarArrayBuffer_Dev::VarArrayBuffer_Dev(const Var& var)
22 : Var(var), buffer_(NULL) {
23 if (var.is_array_buffer()) {
24 buffer_ = Map();
25 } else {
26 PP_NOTREACHED();
27 var_ = PP_MakeNull();
28 }
29 }
30
31 VarArrayBuffer_Dev::VarArrayBuffer_Dev(uint32_t size_in_bytes)
32 : buffer_(NULL) {
33 if (has_interface<PPB_VarArrayBuffer_Dev>()) {
34 var_ = get_interface<PPB_VarArrayBuffer_Dev>()->Create(size_in_bytes);
35 buffer_ = Map();
36 } else {
37 PP_NOTREACHED();
38 var_ = PP_MakeNull();
39 }
40 }
41
42 uint32_t VarArrayBuffer_Dev::ByteLength() const {
43 if (has_interface<PPB_VarArrayBuffer_Dev>()) {
44 return get_interface<PPB_VarArrayBuffer_Dev>()->ByteLength(var_);
45 }
46 PP_NOTREACHED();
47 return 0;
48 }
49
50 const void* VarArrayBuffer_Dev::Map() const {
51 return const_cast<VarArrayBuffer_Dev*>(this)->Map();
52 }
53
54 void* VarArrayBuffer_Dev::Map() {
55 // TODO(dmichael): This is not thread-safe.
56 if (buffer_)
57 return buffer_;
58 if (has_interface<PPB_VarArrayBuffer_Dev>()) {
59 buffer_ = get_interface<PPB_VarArrayBuffer_Dev>()->Map(var_);
60 return buffer_;
61 }
62 PP_NOTREACHED();
63 return 0;
64 }
65
66 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/cpp/dev/var_array_buffer_dev.h ('k') | ppapi/cpp/var.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698