OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 ~AudioArray() { WTF::Partitions::fastFree(m_allocation); } | 52 ~AudioArray() { WTF::Partitions::fastFree(m_allocation); } |
53 | 53 |
54 // It's OK to call allocate() multiple times, but data will *not* be copied | 54 // It's OK to call allocate() multiple times, but data will *not* be copied |
55 // from an initial allocation if re-allocated. Allocations are | 55 // from an initial allocation if re-allocated. Allocations are |
56 // zero-initialized. | 56 // zero-initialized. |
57 void allocate(size_t n) { | 57 void allocate(size_t n) { |
58 // Although n is a size_t, its true limit is max unsigned because we use | 58 // Although n is a size_t, its true limit is max unsigned because we use |
59 // unsigned in zeroRange() and copyToRange(). Also check for integer | 59 // unsigned in zeroRange() and copyToRange(). Also check for integer |
60 // overflow. | 60 // overflow. |
61 RELEASE_ASSERT(n <= std::numeric_limits<unsigned>::max() / sizeof(T)); | 61 CHECK_LE(n, std::numeric_limits<unsigned>::max() / sizeof(T)); |
62 | 62 |
63 unsigned initialSize = sizeof(T) * n; | 63 unsigned initialSize = sizeof(T) * n; |
64 | 64 |
65 #if USE(WEBAUDIO_FFMPEG) || USE(WEBAUDIO_OPENMAX_DL_FFT) | 65 #if USE(WEBAUDIO_FFMPEG) || USE(WEBAUDIO_OPENMAX_DL_FFT) |
66 const size_t alignment = 32; | 66 const size_t alignment = 32; |
67 #else | 67 #else |
68 const size_t alignment = 16; | 68 const size_t alignment = 16; |
69 #endif | 69 #endif |
70 | 70 |
71 if (m_allocation) | 71 if (m_allocation) |
72 WTF::Partitions::fastFree(m_allocation); | 72 WTF::Partitions::fastFree(m_allocation); |
73 | 73 |
74 bool isAllocationGood = false; | 74 bool isAllocationGood = false; |
75 | 75 |
76 while (!isAllocationGood) { | 76 while (!isAllocationGood) { |
77 // Initially we try to allocate the exact size, but if it's not aligned | 77 // Initially we try to allocate the exact size, but if it's not aligned |
78 // then we'll have to reallocate and from then on allocate extra. | 78 // then we'll have to reallocate and from then on allocate extra. |
79 static size_t extraAllocationBytes = 0; | 79 static size_t extraAllocationBytes = 0; |
80 | 80 |
81 // Again, check for integer overflow. | 81 // Again, check for integer overflow. |
82 RELEASE_ASSERT(initialSize + extraAllocationBytes >= initialSize); | 82 CHECK_GE(initialSize + extraAllocationBytes, initialSize); |
83 | 83 |
84 T* allocation = static_cast<T*>(WTF::Partitions::fastMalloc( | 84 T* allocation = static_cast<T*>(WTF::Partitions::fastMalloc( |
85 initialSize + extraAllocationBytes, | 85 initialSize + extraAllocationBytes, |
86 WTF_HEAP_PROFILER_TYPE_NAME(AudioArray<T>))); | 86 WTF_HEAP_PROFILER_TYPE_NAME(AudioArray<T>))); |
87 RELEASE_ASSERT(allocation); | 87 CHECK(allocation); |
88 | 88 |
89 T* alignedData = alignedAddress(allocation, alignment); | 89 T* alignedData = alignedAddress(allocation, alignment); |
90 | 90 |
91 if (alignedData == allocation || extraAllocationBytes == alignment) { | 91 if (alignedData == allocation || extraAllocationBytes == alignment) { |
92 m_allocation = allocation; | 92 m_allocation = allocation; |
93 m_alignedData = alignedData; | 93 m_alignedData = alignedData; |
94 m_size = n; | 94 m_size = n; |
95 isAllocationGood = true; | 95 isAllocationGood = true; |
96 zero(); | 96 zero(); |
97 } else { | 97 } else { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 T* m_alignedData; | 152 T* m_alignedData; |
153 size_t m_size; | 153 size_t m_size; |
154 }; | 154 }; |
155 | 155 |
156 typedef AudioArray<float> AudioFloatArray; | 156 typedef AudioArray<float> AudioFloatArray; |
157 typedef AudioArray<double> AudioDoubleArray; | 157 typedef AudioArray<double> AudioDoubleArray; |
158 | 158 |
159 } // namespace blink | 159 } // namespace blink |
160 | 160 |
161 #endif // AudioArray_h | 161 #endif // AudioArray_h |
OLD | NEW |