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