| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2008, Google Inc. All rights reserved. | 2 * Copyright (c) 2008, Google Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> | 3 * Copyright (C) 2009 Dirk Schulze <krit@webkit.org> |
| 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. | 4 * Copyright (C) 2010 Torch Mobile (Beijing) Co. Ltd. All rights reserved. |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions are | 7 * modification, are permitted provided that the following conditions are |
| 8 * met: | 8 * met: |
| 9 * | 9 * |
| 10 * * Redistributions of source code must retain the above copyright | 10 * * Redistributions of source code must retain the above copyright |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 if (m_surface->colorSpace()) | 339 if (m_surface->colorSpace()) |
| 340 bytesPerPixel = SkColorTypeBytesPerPixel(m_surface->colorType()); | 340 bytesPerPixel = SkColorTypeBytesPerPixel(m_surface->colorType()); |
| 341 CheckedNumeric<int> dataSize = bytesPerPixel; | 341 CheckedNumeric<int> dataSize = bytesPerPixel; |
| 342 dataSize *= rect.width(); | 342 dataSize *= rect.width(); |
| 343 dataSize *= rect.height(); | 343 dataSize *= rect.height(); |
| 344 if (!dataSize.IsValid()) | 344 if (!dataSize.IsValid()) |
| 345 return false; | 345 return false; |
| 346 | 346 |
| 347 if (!isSurfaceValid()) { | 347 if (!isSurfaceValid()) { |
| 348 size_t allocSizeInBytes = rect.width() * rect.height() * bytesPerPixel; | 348 size_t allocSizeInBytes = rect.width() * rect.height() * bytesPerPixel; |
| 349 void* data; | 349 auto data = WTF::ArrayBufferContents::createDataHandle( |
| 350 WTF::ArrayBufferContents::allocateMemoryOrNull( | 350 allocSizeInBytes, WTF::ArrayBufferContents::ZeroInitialize); |
| 351 allocSizeInBytes, WTF::ArrayBufferContents::ZeroInitialize, data); | |
| 352 if (!data) | 351 if (!data) |
| 353 return false; | 352 return false; |
| 354 WTF::ArrayBufferContents result(data, allocSizeInBytes, | 353 WTF::ArrayBufferContents result(std::move(data), allocSizeInBytes, |
| 355 WTF::ArrayBufferContents::NotShared); | 354 WTF::ArrayBufferContents::NotShared); |
| 356 result.transfer(contents); | 355 result.transfer(contents); |
| 357 return true; | 356 return true; |
| 358 } | 357 } |
| 359 | 358 |
| 360 DCHECK(canvas()); | 359 DCHECK(canvas()); |
| 361 | 360 |
| 362 if (ExpensiveCanvasHeuristicParameters::GetImageDataForcesNoAcceleration && | 361 if (ExpensiveCanvasHeuristicParameters::GetImageDataForcesNoAcceleration && |
| 363 !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled()) { | 362 !RuntimeEnabledFeatures::canvas2dFixedRenderingModeEnabled()) { |
| 364 const_cast<ImageBuffer*>(this)->disableAcceleration(); | 363 const_cast<ImageBuffer*>(this)->disableAcceleration(); |
| 365 } | 364 } |
| 366 | 365 |
| 367 sk_sp<SkImage> snapshot = m_surface->newImageSnapshot( | 366 sk_sp<SkImage> snapshot = m_surface->newImageSnapshot( |
| 368 PreferNoAcceleration, SnapshotReasonGetImageData); | 367 PreferNoAcceleration, SnapshotReasonGetImageData); |
| 369 if (!snapshot) | 368 if (!snapshot) |
| 370 return false; | 369 return false; |
| 371 | 370 |
| 372 const bool mayHaveStrayArea = | 371 const bool mayHaveStrayArea = |
| 373 m_surface->isAccelerated() // GPU readback may fail silently | 372 m_surface->isAccelerated() // GPU readback may fail silently |
| 374 || rect.x() < 0 || rect.y() < 0 || | 373 || rect.x() < 0 || rect.y() < 0 || |
| 375 rect.maxX() > m_surface->size().width() || | 374 rect.maxX() > m_surface->size().width() || |
| 376 rect.maxY() > m_surface->size().height(); | 375 rect.maxY() > m_surface->size().height(); |
| 377 size_t allocSizeInBytes = rect.width() * rect.height() * bytesPerPixel; | 376 size_t allocSizeInBytes = rect.width() * rect.height() * bytesPerPixel; |
| 378 void* data; | |
| 379 WTF::ArrayBufferContents::InitializationPolicy initializationPolicy = | 377 WTF::ArrayBufferContents::InitializationPolicy initializationPolicy = |
| 380 mayHaveStrayArea ? WTF::ArrayBufferContents::ZeroInitialize | 378 mayHaveStrayArea ? WTF::ArrayBufferContents::ZeroInitialize |
| 381 : WTF::ArrayBufferContents::DontInitialize; | 379 : WTF::ArrayBufferContents::DontInitialize; |
| 382 WTF::ArrayBufferContents::allocateMemoryOrNull(allocSizeInBytes, | 380 auto data = WTF::ArrayBufferContents::createDataHandle(allocSizeInBytes, |
| 383 initializationPolicy, data); | 381 initializationPolicy); |
| 384 if (!data) | 382 if (!data) |
| 385 return false; | 383 return false; |
| 386 WTF::ArrayBufferContents result(data, allocSizeInBytes, | 384 WTF::ArrayBufferContents result(std::move(data), allocSizeInBytes, |
| 387 WTF::ArrayBufferContents::NotShared); | 385 WTF::ArrayBufferContents::NotShared); |
| 388 | 386 |
| 389 // Skia does not support unpremultiplied read with an F16 to 8888 conversion | 387 // Skia does not support unpremultiplied read with an F16 to 8888 conversion |
| 390 bool useF16Workaround = m_surface->colorType() == kRGBA_F16_SkColorType; | 388 bool useF16Workaround = m_surface->colorType() == kRGBA_F16_SkColorType; |
| 391 | 389 |
| 392 SkAlphaType alphaType = (multiplied == Premultiplied || useF16Workaround) | 390 SkAlphaType alphaType = (multiplied == Premultiplied || useF16Workaround) |
| 393 ? kPremul_SkAlphaType | 391 ? kPremul_SkAlphaType |
| 394 : kUnpremul_SkAlphaType; | 392 : kUnpremul_SkAlphaType; |
| 395 // The workaround path use a canvas draw under the hood, which can only | 393 // The workaround path use a canvas draw under the hood, which can only |
| 396 // use N32 at this time. | 394 // use N32 at this time. |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 608 DCHECK(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); | 606 DCHECK(MIMETypeRegistry::isSupportedImageMIMETypeForEncoding(mimeType)); |
| 609 | 607 |
| 610 Vector<unsigned char> result; | 608 Vector<unsigned char> result; |
| 611 if (!encodeImage(mimeType, quality, &result)) | 609 if (!encodeImage(mimeType, quality, &result)) |
| 612 return "data:,"; | 610 return "data:,"; |
| 613 | 611 |
| 614 return "data:" + mimeType + ";base64," + base64Encode(result); | 612 return "data:" + mimeType + ";base64," + base64Encode(result); |
| 615 } | 613 } |
| 616 | 614 |
| 617 } // namespace blink | 615 } // namespace blink |
| OLD | NEW |