Implement pixel dumping in Windows DRT
authoraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Nov 2007 00:02:55 +0000 (00:02 +0000)
committeraroben@apple.com <aroben@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 26 Nov 2007 00:02:55 +0000 (00:02 +0000)
        Part of http://bugs.webkit.org/show_bug.cgi?id=16133
        <rdar://5071708>

        Reviewed by Sam.

        * DumpRenderTree/cg/PixelDumpSupportCG.cpp: Added.
        (printPNG): Dumps a CGImageRef as a PNG to stdout, along with a
        Content-Length header.
        (getMD5HashStringForBitmap):
        (dumpWebViewAsPixelsAndCompareWithExpected):
        * DumpRenderTree/cg/PixelDumpSupportCG.h: Copied from WebKitTools/DumpRenderTree/mac/DumpRenderTreePasteboard.h.
        * DumpRenderTree/win/DumpRenderTree.cpp:
        (dump): Do a pixel dump if requested.
        (main): Parse pixel test options.
        * DumpRenderTree/win/DumpRenderTree.vcproj: Added new files and added
        the cg/ subdirectory to the include path.
        * DumpRenderTree/win/MD5.cpp: Added. Windows MD5 functions aren't
        available in a header or import library, so we have to go through this
        LoadLibrary/GetProcAddress dance to use them.
        (cryptDLL):
        (init):
        (update):
        (final):
        (MD5_Init):
        (MD5_Update):
        (MD5_Final):
        * DumpRenderTree/win/MD5.h: Added.
        * DumpRenderTree/win/PixelDumpSupport.h: Added. This file should be
        moved up to the top level to share it with Mac eventually.
        * DumpRenderTree/win/PixelDumpSupportWin.cpp: Added.
        (getBitmapContextFromWebView): Forces the WebView to paint using a
        WM_PRINTCLIENT message, and puts the result in a CGBitmapContext.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28021 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKitTools/ChangeLog
WebKitTools/DumpRenderTree/cg/PixelDumpSupportCG.cpp [new file with mode: 0644]
WebKitTools/DumpRenderTree/cg/PixelDumpSupportCG.h [new file with mode: 0644]
WebKitTools/DumpRenderTree/win/DumpRenderTree.cpp
WebKitTools/DumpRenderTree/win/DumpRenderTree.vcproj
WebKitTools/DumpRenderTree/win/MD5.cpp [new file with mode: 0644]
WebKitTools/DumpRenderTree/win/MD5.h [new file with mode: 0644]
WebKitTools/DumpRenderTree/win/PixelDumpSupport.h [new file with mode: 0644]
WebKitTools/DumpRenderTree/win/PixelDumpSupportWin.cpp [new file with mode: 0644]

index abdc510..ec7e5e1 100644 (file)
@@ -1,5 +1,42 @@
 2007-11-25  Adam Roben  <aroben@apple.com>
 
+        Implement pixel dumping in Windows DRT
+
+        Part of http://bugs.webkit.org/show_bug.cgi?id=16133
+        <rdar://5071708>
+
+        Reviewed by Sam.
+
+        * DumpRenderTree/cg/PixelDumpSupportCG.cpp: Added.
+        (printPNG): Dumps a CGImageRef as a PNG to stdout, along with a
+        Content-Length header.
+        (getMD5HashStringForBitmap):
+        (dumpWebViewAsPixelsAndCompareWithExpected):
+        * DumpRenderTree/cg/PixelDumpSupportCG.h: Copied from WebKitTools/DumpRenderTree/mac/DumpRenderTreePasteboard.h.
+        * DumpRenderTree/win/DumpRenderTree.cpp:
+        (dump): Do a pixel dump if requested.
+        (main): Parse pixel test options.
+        * DumpRenderTree/win/DumpRenderTree.vcproj: Added new files and added
+        the cg/ subdirectory to the include path.
+        * DumpRenderTree/win/MD5.cpp: Added. Windows MD5 functions aren't
+        available in a header or import library, so we have to go through this
+        LoadLibrary/GetProcAddress dance to use them.
+        (cryptDLL):
+        (init):
+        (update):
+        (final):
+        (MD5_Init):
+        (MD5_Update):
+        (MD5_Final):
+        * DumpRenderTree/win/MD5.h: Added.
+        * DumpRenderTree/win/PixelDumpSupport.h: Added. This file should be
+        moved up to the top level to share it with Mac eventually.
+        * DumpRenderTree/win/PixelDumpSupportWin.cpp: Added.
+        (getBitmapContextFromWebView): Forces the WebView to paint using a
+        WM_PRINTCLIENT message, and puts the result in a CGBitmapContext.
+
+2007-11-25  Adam Roben  <aroben@apple.com>
+
         Clean up Windows DRT's option parsing a little bit
 
         Reviewed by Sam.
