OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, Google Inc. All rights reserved. | 2 * Copyright (c) 2013, 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * 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 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 } | 169 } |
170 | 170 |
171 void ImageBitmapFactories::ImageBitmapLoader::rejectPromise() | 171 void ImageBitmapFactories::ImageBitmapLoader::rejectPromise() |
172 { | 172 { |
173 m_resolver->reject(ScriptValue(m_resolver->scriptState(), v8::Null(m_resolve
r->scriptState()->isolate()))); | 173 m_resolver->reject(ScriptValue(m_resolver->scriptState(), v8::Null(m_resolve
r->scriptState()->isolate()))); |
174 m_factory->didFinishLoading(this); | 174 m_factory->didFinishLoading(this); |
175 } | 175 } |
176 | 176 |
177 void ImageBitmapFactories::ImageBitmapLoader::didFinishLoading() | 177 void ImageBitmapFactories::ImageBitmapLoader::didFinishLoading() |
178 { | 178 { |
179 if (!m_loader.arrayBufferResult()) { | 179 RefPtr<DOMArrayBuffer> buffer = m_loader.arrayBufferResultOrNull(); |
| 180 if (!buffer) { |
180 rejectPromise(); | 181 rejectPromise(); |
181 return; | 182 return; |
182 } | 183 } |
183 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create((char*)m_loader.arr
ayBufferResult()->data(), m_loader.arrayBufferResult()->byteLength()); | 184 // TODO(junov) crbug.com/549191: Is there a way to transfer 'buffer' without
making a copy? |
| 185 // The loaded data is read-only, so it should be possible to avoid copying. |
| 186 RefPtr<SharedBuffer> sharedBuffer = SharedBuffer::create((char*)buffer->data
(), buffer->byteLength()); |
184 | 187 |
185 OwnPtr<ImageSource> source = adoptPtr(new ImageSource()); | 188 OwnPtr<ImageSource> source = adoptPtr(new ImageSource()); |
186 source->setData(*sharedBuffer, true); | 189 source->setData(*sharedBuffer, true); |
187 | 190 |
188 RefPtr<SkImage> frame = source->createFrameAtIndex(0); | 191 RefPtr<SkImage> frame = source->createFrameAtIndex(0); |
189 ASSERT(!frame || (frame->width() && frame->height())); | 192 ASSERT(!frame || (frame->width() && frame->height())); |
190 if (!frame) { | 193 if (!frame) { |
191 rejectPromise(); | 194 rejectPromise(); |
192 return; | 195 return; |
193 } | 196 } |
(...skipping 14 matching lines...) Expand all Loading... |
208 rejectPromise(); | 211 rejectPromise(); |
209 } | 212 } |
210 | 213 |
211 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader) | 214 DEFINE_TRACE(ImageBitmapFactories::ImageBitmapLoader) |
212 { | 215 { |
213 visitor->trace(m_factory); | 216 visitor->trace(m_factory); |
214 visitor->trace(m_resolver); | 217 visitor->trace(m_resolver); |
215 } | 218 } |
216 | 219 |
217 } // namespace blink | 220 } // namespace blink |
OLD | NEW |