| 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 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 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); | 37 static inline PassRefPtr<Float32Array> create(unsigned length); |
| 38 static inline PassRefPtr<Float32Array> create(const float* array, unsigned l
ength); | 38 static inline PassRefPtr<Float32Array> create(const float* array, |
| 39 static inline PassRefPtr<Float32Array> create(PassRefPtr<ArrayBuffer>, unsig
ned byteOffset, unsigned length); | 39 unsigned length); |
| 40 static inline PassRefPtr<Float32Array> create(PassRefPtr<ArrayBuffer>, |
| 41 unsigned byteOffset, |
| 42 unsigned length); |
| 40 | 43 |
| 41 static inline PassRefPtr<Float32Array> createOrNull(unsigned length); | 44 static inline PassRefPtr<Float32Array> createOrNull(unsigned length); |
| 42 | 45 |
| 43 using TypedArrayBase<float>::set; | 46 using TypedArrayBase<float>::set; |
| 44 | 47 |
| 45 void set(unsigned index, double value) | 48 void set(unsigned index, double value) { |
| 46 { | 49 if (index >= TypedArrayBase<float>::m_length) |
| 47 if (index >= TypedArrayBase<float>::m_length) | 50 return; |
| 48 return; | 51 TypedArrayBase<float>::data()[index] = static_cast<float>(value); |
| 49 TypedArrayBase<float>::data()[index] = static_cast<float>(value); | 52 } |
| 50 } | |
| 51 | 53 |
| 52 ViewType type() const override | 54 ViewType type() const override { return TypeFloat32; } |
| 53 { | |
| 54 return TypeFloat32; | |
| 55 } | |
| 56 | 55 |
| 57 private: | 56 private: |
| 58 inline Float32Array(PassRefPtr<ArrayBuffer>, unsigned byteOffset, unsigned l
ength); | 57 inline Float32Array(PassRefPtr<ArrayBuffer>, |
| 59 // Make constructor visible to superclass. | 58 unsigned byteOffset, |
| 60 friend class TypedArrayBase<float>; | 59 unsigned length); |
| 60 // Make constructor visible to superclass. |
| 61 friend class TypedArrayBase<float>; |
| 61 }; | 62 }; |
| 62 | 63 |
| 63 PassRefPtr<Float32Array> Float32Array::create(unsigned length) | 64 PassRefPtr<Float32Array> Float32Array::create(unsigned length) { |
| 64 { | 65 return TypedArrayBase<float>::create<Float32Array>(length); |
| 65 return TypedArrayBase<float>::create<Float32Array>(length); | |
| 66 } | 66 } |
| 67 | 67 |
| 68 PassRefPtr<Float32Array> Float32Array::create(const float* array, unsigned lengt
h) | 68 PassRefPtr<Float32Array> Float32Array::create(const float* array, |
| 69 { | 69 unsigned length) { |
| 70 return TypedArrayBase<float>::create<Float32Array>(array, length); | 70 return TypedArrayBase<float>::create<Float32Array>(array, length); |
| 71 } | 71 } |
| 72 | 72 |
| 73 PassRefPtr<Float32Array> Float32Array::create(PassRefPtr<ArrayBuffer> buffer, un
signed byteOffset, unsigned length) | 73 PassRefPtr<Float32Array> Float32Array::create(PassRefPtr<ArrayBuffer> buffer, |
| 74 { | 74 unsigned byteOffset, |
| 75 return TypedArrayBase<float>::create<Float32Array>(buffer, byteOffset, lengt
h); | 75 unsigned length) { |
| 76 return TypedArrayBase<float>::create<Float32Array>(buffer, byteOffset, |
| 77 length); |
| 76 } | 78 } |
| 77 | 79 |
| 78 PassRefPtr<Float32Array> Float32Array::createOrNull(unsigned length) | 80 PassRefPtr<Float32Array> Float32Array::createOrNull(unsigned length) { |
| 79 { | 81 return TypedArrayBase<float>::createOrNull<Float32Array>(length); |
| 80 return TypedArrayBase<float>::createOrNull<Float32Array>(length); | |
| 81 } | 82 } |
| 82 | 83 |
| 83 Float32Array::Float32Array(PassRefPtr<ArrayBuffer> buffer, unsigned byteOffset,
unsigned length) | 84 Float32Array::Float32Array(PassRefPtr<ArrayBuffer> buffer, |
| 84 : TypedArrayBase<float>(buffer, byteOffset, length) | 85 unsigned byteOffset, |
| 85 { | 86 unsigned length) |
| 86 } | 87 : TypedArrayBase<float>(buffer, byteOffset, length) {} |
| 87 | 88 |
| 88 } // namespace WTF | 89 } // namespace WTF |
| 89 | 90 |
| 90 using WTF::Float32Array; | 91 using WTF::Float32Array; |
| 91 | 92 |
| 92 #endif // Float32Array_h | 93 #endif // Float32Array_h |
| OLD | NEW |