diff --git a/WebKitTools/DumpRenderTree/cg/PixelDumpSupportCG.cpp b/WebKitTools/DumpRenderTree/cg/PixelDumpSupportCG.cpp
new file mode 100644 (file)
index 0000000..2e7d79b
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2005, 2006, 2007 Apple, Inc. All rights reserved.
+ *           (C) 2007 Graham Dennis (graham.dennis@gmail.com)
+ *           (C) 2007 Eric Seidel <eric@webkit.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "PixelDumpSupportCG.h"
+
+#include <ImageIO/CGImageDestination.h>
+#include <wtf/Assertions.h>
+#include <wtf/RetainPtr.h>
+#include <wtf/StringExtras.h>
+
+#if PLATFORM(WIN)
+#include "MD5.h"
+#elif PLATFORM(MAC)
+#define COMMON_DIGEST_FOR_OPENSSL
+#include <CommonCrypto/CommonDigest.h>
+#endif
+
+static const CFStringRef kUTTypePNG = CFSTR("public.png");
+
+static void printPNG(CGImageRef image)
+{
+    RetainPtr<CFMutableDataRef> imageData(AdoptCF, CFDataCreateMutable(0, 0));
+    RetainPtr<CGImageDestinationRef> imageDest(AdoptCF, CGImageDestinationCreateWithData(imageData.get(), kUTTypePNG, 1, 0));
+    CGImageDestinationAddImage(imageDest.get(), image, 0);
+    CGImageDestinationFinalize(imageDest.get());
+    printf("Content-length: %lu\n", CFDataGetLength(imageData.get()));
+    fwrite(CFDataGetBytePtr(imageData.get()), 1, CFDataGetLength(imageData.get()), stdout);
+}
+
+static void getMD5HashStringForBitmap(CGContextRef bitmap, char string[33])
+{
+    MD5_CTX md5Context;
+    unsigned char hash[16];
+
+    size_t bitsPerPixel = CGBitmapContextGetBitsPerPixel(bitmap);
+    ASSERT(bitsPerPixel == 32); // ImageDiff assumes 32 bit RGBA, we must as well.
+    size_t bytesPerPixel = bitsPerPixel / 8;
+    size_t pixelsHigh = CGBitmapContextGetHeight(bitmap);
+    size_t pixelsWide = CGBitmapContextGetWidth(bitmap);
+    size_t bytesPerRow = CGBitmapContextGetBytesPerRow(bitmap);
+    ASSERT(bytesPerRow >= (pixelsWide * bytesPerPixel));
+
+    MD5_Init(&md5Context);
+    unsigned char* bitmapData = static_cast<unsigned char*>(CGBitmapContextGetData(bitmap));
+    for (unsigned row = 0; row < pixelsHigh; row++) {
+        MD5_Update(&md5Context, bitmapData, static_cast<unsigned>(pixelsWide * bytesPerPixel));
+        bitmapData += bytesPerRow;
+    }
+    MD5_Final(hash, &md5Context);
+
+    string[0] = '\0';
+    for (int i = 0; i < 16; i++)
+        snprintf(string, 33, "%s%02x", string, hash[i]);
+}
+
+void dumpWebViewAsPixelsAndCompareWithExpected(const char* /*currentTest*/, bool /*forceAllTestsToDumpPixels*/)
+{
+    RetainPtr<CGContextRef> context = getBitmapContextFromWebView();
+
+    // Compute the actual hash to compare to the expected image's hash.
+    char actualHash[33];
+    getMD5HashStringForBitmap(context.get(), actualHash);
+    printf("\nActualHash: %s\n", actualHash);
+
+    // FIXME: We should compare the actualHash to the expected hash here and
+    // only set dumpImage to true if they don't match, but DRT doesn't have
+    // enough information currently to find the expected checksum file.
+    bool dumpImage = true;
+
+    if (dumpImage) {
+        RetainPtr<CGImageRef> image(AdoptCF, CGBitmapContextCreateImage(context.get()));
+        printPNG(image.get());
+    }
+
+    printf("#EOF\n");
+}
diff --git a/WebKitTools/DumpRenderTree/cg/PixelDumpSupportCG.h b/WebKitTools/DumpRenderTree/cg/PixelDumpSupportCG.h
new file mode 100644 (file)
index 0000000..d443d13
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2005, 2006, 2007 Apple, Inc. All rights reserved.
+ *           (C) 2007 Graham Dennis (graham.dennis@gmail.com)
+ *           (C) 2007 Eric Seidel <eric@webkit.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef PixelDumpSupportCG_h
+#define PixelDumpSupportCG_h
+
+#include <wtf/Platform.h>
+#include <wtf/RetainPtr.h>
+
+typedef struct CGContext* CGContextRef;
+
+RetainPtr<CGContextRef> getBitmapContextFromWebView();
+
+#endif // PixelDumpSupportCG_h
index 014ecd4..84dc6d7 100644 (file)
@@ -31,6 +31,7 @@
 #include "EditingDelegate.h"
 #include "FrameLoaderDelegate.h"
 #include "LayoutTestController.h"
