| 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 ImageData::imageDataStorageFormat(colorSettings->storageFormat()); | 220 ImageData::imageDataStorageFormat(colorSettings->storageFormat()); |
| 221 } | 221 } |
| 222 DOMArrayBufferView* dataArray = | 222 DOMArrayBufferView* dataArray = |
| 223 allocateAndValidateDataArray(4 * static_cast<unsigned>(size.width()) * | 223 allocateAndValidateDataArray(4 * static_cast<unsigned>(size.width()) * |
| 224 static_cast<unsigned>(size.height()), | 224 static_cast<unsigned>(size.height()), |
| 225 storageFormat); | 225 storageFormat); |
| 226 return dataArray ? new ImageData(size, dataArray, colorSettings) : nullptr; | 226 return dataArray ? new ImageData(size, dataArray, colorSettings) : nullptr; |
| 227 } | 227 } |
| 228 | 228 |
| 229 ImageData* ImageData::create(const IntSize& size, | 229 ImageData* ImageData::create(const IntSize& size, |
| 230 DOMArrayBufferView* dataArray, | 230 NotShared<DOMArrayBufferView> dataArray, |
| 231 const ImageDataColorSettings* colorSettings) { | 231 const ImageDataColorSettings* colorSettings) { |
| 232 if (!ImageData::validateConstructorArguments(kParamSize | kParamData, &size, | 232 if (!ImageData::validateConstructorArguments(kParamSize | kParamData, &size, |
| 233 0, 0, dataArray, colorSettings)) | 233 0, 0, dataArray.view(), |
| 234 colorSettings)) |
| 234 return nullptr; | 235 return nullptr; |
| 235 return new ImageData(size, dataArray, colorSettings); | 236 return new ImageData(size, dataArray.view(), colorSettings); |
| 236 } | 237 } |
| 237 | 238 |
| 238 ImageData* ImageData::create(unsigned width, | 239 ImageData* ImageData::create(unsigned width, |
| 239 unsigned height, | 240 unsigned height, |
| 240 ExceptionState& exceptionState) { | 241 ExceptionState& exceptionState) { |
| 241 if (!ImageData::validateConstructorArguments(kParamWidth | kParamHeight, | 242 if (!ImageData::validateConstructorArguments(kParamWidth | kParamHeight, |
| 242 nullptr, width, height, nullptr, | 243 nullptr, width, height, nullptr, |
| 243 nullptr, &exceptionState)) | 244 nullptr, &exceptionState)) |
| 244 return nullptr; | 245 return nullptr; |
| 245 | 246 |
| 246 DOMArrayBufferView* byteArray = allocateAndValidateDataArray( | 247 DOMArrayBufferView* byteArray = allocateAndValidateDataArray( |
| 247 4 * width * height, kUint8ClampedArrayStorageFormat, &exceptionState); | 248 4 * width * height, kUint8ClampedArrayStorageFormat, &exceptionState); |
| 248 return byteArray ? new ImageData(IntSize(width, height), byteArray) : nullptr; | 249 return byteArray ? new ImageData(IntSize(width, height), byteArray) : nullptr; |
| 249 } | 250 } |
| 250 | 251 |
| 251 ImageData* ImageData::create(DOMUint8ClampedArray* data, | 252 ImageData* ImageData::create(NotShared<DOMUint8ClampedArray> data, |
| 252 unsigned width, | 253 unsigned width, |
| 253 ExceptionState& exceptionState) { | 254 ExceptionState& exceptionState) { |
| 254 if (!ImageData::validateConstructorArguments(kParamData | kParamWidth, | 255 if (!ImageData::validateConstructorArguments(kParamData | kParamWidth, |
| 255 nullptr, width, 0, data, nullptr, | 256 nullptr, width, 0, data.view(), |
| 256 &exceptionState)) | 257 nullptr, &exceptionState)) |
| 257 return nullptr; | 258 return nullptr; |
| 258 | 259 |
| 259 unsigned height = data->length() / (width * 4); | 260 unsigned height = data.view()->length() / (width * 4); |
| 260 return new ImageData(IntSize(width, height), data); | 261 return new ImageData(IntSize(width, height), data.view()); |
| 261 } | 262 } |
| 262 | 263 |
| 263 ImageData* ImageData::create(DOMUint8ClampedArray* data, | 264 ImageData* ImageData::create(NotShared<DOMUint8ClampedArray> data, |
| 264 unsigned width, | 265 unsigned width, |
| 265 unsigned height, | 266 unsigned height, |
| 266 ExceptionState& exceptionState) { | 267 ExceptionState& exceptionState) { |
| 267 if (!ImageData::validateConstructorArguments( | 268 if (!ImageData::validateConstructorArguments( |
| 268 kParamData | kParamWidth | kParamHeight, nullptr, width, height, data, | 269 kParamData | kParamWidth | kParamHeight, nullptr, width, height, |
| 269 nullptr, &exceptionState)) | 270 data.view(), nullptr, &exceptionState)) |
| 270 return nullptr; | 271 return nullptr; |
| 271 | 272 |
| 272 return new ImageData(IntSize(width, height), data); | 273 return new ImageData(IntSize(width, height), data.view()); |
| 273 } | 274 } |
| 274 | 275 |
| 275 ImageData* ImageData::createImageData( | 276 ImageData* ImageData::createImageData( |
| 276 unsigned width, | 277 unsigned width, |
| 277 unsigned height, | 278 unsigned height, |
| 278 const ImageDataColorSettings& colorSettings, | 279 const ImageDataColorSettings& colorSettings, |
| 279 ExceptionState& exceptionState) { | 280 ExceptionState& exceptionState) { |
| 280 if (!ImageData::validateConstructorArguments(kParamWidth | kParamHeight, | 281 if (!ImageData::validateConstructorArguments(kParamWidth | kParamHeight, |
| 281 nullptr, width, height, nullptr, | 282 nullptr, width, height, nullptr, |
| 282 &colorSettings, &exceptionState)) | 283 &colorSettings, &exceptionState)) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 298 unsigned height, | 299 unsigned height, |
| 299 ImageDataColorSettings& colorSettings, | 300 ImageDataColorSettings& colorSettings, |
| 300 ExceptionState& exceptionState) { | 301 ExceptionState& exceptionState) { |
| 301 DOMArrayBufferView* bufferView = nullptr; | 302 DOMArrayBufferView* bufferView = nullptr; |
| 302 // When pixels data is provided, we need to override the storage format of | 303 // When pixels data is provided, we need to override the storage format of |
| 303 // ImageDataColorSettings with the one that matches the data type of the | 304 // ImageDataColorSettings with the one that matches the data type of the |
| 304 // pixels. | 305 // pixels. |
| 305 String storageFormatName; | 306 String storageFormatName; |
| 306 | 307 |
| 307 if (data.isUint8ClampedArray()) { | 308 if (data.isUint8ClampedArray()) { |
| 308 bufferView = data.getAsUint8ClampedArray(); | 309 bufferView = data.getAsUint8ClampedArray().view(); |
| 309 storageFormatName = kUint8ClampedArrayStorageFormatName; | 310 storageFormatName = kUint8ClampedArrayStorageFormatName; |
| 310 } else if (data.isUint16Array()) { | 311 } else if (data.isUint16Array()) { |
| 311 bufferView = data.getAsUint16Array(); | 312 bufferView = data.getAsUint16Array().view(); |
| 312 storageFormatName = kUint16ArrayStorageFormatName; | 313 storageFormatName = kUint16ArrayStorageFormatName; |
| 313 } else if (data.isFloat32Array()) { | 314 } else if (data.isFloat32Array()) { |
| 314 bufferView = data.getAsFloat32Array(); | 315 bufferView = data.getAsFloat32Array().view(); |
| 315 storageFormatName = kFloat32ArrayStorageFormatName; | 316 storageFormatName = kFloat32ArrayStorageFormatName; |
| 316 } else { | 317 } else { |
| 317 NOTREACHED(); | 318 NOTREACHED(); |
| 318 } | 319 } |
| 319 | 320 |
| 320 if (storageFormatName != colorSettings.storageFormat()) | 321 if (storageFormatName != colorSettings.storageFormat()) |
| 321 colorSettings.setStorageFormat(storageFormatName); | 322 colorSettings.setStorageFormat(storageFormatName); |
| 322 | 323 |
| 323 if (!ImageData::validateConstructorArguments( | 324 if (!ImageData::validateConstructorArguments( |
| 324 kParamData | kParamWidth | kParamHeight, nullptr, width, height, | 325 kParamData | kParamWidth | kParamHeight, nullptr, width, height, |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 SECURITY_CHECK(static_cast<unsigned>(size.width() * size.height() * 4) <= | 755 SECURITY_CHECK(static_cast<unsigned>(size.width() * size.height() * 4) <= |
| 755 m_dataF32->length()); | 756 m_dataF32->length()); |
| 756 break; | 757 break; |
| 757 | 758 |
| 758 default: | 759 default: |
| 759 NOTREACHED(); | 760 NOTREACHED(); |
| 760 } | 761 } |
| 761 } | 762 } |
| 762 | 763 |
| 763 } // namespace blink | 764 } // namespace blink |
| OLD | NEW |