Title: [249921] trunk/Source
Revision
249921
Author
bfulg...@apple.com
Date
2019-09-16 14:39:45 -0700 (Mon, 16 Sep 2019)

Log Message

[FTW] Correct lifespan of other SharedBitmaps
https://bugs.webkit.org/show_bug.cgi?id=201800

Reviewed by Dean Jackson.

The pop-up menu code creates its own SharedBitmap in the WebContent process,
which needs to release its handle before destruction, otherwise the UIProcess
will be unable to access the GPU texture (since it will have been cleaned up).

Source/WebCore:

This patch also audits other uses of SharedBitmap to make sure a similar
problem doesn't exist elsewhere.

* platform/graphics/win/Direct2DUtilities.cpp:
(WebCore::Direct2D::toDXGIDevice): Switch to IDXGIDevice1 (since that is our
minimum target DX).
(WebCore::Direct2D::factoryForDXGIDevice): Ditto.
(WebCore::Direct2D::swapChainOfSizeForWindowAndDevice): Added.
* platform/graphics/win/Direct2DUtilities.h:
* platform/graphics/win/GraphicsContextDirect2D.cpp:
(WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate): Correct
a very silly use-after-move in the implementation.
* platform/graphics/win/PlatformContextDirect2D.h:
(WebCore::PlatformContextDirect2D::d3dDevice const): Added.
(WebCore::PlatformContextDirect2D::setD3DDevice):

Source/WebKit:

Since WebPopupMenuProxyWin has its own HWND and WinProc, it needs its own
swapChain to handle syncing of content to the screen.

This patch also audits other uses of SharedBitmap to make sure a similar
problem doesn't exist elsewhere.

* Shared/ShareableBitmap.h:
* Shared/win/ShareableBitmapDirect2D.cpp:
(WebKit::ShareableBitmap::paint):
(WebKit::ShareableBitmap::createDirect2DSurface):
* UIProcess/win/WebPopupMenuProxyWin.cpp:
(WebKit::WebPopupMenuProxyWin::showPopupMenu): Add Direct2D code paths.
(WebKit::WebPopupMenuProxyWin::paint): Update for Direct2D.
(WebKit::WebPopupMenuProxyWin::setupSwapChain): Added.
(WebKit::WebPopupMenuProxyWin::configureBackingStore): Added.
* UIProcess/win/WebPopupMenuProxyWin.h:
* UIProcess/win/WebView.cpp:
(WebKit::WebView::setupSwapChain): Move some implementation code to the
Direct2DUtilities file.
* UIProcess/win/WebView.h:
(WebKit::WebView::d3dDevice const):
(WebKit::WebView::d3dImmediateContext const):
(WebKit::WebView::d3dDevice): Deleted.
* WebProcess/WebCoreSupport/WebPopupMenu.cpp:
(WebKit::WebPopupMenu::show):
* WebProcess/WebPage/FindController.cpp:
(WebKit::FindController::getImageForFindMatch): Prevent WebContent process from
destroying SharedBitmap before the UIProcess can receive it.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (249920 => 249921)


--- trunk/Source/WebCore/ChangeLog	2019-09-16 21:21:29 UTC (rev 249920)
+++ trunk/Source/WebCore/ChangeLog	2019-09-16 21:39:45 UTC (rev 249921)
@@ -1,3 +1,30 @@
+2019-09-16  Brent Fulgham  <bfulg...@apple.com>
+
+        [FTW] Correct lifespan of other SharedBitmaps
+        https://bugs.webkit.org/show_bug.cgi?id=201800
+
+        Reviewed by Dean Jackson.
+
+        The pop-up menu code creates its own SharedBitmap in the WebContent process,
+        which needs to release its handle before destruction, otherwise the UIProcess
+        will be unable to access the GPU texture (since it will have been cleaned up).
+
+        This patch also audits other uses of SharedBitmap to make sure a similar
+        problem doesn't exist elsewhere.
+
+        * platform/graphics/win/Direct2DUtilities.cpp:
+        (WebCore::Direct2D::toDXGIDevice): Switch to IDXGIDevice1 (since that is our
+        minimum target DX).
+        (WebCore::Direct2D::factoryForDXGIDevice): Ditto.
+        (WebCore::Direct2D::swapChainOfSizeForWindowAndDevice): Added.
+        * platform/graphics/win/Direct2DUtilities.h:
+        * platform/graphics/win/GraphicsContextDirect2D.cpp:
+        (WebCore::GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate): Correct
+        a very silly use-after-move in the implementation.
+        * platform/graphics/win/PlatformContextDirect2D.h:
+        (WebCore::PlatformContextDirect2D::d3dDevice const): Added.
+        (WebCore::PlatformContextDirect2D::setD3DDevice):
+
 2019-09-16  Chris Dumez  <cdu...@apple.com>
 
         Simplify WebResourceLoadObserver now that we have one WebProcess per session