+#include "PixelDumpSupport.h"
 #include "PolicyDelegate.h"
 #include "UIDelegate.h"
 #include "WorkQueueItem.h"
@@ -69,6 +70,8 @@ static LPCWSTR fontsEnvironmentVariable = L"WEBKIT_TESTFONTS";
 const LPCWSTR kDumpRenderTreeClassName = L"DumpRenderTreeWindow";
 
 static bool dumpTree = true;
+static bool dumpPixels;
+static bool dumpAllPixels;
 static bool printSeparators;
 static bool leakChecking = false;
 static bool timedOut = false;
@@ -565,6 +568,14 @@ void dump()
 
     if (printSeparators)
         puts("#EOF");
+
+    if (dumpPixels) {
+        if (layoutTestController->dumpAsText() || layoutTestController->dumpDOMAsWebArchive() || layoutTestController->dumpSourceAsWebArchive())
+            printf("#EOF\n");
+        else
+            dumpWebViewAsPixelsAndCompareWithExpected(currentTest, dumpAllPixels);
+    }
+
 fail:
     SysFreeString(resultString);
     // This will exit from our message loop
@@ -820,6 +831,16 @@ int main(int argc, char* argv[])
             continue;
         }
 
+        if (!stricmp(argv[i], "--dump-all-pixels")) {
+            dumpAllPixels = true;
+            continue;
+        }
+
+        if (!stricmp(argv[i], "--pixel-tests")) {
+            dumpPixels = true;
+            continue;
+        }
+
         tests.append(argv[i]);
     }
 
index 6447bc4..b587a37 100644 (file)
@@ -1,7 +1,7 @@
-<?xml version="1.0" encoding="windows-1251"?>\r
+<?xml version="1.0" encoding="Windows-1252"?>\r
 <VisualStudioProject\r
        ProjectType="Visual C++"\r
-       Version="8,00"\r
+       Version="8.00"\r
        Name="DumpRenderTree"\r
        ProjectGUID="{6567DFD4-D6DE-4CD5-825D-17E353D160E1}"\r
        RootNamespace="DumpRenderTree"\r
@@ -41,7 +41,7 @@
                        <Tool\r
                                Name="VCCLCompilerTool"\r
                                Optimization="0"\r
-                               AdditionalIncludeDirectories="&quot;$(ProjectDir)\.&quot;;&quot;$(ProjectDir)\..&quot;;&quot;$(WebKitOutputDir)\Include&quot;;&quot;$(WebKitOutputDir)\Include\WebCore\ForwardingHeaders&quot;;&quot;$(WebKitOutputDir)\Include\JavaScriptCore&quot;;&quot;$(WebKitLibrariesDir)\Include&quot;;&quot;$(WebKitLibrariesDir)\include\pthreads&quot;;&quot;$(WebKitOutputDir)\Include\WebCore&quot;;&quot;$(WebKitLibrariesDir)\Include\WebCore&quot;"\r
+                               AdditionalIncludeDirectories="&quot;$(ProjectDir)\.&quot;;&quot;$(ProjectDir)\..&quot;;&quot;$(ProjectDir)\..\cg&quot;;&quot;$(WebKitOutputDir)\Include&quot;;&quot;$(WebKitOutputDir)\Include\WebCore\ForwardingHeaders&quot;;&quot;$(WebKitOutputDir)\Include\JavaScriptCore&quot;;&quot;$(WebKitLibrariesDir)\Include&quot;;&quot;$(WebKitLibrariesDir)\include\pthreads&quot;;&quot;$(WebKitOutputDir)\Include\WebCore&quot;;&quot;$(WebKitLibrariesDir)\Include\WebCore&quot;"\r
                                PreprocessorDefinitions="WIN32;_CONSOLE;_SCL_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE"\r
                                MinimalRebuild="true"\r
                                BasicRuntimeChecks="3"\r
                        />\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
