| 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 "platform/graphics/gpu/WebGLImageConversion.h" | 5 #include "platform/graphics/gpu/WebGLImageConversion.h" |
| 6 | 6 |
| 7 #include "platform/CheckedInt.h" | 7 #include "platform/CheckedInt.h" |
| 8 #include "platform/graphics/ImageObserver.h" | 8 #include "platform/graphics/ImageObserver.h" |
| 9 #include "platform/graphics/cpu/arm/WebGLImageConversionNEON.h" | 9 #include "platform/graphics/cpu/arm/WebGLImageConversionNEON.h" |
| 10 #include "platform/graphics/cpu/mips/WebGLImageConversionMSA.h" | 10 #include "platform/graphics/cpu/mips/WebGLImageConversionMSA.h" |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 } | 420 } |
| 421 | 421 |
| 422 template<> void unpack<WebGLImageConversion::DataFormatBGRA8, uint8_t, uint8_t>(
const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) | 422 template<> void unpack<WebGLImageConversion::DataFormatBGRA8, uint8_t, uint8_t>(
const uint8_t* source, uint8_t* destination, unsigned pixelsPerRow) |
| 423 { | 423 { |
| 424 const uint32_t* source32 = reinterpret_cast_ptr<const uint32_t*>(source); | 424 const uint32_t* source32 = reinterpret_cast_ptr<const uint32_t*>(source); |
| 425 uint32_t* destination32 = reinterpret_cast_ptr<uint32_t*>(destination); | 425 uint32_t* destination32 = reinterpret_cast_ptr<uint32_t*>(destination); |
| 426 | 426 |
| 427 #if CPU(X86) || CPU(X86_64) | 427 #if CPU(X86) || CPU(X86_64) |
| 428 SIMD::unpackOneRowOfBGRA8LittleToRGBA8(source32, destination32, pixelsPerRow
); | 428 SIMD::unpackOneRowOfBGRA8LittleToRGBA8(source32, destination32, pixelsPerRow
); |
| 429 #endif | 429 #endif |
| 430 #if HAVE(MIPS_MSA_INTRINSICS) |
| 431 SIMD::unpackOneRowOfBGRA8LittleToRGBA8MSA(source32, destination32, pixelsPer
Row); |
| 432 #endif |
| 430 for (unsigned i = 0; i < pixelsPerRow; ++i) { | 433 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
| 431 uint32_t bgra = source32[i]; | 434 uint32_t bgra = source32[i]; |
| 432 #if CPU(BIG_ENDIAN) | 435 #if CPU(BIG_ENDIAN) |
| 433 uint32_t brMask = 0xff00ff00; | 436 uint32_t brMask = 0xff00ff00; |
| 434 uint32_t gaMask = 0x00ff00ff; | 437 uint32_t gaMask = 0x00ff00ff; |
| 435 #else | 438 #else |
| 436 uint32_t brMask = 0x00ff00ff; | 439 uint32_t brMask = 0x00ff00ff; |
| 437 uint32_t gaMask = 0xff00ff00; | 440 uint32_t gaMask = 0xff00ff00; |
| 438 #endif | 441 #endif |
| 439 uint32_t rgba = (((bgra >> 16) | (bgra << 16)) & brMask) | (bgra & gaMas
k); | 442 uint32_t rgba = (((bgra >> 16) | (bgra << 16)) & brMask) | (bgra & gaMas
k); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 468 } | 471 } |
| 469 | 472 |
| 470 template<> void unpack<WebGLImageConversion::DataFormatRGBA4444, uint16_t, uint8
_t>(const uint16_t* source, uint8_t* destination, unsigned pixelsPerRow) | 473 template<> void unpack<WebGLImageConversion::DataFormatRGBA4444, uint16_t, uint8
_t>(const uint16_t* source, uint8_t* destination, unsigned pixelsPerRow) |
| 471 { | 474 { |
| 472 #if CPU(X86) || CPU(X86_64) | 475 #if CPU(X86) || CPU(X86_64) |
| 473 SIMD::unpackOneRowOfRGBA4444LittleToRGBA8(source, destination, pixelsPerRow)
; | 476 SIMD::unpackOneRowOfRGBA4444LittleToRGBA8(source, destination, pixelsPerRow)
; |
| 474 #endif | 477 #endif |
| 475 #if HAVE(ARM_NEON_INTRINSICS) | 478 #if HAVE(ARM_NEON_INTRINSICS) |
| 476 SIMD::unpackOneRowOfRGBA4444ToRGBA8(source, destination, pixelsPerRow); | 479 SIMD::unpackOneRowOfRGBA4444ToRGBA8(source, destination, pixelsPerRow); |
| 477 #endif | 480 #endif |
| 481 #if HAVE(MIPS_MSA_INTRINSICS) |
| 482 SIMD::unpackOneRowOfRGBA4444ToRGBA8MSA(source, destination, pixelsPerRow); |
| 483 #endif |
| 478 for (unsigned i = 0; i < pixelsPerRow; ++i) { | 484 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
| 479 uint16_t packedValue = source[0]; | 485 uint16_t packedValue = source[0]; |
| 480 uint8_t r = packedValue >> 12; | 486 uint8_t r = packedValue >> 12; |
| 481 uint8_t g = (packedValue >> 8) & 0x0F; | 487 uint8_t g = (packedValue >> 8) & 0x0F; |
| 482 uint8_t b = (packedValue >> 4) & 0x0F; | 488 uint8_t b = (packedValue >> 4) & 0x0F; |
| 483 uint8_t a = packedValue & 0x0F; | 489 uint8_t a = packedValue & 0x0F; |
| 484 destination[0] = r << 4 | r; | 490 destination[0] = r << 4 | r; |
| 485 destination[1] = g << 4 | g; | 491 destination[1] = g << 4 | g; |
| 486 destination[2] = b << 4 | b; | 492 destination[2] = b << 4 | b; |
| 487 destination[3] = a << 4 | a; | 493 destination[3] = a << 4 | a; |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 source += 4; | 747 source += 4; |
| 742 destination += 4; | 748 destination += 4; |
| 743 } | 749 } |
| 744 } | 750 } |
| 745 | 751 |
| 746 // FIXME: this routine is lossy and must be removed. | 752 // FIXME: this routine is lossy and must be removed. |
| 747 template<> void pack<WebGLImageConversion::DataFormatRGBA8, WebGLImageConversion
::AlphaDoUnmultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destinati
on, unsigned pixelsPerRow) | 753 template<> void pack<WebGLImageConversion::DataFormatRGBA8, WebGLImageConversion
::AlphaDoUnmultiply, uint8_t, uint8_t>(const uint8_t* source, uint8_t* destinati
on, unsigned pixelsPerRow) |
| 748 { | 754 { |
| 749 #if CPU(X86) || CPU(X86_64) | 755 #if CPU(X86) || CPU(X86_64) |
| 750 SIMD::packOneRowOfRGBA8LittleToRGBA8(source, destination, pixelsPerRow); | 756 SIMD::packOneRowOfRGBA8LittleToRGBA8(source, destination, pixelsPerRow); |
| 751 #else | 757 #endif |
| 758 #if HAVE(MIPS_MSA_INTRINSICS) |
| 759 SIMD::packOneRowOfRGBA8LittleToRGBA8MSA(source, destination, pixelsPerRow); |
| 760 #endif |
| 752 for (unsigned i = 0; i < pixelsPerRow; ++i) { | 761 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
| 753 float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f; | 762 float scaleFactor = source[3] ? 255.0f / source[3] : 1.0f; |
| 754 uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * s
caleFactor); | 763 uint8_t sourceR = static_cast<uint8_t>(static_cast<float>(source[0]) * s
caleFactor); |
| 755 uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * s
caleFactor); | 764 uint8_t sourceG = static_cast<uint8_t>(static_cast<float>(source[1]) * s
caleFactor); |
| 756 uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * s
caleFactor); | 765 uint8_t sourceB = static_cast<uint8_t>(static_cast<float>(source[2]) * s
caleFactor); |
| 757 destination[0] = sourceR; | 766 destination[0] = sourceR; |
| 758 destination[1] = sourceG; | 767 destination[1] = sourceG; |
| 759 destination[2] = sourceB; | 768 destination[2] = sourceB; |
| 760 destination[3] = source[3]; | 769 destination[3] = source[3]; |
| 761 source += 4; | 770 source += 4; |
| 762 destination += 4; | 771 destination += 4; |
| 763 } | 772 } |
| 764 #endif | |
| 765 } | 773 } |
| 766 | 774 |
| 767 template<> void pack<WebGLImageConversion::DataFormatRGBA4444, WebGLImageConvers
ion::AlphaDoNothing, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destina
tion, unsigned pixelsPerRow) | 775 template<> void pack<WebGLImageConversion::DataFormatRGBA4444, WebGLImageConvers
ion::AlphaDoNothing, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destina
tion, unsigned pixelsPerRow) |
| 768 { | 776 { |
| 769 #if HAVE(ARM_NEON_INTRINSICS) | 777 #if HAVE(ARM_NEON_INTRINSICS) |
| 770 SIMD::packOneRowOfRGBA8ToUnsignedShort4444(source, destination, pixelsPerRow
); | 778 SIMD::packOneRowOfRGBA8ToUnsignedShort4444(source, destination, pixelsPerRow
); |
| 771 #endif | 779 #endif |
| 772 for (unsigned i = 0; i < pixelsPerRow; ++i) { | 780 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
| 773 *destination = (((source[0] & 0xF0) << 8) | 781 *destination = (((source[0] & 0xF0) << 8) |
| 774 | ((source[1] & 0xF0) << 4) | 782 | ((source[1] & 0xF0) << 4) |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 source += 4; | 818 source += 4; |
| 811 destination += 1; | 819 destination += 1; |
| 812 } | 820 } |
| 813 } | 821 } |
| 814 | 822 |
| 815 template<> void pack<WebGLImageConversion::DataFormatRGBA5551, WebGLImageConvers
ion::AlphaDoNothing, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destina
tion, unsigned pixelsPerRow) | 823 template<> void pack<WebGLImageConversion::DataFormatRGBA5551, WebGLImageConvers
ion::AlphaDoNothing, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destina
tion, unsigned pixelsPerRow) |
| 816 { | 824 { |
| 817 #if HAVE(ARM_NEON_INTRINSICS) | 825 #if HAVE(ARM_NEON_INTRINSICS) |
| 818 SIMD::packOneRowOfRGBA8ToUnsignedShort5551(source, destination, pixelsPerRow
); | 826 SIMD::packOneRowOfRGBA8ToUnsignedShort5551(source, destination, pixelsPerRow
); |
| 819 #endif | 827 #endif |
| 828 #if HAVE(MIPS_MSA_INTRINSICS) |
| 829 SIMD::packOneRowOfRGBA8ToUnsignedShort5551MSA(source, destination, pixelsPer
Row); |
| 830 #endif |
| 820 for (unsigned i = 0; i < pixelsPerRow; ++i) { | 831 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
| 821 *destination = (((source[0] & 0xF8) << 8) | 832 *destination = (((source[0] & 0xF8) << 8) |
| 822 | ((source[1] & 0xF8) << 3) | 833 | ((source[1] & 0xF8) << 3) |
| 823 | ((source[2] & 0xF8) >> 2) | 834 | ((source[2] & 0xF8) >> 2) |
| 824 | (source[3] >> 7)); | 835 | (source[3] >> 7)); |
| 825 source += 4; | 836 source += 4; |
| 826 destination += 1; | 837 destination += 1; |
| 827 } | 838 } |
| 828 } | 839 } |
| 829 | 840 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 858 source += 4; | 869 source += 4; |
| 859 destination += 1; | 870 destination += 1; |
| 860 } | 871 } |
| 861 } | 872 } |
| 862 | 873 |
| 863 template<> void pack<WebGLImageConversion::DataFormatRGB565, WebGLImageConversio
n::AlphaDoNothing, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destinati
on, unsigned pixelsPerRow) | 874 template<> void pack<WebGLImageConversion::DataFormatRGB565, WebGLImageConversio
n::AlphaDoNothing, uint8_t, uint16_t>(const uint8_t* source, uint16_t* destinati
on, unsigned pixelsPerRow) |
| 864 { | 875 { |
| 865 #if HAVE(ARM_NEON_INTRINSICS) | 876 #if HAVE(ARM_NEON_INTRINSICS) |
| 866 SIMD::packOneRowOfRGBA8ToUnsignedShort565(source, destination, pixelsPerRow)
; | 877 SIMD::packOneRowOfRGBA8ToUnsignedShort565(source, destination, pixelsPerRow)
; |
| 867 #endif | 878 #endif |
| 879 #if HAVE(MIPS_MSA_INTRINSICS) |
| 880 SIMD::packOneRowOfRGBA8ToUnsignedShort565MSA(source, destination, pixelsPerR
ow); |
| 881 #endif |
| 868 for (unsigned i = 0; i < pixelsPerRow; ++i) { | 882 for (unsigned i = 0; i < pixelsPerRow; ++i) { |
| 869 *destination = (((source[0] & 0xF8) << 8) | 883 *destination = (((source[0] & 0xF8) << 8) |
| 870 | ((source[1] & 0xFC) << 3) | 884 | ((source[1] & 0xFC) << 3) |
| 871 | ((source[2] & 0xF8) >> 3)); | 885 | ((source[2] & 0xF8) >> 3)); |
| 872 source += 4; | 886 source += 4; |
| 873 destination += 1; | 887 destination += 1; |
| 874 } | 888 } |
| 875 } | 889 } |
| 876 | 890 |
| 877 template<> void pack<WebGLImageConversion::DataFormatRGB565, WebGLImageConversio
n::AlphaDoPremultiply, uint8_t, uint16_t>(const uint8_t* source, uint16_t* desti
nation, unsigned pixelsPerRow) | 891 template<> void pack<WebGLImageConversion::DataFormatRGB565, WebGLImageConversio
n::AlphaDoPremultiply, uint8_t, uint16_t>(const uint8_t* source, uint16_t* desti
nation, unsigned pixelsPerRow) |
| (...skipping 1529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2407 } | 2421 } |
| 2408 | 2422 |
| 2409 FormatConverter converter(width, height, sourceData, destinationData, srcStr
ide, dstStride); | 2423 FormatConverter converter(width, height, sourceData, destinationData, srcStr
ide, dstStride); |
| 2410 converter.convert(sourceDataFormat, dstDataFormat, alphaOp); | 2424 converter.convert(sourceDataFormat, dstDataFormat, alphaOp); |
| 2411 if (!converter.Success()) | 2425 if (!converter.Success()) |
| 2412 return false; | 2426 return false; |
| 2413 return true; | 2427 return true; |
| 2414 } | 2428 } |
| 2415 | 2429 |
| 2416 } // namespace blink | 2430 } // namespace blink |
| OLD | NEW |