Modified: trunk/Source/WebCore/platform/graphics/win/Direct2DUtilities.cpp (249920 => 249921)


--- trunk/Source/WebCore/platform/graphics/win/Direct2DUtilities.cpp	2019-09-16 21:21:29 UTC (rev 249920)
+++ trunk/Source/WebCore/platform/graphics/win/Direct2DUtilities.cpp	2019-09-16 21:39:45 UTC (rev 249921)
@@ -412,13 +412,13 @@
     return true;
 }
 
-COMPtr<IDXGIDevice> toDXGIDevice(const COMPtr<ID3D11Device1>& d3dDevice)
+COMPtr<IDXGIDevice1> toDXGIDevice(const COMPtr<ID3D11Device1>& d3dDevice)
 {
     if (!d3dDevice)
         return nullptr;
 
-    COMPtr<IDXGIDevice> dxgiDevice;
-    HRESULT hr = d3dDevice->QueryInterface(__uuidof(IDXGIDevice), (void **)&dxgiDevice);
+    COMPtr<IDXGIDevice1> dxgiDevice;
+    HRESULT hr = d3dDevice->QueryInterface(__uuidof(IDXGIDevice1), (void **)&dxgiDevice);
     if (!SUCCEEDED(hr))
         return nullptr;
 
@@ -425,7 +425,7 @@
     return dxgiDevice;
 }
 
-COMPtr<IDXGIFactory2> factoryForDXGIDevice(const COMPtr<IDXGIDevice>& device)
+COMPtr<IDXGIFactory2> factoryForDXGIDevice(const COMPtr<IDXGIDevice1>& device)
 {
     if (!device)
         return nullptr;
@@ -445,6 +445,33 @@
     return factory2;
 }
 
+COMPtr<IDXGISwapChain> swapChainOfSizeForWindowAndDevice(const WebCore::IntSize& size, HWND window, const COMPtr<ID3D11Device1>& device)
+{
+    if (!device)
+        return nullptr;
+
+    DXGI_SWAP_CHAIN_DESC1 swapChainDescription;
+    ::ZeroMemory(&swapChainDescription, sizeof(swapChainDescription));
+    swapChainDescription.Width = size.width();
+    swapChainDescription.Height = size.height();
+    swapChainDescription.Format = webkitTextureFormat;
+    swapChainDescription.SampleDesc.Count = 1;
+    swapChainDescription.SampleDesc.Quality = 0;
+    swapChainDescription.BufferUsage = DXGI_USAGE_SHADER_INPUT | DXGI_USAGE_RENDER_TARGET_OUTPUT;
+    swapChainDescription.BufferCount = 1;
+    swapChainDescription.Flags = DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE;
+
+    auto factory = Direct2D::factoryForDXGIDevice(Direct2D::toDXGIDevice(device));
+
+    COMPtr<IDXGISwapChain1> swapChain1;
+    HRESULT hr = factory->CreateSwapChainForHwnd(device.get(), window, &swapChainDescription, nullptr, nullptr, &swapChain1);
+    if (!SUCCEEDED(hr))
+        return nullptr;
+
+    COMPtr<IDXGISwapChain> swapChain(Query, swapChain1);
+    return swapChain;
+}
+
 } // namespace Direct2D
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/win/Direct2DUtilities.h (249920 => 249921)


