Title: [237616] trunk/Tools
Revision
237616
Author
[email protected]
Date
2018-10-30 19:29:21 -0700 (Tue, 30 Oct 2018)

Log Message

[Win][Direct2D] Support building DumpRenderTree for Direct2D
https://bugs.webkit.org/show_bug.cgi?id=191093
<rdar://problem/45685706>

Reviewed by Alex Christensen.

* DumpRenderTree/PixelDumpSupport.cpp: Update for Direct2D use.
* DumpRenderTree/PlatformWin.cmake: Add support for Direct2D build.
* DumpRenderTree/win/PixelDumpSupportDirect2D.cpp: Added.
(pixelDumpSystemFactory): Added.
(printPNG): Create stub.
(computeMD5HashStringForBitmapContext): Ditto.
(dumpBitmap): Ditto.
* DumpRenderTree/win/PixelDumpSupportDirect2D.h: Added.
(BitmapContext::createByAdoptingBitmapAndContext):
(BitmapContext::~BitmapContext):
(BitmapContext::platformContext const):
(BitmapContext::BitmapContext):
* DumpRenderTree/win/PixelDumpSupportWin.cpp:
(createBitmapContextFromWebView): Update to support Direct2D.
* MiniBrowser/win/MiniBrowserReplace.h: Drive-by fix: The old WebKit
logo is no longer available at this location. Switch to the new logo.

Modified Paths

Added Paths

Diff

Modified: trunk/Tools/ChangeLog (237615 => 237616)


--- trunk/Tools/ChangeLog	2018-10-31 02:27:51 UTC (rev 237615)
+++ trunk/Tools/ChangeLog	2018-10-31 02:29:21 UTC (rev 237616)
@@ -1,3 +1,28 @@
+2018-10-30  Brent Fulgham  <[email protected]>
+
+        [Win][Direct2D] Support building DumpRenderTree for Direct2D
+        https://bugs.webkit.org/show_bug.cgi?id=191093
+        <rdar://problem/45685706>
+
+        Reviewed by Alex Christensen.
+
+        * DumpRenderTree/PixelDumpSupport.cpp: Update for Direct2D use.
+        * DumpRenderTree/PlatformWin.cmake: Add support for Direct2D build.
+        * DumpRenderTree/win/PixelDumpSupportDirect2D.cpp: Added.
+        (pixelDumpSystemFactory): Added.
+        (printPNG): Create stub.
+        (computeMD5HashStringForBitmapContext): Ditto.
+        (dumpBitmap): Ditto.
+        * DumpRenderTree/win/PixelDumpSupportDirect2D.h: Added.
+        (BitmapContext::createByAdoptingBitmapAndContext):
+        (BitmapContext::~BitmapContext):
+        (BitmapContext::platformContext const):
+        (BitmapContext::BitmapContext):
+        * DumpRenderTree/win/PixelDumpSupportWin.cpp:
+        (createBitmapContextFromWebView): Update to support Direct2D.
+        * MiniBrowser/win/MiniBrowserReplace.h: Drive-by fix: The old WebKit
+        logo is no longer available at this location. Switch to the new logo.
+
 2018-10-30  Jonathan Bedard  <[email protected]>
 
         webkitpy: Support alternate simctl list outputs

Modified: trunk/Tools/DumpRenderTree/PixelDumpSupport.cpp (237615 => 237616)


--- trunk/Tools/DumpRenderTree/PixelDumpSupport.cpp	2018-10-31 02:27:51 UTC (rev 237615)
+++ trunk/Tools/DumpRenderTree/PixelDumpSupport.cpp	2018-10-31 02:29:21 UTC (rev 237616)
@@ -41,6 +41,8 @@
 #include "PixelDumpSupportCG.h"
 #elif USE(CAIRO)
 #include "PixelDumpSupportCairo.h"
+#elif USE(DIRECT2D)
+#include "PixelDumpSupportDirect2D.h"
 #endif
 
 void dumpWebViewAsPixelsAndCompareWithExpected(const std::string& expectedHash)

Modified: trunk/Tools/DumpRenderTree/PlatformWin.cmake (237615 => 237616)


--- trunk/Tools/DumpRenderTree/PlatformWin.cmake	2018-10-31 02:27:51 UTC (rev 237615)
+++ trunk/Tools/DumpRenderTree/PlatformWin.cmake	2018-10-31 02:29:21 UTC (rev 237616)
@@ -1,3 +1,5 @@
+set(USE_DIRECT2D 1)
+
 set(DumpRenderTreeLib_SOURCES
     ${DumpRenderTree_SOURCES}
 
@@ -91,17 +93,28 @@
         cairo/PixelDumpSupportCairo.cpp
     )
 else ()
