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

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

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: Clarify ByteLength behavior when not mapped. 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 #include "ppapi/cpp/dev/var_array_buffer_dev.h" 5 #include "ppapi/cpp/dev/var_array_buffer_dev.h"
6 6
7 #include <limits>
8
7 #include "ppapi/c/dev/ppb_var_array_buffer_dev.h" 9 #include "ppapi/c/dev/ppb_var_array_buffer_dev.h"
8 #include "ppapi/cpp/logging.h" 10 #include "ppapi/cpp/logging.h"
9 #include "ppapi/cpp/module_impl.h" 11 #include "ppapi/cpp/module_impl.h"
10 12
11 namespace pp { 13 namespace pp {
12 14
13 namespace { 15 namespace {
14 16
15 template <> const char* interface_name<PPB_VarArrayBuffer_Dev>() { 17 template <> const char* interface_name<PPB_VarArrayBuffer_Dev>() {
16 return PPB_VAR_ARRAY_BUFFER_DEV_INTERFACE; 18 return PPB_VAR_ARRAY_BUFFER_DEV_INTERFACE;
17 } 19 }
18 20
19 } // namespace 21 } // namespace
20 22
21 VarArrayBuffer_Dev::VarArrayBuffer_Dev(const Var& var) 23 VarArrayBuffer_Dev::VarArrayBuffer_Dev(const Var& var) : Var(var) {
22 : Var(var), buffer_(NULL) { 24 if (!var.is_array_buffer()) {
23 if (var.is_array_buffer()) { 25 PP_NOTREACHED();
24 buffer_ = Map(); 26 var_ = PP_MakeNull();
27 }
28 }
29
30 VarArrayBuffer_Dev::VarArrayBuffer_Dev(uint32_t size_in_bytes) {
31 if (has_interface<PPB_VarArrayBuffer_Dev>()) {
32 var_ = get_interface<PPB_VarArrayBuffer_Dev>()->Create(size_in_bytes);
33 needs_release_ = true;
25 } else { 34 } else {
26 PP_NOTREACHED(); 35 PP_NOTREACHED();
27 var_ = PP_MakeNull(); 36 var_ = PP_MakeNull();
28 } 37 }
29 } 38 }
30 39
31 VarArrayBuffer_Dev::VarArrayBuffer_Dev(uint32_t size_in_bytes) 40 pp::VarArrayBuffer_Dev& VarArrayBuffer_Dev::operator=(
32 : buffer_(NULL) { 41 const VarArrayBuffer_Dev& other) {
33 if (has_interface<PPB_VarArrayBuffer_Dev>()) { 42 Var::operator=(other);
bbudge 2012/01/26 17:20:26 Isn't it a problem that you can assign a non-Array
dmichael (off chromium) 2012/01/26 18:33:48 Good point; I was only really thinking about stati
34 var_ = get_interface<PPB_VarArrayBuffer_Dev>()->Create(size_in_bytes); 43 return *this;
35 needs_release_ = true;
36 buffer_ = Map();
37 } else {
38 PP_NOTREACHED();
39 var_ = PP_MakeNull();
40 }
41 } 44 }
42 45
43 uint32_t VarArrayBuffer_Dev::ByteLength() const { 46 uint32_t VarArrayBuffer_Dev::ByteLength() const {
44 if (has_interface<PPB_VarArrayBuffer_Dev>()) { 47 uint32_t byte_length = std::numeric_limits<uint32_t>::max();
45 return get_interface<PPB_VarArrayBuffer_Dev>()->ByteLength(var_); 48 if (is_array_buffer() && has_interface<PPB_VarArrayBuffer_Dev>())
46 } 49 get_interface<PPB_VarArrayBuffer_Dev>()->ByteLength(var_, &byte_length);
47 PP_NOTREACHED(); 50 else
48 return 0; 51 PP_NOTREACHED();
49 } 52 return byte_length;
50
51 const void* VarArrayBuffer_Dev::Map() const {
52 return const_cast<VarArrayBuffer_Dev*>(this)->Map();
53 } 53 }
54 54
55 void* VarArrayBuffer_Dev::Map() { 55 void* VarArrayBuffer_Dev::Map() {
56 // TODO(dmichael): This is not thread-safe. 56 if (is_array_buffer() && has_interface<PPB_VarArrayBuffer_Dev>())
57 if (buffer_) 57 return get_interface<PPB_VarArrayBuffer_Dev>()->Map(var_);
58 return buffer_;
59 if (has_interface<PPB_VarArrayBuffer_Dev>()) {
60 buffer_ = get_interface<PPB_VarArrayBuffer_Dev>()->Map(var_);
61 return buffer_;
62 }
63 PP_NOTREACHED(); 58 PP_NOTREACHED();
64 return 0; 59 return NULL;
60 }
61
62 void VarArrayBuffer_Dev::Unmap() {
63 if (is_array_buffer() && has_interface<PPB_VarArrayBuffer_Dev>())
64 get_interface<PPB_VarArrayBuffer_Dev>()->Map(var_);
bbudge 2012/01/26 17:20:26 Reading the code, it still seems weird to see Unma
dmichael (off chromium) 2012/01/26 18:33:48 Gah. You were completely right the first time. I r
65 else
66 PP_NOTREACHED();
65 } 67 }
66 68
67 } // namespace pp 69 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698