--- trunk/Source/WebCore/platform/graphics/win/Direct2DUtilities.h	2019-09-16 21:21:29 UTC (rev 249920)
+++ trunk/Source/WebCore/platform/graphics/win/Direct2DUtilities.h	2019-09-16 21:39:45 UTC (rev 249921)
@@ -40,8 +40,10 @@
 interface ID2D1RenderTarget;
 interface ID3D11Device1;
 interface ID3D11DeviceContext1;
-interface IDXGIDevice;
+interface ID3D11RenderTargetView;
+interface IDXGIDevice1;
 interface IDXGIFactory2;
+interface IDXGISwapChain;
 interface IDXGISurface1;
 interface IWICBitmapSource;
 interface IWICBitmap;
@@ -49,6 +51,7 @@
 struct D2D1_BITMAP_PROPERTIES;
 struct D2D1_PIXEL_FORMAT;
 struct D2D1_RENDER_TARGET_PROPERTIES;
+struct D3D11_VIEWPORT;
 
 namespace WebCore {
 
@@ -87,8 +90,9 @@
 WEBCORE_EXPORT ID3D11DeviceContext1* dxgiImmediateContext();
 WEBCORE_EXPORT ID3D11Device1* defaultDirectXDevice();
 WEBCORE_EXPORT bool createDeviceAndContext(COMPtr<ID3D11Device1>&, COMPtr<ID3D11DeviceContext1>&);
-WEBCORE_EXPORT COMPtr<IDXGIDevice> toDXGIDevice(const COMPtr<ID3D11Device1>&);
-WEBCORE_EXPORT COMPtr<IDXGIFactory2> factoryForDXGIDevice(const COMPtr<IDXGIDevice>&);
+WEBCORE_EXPORT COMPtr<IDXGIDevice1> toDXGIDevice(const COMPtr<ID3D11Device1>&);
+WEBCORE_EXPORT COMPtr<IDXGIFactory2> factoryForDXGIDevice(const COMPtr<IDXGIDevice1>&);
+WEBCORE_EXPORT COMPtr<IDXGISwapChain> swapChainOfSizeForWindowAndDevice(const WebCore::IntSize&, HWND, const COMPtr<ID3D11Device1>&);
 
 void writeDiagnosticPNGToPath(ID2D1RenderTarget*, ID2D1Bitmap*, LPCWSTR fileName);
 

Modified: trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp (249920 => 249921)


--- trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp	2019-09-16 21:21:29 UTC (rev 249920)
+++ trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp	2019-09-16 21:39:45 UTC (rev 249921)
@@ -296,7 +296,7 @@
 
 GraphicsContextPlatformPrivate::GraphicsContextPlatformPrivate(std::unique_ptr<PlatformContextDirect2D>&& ownedPlatformContext, GraphicsContext::BitmapRenderingContextType renderingType)
     : m_ownedPlatformContext(WTFMove(ownedPlatformContext))
-    , m_platformContext(*ownedPlatformContext)
+    , m_platformContext(*m_ownedPlatformContext)
     , m_rendererType(renderingType)
 {
     if (!m_platformContext.renderTarget())

Modified: trunk/Source/WebCore/platform/graphics/win/PlatformContextDirect2D.h (249920 => 249921)


--- trunk/Source/WebCore/platform/graphics/win/PlatformContextDirect2D.h	2019-09-16 21:21:29 UTC (rev 249920)
+++ trunk/Source/WebCore/platform/graphics/win/PlatformContextDirect2D.h	2019-09-16 21:39:45 UTC (rev 249921)
@@ -32,6 +32,7 @@
 #include <d2d1.h>
 #include <d2d1_1.h>
 #include <d2d1effects.h>
+#include <d3d11_1.h>
 
 namespace WebCore {
 
@@ -54,6 +55,9 @@
     ID2D1RenderTarget* renderTarget() { return m_renderTarget.get(); }
     void setRenderTarget(ID2D1RenderTarget* renderTarget) { m_renderTarget = renderTarget; }
 
+    ID3D11Device1* d3dDevice() const { return m_d3dDevice.get(); }
+    void setD3DDevice(ID3D11Device1* device) { m_d3dDevice = device; }
+
     GraphicsContextPlatformPrivate* graphicsContextPrivate() { return m_graphicsContextPrivate; }
     void setGraphicsContextPrivate(GraphicsContextPlatformPrivate* graphicsContextPrivate) { m_graphicsContextPrivate = graphicsContextPrivate; }
 
@@ -127,6 +131,8 @@
     COMPtr<ID2D1BitmapBrush> m_patternStrokeBrush;
     COMPtr<ID2D1BitmapBrush> m_patternFillBrush;
 
+    COMPtr<ID3D11Device1> m_d3dDevice;
+
     WTF::Function<void()> m_preDrawHandler;
     WTF::Function<void()> m_postDrawHandler;
 

Modified: trunk/Source/WebKit/ChangeLog (249920 => 249921)


--- trunk/Source/WebKit/ChangeLog	2019-09-16 21:21:29 UTC (rev 249920)
+++ trunk/Source/WebKit/ChangeLog	2019-09-16 21:39:45 UTC (rev 249921)
@@ -1,3 +1,43 @@
+2019-09-16  Brent Fulgham  <bfulg...@apple.com>
+
+        [FTW] Correct lifespan of other SharedBitmaps
+        https://bugs.webkit.org/show_bug.cgi?id=201800
+
+        Reviewed by Dean Jackson.
+
+        The pop-up menu code creates its own SharedBitmap in the WebContent process,
+        which needs to release its handle before destruction, otherwise the UIProcess
+        will be unable to access the GPU texture (since it will have been cleaned up).
+
+        Since WebPopupMenuProxyWin has its own HWND and WinProc, it needs its own
+        swapChain to handle syncing of content to the screen.
+
+        This patch also audits other uses of SharedBitmap to make sure a similar
+        problem doesn't exist elsewhere.
+
+        * Shared/ShareableBitmap.h:
+        * Shared/win/ShareableBitmapDirect2D.cpp:
+        (WebKit::ShareableBitmap::paint):
+        (WebKit::ShareableBitmap::createDirect2DSurface):
+        * UIProcess/win/WebPopupMenuProxyWin.cpp:
+        (WebKit::WebPopupMenuProxyWin::showPopupMenu): Add Direct2D code paths.
+        (WebKit::WebPopupMenuProxyWin::paint): Update for Direct2D.
+        (WebKit::WebPopupMenuProxyWin::setupSwapChain): Added.
+        (WebKit::WebPopupMenuProxyWin::configureBackingStore): Added.
+        * UIProcess/win/WebPopupMenuProxyWin.h:
+        * UIProcess/win/WebView.cpp:
+        (WebKit::WebView::setupSwapChain): Move some implementation code to the
+        Direct2DUtilities file.
+        * UIProcess/win/WebView.h:
+        (WebKit::WebView::d3dDevice const):
+        (WebKit::WebView::d3dImmediateContext const):
+        (WebKit::WebView::d3dDevice): Deleted.
+        * WebProcess/WebCoreSupport/WebPopupMenu.cpp:
+        (WebKit::WebPopupMenu::show):
+        * WebProcess/WebPage/FindController.cpp:
+        (WebKit::FindController::getImageForFindMatch): Prevent WebContent process from
+        destroying SharedBitmap before the UIProcess can receive it.
+
 2019-09-16  Chris Dumez  <cdu...@apple.com>
 
         Simplify WebResourceLoadObserver now that we have one WebProcess per session

Modified: trunk/Source/WebKit/Shared/ShareableBitmap.h (249920 => 249921)


--- trunk/Source/WebKit/Shared/ShareableBitmap.h	2019-09-16 21:21:29 UTC (rev 249920)
+++ trunk/Source/WebKit/Shared/ShareableBitmap.h	2019-09-16 21:39:45 UTC (rev 249921)
@@ -174,6 +174,7 @@
 #if USE(DIRECT2D)
     COMPtr<IDXGISurface1> m_surface;
     COMPtr<IDXGIKeyedMutex> m_surfaceMutex;
+    COMPtr<ID2D1Bitmap> m_bitmap;
 #endif
 
     // If the shareable bitmap is backed by shared memory, this points to the shared memory object.

Modified: trunk/Source/WebKit/Shared/win/ShareableBitmapDirect2D.cpp (249920 => 249921)


--- trunk/Source/WebKit/Shared/win/ShareableBitmapDirect2D.cpp	2019-09-16 21:21:29 UTC (rev 249920)
+++ trunk/Source/WebKit/Shared/win/ShareableBitmapDirect2D.cpp	2019-09-16 21:39:45 UTC (rev 249921)
@@ -114,7 +114,7 @@
 
 void ShareableBitmap::paint(GraphicsContext& context, float scaleFactor, const IntPoint& dstPoint, const IntRect& srcRect)
 {
-    auto surface = createDirect2DSurface(nullptr, context.platformContext()->renderTarget());
+    auto surface = createDirect2DSurface(context.platformContext()->d3dDevice(), context.platformContext()->renderTarget());
 
 #ifndef _NDEBUG
     auto bitmapSize = surface->GetPixelSize();
@@ -139,27 +139,28 @@
     if (!directXDevice)
         directXDevice = Direct2D::defaultDirectXDevice();
 
-    COMPtr<ID3D11Texture2D> texture;
-    HRESULT hr = directXDevice->OpenSharedResource1(m_configuration.sharedResourceHandle, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&texture));
-    if (!SUCCEEDED(hr))
-        return nullptr;
+    if (!m_bitmap) {
+        COMPtr<ID3D11Texture2D> texture;
+        HRESULT hr = directXDevice->OpenSharedResource1(m_configuration.sharedResourceHandle, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&texture));
+        if (!SUCCEEDED(hr))
+            return nullptr;
 
-    hr = texture->QueryInterface(&m_surface);
-    RELEASE_ASSERT(SUCCEEDED(hr));
+        hr = texture->QueryInterface(&m_surface);
+        RELEASE_ASSERT(SUCCEEDED(hr));
 
-    // Lock the surface to the current device while rendering.
-    hr = m_surface->QueryInterface(&m_surfaceMutex);
-    RELEASE_ASSERT(SUCCEEDED(hr));
-    hr = m_surfaceMutex->AcquireSync(1, INFINITE);
-    RELEASE_ASSERT(SUCCEEDED(hr));
+        // Lock the surface to the current device while rendering.
+        hr = m_surface->QueryInterface(&m_surfaceMutex);
+        RELEASE_ASSERT(SUCCEEDED(hr));
+        hr = m_surfaceMutex->AcquireSync(1, INFINITE);
+        RELEASE_ASSERT(SUCCEEDED(hr));
 
-    COMPtr<ID2D1Bitmap> bitmap;
-    auto bitmapProperties = Direct2D::bitmapProperties();
-    hr = renderTarget->CreateSharedBitmap(__uuidof(IDXGISurface1), reinterpret_cast<void*>(m_surface.get()), &bitmapProperties, &bitmap);
-    if (!SUCCEEDED(hr))
-        return nullptr;
+        auto bitmapProperties = Direct2D::bitmapProperties();
+        hr = renderTarget->CreateSharedBitmap(__uuidof(IDXGISurface1), reinterpret_cast<void*>(m_surface.get()), &bitmapProperties, &m_bitmap);
+        if (!SUCCEEDED(hr))
+            return nullptr;
+    }
 
-    return bitmap;
+    return m_bitmap;
 }
 
 RefPtr<Image> ShareableBitmap::createImage()

Modified: trunk/Source/WebKit/UIProcess/win/WebPopupMenuProxyWin.cpp (249920 => 249921)


--- trunk/Source/WebKit/UIProcess/win/WebPopupMenuProxyWin.cpp	2019-09-16 21:21:29 UTC (rev 249920)
+++ trunk/Source/WebKit/UIProcess/win/WebPopupMenuProxyWin.cpp	2019-09-16 21:39:45 UTC (rev 249921)
@@ -42,6 +42,13 @@
 #include <WebCore/WebCoreInstanceHandle.h>
 #include <windowsx.h>
 
+#if USE(DIRECT2D)
+#include <WebCore/Direct2DUtilities.h>
+#include <d3d11_1.h>
+#include <directxcolors.h> 
+#include <dxgi.h>
+#endif
+
 namespace WebKit {
 using namespace WebCore;
 
@@ -205,6 +212,11 @@
 
         if (!m_popup)
             return;
+
+#if USE(DIRECT2D)
+        Direct2D::createDeviceAndContext(m_d3dDevice, m_immediateContext);
+        setupSwapChain(m_windowRect.size());
+#endif
     }
 
     BOOL shouldAnimate = FALSE;
@@ -813,6 +825,7 @@
     if (!m_popup)
         return;
 
+#if !USE(DIRECT2D)
     if (!m_DC) {
         m_DC = adoptGDIObject(::CreateCompatibleDC(HWndDC(m_popup)));
         if (!m_DC)
@@ -838,7 +851,23 @@
     }
 
     GraphicsContext context(m_DC.get());
+#else
+    COMPtr<ID3D11Texture2D> backBuffer; 
+    HRESULT hr = m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&backBuffer)); 
+    if (!SUCCEEDED(hr))
+        return;
 
