[Win][Direct2D] Implement GraphicsContext::releaseWindowsContext.
authorpvollan@apple.com <pvollan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Oct 2016 22:37:21 +0000 (22:37 +0000)
committerpvollan@apple.com <pvollan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 27 Oct 2016 22:37:21 +0000 (22:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=163988

Reviewed by Brent Fulgham.

This method is needed to draw native controls.

* platform/graphics/win/GraphicsContextDirect2D.cpp:
(WebCore::GraphicsContext::releaseWindowsContext):

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

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp

index 101a3b5..e2ef345 100644 (file)
@@ -1,3 +1,15 @@
+2016-10-27  Per Arne Vollan  <pvollan@apple.com>
+
+        [Win][Direct2D] Implement GraphicsContext::releaseWindowsContext.
+        https://bugs.webkit.org/show_bug.cgi?id=163988
+
+        Reviewed by Brent Fulgham.
+
+        This method is needed to draw native controls.
+
+        * platform/graphics/win/GraphicsContextDirect2D.cpp:
+        (WebCore::GraphicsContext::releaseWindowsContext):
+
 2016-10-27  Joseph Pecoraro  <pecoraro@apple.com>
 
         Web Inspector: Worker should recover if Inspector is closed and never sent Worker.initialized command
index c0780d8..c310bce 100644 (file)
@@ -257,6 +257,35 @@ void GraphicsContext::drawNativeImage(const COMPtr<ID2D1Bitmap>& image, const Fl
 
 void GraphicsContext::releaseWindowsContext(HDC hdc, const IntRect& dstRect, bool supportAlphaBlend, bool mayCreateBitmap)
 {
+    bool createdBitmap = mayCreateBitmap && (!m_data->m_hdc || isInTransparencyLayer());
+    if (!createdBitmap) {
+        m_data->restore();
+        return;
+    }
+
+    if (!hdc || dstRect.isEmpty())
+        return;
+
+    auto sourceBitmap = adoptGDIObject(static_cast<HBITMAP>(::GetCurrentObject(hdc, OBJ_BITMAP)));
+
+    DIBPixelData pixelData(sourceBitmap.get());
+    ASSERT(pixelData.bitsPerPixel() == 32);
+
+    auto bitmapProperties = D2D1::BitmapProperties(D2D1::PixelFormat(DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE));
+
+    COMPtr<ID2D1Bitmap> bitmap;
+    HRESULT hr = platformContext()->CreateBitmap(pixelData.size(), pixelData.buffer(), pixelData.bytesPerRow(), &bitmapProperties, &bitmap);
+    ASSERT(SUCCEEDED(hr));
+
+    if (!didBeginDraw())
+        platformContext()->BeginDraw();
+
+    platformContext()->DrawBitmap(bitmap.get(), dstRect);
+
+    if (!didBeginDraw())
+        hr = platformContext()->EndDraw();
+
+    ::DeleteDC(hdc);
 }
 
 void GraphicsContext::drawWindowsBitmap(WindowsBitmap* image, const IntPoint& point)