-    list(APPEND DumpRenderTree_INCLUDE_DIRECTORIES
-        cg
-    )
-    list(APPEND DumpRenderTreeLib_SOURCES
-        cg/PixelDumpSupportCG.cpp
-    )
     list(APPEND DumpRenderTreeLib_LIBRARIES
         CFNetwork
-        CoreGraphics
         CoreText
     )
+    if (${USE_DIRECT2D})
+        list(APPEND DumpRenderTreeLib_SOURCES
+            win/PixelDumpSupportDirect2D.cpp
+        )
+        list(APPEND DumpRenderTreeLib_LIBRARIES
+            D2d1
+        )
+    else ()
+        list(APPEND DumpRenderTree_INCLUDE_DIRECTORIES
+            cg
+        )
+        list(APPEND DumpRenderTreeLib_SOURCES
+            cg/PixelDumpSupportCG.cpp
+        )
+        list(APPEND DumpRenderTreeLib_LIBRARIES
+            CoreGraphics
+        )
+    endif ()
 endif ()
 
 WEBKIT_ADD_PRECOMPILED_HEADER("DumpRenderTreePrefix.h" "win/DumpRenderTreePrefix.cpp" DumpRenderTreeLib_SOURCES)

Added: trunk/Tools/DumpRenderTree/win/PixelDumpSupportDirect2D.cpp (0 => 237616)


--- trunk/Tools/DumpRenderTree/win/PixelDumpSupportDirect2D.cpp	                        (rev 0)
+++ trunk/Tools/DumpRenderTree/win/PixelDumpSupportDirect2D.cpp	2018-10-31 02:29:21 UTC (rev 237616)
@@ -0,0 +1,82 @@
+/*
+* Copyright (C) 2018 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.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``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 INC. OR
+* 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 "config.h"
+#include "PixelDumpSupportDirect2D.h"
+
+#include "DumpRenderTree.h"
+#include "MD5.h"
+#include "PixelDumpSupport.h"
+#include <algorithm>
+#include <ctype.h>
+#include <d2d1.h>
+#include <wtf/Assertions.h>
+#include <wtf/RefPtr.h>
+#include <wtf/RetainPtr.h>
+#include <wtf/StringExtras.h>
+
+
+static const CFStringRef kUTTypePNG = CFSTR("public.png");
+
+ID2D1Factory* pixelDumpSystemFactory()
+{
+    static ID2D1Factory* direct2DFactory = nullptr;
+    if (!direct2DFactory) {
+#ifndef NDEBUG
+        D2D1_FACTORY_OPTIONS options = { };
+        options.debugLevel = D2D1_DEBUG_LEVEL_INFORMATION;
+        HRESULT hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED, options, &direct2DFactory);
+#else
+        HRESULT hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_MULTI_THREADED, &direct2DFactory);
+#endif
+        RELEASE_ASSERT(SUCCEEDED(hr));
+    }
+
+    return direct2DFactory;
+}
+
+static void printPNG(ID2D1Bitmap* image, const char* checksum)
+{
+    UNUSED_PARAM(image);
+    UNUSED_PARAM(checksum);
+    // Not implemented.
+}
+
+void computeMD5HashStringForBitmapContext(BitmapContext* context, char hashString[33])
+{
+    UNUSED_PARAM(context);
+    UNUSED_PARAM(hashString);
+    // Not implemented.
+}
+
+void dumpBitmap(BitmapContext* context, const char* checksum)
+{
+    _com_ptr_t<_com_IIID<ID2D1Bitmap, &__uuidof(ID2D1Bitmap)>> image;
+    HRESULT hr = context->platformContext()->GetBitmap(&image);
+    if (!SUCCEEDED(hr))
+        return;
+
+    printPNG(image.GetInterfacePtr(), checksum);
+}

Added: trunk/Tools/DumpRenderTree/win/PixelDumpSupportDirect2D.h (0 => 237616)


--- trunk/Tools/DumpRenderTree/win/PixelDumpSupportDirect2D.h	                        (rev 0)
+++ trunk/Tools/DumpRenderTree/win/PixelDumpSupportDirect2D.h	2018-10-31 02:29:21 UTC (rev 237616)
@@ -0,0 +1,64 @@
+/*
+* Copyright (C) 2018 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.
+*
+* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``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 INC. OR
+* 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.
+*/
+
+
+#pragma once
+
+#include <comip.h>
+#include <d2d1.h>
+#include <wtf/RefCounted.h>
+#include <wtf/RetainPtr.h>
+
+typedef HBITMAP PlatformBitmapBuffer;
+
+class BitmapContext : public RefCounted<BitmapContext> {
+public:
+    static Ref<BitmapContext> createByAdoptingBitmapAndContext(PlatformBitmapBuffer buffer, ID2D1RenderTarget* context)
+    {
+        return adoptRef(*new BitmapContext(buffer, context));
+    }
+
+    ~BitmapContext()
+    {
+        if (m_buffer)
+            DeleteObject(m_buffer);
+    }
+
+    ID2D1BitmapRenderTarget* platformContext() const { return m_context.GetInterfacePtr(); }
+
+private:
+    BitmapContext(PlatformBitmapBuffer buffer, ID2D1RenderTarget* context)
+        : m_buffer(buffer)
+        , m_context(context)
+    {
+    }
+
+    PlatformBitmapBuffer m_buffer;
+    _com_ptr_t<_com_IIID<ID2D1Bitmap, &__uuidof(ID2D1Bitmap)>> m_bitmap;
+    _com_ptr_t<_com_IIID<ID2D1BitmapRenderTarget, &__uuidof(ID2D1BitmapRenderTarget)>> m_context;
+};
+
+RefPtr<BitmapContext> createBitmapContextFromWebView(bool onscreen, bool incrementalRepaint, bool sweepHorizontally, bool drawSelectionRect);
+ID2D1Factory* pixelDumpSystemFactory();