+    COMPtr<IDXGISurface1> surface(Query, backBuffer);
+    if (!surface)
+        return;
+
+    auto renderTarget = WebCore::Direct2D::createSurfaceRenderTarget(surface.get());
+
+    PlatformContextDirect2D platformContext(renderTarget.get());
+    platformContext.setD3DDevice(m_d3dDevice.get());
+    GraphicsContext context(&platformContext, GraphicsContext::BitmapRenderingContextType::GPUMemory);
+#endif
+
     IntRect translatedDamageRect = damageRect;
     translatedDamageRect.move(IntSize(0, m_scrollOffset * m_itemHeight));
     m_data.m_notSelectedBackingStore->paint(context, damageRect.location(), translatedDamageRect);
@@ -852,11 +881,15 @@
     if (m_scrollbar)
         m_scrollbar->paint(context, damageRect);
 
-
+#if !USE(DIRECT2D)
     HWndDC hWndDC;
     HDC localDC = hdc ? hdc : hWndDC.setHWnd(m_popup);
 
     ::BitBlt(localDC, damageRect.x(), damageRect.y(), damageRect.width(), damageRect.height(), m_DC.get(), damageRect.x(), damageRect.y(), SRCCOPY);
+#else
+    context.flush();
+    m_swapChain->Present(0, 0); 
+#endif
 }
 
 bool WebPopupMenuProxyWin::setFocusedIndex(int i, bool hotTracking)
