| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/shared_impl/ppb_var_shared.h" | 5 #include "ppapi/shared_impl/ppb_var_shared.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "ppapi/c/dev/ppb_var_array_buffer_dev.h" |
| 9 #include "ppapi/c/ppb_var.h" | 10 #include "ppapi/c/ppb_var.h" |
| 10 #include "ppapi/c/pp_var.h" | 11 #include "ppapi/c/pp_var.h" |
| 11 #include "ppapi/shared_impl/ppapi_globals.h" | 12 #include "ppapi/shared_impl/ppapi_globals.h" |
| 12 #include "ppapi/shared_impl/proxy_lock.h" | 13 #include "ppapi/shared_impl/proxy_lock.h" |
| 13 #include "ppapi/shared_impl/var.h" | 14 #include "ppapi/shared_impl/var.h" |
| 14 #include "ppapi/shared_impl/var_tracker.h" | 15 #include "ppapi/shared_impl/var_tracker.h" |
| 15 | 16 |
| 16 using ppapi::PpapiGlobals; | 17 using ppapi::PpapiGlobals; |
| 17 using ppapi::StringVar; | 18 using ppapi::StringVar; |
| 18 | 19 |
| 19 namespace ppapi { | 20 namespace ppapi { |
| 21 namespace { |
| 22 |
| 23 |
| 24 // PPB_Var methods ------------------------------------------------------------- |
| 20 | 25 |
| 21 void AddRefVar(PP_Var var) { | 26 void AddRefVar(PP_Var var) { |
| 22 ppapi::ProxyAutoLock lock; | 27 ppapi::ProxyAutoLock lock; |
| 23 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var); | 28 PpapiGlobals::Get()->GetVarTracker()->AddRefVar(var); |
| 24 } | 29 } |
| 25 | 30 |
| 26 void ReleaseVar(PP_Var var) { | 31 void ReleaseVar(PP_Var var) { |
| 27 ppapi::ProxyAutoLock lock; | 32 ppapi::ProxyAutoLock lock; |
| 28 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var); | 33 PpapiGlobals::Get()->GetVarTracker()->ReleaseVar(var); |
| 29 } | 34 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 41 ppapi::ProxyAutoLock lock; | 46 ppapi::ProxyAutoLock lock; |
| 42 StringVar* str = StringVar::FromPPVar(var); | 47 StringVar* str = StringVar::FromPPVar(var); |
| 43 if (str) { | 48 if (str) { |
| 44 *len = static_cast<uint32_t>(str->value().size()); | 49 *len = static_cast<uint32_t>(str->value().size()); |
| 45 return str->value().c_str(); | 50 return str->value().c_str(); |
| 46 } | 51 } |
| 47 *len = 0; | 52 *len = 0; |
| 48 return NULL; | 53 return NULL; |
| 49 } | 54 } |
| 50 | 55 |
| 51 namespace { | |
| 52 const PPB_Var var_interface = { | 56 const PPB_Var var_interface = { |
| 53 &AddRefVar, | 57 &AddRefVar, |
| 54 &ReleaseVar, | 58 &ReleaseVar, |
| 55 &VarFromUtf8, | 59 &VarFromUtf8, |
| 56 &VarToUtf8 | 60 &VarToUtf8 |
| 57 }; | 61 }; |
| 58 | 62 |
| 59 const PPB_Var_1_0 var_interface1_0 = { | 63 const PPB_Var_1_0 var_interface1_0 = { |
| 60 &AddRefVar, | 64 &AddRefVar, |
| 61 &ReleaseVar, | 65 &ReleaseVar, |
| 62 &VarFromUtf8_1_0, | 66 &VarFromUtf8_1_0, |
| 63 &VarToUtf8 | 67 &VarToUtf8 |
| 64 }; | 68 }; |
| 69 |
| 70 |
| 71 // PPB_VarArrayBuffer_Dev methods ---------------------------------------------- |
| 72 |
| 73 PP_Var CreateArrayBufferVar(uint32_t size_in_bytes) { |
| 74 return PpapiGlobals::Get()->GetVarTracker()->MakeArrayBufferPPVar( |
| 75 size_in_bytes); |
| 76 } |
| 77 |
| 78 uint32_t ByteLength(struct PP_Var array) { |
| 79 ArrayBufferVar* buffer = ArrayBufferVar::FromPPVar(array); |
| 80 if (!buffer) |
| 81 return 0; |
| 82 return buffer->ByteLength(); |
| 83 } |
| 84 |
| 85 void* Map(struct PP_Var array) { |
| 86 ArrayBufferVar* buffer = ArrayBufferVar::FromPPVar(array); |
| 87 if (!buffer) |
| 88 return NULL; |
| 89 return buffer->Map(); |
| 90 } |
| 91 |
| 92 const PPB_VarArrayBuffer_Dev var_arraybuffer_interface = { |
| 93 &CreateArrayBufferVar, |
| 94 &ByteLength, |
| 95 &Map |
| 96 }; |
| 97 |
| 65 } // namespace | 98 } // namespace |
| 66 | 99 |
| 67 // static | 100 // static |
| 68 const PPB_Var* PPB_Var_Shared::GetVarInterface() { | 101 const PPB_Var* PPB_Var_Shared::GetVarInterface() { |
| 69 return &var_interface; | 102 return &var_interface; |
| 70 } | 103 } |
| 71 | 104 |
| 72 // static | 105 // static |
| 73 const PPB_Var_1_0* PPB_Var_Shared::GetVarInterface1_0() { | 106 const PPB_Var_1_0* PPB_Var_Shared::GetVarInterface1_0() { |
| 74 return &var_interface1_0; | 107 return &var_interface1_0; |
| 75 } | 108 } |
| 76 | 109 |
| 110 // static |
| 111 const PPB_VarArrayBuffer_Dev* PPB_Var_Shared::GetVarArrayBufferInterface() { |
| 112 return &var_arraybuffer_interface; |
| 113 } |
| 114 |
| 77 } // namespace ppapi | 115 } // namespace ppapi |
| 78 | 116 |
| OLD | NEW |