| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef PPAPI_C_PP_VAR_H_ | 5 #ifndef PPAPI_C_PP_VAR_H_ |
| 6 #define PPAPI_C_PP_VAR_H_ | 6 #define PPAPI_C_PP_VAR_H_ |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * @file | 9 * @file |
| 10 * Defines the API ... | 10 * Defines the API ... |
| 11 * | 11 * |
| 12 * @addtogroup PP | 12 * @addtogroup PP |
| 13 * @{ | 13 * @{ |
| 14 */ | 14 */ |
| 15 | 15 |
| 16 #include "ppapi/c/pp_bool.h" | 16 #include "ppapi/c/pp_bool.h" |
| 17 #include "ppapi/c/pp_macros.h" | 17 #include "ppapi/c/pp_macros.h" |
| 18 #include "ppapi/c/pp_stdint.h" | 18 #include "ppapi/c/pp_stdint.h" |
| 19 | 19 |
| 20 typedef enum { | 20 typedef enum { |
| 21 PP_VARTYPE_UNDEFINED, | 21 PP_VARTYPE_UNDEFINED, |
| 22 PP_VARTYPE_NULL, | 22 PP_VARTYPE_NULL, |
| 23 PP_VARTYPE_BOOL, | 23 PP_VARTYPE_BOOL, |
| 24 PP_VARTYPE_INT32, | 24 PP_VARTYPE_INT32, |
| 25 PP_VARTYPE_DOUBLE, | 25 PP_VARTYPE_DOUBLE, |
| 26 PP_VARTYPE_STRING, | 26 PP_VARTYPE_STRING, |
| 27 PP_VARTYPE_OBJECT | 27 PP_VARTYPE_OBJECT |
| 28 } PP_VarType; | 28 } PP_VarType; |
| 29 | |
| 30 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VarType, 4); | 29 PP_COMPILE_ASSERT_SIZE_IN_BYTES(PP_VarType, 4); |
| 31 | 30 |
| 32 /** | 31 /** |
| 33 * Do not rely on having a predictable and reproducible | 32 * Do not rely on having a predictable and reproducible |
| 34 * int/double differentiation. | 33 * int/double differentiation. |
| 35 * JavaScript has a "number" type for holding a number, and | 34 * JavaScript has a "number" type for holding a number, and |
| 36 * does not differentiate between floating point and integer numbers. The | 35 * does not differentiate between floating point and integer numbers. The |
| 37 * JavaScript library will try to optimize operations by using integers | 36 * JavaScript library will try to optimize operations by using integers |
| 38 * when possible, but could end up with doubles depending on how the number | 37 * when possible, but could end up with doubles depending on how the number |
| 39 * was arrived at. | 38 * was arrived at. |
| 40 * | 39 * |
| 41 * Your best bet is to have a wrapper for variables | 40 * Your best bet is to have a wrapper for variables |
| 42 * that always gets out the type you expect, converting as necessary. | 41 * that always gets out the type you expect, converting as necessary. |
| 43 */ | 42 */ |
| 44 struct PP_Var { | 43 struct PP_Var { |
| 45 PP_VarType type; | 44 PP_VarType type; |
| 45 |
| 46 /** Ensures @a value is aligned on an 8-byte boundary relative to the |
| 47 * start of the struct. Some compilers align doubles on 8-byte boundaries |
| 48 * for 32-bit x86, and some align on 4-byte boundaries. |
| 49 */ |
| 50 int32_t padding; |
| 51 |
| 46 union { | 52 union { |
| 47 PP_Bool as_bool; | 53 PP_Bool as_bool; |
| 48 int32_t as_int; | 54 int32_t as_int; |
| 49 double as_double; | 55 double as_double; |
| 50 | 56 |
| 51 /** | 57 /** |
| 52 * Internal ID for strings and objects. The identifier is an opaque handle | 58 * Internal ID for strings and objects. The identifier is an opaque handle |
| 53 * assigned by the browser to the plugin. It is guaranteed never to be 0, | 59 * assigned by the browser to the plugin. It is guaranteed never to be 0, |
| 54 * so a plugin can initialize this ID to 0 to indicate a "NULL handle." | 60 * so a plugin can initialize this ID to 0 to indicate a "NULL handle." |
| 55 */ | 61 */ |
| 56 int64_t as_id; | 62 int64_t as_id; |
| 57 } value; | 63 } value; |
| 58 }; | 64 }; |
| 65 PP_COMPILE_ASSERT_STRUCT_SIZE_IN_BYTES(PP_Var, 16); |
| 59 | 66 |
| 60 PP_INLINE struct PP_Var PP_MakeUndefined() { | 67 PP_INLINE struct PP_Var PP_MakeUndefined() { |
| 61 struct PP_Var result = { PP_VARTYPE_UNDEFINED, {PP_FALSE} }; | 68 struct PP_Var result = { PP_VARTYPE_UNDEFINED, 0, {PP_FALSE} }; |
| 62 return result; | 69 return result; |
| 63 } | 70 } |
| 64 | 71 |
| 65 PP_INLINE struct PP_Var PP_MakeNull() { | 72 PP_INLINE struct PP_Var PP_MakeNull() { |
| 66 struct PP_Var result = { PP_VARTYPE_NULL, {PP_FALSE} }; | 73 struct PP_Var result = { PP_VARTYPE_NULL, 0, {PP_FALSE} }; |
| 67 return result; | 74 return result; |
| 68 } | 75 } |
| 69 | 76 |
| 70 PP_INLINE struct PP_Var PP_MakeBool(PP_Bool value) { | 77 PP_INLINE struct PP_Var PP_MakeBool(PP_Bool value) { |
| 71 struct PP_Var result = { PP_VARTYPE_BOOL, {PP_FALSE} }; | 78 struct PP_Var result = { PP_VARTYPE_BOOL, 0, {PP_FALSE} }; |
| 72 result.value.as_bool = value; | 79 result.value.as_bool = value; |
| 73 return result; | 80 return result; |
| 74 } | 81 } |
| 75 | 82 |
| 76 PP_INLINE struct PP_Var PP_MakeInt32(int32_t value) { | 83 PP_INLINE struct PP_Var PP_MakeInt32(int32_t value) { |
| 77 struct PP_Var result = { PP_VARTYPE_INT32, {PP_FALSE} }; | 84 struct PP_Var result = { PP_VARTYPE_INT32, 0, {PP_FALSE} }; |
| 78 result.value.as_int = value; | 85 result.value.as_int = value; |
| 79 return result; | 86 return result; |
| 80 } | 87 } |
| 81 | 88 |
| 82 PP_INLINE struct PP_Var PP_MakeDouble(double value) { | 89 PP_INLINE struct PP_Var PP_MakeDouble(double value) { |
| 83 struct PP_Var result = { PP_VARTYPE_DOUBLE, {PP_FALSE} }; | 90 struct PP_Var result = { PP_VARTYPE_DOUBLE, 0, {PP_FALSE} }; |
| 84 result.value.as_double = value; | 91 result.value.as_double = value; |
| 85 return result; | 92 return result; |
| 86 } | 93 } |
| 87 | 94 |
| 88 /** | 95 /** |
| 89 * @} | 96 * @} |
| 90 * End addtogroup PP | 97 * End addtogroup PP |
| 91 */ | 98 */ |
| 92 #endif // PPAPI_C_PP_VAR_H_ | 99 #endif // PPAPI_C_PP_VAR_H_ |
| OLD | NEW |