@@ -959,4 +992,45 @@
     return false;
 }
 
+#if USE(DIRECT2D)
+void WebPopupMenuProxyWin::setupSwapChain(const WebCore::IntSize& size)
+{
+    m_swapChain = Direct2D::swapChainOfSizeForWindowAndDevice(size, m_popup, m_d3dDevice);
+    RELEASE_ASSERT(m_swapChain);
+    auto factory = Direct2D::factoryForDXGIDevice(Direct2D::toDXGIDevice(m_d3dDevice));
+
+    factory->MakeWindowAssociation(m_popup, 0);
+    configureBackingStore(size);
+}
+
+void WebPopupMenuProxyWin::configureBackingStore(const WebCore::IntSize& size)
+{
+    ASSERT(m_swapChain);
+    ASSERT(m_d3dDevice);
+    ASSERT(m_immediateContext);
+
+    // Create a render target view 
+    COMPtr<ID3D11Texture2D> backBuffer; 
+    HRESULT hr = m_swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&backBuffer)); 
+    RELEASE_ASSERT(SUCCEEDED(hr));
+
+    hr = m_d3dDevice->CreateRenderTargetView(backBuffer.get(), nullptr, &m_renderTargetView); 
+    RELEASE_ASSERT(SUCCEEDED(hr));
+
+    auto* renderTargetView = m_renderTargetView.get();
+    m_immediateContext->OMSetRenderTargets(1, &renderTargetView, nullptr);
+
+    // Setup the viewport 
+    D3D11_VIEWPORT viewport;
+    viewport.Width = (FLOAT)size.width();
+    viewport.Height = (FLOAT)size.height();
+    viewport.MinDepth = 0.0f;
+    viewport.MaxDepth = 1.0f;
+    viewport.TopLeftX = 0;
+    viewport.TopLeftY = 0;
+    m_immediateContext->RSSetViewports(1, &viewport);
+
+    m_immediateContext->ClearRenderTargetView(m_renderTargetView.get(), DirectX::Colors::BlanchedAlmond); 
+}
+#endif
 } // namespace WebKit