Modified: trunk/Tools/DumpRenderTree/win/PixelDumpSupportWin.cpp (237615 => 237616)


--- trunk/Tools/DumpRenderTree/win/PixelDumpSupportWin.cpp	2018-10-31 02:27:51 UTC (rev 237615)
+++ trunk/Tools/DumpRenderTree/win/PixelDumpSupportWin.cpp	2018-10-31 02:29:21 UTC (rev 237616)
@@ -32,6 +32,8 @@
 #include "PixelDumpSupportCG.h"
 #elif USE(CAIRO)
 #include "PixelDumpSupportCairo.h"
+#elif USE(DIRECT2D)
+#include "PixelDumpSupportDirect2D.h"
 #endif
 
 #include "DumpRenderTree.h"
@@ -94,8 +96,20 @@
     cairo_surface_t* image = cairo_image_surface_create_for_data((unsigned char*)info.bmBits, CAIRO_FORMAT_ARGB32, 
                                                       info.bmWidth, info.bmHeight, info.bmWidthBytes); 
     cairo_t* context = cairo_create(image); 
-    cairo_surface_destroy(image); 
+    cairo_surface_destroy(image);
+#elif USE(DIRECT2D)
+    auto targetProperties = D2D1::RenderTargetProperties();
+    targetProperties.pixelFormat = D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE);
+
+    COMPtr<ID2D1DCRenderTarget> renderTarget;
+    HRESULT hr = pixelDumpSystemFactory()->CreateDCRenderTarget(&targetProperties, &renderTarget);
+    if (!SUCCEEDED(hr))
+        return nullptr;
+
+    hr = renderTarget->BindDC(memoryDC.get(), &frame);
+    if (!SUCCEEDED(hr))
+        return nullptr;
 #endif 
 
-   return BitmapContext::createByAdoptingBitmapAndContext(bitmap, context);
+    return BitmapContext::createByAdoptingBitmapAndContext(bitmap, renderTarget.get());
 }

Modified: trunk/Tools/MiniBrowser/win/MiniBrowserReplace.h (237615 => 237616)


--- trunk/Tools/MiniBrowser/win/MiniBrowserReplace.h	2018-10-31 02:27:51 UTC (rev 237615)
+++ trunk/Tools/MiniBrowser/win/MiniBrowserReplace.h	2018-10-31 02:29:21 UTC (rev 237616)
@@ -27,7 +27,7 @@
 
 // This file is to make it easier for users to manage changes to the internals of MiniBrowser
 
-static const wchar_t* defaultHTML = L"<p style=\"background-color: #00FF00\">Testing</p><img id=\"webkit logo\" src="" alt=\"Face\"><div style=\"border: solid blue; background: white;\" contenteditable=\"true\">div with blue border</div><ul><li>foo<li>bar<li>baz</ul>";
+static const wchar_t* defaultHTML = L"<p style=\"background-color: #00FF00\">Testing</p><img id=\"webkit logo\" src="" alt=\"WebKit Logo\" height=\"50\" width=\"50\"><div style=\"border: solid blue; background: white;\" contenteditable=\"true\">div with blue border</div><ul><li>foo<li>bar<li>baz</ul>";
 
 static void processCrashReport(const wchar_t* fileName) { ::MessageBox(0, fileName, L"Crash Report", MB_OK); }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to