OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2008 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 * | 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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 ImageData::GetImageDataStorageFormat(color_settings->storageFormat()); | 222 ImageData::GetImageDataStorageFormat(color_settings->storageFormat()); |
223 } | 223 } |
224 DOMArrayBufferView* data_array = | 224 DOMArrayBufferView* data_array = |
225 AllocateAndValidateDataArray(4 * static_cast<unsigned>(size.Width()) * | 225 AllocateAndValidateDataArray(4 * static_cast<unsigned>(size.Width()) * |
226 static_cast<unsigned>(size.Height()), | 226 static_cast<unsigned>(size.Height()), |
227 storage_format); | 227 storage_format); |
228 return data_array ? new ImageData(size, data_array, color_settings) : nullptr; | 228 return data_array ? new ImageData(size, data_array, color_settings) : nullptr; |
229 } | 229 } |
230 | 230 |
231 ImageData* ImageData::Create(const IntSize& size, | 231 ImageData* ImageData::Create(const IntSize& size, |
232 DOMArrayBufferView* data_array, | 232 NotShared<DOMArrayBufferView> data_array, |
233 const ImageDataColorSettings* color_settings) { | 233 const ImageDataColorSettings* color_settings) { |
234 if (!ImageData::ValidateConstructorArguments( | 234 if (!ImageData::ValidateConstructorArguments(kParamSize | kParamData, &size, |
235 kParamSize | kParamData, &size, 0, 0, data_array, color_settings)) | 235 0, 0, data_array.View(), |
| 236 color_settings)) |
236 return nullptr; | 237 return nullptr; |
237 return new ImageData(size, data_array, color_settings); | 238 return new ImageData(size, data_array.View(), color_settings); |
238 } | 239 } |
239 | 240 |
240 ImageData* ImageData::Create(unsigned width, | 241 ImageData* ImageData::Create(unsigned width, |
241 unsigned height, | 242 unsigned height, |
242 ExceptionState& exception_state) { | 243 ExceptionState& exception_state) { |
243 if (!ImageData::ValidateConstructorArguments(kParamWidth | kParamHeight, | 244 if (!ImageData::ValidateConstructorArguments(kParamWidth | kParamHeight, |
244 nullptr, width, height, nullptr, | 245 nullptr, width, height, nullptr, |
245 nullptr, &exception_state)) | 246 nullptr, &exception_state)) |
246 return nullptr; | 247 return nullptr; |
247 | 248 |
248 DOMArrayBufferView* byte_array = AllocateAndValidateDataArray( | 249 DOMArrayBufferView* byte_array = AllocateAndValidateDataArray( |
249 4 * width * height, kUint8ClampedArrayStorageFormat, &exception_state); | 250 4 * width * height, kUint8ClampedArrayStorageFormat, &exception_state); |
250 return byte_array ? new ImageData(IntSize(width, height), byte_array) | 251 return byte_array ? new ImageData(IntSize(width, height), byte_array) |
251 : nullptr; | 252 : nullptr; |
252 } | 253 } |
253 | 254 |
254 ImageData* ImageData::Create(DOMUint8ClampedArray* data, | 255 ImageData* ImageData::Create(NotShared<DOMUint8ClampedArray> data, |
255 unsigned width, | 256 unsigned width, |
256 ExceptionState& exception_state) { | 257 ExceptionState& exception_state) { |
257 if (!ImageData::ValidateConstructorArguments(kParamData | kParamWidth, | 258 if (!ImageData::ValidateConstructorArguments(kParamData | kParamWidth, |
258 nullptr, width, 0, data, nullptr, | 259 nullptr, width, 0, data.View(), |
259 &exception_state)) | 260 nullptr, &exception_state)) |
260 return nullptr; | 261 return nullptr; |
261 | 262 |
262 unsigned height = data->length() / (width * 4); | 263 unsigned height = data.View()->length() / (width * 4); |
263 return new ImageData(IntSize(width, height), data); | 264 return new ImageData(IntSize(width, height), data.View()); |
264 } | 265 } |
265 | 266 |
266 ImageData* ImageData::Create(DOMUint8ClampedArray* data, | 267 ImageData* ImageData::Create(NotShared<DOMUint8ClampedArray> data, |
267 unsigned width, | 268 unsigned width, |
268 unsigned height, | 269 unsigned height, |
269 ExceptionState& exception_state) { | 270 ExceptionState& exception_state) { |
270 if (!ImageData::ValidateConstructorArguments( | 271 if (!ImageData::ValidateConstructorArguments( |
271 kParamData | kParamWidth | kParamHeight, nullptr, width, height, data, | 272 kParamData | kParamWidth | kParamHeight, nullptr, width, height, |
272 nullptr, &exception_state)) | 273 data.View(), nullptr, &exception_state)) |
273 return nullptr; | 274 return nullptr; |
274 | 275 |
275 return new ImageData(IntSize(width, height), data); | 276 return new ImageData(IntSize(width, height), data.View()); |
276 } | 277 } |
277 | 278 |
278 ImageData* ImageData::createImageData( | 279 ImageData* ImageData::createImageData( |
279 unsigned width, | 280 unsigned width, |
280 unsigned height, | 281 unsigned height, |
281 const ImageDataColorSettings& color_settings, | 282 const ImageDataColorSettings& color_settings, |
282 ExceptionState& exception_state) { | 283 ExceptionState& exception_state) { |
283 if (!ImageData::ValidateConstructorArguments( | 284 if (!ImageData::ValidateConstructorArguments( |
284 kParamWidth | kParamHeight, nullptr, width, height, nullptr, | 285 kParamWidth | kParamHeight, nullptr, width, height, nullptr, |
285 &color_settings, &exception_state)) | 286 &color_settings, &exception_state)) |
(...skipping 15 matching lines...) Expand all Loading... |
301 unsigned height, | 302 unsigned height, |
302 ImageDataColorSettings& color_settings, | 303 ImageDataColorSettings& color_settings, |
303 ExceptionState& exception_state) { | 304 ExceptionState& exception_state) { |
304 DOMArrayBufferView* buffer_view = nullptr; | 305 DOMArrayBufferView* buffer_view = nullptr; |
305 // When pixels data is provided, we need to override the storage format of | 306 // When pixels data is provided, we need to override the storage format of |
306 // ImageDataColorSettings with the one that matches the data type of the | 307 // ImageDataColorSettings with the one that matches the data type of the |
307 // pixels. | 308 // pixels. |
308 String storage_format_name; | 309 String storage_format_name; |
309 | 310 |
310 if (data.isUint8ClampedArray()) { | 311 if (data.isUint8ClampedArray()) { |
311 buffer_view = data.getAsUint8ClampedArray(); | 312 buffer_view = data.getAsUint8ClampedArray().View(); |
312 storage_format_name = kUint8ClampedArrayStorageFormatName; | 313 storage_format_name = kUint8ClampedArrayStorageFormatName; |
313 } else if (data.isUint16Array()) { | 314 } else if (data.isUint16Array()) { |
314 buffer_view = data.getAsUint16Array(); | 315 buffer_view = data.getAsUint16Array().View(); |
315 storage_format_name = kUint16ArrayStorageFormatName; | 316 storage_format_name = kUint16ArrayStorageFormatName; |
316 } else if (data.isFloat32Array()) { | 317 } else if (data.isFloat32Array()) { |
317 buffer_view = data.getAsFloat32Array(); | 318 buffer_view = data.getAsFloat32Array().View(); |
318 storage_format_name = kFloat32ArrayStorageFormatName; | 319 storage_format_name = kFloat32ArrayStorageFormatName; |
319 } else { | 320 } else { |
320 NOTREACHED(); | 321 NOTREACHED(); |
321 } | 322 } |
322 | 323 |
323 if (storage_format_name != color_settings.storageFormat()) | 324 if (storage_format_name != color_settings.storageFormat()) |
324 color_settings.setStorageFormat(storage_format_name); | 325 color_settings.setStorageFormat(storage_format_name); |
325 | 326 |
326 if (!ImageData::ValidateConstructorArguments( | 327 if (!ImageData::ValidateConstructorArguments( |
327 kParamData | kParamWidth | kParamHeight, nullptr, width, height, | 328 kParamData | kParamWidth | kParamHeight, nullptr, width, height, |
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
759 SECURITY_CHECK(static_cast<unsigned>(size.Width() * size.Height() * 4) <= | 760 SECURITY_CHECK(static_cast<unsigned>(size.Width() * size.Height() * 4) <= |
760 data_f32_->length()); | 761 data_f32_->length()); |
761 break; | 762 break; |
762 | 763 |
763 default: | 764 default: |
764 NOTREACHED(); | 765 NOTREACHED(); |
765 } | 766 } |
766 } | 767 } |
767 | 768 |
768 } // namespace blink | 769 } // namespace blink |
OLD | NEW |