Modified: trunk/Source/WebKit/UIProcess/win/WebPopupMenuProxyWin.h (249920 => 249921)


--- trunk/Source/WebKit/UIProcess/win/WebPopupMenuProxyWin.h	2019-09-16 21:21:29 UTC (rev 249920)
+++ trunk/Source/WebKit/UIProcess/win/WebPopupMenuProxyWin.h	2019-09-16 21:39:45 UTC (rev 249921)
@@ -33,6 +33,13 @@
 #include <WebCore/ScrollableArea.h>
 #include <WebCore/Scrollbar.h>
 
+#if USE(DIRECT2D)
+interface ID3D11Device1;
+interface ID3D11DeviceContext1;
+interface ID3D11RenderTargetView;
+interface IDXGISwapChain;
+#endif
+
 namespace WebKit {
 
 class WebView;
@@ -122,6 +129,11 @@
     void incrementWheelDelta(int delta);
     void reduceWheelDelta(int delta);
 
+#if USE(DIRECT2D)
+    void setupSwapChain(const WebCore::IntSize&);
+    void configureBackingStore(const WebCore::IntSize&);
+#endif
+
     WebView* m_webView;
     Vector<WebPopupItem> m_items;
     PlatformPopupMenuData m_data;
@@ -128,6 +140,12 @@
     int m_newSelectedIndex { 0 };
 
     RefPtr<WebCore::Scrollbar> m_scrollbar;
+#if USE(DIRECT2D)
+    COMPtr<ID3D11Device1> m_d3dDevice;
+    COMPtr<ID3D11DeviceContext1> m_immediateContext;
+    COMPtr<ID3D11RenderTargetView> m_renderTargetView; 
+    COMPtr<IDXGISwapChain> m_swapChain;
+#endif
     GDIObject<HDC> m_DC;
     GDIObject<HBITMAP> m_bmp;
     HWND m_popup { nullptr };

Modified: trunk/Source/WebKit/UIProcess/win/WebView.cpp (249920 => 249921)


--- trunk/Source/WebKit/UIProcess/win/WebView.cpp	2019-09-16 21:21:29 UTC (rev 249920)
+++ trunk/Source/WebKit/UIProcess/win/WebView.cpp	2019-09-16 21:39:45 UTC (rev 249921)
@@ -956,24 +956,11 @@
     if (!m_d3dDevice)
         return;
 
-    DXGI_SWAP_CHAIN_DESC1 swapChainDescription;
-    ::ZeroMemory(&swapChainDescription, sizeof(swapChainDescription));
-    swapChainDescription.Width = size.width();
-    swapChainDescription.Height = size.height();
-    swapChainDescription.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
-    swapChainDescription.SampleDesc.Count = 1;
-    swapChainDescription.SampleDesc.Quality = 0;
-    swapChainDescription.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
-    swapChainDescription.BufferCount = 1;
+    m_swapChain = Direct2D::swapChainOfSizeForWindowAndDevice(size, m_window, m_d3dDevice);
+    RELEASE_ASSERT(m_swapChain);
 
     auto factory = Direct2D::factoryForDXGIDevice(Direct2D::toDXGIDevice(m_d3dDevice));
 
-    IDXGISwapChain1* swapChain1 = nullptr;
-    HRESULT hr = factory->CreateSwapChainForHwnd(m_d3dDevice.get(), m_window, &swapChainDescription, nullptr, nullptr, &swapChain1);
-    if (SUCCEEDED(hr))
-        hr = swapChain1->QueryInterface(__uuidof(IDXGISwapChain), reinterpret_cast<void**>(&m_swapChain));
-    RELEASE_ASSERT(SUCCEEDED(hr));
-
     factory->MakeWindowAssociation(m_window, 0);
     configureBackingStore(size);
 }