-                               AdditionalIncludeDirectories="&quot;$(ProjectDir)\.&quot;;&quot;$(ProjectDir)\..&quot;;&quot;$(WebKitOutputDir)\Include&quot;;&quot;$(WebKitOutputDir)\Include\WebCore\ForwardingHeaders&quot;;&quot;$(WebKitOutputDir)\Include\JavaScriptCore&quot;;&quot;$(WebKitLibrariesDir)\Include&quot;;&quot;$(WebKitLibrariesDir)\include\pthreads&quot;;&quot;$(WebKitOutputDir)\Include\WebCore&quot;;&quot;$(WebKitLibrariesDir)\Include\WebCore&quot;"\r
+                               AdditionalIncludeDirectories="&quot;$(ProjectDir)\.&quot;;&quot;$(ProjectDir)\..&quot;;&quot;$(ProjectDir)\..\cg&quot;;&quot;$(WebKitOutputDir)\Include&quot;;&quot;$(WebKitOutputDir)\Include\WebCore\ForwardingHeaders&quot;;&quot;$(WebKitOutputDir)\Include\JavaScriptCore&quot;;&quot;$(WebKitLibrariesDir)\Include&quot;;&quot;$(WebKitLibrariesDir)\include\pthreads&quot;;&quot;$(WebKitOutputDir)\Include\WebCore&quot;;&quot;$(WebKitLibrariesDir)\Include\WebCore&quot;"\r
                                PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_SCL_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE"\r
                                RuntimeLibrary="2"\r
                                UsePrecompiledHeader="0"\r
                        <Tool\r
                                Name="VCCLCompilerTool"\r
                                Optimization="0"\r
-                               AdditionalIncludeDirectories="&quot;$(ProjectDir)\.&quot;;&quot;$(ProjectDir)\..&quot;;&quot;$(WebKitOutputDir)\Include&quot;;&quot;$(WebKitOutputDir)\Include\WebCore\ForwardingHeaders&quot;;&quot;$(WebKitOutputDir)\Include\JavaScriptCore&quot;;&quot;$(WebKitLibrariesDir)\Include&quot;;&quot;$(WebKitLibrariesDir)\include\pthreads&quot;;&quot;$(WebKitOutputDir)\Include\WebCore&quot;;&quot;$(WebKitLibrariesDir)\Include\WebCore&quot;"\r
+                               AdditionalIncludeDirectories="&quot;$(ProjectDir)\.&quot;;&quot;$(ProjectDir)\..&quot;;&quot;$(ProjectDir)\..\cg&quot;;&quot;$(WebKitOutputDir)\Include&quot;;&quot;$(WebKitOutputDir)\Include\WebCore\ForwardingHeaders&quot;;&quot;$(WebKitOutputDir)\Include\JavaScriptCore&quot;;&quot;$(WebKitLibrariesDir)\Include&quot;;&quot;$(WebKitLibrariesDir)\include\pthreads&quot;;&quot;$(WebKitOutputDir)\Include\WebCore&quot;;&quot;$(WebKitLibrariesDir)\Include\WebCore&quot;"\r
                                PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_SCL_SECURE_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE"\r
                                MinimalRebuild="true"\r
                                BasicRuntimeChecks="3"\r
                        >\r
                </File>\r
                <File\r
+                       RelativePath=".\MD5.cpp"\r
+                       >\r
+               </File>\r
+               <File\r
+                       RelativePath=".\MD5.h"\r
+                       >\r
+               </File>\r
+               <File\r
+                       RelativePath=".\PixelDumpSupport.h"\r
+                       >\r
+               </File>\r
+               <File\r
+                       RelativePath="..\cg\PixelDumpSupportCG.cpp"\r
+                       >\r
+               </File>\r
+               <File\r
+                       RelativePath="..\cg\PixelDumpSupportCG.h"\r
+                       >\r
+               </File>\r
+               <File\r
+                       RelativePath=".\PixelDumpSupportWin.cpp"\r
+                       >\r
+               </File>\r
+               <File\r
                        RelativePath="..\WorkQueue.cpp"\r
                        >\r
                </File>\r
