| 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 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 WTF::ArrayBufferContents::InitializationPolicy initialization_policy = | 391 WTF::ArrayBufferContents::InitializationPolicy initialization_policy = |
| 392 may_have_stray_area ? WTF::ArrayBufferContents::kZeroInitialize | 392 may_have_stray_area ? WTF::ArrayBufferContents::kZeroInitialize |
| 393 : WTF::ArrayBufferContents::kDontInitialize; | 393 : WTF::ArrayBufferContents::kDontInitialize; |
| 394 auto data = WTF::ArrayBufferContents::CreateDataHandle(alloc_size_in_bytes, | 394 auto data = WTF::ArrayBufferContents::CreateDataHandle(alloc_size_in_bytes, |
| 395 initialization_policy); | 395 initialization_policy); |
| 396 if (!data) | 396 if (!data) |
| 397 return false; | 397 return false; |
| 398 WTF::ArrayBufferContents result(std::move(data), alloc_size_in_bytes, | 398 WTF::ArrayBufferContents result(std::move(data), alloc_size_in_bytes, |
| 399 WTF::ArrayBufferContents::kNotShared); | 399 WTF::ArrayBufferContents::kNotShared); |
| 400 | 400 |
| 401 // Skia does not support unpremultiplied read with an F16 to 8888 conversion | 401 SkAlphaType alpha_type = (multiplied == kPremultiplied) |
| 402 bool use_f16_workaround = surface_->ColorType() == kRGBA_F16_SkColorType; | |
| 403 | |
| 404 SkAlphaType alpha_type = (multiplied == kPremultiplied || use_f16_workaround) | |
| 405 ? kPremul_SkAlphaType | 402 ? kPremul_SkAlphaType |
| 406 : kUnpremul_SkAlphaType; | 403 : kUnpremul_SkAlphaType; |
| 407 // The workaround path use a canvas draw under the hood, which can only | 404 SkColorType color_type = (surface_->ColorType() == kRGBA_F16_SkColorType) |
| 408 // use N32 at this time. | 405 ? kRGBA_F16_SkColorType |
| 409 SkColorType color_type = | 406 : kRGBA_8888_SkColorType; |
| 410 use_f16_workaround ? kN32_SkColorType : kRGBA_8888_SkColorType; | |
| 411 | |
| 412 // Only use sRGB when the surface has a color space. Converting untagged | |
| 413 // pixels to a particular color space is not well-defined in Skia. | |
| 414 sk_sp<SkColorSpace> color_space = nullptr; | |
| 415 if (surface_->ColorSpace()) { | |
| 416 color_space = SkColorSpace::MakeSRGB(); | |
| 417 } | |
| 418 | 407 |
| 419 SkImageInfo info = SkImageInfo::Make(rect.Width(), rect.Height(), color_type, | 408 SkImageInfo info = SkImageInfo::Make(rect.Width(), rect.Height(), color_type, |
| 420 alpha_type, std::move(color_space)); | 409 alpha_type, surface_->ColorSpace()); |
| 421 | 410 |
| 422 snapshot->readPixels(info, result.Data(), bytes_per_pixel * rect.Width(), | 411 snapshot->readPixels(info, result.Data(), bytes_per_pixel * rect.Width(), |
| 423 rect.X(), rect.Y()); | 412 rect.X(), rect.Y()); |
| 424 gpu_readback_invoked_in_current_frame_ = true; | 413 gpu_readback_invoked_in_current_frame_ = true; |
| 425 | |
| 426 if (use_f16_workaround) { | |
| 427 uint32_t* pixel = (uint32_t*)result.Data(); | |
| 428 size_t pixel_count = alloc_size_in_bytes / sizeof(uint32_t); | |
| 429 // TODO(skbug.com/5853): make readPixels support RGBA output so that we no | |
| 430 // longer | |
| 431 // have to do this. | |
| 432 if (kN32_SkColorType == kBGRA_8888_SkColorType) { | |
| 433 // Convert BGRA to RGBA if necessary on this platform. | |
| 434 SkSwapRB(pixel, pixel, pixel_count); | |
| 435 } | |
| 436 // TODO(skbug.com/5853): We should really be doing the unpremultiply in | |
| 437 // linear space | |
| 438 // and skia should provide that service. | |
| 439 if (multiplied == kUnmultiplied) { | |
| 440 for (; pixel_count; --pixel_count) { | |
| 441 *pixel = SkUnPreMultiply::UnPreMultiplyPreservingByteOrder(*pixel); | |
| 442 ++pixel; | |
| 443 } | |
| 444 } | |
| 445 } | |
| 446 | |
| 447 result.Transfer(contents); | 414 result.Transfer(contents); |
| 448 return true; | 415 return true; |
| 449 } | 416 } |
| 450 | 417 |
| 451 void ImageBuffer::PutByteArray(Multiply multiplied, | 418 void ImageBuffer::PutByteArray(Multiply multiplied, |
| 452 const unsigned char* source, | 419 const unsigned char* source, |
| 453 const IntSize& source_size, | 420 const IntSize& source_size, |
| 454 const IntRect& source_rect, | 421 const IntRect& source_rect, |
| 455 const IntPoint& dest_point) { | 422 const IntPoint& dest_point) { |
| 456 if (!IsSurfaceValid()) | 423 if (!IsSurfaceValid()) |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 DCHECK(MIMETypeRegistry::IsSupportedImageMIMETypeForEncoding(mime_type)); | 592 DCHECK(MIMETypeRegistry::IsSupportedImageMIMETypeForEncoding(mime_type)); |
| 626 | 593 |
| 627 Vector<unsigned char> result; | 594 Vector<unsigned char> result; |
| 628 if (!EncodeImage(mime_type, quality, &result)) | 595 if (!EncodeImage(mime_type, quality, &result)) |
| 629 return "data:,"; | 596 return "data:,"; |
| 630 | 597 |
| 631 return "data:" + mime_type + ";base64," + Base64Encode(result); | 598 return "data:" + mime_type + ";base64," + Base64Encode(result); |
| 632 } | 599 } |
| 633 | 600 |
| 634 } // namespace blink | 601 } // namespace blink |
| OLD | NEW |