Modified: trunk/Source/WebKit/UIProcess/win/WebView.h (249920 => 249921)


--- trunk/Source/WebKit/UIProcess/win/WebView.h	2019-09-16 21:21:29 UTC (rev 249920)
+++ trunk/Source/WebKit/UIProcess/win/WebView.h	2019-09-16 21:39:45 UTC (rev 249921)
@@ -84,7 +84,8 @@
     DrawingAreaProxy* drawingArea() { return page() ? page()->drawingArea() : nullptr; }
 
 #if USE(DIRECT2D)
-    ID3D11Device1* d3dDevice() { return m_d3dDevice.get(); }
+    ID3D11Device1* d3dDevice() const { return m_d3dDevice.get(); }
+    ID3D11DeviceContext1* d3dImmediateContext() const { return m_immediateContext.get(); }
 #endif
 
 private:

Modified: trunk/Source/WebKit/WebProcess/WebCoreSupport/WebPopupMenu.cpp (249920 => 249921)


--- trunk/Source/WebKit/WebProcess/WebCoreSupport/WebPopupMenu.cpp	2019-09-16 21:21:29 UTC (rev 249920)
+++ trunk/Source/WebKit/WebProcess/WebCoreSupport/WebPopupMenu.cpp	2019-09-16 21:39:45 UTC (rev 249921)
@@ -112,6 +112,12 @@
     setUpPlatformData(pageCoordinates, platformData);
 
     WebProcess::singleton().parentProcessConnection()->send(Messages::WebPageProxy::ShowPopupMenu(pageCoordinates, static_cast<uint64_t>(m_popupClient->menuStyle().textDirection()), items, index, platformData), m_page->identifier());
+
+#if USE(DIRECT2D)
+    // Don't destroy the shared handle in the WebContent process. It will be destroyed in the UIProcess.
+    platformData.m_notSelectedBackingStore->leakSharedResource();
+    platformData.m_selectedBackingStore->leakSharedResource();
+#endif
 }
 
 void WebPopupMenu::hide()

Modified: trunk/Source/WebKit/WebProcess/WebPage/FindController.cpp (249920 => 249921)


--- trunk/Source/WebKit/WebProcess/WebPage/FindController.cpp	2019-09-16 21:21:29 UTC (rev 249920)
+++ trunk/Source/WebKit/WebProcess/WebPage/FindController.cpp	2019-09-16 21:39:45 UTC (rev 249921)
@@ -328,6 +328,10 @@
         return;
 
     m_webPage->send(Messages::WebPageProxy::DidGetImageForFindMatch(handle, matchIndex));
+#if USE(DIRECT2D)
+    // Don't destroy the shared handle in the WebContent process. It will be destroyed in the UIProcess.
+    selectionSnapshot->leakSharedResource();
+#endif
 }
 
 void FindController::selectFindMatch(uint32_t matchIndex)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to