⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 94026 in webkit


Ignore:
Timestamp:
Aug 29, 2011, 3:54:06 PM (15 years ago)
Author:
commit-queue@webkit.org
Message:

Speed up texImage from BGRA
https://bugs.webkit.org/show_bug.cgi?id=66884

Patch by John Bauman <jbauman@chromium.org> on 2011-08-29
Reviewed by Kenneth Russell.

BGRA input is common coming from skia, so optimize BGRA->RGBA
conversion and also avoid the pointless RGBA to RGBA conversion.

  • platform/graphics/GraphicsContext3D.cpp:

(WebCore::doUnpackingAndPacking):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r94024 r94026  
     12011-08-29  John Bauman  <jbauman@chromium.org>
     2
     3        Speed up texImage from BGRA
     4        https://bugs.webkit.org/show_bug.cgi?id=66884
     5
     6        Reviewed by Kenneth Russell.
     7
     8        BGRA input is common coming from skia, so optimize BGRA->RGBA
     9        conversion and also avoid the pointless RGBA to RGBA conversion.
     10
     11        * platform/graphics/GraphicsContext3D.cpp:
     12        (WebCore::doUnpackingAndPacking):
     13
    1142011-08-29  Matthew Delaney  <mdelaney@apple.com>
    215
  • trunk/Source/WebCore/platform/graphics/GraphicsContext3D.cpp

    r93564 r94026  
    475475void unpackOneRowOfBGRA8ToRGBA8(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
    476476{
    477     for (unsigned int i = 0; i < pixelsPerRow; ++i) {
    478         destination[0] = source[2];
    479         destination[1] = source[1];
    480         destination[2] = source[0];
    481         destination[3] = source[3];
    482         source += 4;
    483         destination += 4;
     477    const uint32_t* source32 = reinterpret_cast<const uint32_t*>(source);
     478    uint32_t* destination32 = reinterpret_cast<uint32_t*>(destination);
     479    for (unsigned int i = 0; i < pixelsPerRow; ++i) {
     480        uint32_t bgra = source32[i];
     481#if CPU(BIG_ENDIAN)
     482        uint32_t brMask = 0xff00ff00;
     483        uint32_t gaMask = 0x00ff00ff;
     484#else
     485        uint32_t brMask = 0x00ff00ff;
     486        uint32_t gaMask = 0xff00ff00;
     487#endif
     488        uint32_t rgba = (((bgra >> 16) | (bgra << 16)) & brMask) | (bgra & gaMask);
     489        destination32[i] = rgba;
    484490    }
    485491}
     
    869875        source += 4;
    870876        destination += 3;
    871     }
    872 }
    873 
    874 // This is only used when the source format is different than SourceFormatRGBA8.
    875 void packOneRowOfRGBA8ToRGBA8(const uint8_t* source, uint8_t* destination, unsigned int pixelsPerRow)
    876 {
    877     for (unsigned int i = 0; i < pixelsPerRow; ++i) {
    878         destination[0] = source[0];
    879         destination[1] = source[1];
    880         destination[2] = source[2];
    881         destination[3] = source[3];
    882         source += 4;
    883         destination += 4;
    884877    }
    885878}
     
    11511144                                  unsigned int destinationElementsPerPixel)
    11521145{
    1153     OwnArrayPtr<IntermediateType> temporaryRGBAData = adoptArrayPtr(new IntermediateType[width * 4]);
    1154     const SourceType* endPointer = sourceData + height * sourceElementsPerRow;
    1155     unsigned int destinationElementsPerRow = width * destinationElementsPerPixel;
    1156     while (sourceData < endPointer) {
    1157         rowUnpackingFunc(sourceData, temporaryRGBAData.get(), width);
    1158         rowPackingFunc(temporaryRGBAData.get(), destinationData, width);
    1159         sourceData += sourceElementsPerRow;
    1160         destinationData += destinationElementsPerRow;
     1146    if (!rowPackingFunc) {
     1147        // The row packing is trivial, so don't bother with a temporary buffer.
     1148        const SourceType* endPointer = sourceData + height * sourceElementsPerRow;
     1149        unsigned int destinationElementsPerRow = width * destinationElementsPerPixel;
     1150        while (sourceData < endPointer) {
     1151            rowUnpackingFunc(sourceData, reinterpret_cast<IntermediateType*>(destinationData), width);
     1152            sourceData += sourceElementsPerRow;
     1153            destinationData += destinationElementsPerRow;
     1154        }
     1155    } else {
     1156        OwnArrayPtr<IntermediateType> temporaryRGBAData = adoptArrayPtr(new IntermediateType[width * 4]);
     1157        const SourceType* endPointer = sourceData + height * sourceElementsPerRow;
     1158        unsigned int destinationElementsPerRow = width * destinationElementsPerPixel;
     1159        while (sourceData < endPointer) {
     1160            rowUnpackingFunc(sourceData, temporaryRGBAData.get(), width);
     1161            rowPackingFunc(temporaryRGBAData.get(), destinationData, width);
     1162            sourceData += sourceElementsPerRow;
     1163            destinationData += destinationElementsPerRow;
     1164        }
    11611165    }
    11621166}
     
    11981202        unsigned int destinationElementsPerRow = width * destinationElementsPerPixel;
    11991203        while (source < endPointer) {
    1200             rowPackingFunc(source, destinationData, width);
     1204            if (rowPackingFunc)
     1205                rowPackingFunc(source, destinationData, width);
     1206            else
     1207                memcpy(destinationData, source, width * 4);
    12011208            source += sourceElementsPerRow;
    12021209            destinationData += destinationElementsPerRow;
     
    14361443            case AlphaDoNothing:
    14371444                ASSERT(sourceDataFormat != SourceFormatRGBA8 || sourceUnpackAlignment > 4); // Handled above with fast case.
    1438                 doPacking<uint8_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, packOneRowOfRGBA8ToRGBA8, 4);
     1445                doPacking<uint8_t>(sourceData, sourceDataFormat, width, height, sourceUnpackAlignment, destination, 0, 4);
    14391446                break;
    14401447            case AlphaDoPremultiply:
Note: See TracChangeset for help on using the changeset viewer.