OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
3 * Copyright (C) 2009 Google Inc. All rights reserved. | 3 * Copyright (C) 2009 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 16 matching lines...) Expand all Loading... |
27 #ifndef Float32Array_h | 27 #ifndef Float32Array_h |
28 #define Float32Array_h | 28 #define Float32Array_h |
29 | 29 |
30 #include "wtf/MathExtras.h" | 30 #include "wtf/MathExtras.h" |
31 #include "wtf/TypedArrayBase.h" | 31 #include "wtf/TypedArrayBase.h" |
32 | 32 |
33 namespace WTF { | 33 namespace WTF { |
34 | 34 |
35 class Float32Array final : public TypedArrayBase<float> { | 35 class Float32Array final : public TypedArrayBase<float> { |
36 public: | 36 public: |
37 static inline PassRefPtr<Float32Array> create(unsigned length); | |
38 static inline PassRefPtr<Float32Array> create(const float* array, unsigned l
ength); | |
39 static inline PassRefPtr<Float32Array> create(PassRefPtr<ArrayBuffer>, unsig
ned byteOffset, unsigned length); | 37 static inline PassRefPtr<Float32Array> create(PassRefPtr<ArrayBuffer>, unsig
ned byteOffset, unsigned length); |
40 | 38 static inline PassRefPtr<Float32Array> createOrNull(const float* array, unsi
gned length); |
| 39 static inline PassRefPtr<Float32Array> deprecatedCreateOrCrash(const float*
array, unsigned length); // Prefer createOrNull |
41 static inline PassRefPtr<Float32Array> createOrNull(unsigned length); | 40 static inline PassRefPtr<Float32Array> createOrNull(unsigned length); |
42 | 41 |
43 using TypedArrayBase<float>::set; | 42 using TypedArrayBase<float>::set; |
44 | 43 |
45 void set(unsigned index, double value) | 44 void set(unsigned index, double value) |
46 { | 45 { |
47 if (index >= TypedArrayBase<float>::m_length) | 46 if (index >= TypedArrayBase<float>::m_length) |
48 return; | 47 return; |
49 TypedArrayBase<float>::data()[index] = static_cast<float>(value); | 48 TypedArrayBase<float>::data()[index] = static_cast<float>(value); |
50 } | 49 } |
51 | 50 |
52 ViewType type() const override | 51 ViewType type() const override |
53 { | 52 { |
54 return TypeFloat32; | 53 return TypeFloat32; |
55 } | 54 } |
56 | 55 |
57 private: | 56 private: |
58 inline Float32Array(PassRefPtr<ArrayBuffer>, unsigned byteOffset, unsigned l
ength); | 57 inline Float32Array(PassRefPtr<ArrayBuffer>, unsigned byteOffset, unsigned l
ength); |
59 // Make constructor visible to superclass. | 58 // Make constructor visible to superclass. |
60 friend class TypedArrayBase<float>; | 59 friend class TypedArrayBase<float>; |
61 }; | 60 }; |
62 | 61 |
63 PassRefPtr<Float32Array> Float32Array::create(unsigned length) | 62 PassRefPtr<Float32Array> Float32Array::createOrNull(unsigned length) |
64 { | 63 { |
65 return TypedArrayBase<float>::create<Float32Array>(length); | 64 return TypedArrayBase<float>::createOrNull<Float32Array>(length); |
66 } | 65 } |
67 | 66 |
68 PassRefPtr<Float32Array> Float32Array::create(const float* array, unsigned lengt
h) | 67 PassRefPtr<Float32Array> Float32Array::createOrNull(const float* array, unsigned
length) |
69 { | 68 { |
70 return TypedArrayBase<float>::create<Float32Array>(array, length); | 69 return TypedArrayBase<float>::createOrNull<Float32Array>(array, length); |
| 70 } |
| 71 |
| 72 PassRefPtr<Float32Array> Float32Array::deprecatedCreateOrCrash(const float* arra
y, unsigned length) |
| 73 { |
| 74 return TypedArrayBase<float>::deprecatedCreateOrCrash<Float32Array>(array, l
ength); |
71 } | 75 } |
72 | 76 |
73 PassRefPtr<Float32Array> Float32Array::create(PassRefPtr<ArrayBuffer> buffer, un
signed byteOffset, unsigned length) | 77 PassRefPtr<Float32Array> Float32Array::create(PassRefPtr<ArrayBuffer> buffer, un
signed byteOffset, unsigned length) |
74 { | 78 { |
75 return TypedArrayBase<float>::create<Float32Array>(buffer, byteOffset, lengt
h); | 79 return TypedArrayBase<float>::create<Float32Array>(buffer, byteOffset, lengt
h); |
76 } | 80 } |
77 | 81 |
78 PassRefPtr<Float32Array> Float32Array::createOrNull(unsigned length) | |
79 { | |
80 return TypedArrayBase<float>::createOrNull<Float32Array>(length); | |
81 } | |
82 | |
83 Float32Array::Float32Array(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset,
unsigned length) | 82 Float32Array::Float32Array(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset,
unsigned length) |
84 : TypedArrayBase<float>(buffer, byteOffset, length) | 83 : TypedArrayBase<float>(buffer, byteOffset, length) |
85 { | 84 { |
86 } | 85 } |
87 | 86 |
88 } // namespace WTF | 87 } // namespace WTF |
89 | 88 |
90 using WTF::Float32Array; | 89 using WTF::Float32Array; |
91 | 90 |
92 #endif // Float32Array_h | 91 #endif // Float32Array_h |
OLD | NEW |