| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "platform/graphics/gpu/WebGLImageConversion.h" | 6 #include "platform/graphics/gpu/WebGLImageConversion.h" |
| 7 | 7 |
| 8 #include "platform/CheckedInt.h" | 8 #include "platform/CheckedInt.h" |
| 9 #include "platform/graphics/ImageObserver.h" | 9 #include "platform/graphics/ImageObserver.h" |
| 10 #include "platform/graphics/cpu/arm/WebGLImageConversionNEON.h" | 10 #if HAVE(ARM_NEON_INTRINSICS) |
| 11 #include "platform/graphics/cpu/arm/gpu/WebGLImageConversionNEON.h" |
| 12 #endif |
| 11 #include "platform/image-decoders/ImageDecoder.h" | 13 #include "platform/image-decoders/ImageDecoder.h" |
| 12 #include "wtf/OwnPtr.h" | 14 #include "wtf/OwnPtr.h" |
| 13 #include "wtf/PassOwnPtr.h" | 15 #include "wtf/PassOwnPtr.h" |
| 14 | 16 |
| 15 namespace blink { | 17 namespace blink { |
| 16 | 18 |
| 17 namespace { | 19 namespace { |
| 18 | 20 |
| 19 WebGLImageConversion::DataFormat getDataFormat(GLenum destinationFormat, GLenum
destinationType) | 21 WebGLImageConversion::DataFormat getDataFormat(GLenum destinationFormat, GLenum
destinationType) |
| 20 { | 22 { |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 uint32_t brMask = 0x00ff00ff; | 298 uint32_t brMask = 0x00ff00ff; |
| 297 uint32_t gaMask = 0xff00ff00; | 299 uint32_t gaMask = 0xff00ff00; |
| 298 #endif | 300 #endif |
| 299 uint32_t rgba = (((bgra >> 16) | (bgra << 16)) & brMask) | (bgra & gaMas
k); | 301 uint32_t rgba = (((bgra >> 16) | (bgra << 16)) & brMask) | (bgra & gaMas
k); |
| 300 destination32[i] = rgba; | 302 destination32[i] = rgba; |
| 301 } | 303 } |
| 302 } | 304 } |
| 303 | 305 |
| 304 template<> void unpack<WebGLImageConversion::DataFormatRGBA5551, uint16_t, uint8
_t>(const uint16_t* source, uint8_t* destination, unsigned pixelsPerRow) | 306 template<> void unpack<WebGLImageConversion::DataFormatRGBA5551, uint16_t, uint8
_t>(const uint16_t* source, uint8_t* destination, unsigned pixelsPerRow) |
| 305 { | 307 { |
| 306 #if HAVE(ARM_NEON_INTRINSICS) | 308 WTF_CPU_ARM_NEON_WRAP(SIMD::unpackOneRowOfRGBA5551ToRGBA8)(source, destinati
on, pixelsPerRow); |
| 307 SIMD::unpackOneRowOfRGBA5551ToRGBA8(source, destination, pixelsPerRow); | |
| 308 #endif | |
| 309 for (unsigned i = 0; i < pixelsPerRow; ++i) { | 309 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
| 310 uint16_t packedValue = source[0]; | 310 uint16_t packedValue = source[0]; |
| 311 uint8_t r = packedValue >> 11; | 311 uint8_t r = packedValue >> 11; |
| 312 uint8_t g = (packedValue >> 6) & 0x1F; | 312 uint8_t g = (packedValue >> 6) & 0x1F; |
| 313 uint8_t b = (packedValue >> 1) & 0x1F; | 313 uint8_t b = (packedValue >> 1) & 0x1F; |
| 314 destination[0] = (r << 3) | (r & 0x7); | 314 destination[0] = (r << 3) | (r & 0x7); |
| 315 destination[1] = (g << 3) | (g & 0x7); | 315 destination[1] = (g << 3) | (g & 0x7); |
| 316 destination[2] = (b << 3) | (b & 0x7); | 316 destination[2] = (b << 3) | (b & 0x7); |
| 317 destination[3] = (packedValue & 0x1) ? 0xFF : 0x0; | 317 destination[3] = (packedValue & 0x1) ? 0xFF : 0x0; |
| 318 source += 1; | 318 source += 1; |
| 319 destination += 4; | 319 destination += 4; |
| 320 } | 320 } |
| 321 } | 321 } |
| 322 | 322 |
| 323 template<> void unpack<WebGLImageConversion::DataFormatRGBA4444, uint16_t, uint8
_t>(const uint16_t* source, uint8_t* destination, unsigned pixelsPerRow) | 323 template<> void unpack<WebGLImageConversion::DataFormatRGBA4444, uint16_t, uint8
_t>(const uint16_t* source, uint8_t* destination, unsigned pixelsPerRow) |
| 324 { | 324 { |
| 325 #if HAVE(ARM_NEON_INTRINSICS) | 325 WTF_CPU_ARM_NEON_WRAP(SIMD::unpackOneRowOfRGBA4444ToRGBA8)(source, destinati
on, pixelsPerRow); |
| 326 SIMD::unpackOneRowOfRGBA4444ToRGBA8(source, destination, pixelsPerRow); | |
| 327 #endif | |
| 328 for (unsigned i = 0; i < pixelsPerRow; ++i) { | 326 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
| 329 uint16_t packedValue = source[0]; | 327 uint16_t packedValue = source[0]; |
| 330 uint8_t r = packedValue >> 12; | 328 uint8_t r = packedValue >> 12; |
| 331 uint8_t g = (packedValue >> 8) & 0x0F; | 329 uint8_t g = (packedValue >> 8) & 0x0F; |
| 332 uint8_t b = (packedValue >> 4) & 0x0F; | 330 uint8_t b = (packedValue >> 4) & 0x0F; |
| 333 uint8_t a = packedValue & 0x0F; | 331 uint8_t a = packedValue & 0x0F; |
| 334 destination[0] = r << 4 | r; | 332 destination[0] = r << 4 | r; |
| 335 destination[1] = g << 4 | g; | 333 destination[1] = g << 4 | g; |
| 336 destination[2] = b << 4 | b; | 334 destination[2] = b << 4 | b; |
| 337 destination[3] = a << 4 | a; | 335 destination[3] = a << 4 | a; |
| 338 source += 1; | 336 source += 1; |
| 339 destination += 4; | 337 destination += 4; |
| 340 } | 338 } |
| 341 } | 339 } |
| 342 | 340 |
| 343 template<> void unpack<WebGLImageConversion::DataFormatRGB565, uint16_t, uint8_t
>(const uint16_t* source, uint8_t* destination, unsigned pixelsPerRow) | 341 template<> void unpack<WebGLImageConversion::DataFormatRGB565, uint16_t, uint8_t
>(const uint16_t* source, uint8_t* destination, unsigned pixelsPerRow) |
| 344 { | 342 { |
| 345 #if HAVE(ARM_NEON_INTRINSICS) | 343 WTF_CPU_ARM_NEON_WRAP(SIMD::unpackOneRowOfRGB565ToRGBA8)(source, destination
, pixelsPerRow); |
| 346 SIMD::unpackOneRowOfRGB565ToRGBA8(source, destination, pixelsPerRow); | |
| 347 #endif | |
| 348 for (unsigned i = 0; i < pixelsPerRow; ++i) { | 344 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
| 349 uint16_t packedValue = source[0]; | 345 uint16_t packedValue = source[0]; |
| 350 uint8_t r = packedValue >> 11; | 346 uint8_t r = packedValue >> 11; |
| 351 uint8_t g = (packedValue >> 5) & 0x3F; | 347 uint8_t g = (packedValue >> 5) & 0x3F; |
| 352 uint8_t b = packedValue & 0x1F; | 348 uint8_t b = packedValue & 0x1F; |
| 353 destination[0] = (r << 3) | (r & 0x7); | 349 destination[0] = (r << 3) | (r & 0x7); |
| 354 destination[1] = (g << 2) | (g & 0x3); | 350 destination[1] = (g << 2) | (g & 0x3); |
| 355 destination[2] = (b << 3) | (b & 0x7); | 351 destination[2] = (b << 3) | (b & 0x7); |
| 356 destination[3] = 0xFF; | 352 destination[3] = 0xFF; |
| 357 source += 1; | 353 source += 1; |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 destination[1] = sourceG; | 691 destination[1] = sourceG; |
| 696 destination[2] = sourceB; | 692 destination[2] = sourceB; |
| 697 destination[3] = source[3]; | 693 destination[3] = source[3]; |
| 698 source += 4; | 694 source += 4; |
| 699 destination += 4; | 695 destination += 4; |
| 700 } | 696 } |
| 701 } | 697 } |
| 702 | 698 |
| 703 template<> void pack<WebGLImageConversion::DataFormatRGBA4444, WebGLImageConvers
ion::AlphaDoNothing, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destina
tion, unsigned pixelsPerRow) | 699 template<> void pack<WebGLImageConversion::DataFormatRGBA4444, WebGLImageConvers
ion::AlphaDoNothing, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destina
tion, unsigned pixelsPerRow) |
| 704 { | 700 { |
| 705 #if HAVE(ARM_NEON_INTRINSICS) | 701 WTF_CPU_ARM_NEON_WRAP(SIMD::packOneRowOfRGBA8ToUnsignedShort4444)(source, de
stination, pixelsPerRow); |
| 706 SIMD::packOneRowOfRGBA8ToUnsignedShort4444(source, destination, pixelsPerRow
); | |
| 707 #endif | |
| 708 for (unsigned i = 0; i < pixelsPerRow; ++i) { | 702 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
| 709 *destination = (((source[0] & 0xF0) << 8) | 703 *destination = (((source[0] & 0xF0) << 8) |
| 710 | ((source[1] & 0xF0) << 4) | 704 | ((source[1] & 0xF0) << 4) |
| 711 | (source[2] & 0xF0) | 705 | (source[2] & 0xF0) |
| 712 | (source[3] >> 4)); | 706 | (source[3] >> 4)); |
| 713 source += 4; | 707 source += 4; |
| 714 destination += 1; | 708 destination += 1; |
| 715 } | 709 } |
| 716 } | 710 } |
| 717 | 711 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 743 | ((sourceG & 0xF0) << 4) | 737 | ((sourceG & 0xF0) << 4) |
| 744 | (sourceB & 0xF0) | 738 | (sourceB & 0xF0) |
| 745 | (source[3] >> 4)); | 739 | (source[3] >> 4)); |
| 746 source += 4; | 740 source += 4; |
| 747 destination += 1; | 741 destination += 1; |
| 748 } | 742 } |
| 749 } | 743 } |
| 750 | 744 |
| 751 template<> void pack<WebGLImageConversion::DataFormatRGBA5551, WebGLImageConvers
ion::AlphaDoNothing, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destina
tion, unsigned pixelsPerRow) | 745 template<> void pack<WebGLImageConversion::DataFormatRGBA5551, WebGLImageConvers
ion::AlphaDoNothing, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destina
tion, unsigned pixelsPerRow) |
| 752 { | 746 { |
| 753 #if HAVE(ARM_NEON_INTRINSICS) | 747 WTF_CPU_ARM_NEON_WRAP(SIMD::packOneRowOfRGBA8ToUnsignedShort5551)(source, de
stination, pixelsPerRow); |
| 754 SIMD::packOneRowOfRGBA8ToUnsignedShort5551(source, destination, pixelsPerRow
); | |
| 755 #endif | |
| 756 for (unsigned i = 0; i < pixelsPerRow; ++i) { | 748 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
| 757 *destination = (((source[0] & 0xF8) << 8) | 749 *destination = (((source[0] & 0xF8) << 8) |
| 758 | ((source[1] & 0xF8) << 3) | 750 | ((source[1] & 0xF8) << 3) |
| 759 | ((source[2] & 0xF8) >> 2) | 751 | ((source[2] & 0xF8) >> 2) |
| 760 | (source[3] >> 7)); | 752 | (source[3] >> 7)); |
| 761 source += 4; | 753 source += 4; |
| 762 destination += 1; | 754 destination += 1; |
| 763 } | 755 } |
| 764 } | 756 } |
| 765 | 757 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 791 | ((sourceG & 0xF8) << 3) | 783 | ((sourceG & 0xF8) << 3) |
| 792 | ((sourceB & 0xF8) >> 2) | 784 | ((sourceB & 0xF8) >> 2) |
| 793 | (source[3] >> 7)); | 785 | (source[3] >> 7)); |
| 794 source += 4; | 786 source += 4; |
| 795 destination += 1; | 787 destination += 1; |
| 796 } | 788 } |
| 797 } | 789 } |
| 798 | 790 |
| 799 template<> void pack<WebGLImageConversion::DataFormatRGB565, WebGLImageConversio
n::AlphaDoNothing, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destinati
on, unsigned pixelsPerRow) | 791 template<> void pack<WebGLImageConversion::DataFormatRGB565, WebGLImageConversio
n::AlphaDoNothing, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destinati
on, unsigned pixelsPerRow) |
| 800 { | 792 { |
| 801 #if HAVE(ARM_NEON_INTRINSICS) | 793 WTF_CPU_ARM_NEON_WRAP(SIMD::packOneRowOfRGBA8ToUnsignedShort565)(source, des
tination, pixelsPerRow); |
| 802 SIMD::packOneRowOfRGBA8ToUnsignedShort565(source, destination, pixelsPerRow)
; | |
| 803 #endif | |
| 804 for (unsigned i = 0; i < pixelsPerRow; ++i) { | 794 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
| 805 *destination = (((source[0] & 0xF8) << 8) | 795 *destination = (((source[0] & 0xF8) << 8) |
| 806 | ((source[1] & 0xFC) << 3) | 796 | ((source[1] & 0xFC) << 3) |
| 807 | ((source[2] & 0xF8) >> 3)); | 797 | ((source[2] & 0xF8) >> 3)); |
| 808 source += 4; | 798 source += 4; |
| 809 destination += 1; | 799 destination += 1; |
| 810 } | 800 } |
| 811 } | 801 } |
| 812 | 802 |
| 813 template<> void pack<WebGLImageConversion::DataFormatRGB565, WebGLImageConversio
n::AlphaDoPremultiply, uint8_t, uint16_t>(const uint8_t* source, uint16_t* desti
nation, unsigned pixelsPerRow) | 803 template<> void pack<WebGLImageConversion::DataFormatRGB565, WebGLImageConversio
n::AlphaDoPremultiply, uint8_t, uint16_t>(const uint8_t* source, uint16_t* desti
nation, unsigned pixelsPerRow) |
| (...skipping 956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1770 } | 1760 } |
| 1771 | 1761 |
| 1772 FormatConverter converter(width, height, sourceData, destinationData, srcStr
ide, dstStride); | 1762 FormatConverter converter(width, height, sourceData, destinationData, srcStr
ide, dstStride); |
| 1773 converter.convert(sourceDataFormat, dstDataFormat, alphaOp); | 1763 converter.convert(sourceDataFormat, dstDataFormat, alphaOp); |
| 1774 if (!converter.Success()) | 1764 if (!converter.Success()) |
| 1775 return false; | 1765 return false; |
| 1776 return true; | 1766 return true; |
| 1777 } | 1767 } |
| 1778 | 1768 |
| 1779 } // namespace blink | 1769 } // namespace blink |
| OLD | NEW |