Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(432)

Side by Side Diff: Source/wtf/ArrayBuffer.h

Issue 1532413002: Added Dartium changes onto 45.0.2454.104 (Closed) Base URL: http://src.chromium.org/blink/branches/chromium/2454
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/platform/MIMETypeRegistry.cpp ('k') | Source/wtf/ArrayBufferContents.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2009 Apple 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 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 26 matching lines...) Expand all
37 class ArrayBuffer; 37 class ArrayBuffer;
38 class ArrayBufferView; 38 class ArrayBufferView;
39 39
40 class WTF_EXPORT ArrayBuffer : public RefCounted<ArrayBuffer> { 40 class WTF_EXPORT ArrayBuffer : public RefCounted<ArrayBuffer> {
41 public: 41 public:
42 static inline PassRefPtr<ArrayBuffer> create(unsigned numElements, unsigned elementByteSize); 42 static inline PassRefPtr<ArrayBuffer> create(unsigned numElements, unsigned elementByteSize);
43 static inline PassRefPtr<ArrayBuffer> create(ArrayBuffer*); 43 static inline PassRefPtr<ArrayBuffer> create(ArrayBuffer*);
44 static inline PassRefPtr<ArrayBuffer> create(const void* source, unsigned by teLength); 44 static inline PassRefPtr<ArrayBuffer> create(const void* source, unsigned by teLength);
45 static inline PassRefPtr<ArrayBuffer> create(ArrayBufferContents&); 45 static inline PassRefPtr<ArrayBuffer> create(ArrayBufferContents&);
46 46
47 // Create an ArrayBuffer for an existing piece of memory with no copying.
48 // The ArrayBuffer does not take ownership of the passed-in memory and care
49 // must be taken to not deallocate the data before the ArrayBuffer has been
50 // deallocated.
51 //
52 // FIXME: This should be removed when pointers into the JS/Dart heap can
53 // can be passed directly.
54 static inline PassRefPtr<ArrayBuffer> createNoCopy(void* source, unsigned by teLength);
55
56 // Only for use by Uint8ClampedArray::createUninitialized and SharedBuffer:: getAsArrayBuffer.
47 static inline PassRefPtr<ArrayBuffer> createOrNull(unsigned numElements, uns igned elementByteSize); 57 static inline PassRefPtr<ArrayBuffer> createOrNull(unsigned numElements, uns igned elementByteSize);
48 58
49 // Only for use by XMLHttpRequest::responseArrayBuffer and Internals::serial izeObject 59 // Only for use by XMLHttpRequest::responseArrayBuffer and Internals::serial izeObject
50 // (through DOMArrayBuffer::createUninitialized). 60 // (through DOMArrayBuffer::createUninitialized).
51 static inline PassRefPtr<ArrayBuffer> createUninitialized(unsigned numElemen ts, unsigned elementByteSize); 61 static inline PassRefPtr<ArrayBuffer> createUninitialized(unsigned numElemen ts, unsigned elementByteSize);
52 62
53 static inline PassRefPtr<ArrayBuffer> createShared(unsigned numElements, uns igned elementByteSize); 63 static inline PassRefPtr<ArrayBuffer> createShared(unsigned numElements, uns igned elementByteSize);
54 static inline PassRefPtr<ArrayBuffer> createShared(const void* source, unsig ned byteLength); 64 static inline PassRefPtr<ArrayBuffer> createShared(const void* source, unsig ned byteLength);
55 65
56 inline void* data(); 66 inline void* data();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 123
114 PassRefPtr<ArrayBuffer> ArrayBuffer::create(const void* source, unsigned byteLen gth) 124 PassRefPtr<ArrayBuffer> ArrayBuffer::create(const void* source, unsigned byteLen gth)
115 { 125 {
116 ArrayBufferContents contents(byteLength, 1, ArrayBufferContents::NotShared, ArrayBufferContents::ZeroInitialize); 126 ArrayBufferContents contents(byteLength, 1, ArrayBufferContents::NotShared, ArrayBufferContents::ZeroInitialize);
117 RELEASE_ASSERT(contents.data()); 127 RELEASE_ASSERT(contents.data());
118 RefPtr<ArrayBuffer> buffer = adoptRef(new ArrayBuffer(contents)); 128 RefPtr<ArrayBuffer> buffer = adoptRef(new ArrayBuffer(contents));
119 memcpy(buffer->data(), source, byteLength); 129 memcpy(buffer->data(), source, byteLength);
120 return buffer.release(); 130 return buffer.release();
121 } 131 }
122 132
133 PassRefPtr<ArrayBuffer> ArrayBuffer::createNoCopy(void* source, unsigned byteLen gth)
134 {
135 // FIXME: What do we pass in for a DeallocationObserver?
136 ArrayBufferContents contents(source, byteLength, ArrayBufferContents::Sharin gType::NotShared);
137 return adoptRef(new ArrayBuffer(contents));
138 }
139
123 PassRefPtr<ArrayBuffer> ArrayBuffer::create(ArrayBufferContents& contents) 140 PassRefPtr<ArrayBuffer> ArrayBuffer::create(ArrayBufferContents& contents)
124 { 141 {
125 RELEASE_ASSERT(contents.data()); 142 RELEASE_ASSERT(contents.data());
126 return adoptRef(new ArrayBuffer(contents)); 143 return adoptRef(new ArrayBuffer(contents));
127 } 144 }
128 145
129 PassRefPtr<ArrayBuffer> ArrayBuffer::createOrNull(unsigned numElements, unsigned elementByteSize) 146 PassRefPtr<ArrayBuffer> ArrayBuffer::createOrNull(unsigned numElements, unsigned elementByteSize)
130 { 147 {
131 return createOrNull(numElements, elementByteSize, ArrayBufferContents::ZeroI nitialize); 148 return createOrNull(numElements, elementByteSize, ArrayBufferContents::ZeroI nitialize);
132 } 149 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 PassRefPtr<ArrayBuffer> ArrayBuffer::createShared(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy policy) 185 PassRefPtr<ArrayBuffer> ArrayBuffer::createShared(unsigned numElements, unsigned elementByteSize, ArrayBufferContents::InitializationPolicy policy)
169 { 186 {
170 ArrayBufferContents contents(numElements, elementByteSize, ArrayBufferConten ts::Shared, policy); 187 ArrayBufferContents contents(numElements, elementByteSize, ArrayBufferConten ts::Shared, policy);
171 RELEASE_ASSERT(contents.data()); 188 RELEASE_ASSERT(contents.data());
172 return adoptRef(new ArrayBuffer(contents)); 189 return adoptRef(new ArrayBuffer(contents));
173 } 190 }
174 191
175 ArrayBuffer::ArrayBuffer(ArrayBufferContents& contents) 192 ArrayBuffer::ArrayBuffer(ArrayBufferContents& contents)
176 : m_firstView(0), m_isNeutered(false) 193 : m_firstView(0), m_isNeutered(false)
177 { 194 {
178 contents.transfer(m_contents); 195 if (contents.isShared())
196 contents.shareWith(m_contents);
197 else
198 contents.transfer(m_contents);
179 } 199 }
180 200
181 void* ArrayBuffer::data() 201 void* ArrayBuffer::data()
182 { 202 {
183 return m_contents.data(); 203 return m_contents.data();
184 } 204 }
185 205
186 const void* ArrayBuffer::data() const 206 const void* ArrayBuffer::data() const
187 { 207 {
188 return m_contents.data(); 208 return m_contents.data();
(...skipping 26 matching lines...) Expand all
215 if (index < 0) 235 if (index < 0)
216 index = currentLength + index; 236 index = currentLength + index;
217 return clampValue(index, 0, currentLength); 237 return clampValue(index, 0, currentLength);
218 } 238 }
219 239
220 } // namespace WTF 240 } // namespace WTF
221 241
222 using WTF::ArrayBuffer; 242 using WTF::ArrayBuffer;
223 243
224 #endif // ArrayBuffer_h 244 #endif // ArrayBuffer_h
OLDNEW
« no previous file with comments | « Source/platform/MIMETypeRegistry.cpp ('k') | Source/wtf/ArrayBufferContents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698