Changeset 83219 in webkit


Ignore:
Timestamp:
Apr 7, 2011 3:21:53 PM (13 years ago)
Author:
tony@chromium.org
Message:

2011-04-07 Tony Chang <tony@chromium.org>

Reviewed by Eric Seidel.

update DRT to embed checksums in png files
https://bugs.webkit.org/show_bug.cgi?id=57871

We insert the bytes for the comment in printPNG rather than at encode
time because each platform does its own PNG encoding (either using CG
or cairo). Putting this in pringPNG avoids having to duplicate this
code, although it's not as clean as doing it at encoding time.

We insert the comment right after the IHDR chunk of the PNG.

  • DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
  • DumpRenderTree/CyclicRedundancyCheck.cpp: Added. (makeCrcTable): Ported from LayoutTests/fast/canvas/webgl/resources/pnglib.js (computeCrc): Ported from LayoutTests/fast/canvas/webgl/resources/pnglib.js
  • DumpRenderTree/CyclicRedundancyCheck.h: Added.
  • DumpRenderTree/PixelDumpSupport.cpp: (dumpWebViewAsPixelsAndCompareWithExpected): (convertChecksumToPNGComment): Generate the bytes to insert. (printPNG): Insert the png comment before the first IDAT section.
  • DumpRenderTree/PixelDumpSupport.h:
  • DumpRenderTree/cairo/PixelDumpSupportCairo.cpp: (printPNG): (dumpBitmap):
  • DumpRenderTree/cg/PixelDumpSupportCG.cpp: (printPNG): (dumpBitmap):
  • DumpRenderTree/win/DumpRenderTree.vcproj:
  • GNUmakefile.am:
Location:
trunk/Tools
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r83198 r83219  
     12011-04-07  Tony Chang  <tony@chromium.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        update DRT to embed checksums in png files
     6        https://bugs.webkit.org/show_bug.cgi?id=57871
     7
     8        We insert the bytes for the comment in printPNG rather than at encode
     9        time because each platform does its own PNG encoding (either using CG
     10        or cairo).  Putting this in pringPNG avoids having to duplicate this
     11        code, although it's not as clean as doing it at encoding time.
     12
     13        We insert the comment right after the IHDR chunk of the PNG.
     14
     15        * DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj:
     16        * DumpRenderTree/CyclicRedundancyCheck.cpp: Added.
     17        (makeCrcTable): Ported from LayoutTests/fast/canvas/webgl/resources/pnglib.js
     18        (computeCrc): Ported from LayoutTests/fast/canvas/webgl/resources/pnglib.js
     19        * DumpRenderTree/CyclicRedundancyCheck.h: Added.
     20        * DumpRenderTree/PixelDumpSupport.cpp:
     21        (dumpWebViewAsPixelsAndCompareWithExpected):
     22        (convertChecksumToPNGComment): Generate the bytes to insert.
     23        (printPNG): Insert the png comment before the first IDAT section.
     24        * DumpRenderTree/PixelDumpSupport.h:
     25        * DumpRenderTree/cairo/PixelDumpSupportCairo.cpp:
     26        (printPNG):
     27        (dumpBitmap):
     28        * DumpRenderTree/cg/PixelDumpSupportCG.cpp:
     29        (printPNG):
     30        (dumpBitmap):
     31        * DumpRenderTree/win/DumpRenderTree.vcproj:
     32        * GNUmakefile.am:
     33
    1342011-04-07  Jeff Miller  <jeffm@apple.com>
    235
  • trunk/Tools/DumpRenderTree/DumpRenderTree.xcodeproj/project.pbxproj

    r82723 r83219  
    6060                5185F6B210714E07007AA393 /* HistoryDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 5185F69F10714A57007AA393 /* HistoryDelegate.mm */; };
    6161                5185F6B310714E12007AA393 /* HistoryDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 5185F69E10714A57007AA393 /* HistoryDelegate.h */; };
     62                53CBB832134E42F3001CE6A4 /* CyclicRedundancyCheck.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53CBB830134E42F3001CE6A4 /* CyclicRedundancyCheck.cpp */; };
     63                53CBB833134E42F3001CE6A4 /* CyclicRedundancyCheck.h in Headers */ = {isa = PBXBuildFile; fileRef = 53CBB831134E42F3001CE6A4 /* CyclicRedundancyCheck.h */; };
    6264                5DB9AC970F722C3600684641 /* AHEM____.TTF in Copy Font Files */ = {isa = PBXBuildFile; fileRef = AA7F10C20CB3C1030003BDC9 /* AHEM____.TTF */; };
    6365                5DB9AC980F722C3600684641 /* WebKitWeightWatcher100.ttf in Copy Font Files */ = {isa = PBXBuildFile; fileRef = 375F09710DAC3CB600C8B4E5 /* WebKitWeightWatcher100.ttf */; };
     
    244246                5185F69E10714A57007AA393 /* HistoryDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HistoryDelegate.h; path = mac/HistoryDelegate.h; sourceTree = "<group>"; };
    245247                5185F69F10714A57007AA393 /* HistoryDelegate.mm */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; name = HistoryDelegate.mm; path = mac/HistoryDelegate.mm; sourceTree = "<group>"; };
     248                53CBB830134E42F3001CE6A4 /* CyclicRedundancyCheck.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CyclicRedundancyCheck.cpp; sourceTree = "<group>"; };
     249                53CBB831134E42F3001CE6A4 /* CyclicRedundancyCheck.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CyclicRedundancyCheck.h; sourceTree = "<group>"; };
    246250                8465E2C60FFA8DF2003B8342 /* PixelDumpSupport.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = PixelDumpSupport.cpp; sourceTree = "<group>"; };
    247251                9335435F03D75502008635CE /* WebKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = WebKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
     
    582586                        isa = PBXGroup;
    583587                        children = (
     588                                53CBB830134E42F3001CE6A4 /* CyclicRedundancyCheck.cpp */,
     589                                53CBB831134E42F3001CE6A4 /* CyclicRedundancyCheck.h */,
    584590                                BCB284F30CFA84F2007E533E /* ImageDiffCG.cpp */,
    585591                                8465E2C60FFA8DF2003B8342 /* PixelDumpSupport.cpp */,
     
    612618                                BCA18B380C9B021900114369 /* AppleScriptController.h in Headers */,
    613619                                A8B91BFF0CF522B4008F91FF /* CheckedMalloc.h in Headers */,
     620                                53CBB833134E42F3001CE6A4 /* CyclicRedundancyCheck.h in Headers */,
    614621                                BCA18B7A0C9B08F100114369 /* DumpRenderTreeDraggingInfo.h in Headers */,
    615622                                A8D79CEA0FC28B2C004AC8FE /* DumpRenderTreeFileDraggingSource.h in Headers */,
     
    800807                                BCA18B390C9B021900114369 /* AppleScriptController.m in Sources */,
    801808                                A8B91BFD0CF522B4008F91FF /* CheckedMalloc.cpp in Sources */,
     809                                53CBB832134E42F3001CE6A4 /* CyclicRedundancyCheck.cpp in Sources */,
    802810                                BCA18C470C9B5B9400114369 /* DumpRenderTree.mm in Sources */,
    803811                                BCA18B7B0C9B08F100114369 /* DumpRenderTreeDraggingInfo.mm in Sources */,
  • trunk/Tools/DumpRenderTree/PixelDumpSupport.cpp

    r70239 r83219  
    3030#include "PixelDumpSupport.h"
    3131
     32#include "CyclicRedundancyCheck.h"
    3233#include "DumpRenderTree.h"
    3334#include "LayoutTestController.h"
     
    3536#include <wtf/Assertions.h>
    3637#include <wtf/RefPtr.h>
     38#include <wtf/Vector.h>
    3739
    3840#if PLATFORM(CG)
     
    7072   
    7173    if (dumpImage)
    72       dumpBitmap(context.get());
     74      dumpBitmap(context.get(), actualHash);
    7375}
    7476
    75 void printPNG(const unsigned char* data, const size_t dataLength)
     77static void appendIntToVector(int number, Vector<unsigned char>& vector)
    7678{
     79    size_t offset = vector.size();
     80    vector.grow(offset + 4);
     81    vector[offset] = ((number >> 24) & 0xff);
     82    vector[offset + 1] = ((number >> 16) & 0xff);
     83    vector[offset + 2] = ((number >> 8) & 0xff);
     84    vector[offset + 3] = (number & 0xff);
     85}
     86
     87static void convertChecksumToPNGComment(const char* checksum, Vector<unsigned char>& bytesToAdd)
     88{
     89    // Chunks of PNG files are <length>, <type>, <data>, <crc>.
     90    static const char textCommentPrefix[] = "\x00\x00\x00\x29tEXtchecksum\x00";
     91    static const size_t prefixLength = sizeof(textCommentPrefix) - 1; // The -1 is for the null at the end of the char[].
     92    static const size_t checksumLength = 32;
     93
     94    bytesToAdd.append(textCommentPrefix, prefixLength);
     95    bytesToAdd.append(checksum, checksumLength);
     96
     97    Vector<unsigned char> dataToCrc;
     98    dataToCrc.append(textCommentPrefix + 4, prefixLength - 4); // Don't include the chunk length in the crc.
     99    dataToCrc.append(checksum, checksumLength);
     100    unsigned long crc32 = computeCrc(dataToCrc);
     101
     102    appendIntToVector(crc32, bytesToAdd);
     103}
     104
     105static size_t offsetAfterIHDRChunk(const unsigned char* data, const size_t dataLength)
     106{
     107    const int pngHeaderLength = 8;
     108    const int pngIHDRChunkLength = 25; // chunk length + "IHDR" + 13 bytes of data + checksum
     109    return pngHeaderLength + pngIHDRChunkLength;
     110}
     111
     112void printPNG(const unsigned char* data, const size_t dataLength, const char* checksum)
     113{
     114    Vector<unsigned char> bytesToAdd;
     115    convertChecksumToPNGComment(checksum, bytesToAdd);
     116
    77117    printf("Content-Type: %s\n", "image/png");
    78     printf("Content-Length: %lu\n", static_cast<unsigned long>(dataLength));
     118    printf("Content-Length: %lu\n", static_cast<unsigned long>(dataLength + bytesToAdd.size()));
     119
     120    size_t insertOffset = offsetAfterIHDRChunk(data, dataLength);
     121
     122    fwrite(data, 1, insertOffset, stdout);
     123    fwrite(bytesToAdd.data(), 1, bytesToAdd.size(), stdout);
    79124
    80125    const size_t bytesToWriteInOneChunk = 1 << 15;
    81     size_t dataRemainingToWrite = dataLength;
     126    data += insertOffset;
     127    size_t dataRemainingToWrite = dataLength - insertOffset;
    82128    while (dataRemainingToWrite) {
    83129        size_t bytesToWriteInThisChunk = std::min(dataRemainingToWrite, bytesToWriteInOneChunk);
  • trunk/Tools/DumpRenderTree/PixelDumpSupport.h

    r63521 r83219  
    3939PassRefPtr<BitmapContext> createPagedBitmapContext();
    4040PassRefPtr<BitmapContext> createBitmapContextFromWebView(bool onscreen, bool incrementalRepaint, bool sweepHorizontally, bool drawSelectionRect);
    41 void dumpBitmap(BitmapContext*);
     41void dumpBitmap(BitmapContext*, const char* checksum);
    4242void dumpWebViewAsPixelsAndCompareWithExpected(const std::string& expectedHash);
    43 void printPNG(const unsigned char* data, const size_t dataLength);
     43void printPNG(const unsigned char* data, const size_t dataLength, const char* checksum);
    4444
    4545#if PLATFORM(MAC)
  • trunk/Tools/DumpRenderTree/cairo/PixelDumpSupportCairo.cpp

    r63130 r83219  
    5050}
    5151
    52 static void printPNG(cairo_surface_t* image)
     52static void printPNG(cairo_surface_t* image, const char* checksum)
    5353{
    5454    Vector<unsigned char> pixelData;
     
    5959    const unsigned char* data = pixelData.data();
    6060
    61     printPNG(data, dataLength);
     61    printPNG(data, dataLength, checksum);
    6262}
    6363
     
    8787}
    8888
    89 void dumpBitmap(BitmapContext* context)
     89void dumpBitmap(BitmapContext* context, const char* checksum)
    9090{
    9191    cairo_surface_t* surface = cairo_get_target(context->cairoContext());
    92     printPNG(surface);
     92    printPNG(surface, checksum);
    9393}
  • trunk/Tools/DumpRenderTree/cg/PixelDumpSupportCG.cpp

    r45505 r83219  
    5656#endif
    5757
    58 static void printPNG(CGImageRef image)
     58static void printPNG(CGImageRef image, const char* checksum)
    5959{
    6060    RetainPtr<CFMutableDataRef> imageData(AdoptCF, CFDataCreateMutable(0, 0));
     
    6666    CFIndex dataLength = CFDataGetLength(imageData.get());
    6767
    68     printPNG(static_cast<const unsigned char*>(data), static_cast<size_t>(dataLength));
     68    printPNG(static_cast<const unsigned char*>(data), static_cast<size_t>(dataLength), checksum);
    6969}
    7070
     
    107107}
    108108
    109 void dumpBitmap(BitmapContext* context)
     109void dumpBitmap(BitmapContext* context, const char* checksum)
    110110{
    111111    RetainPtr<CGImageRef> image(AdoptCF, CGBitmapContextCreateImage(context->cgContext()));
    112     printPNG(image.get());
     112    printPNG(image.get(), checksum);
    113113}
  • trunk/Tools/DumpRenderTree/win/DumpRenderTree.vcproj

    r82477 r83219  
    516516                </File>
    517517                <File
     518                        RelativePath="..\CyclicRedundancyCheck.cpp"
     519                        >
     520                </File>
     521                <File
     522                        RelativePath="..\CyclicRedundancyCheck.h"
     523                        >
     524                </File>
     525                <File
    518526                        RelativePath=".\DraggingInfo.h"
    519527                        >
  • trunk/Tools/GNUmakefile.am

    r81157 r83219  
    5757        Tools/DumpRenderTree/AccessibilityUIElement.cpp \
    5858        Tools/DumpRenderTree/AccessibilityUIElement.h \
     59        Tools/DumpRenderTree/CyclicRedundancyCheck.cpp \
     60        Tools/DumpRenderTree/CyclicRedundancyCheck.h \
    5961        Tools/DumpRenderTree/GCController.cpp \
    6062        Tools/DumpRenderTree/GCController.h \
Note: See TracChangeset for help on using the changeset viewer.