diff --git a/WebKitTools/DumpRenderTree/win/MD5.cpp b/WebKitTools/DumpRenderTree/win/MD5.cpp
new file mode 100644 (file)
index 0000000..4d4c848
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2007 Apple, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "MD5.h"
+
+#include <windows.h>
+
+typedef void (WINAPI*initPtr)(MD5_CTX*);
+typedef void (WINAPI*updatePtr)(MD5_CTX*, unsigned char*, unsigned);
+typedef void (WINAPI*finalPtr)(MD5_CTX*);
+
+static HMODULE cryptDLL()
+{
+    static HMODULE module = LoadLibraryW(L"Cryptdll.dll");
+    return module;
+}
+
+static initPtr init()
+{
+    static initPtr ptr = reinterpret_cast<initPtr>(GetProcAddress(cryptDLL(), "MD5Init"));
+    return ptr;
+}
+
+static updatePtr update()
+{
+    static updatePtr ptr = reinterpret_cast<updatePtr>(GetProcAddress(cryptDLL(), "MD5Update"));
+    return ptr;
+}
+
+static finalPtr final()
+{
+    static finalPtr ptr = reinterpret_cast<finalPtr>(GetProcAddress(cryptDLL(), "MD5Final"));
+    return ptr;
+}
+
+void MD5_Init(MD5_CTX* context)
+{
+    init()(context);
+}
+
+void MD5_Update(MD5_CTX* context, unsigned char* input, unsigned length)
+{
+    update()(context, input, length);
+}
+
+void MD5_Final(unsigned char hash[16], MD5_CTX* context)
+{
+    final()(context);
+
+    for (int i = 0; i < 16; ++i)
+        hash[i] = context->digest[i];
+}
diff --git a/WebKitTools/DumpRenderTree/win/MD5.h b/WebKitTools/DumpRenderTree/win/MD5.h
new file mode 100644 (file)
index 0000000..702bc80
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2007 Apple, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef MD5_h
+#define MD5_h
+
+typedef unsigned long ULONG;
+
+struct MD5_CTX {\r
+    ULONG i[2];\r
+    ULONG buf[4];\r
+    unsigned char in[64];\r
+    unsigned char digest[16];\r
+};
+
+void MD5_Init(MD5_CTX*);
+void MD5_Update(MD5_CTX*, unsigned char* input, unsigned length);
+void MD5_Final(unsigned char hash[16], MD5_CTX*);
+
+#endif // MD5_h
diff --git a/WebKitTools/DumpRenderTree/win/PixelDumpSupport.h b/WebKitTools/DumpRenderTree/win/PixelDumpSupport.h
new file mode 100644 (file)
index 0000000..523c00a
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2007 Apple, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef PixelDumpSupport_h
+#define PixelDumpSupport_h
+
+// FIXME: This file should move out of the win/ subdirectory.
+
+void dumpWebViewAsPixelsAndCompareWithExpected(const char* currentTest, bool forceAllTestsToDumpPixels);
+
+#endif // PixelDumpSupport_h
diff --git a/WebKitTools/DumpRenderTree/win/PixelDumpSupportWin.cpp b/WebKitTools/DumpRenderTree/win/PixelDumpSupportWin.cpp
new file mode 100644 (file)
index 0000000..f6dd82d
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2007 Apple, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ *     its contributors may be used to endorse or promote products derived
+ *     from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "DumpRenderTree.h"
+#include "PixelDumpSupportCG.h"
+
+#include <CoreGraphics/CGBitmapContext.h>
+#include <wtf/Assertions.h>
+#include <wtf/RetainPtr.h>
+
+RetainPtr<CGContextRef> getBitmapContextFromWebView()
+{
+    RECT frame;
+    if (!GetWindowRect(webViewWindow, &frame))
+        return 0;
+
+    BITMAPINFO bmp = {0};
+    bmp.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
+    bmp.bmiHeader.biWidth = frame.right - frame.left;
+    bmp.bmiHeader.biHeight = -(frame.bottom - frame.top);
+    bmp.bmiHeader.biPlanes = 1;
+    bmp.bmiHeader.biBitCount = 32;
+    bmp.bmiHeader.biCompression = BI_RGB;
+
+    // FIXME: Currently we leak this HBITMAP because we don't have a good way
+    // to destroy it when the CGBitmapContext gets destroyed.
+    void* bits = 0;
+    HBITMAP bitmap = CreateDIBSection(0, &bmp, DIB_RGB_COLORS, &bits, 0, 0);
+
+    HDC memoryDC = CreateCompatibleDC(0);
+    SelectObject(memoryDC, bitmap);
+    SendMessage(webViewWindow, WM_PRINTCLIENT, reinterpret_cast<WPARAM>(memoryDC), PRF_CLIENT | PRF_CHILDREN | PRF_OWNED);
+    DeleteDC(memoryDC);
+
+    BITMAP info = {0};
+    GetObject(bitmap, sizeof(info), &info);
+    ASSERT(info.bmBitsPixel == 32);
+
+    RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB());
+    return RetainPtr<CGContextRef>(AdoptCF, CGBitmapContextCreate(info.bmBits, info.bmWidth, info.bmHeight, 8,
+                                                info.bmWidthBytes, colorSpace.get(), kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst));
+}