Title: [88978] trunk/Source/WebKit2
Revision
88978
Author
[email protected]
Date
2011-06-15 15:19:01 -0700 (Wed, 15 Jun 2011)

Log Message

REGRESSION(78201): Windowless Flash plug-ins are transparent on some sites
https://bugs.webkit.org/show_bug.cgi?id=62690
<rdar://problem/9512026>

Reviewed by Ada Chan.

The bug arises when mixing CoreGraphics and GDI. When we create a Windows
bitmap for a windowless plug-in to draw into, we first fill it with "clear",
or all 0s. If the plug-in uses GDI to draw, the GDI calls will ignore the
alpha channel, and if we then use CG to blend this bitmap onto the
GraphicsContext for the rest of the page, CG will treat the 0-filled
alpha channel as being transparent.

To fix this, on Windows, use a GDI-backed GraphicsContext to paint the
page in the WebProcess, and use GDI to blit from the UpdateInfo to the
backing store in the UI process.

* Platform/SharedMemory.h:
(WebKit::SharedMemory::handle):
Return the handle for the memory.

* Shared/ShareableBitmap.h:
Declared windowsContext() to return a HDC with the bitmap selected into it.
Added members to store the HDC and the HBITMAP.

* Shared/win/ShareableBitmapWin.cpp: Added.
(WebKit::ShareableBitmap::windowsContext):
Get the screen DC, and create a compatible DC from it. Create a DIB
section backed by the shared memory, select it into the context, and
return it.

* UIProcess/win/BackingStoreWin.cpp:
(WebKit::BackingStore::incorporateUpdate):
Use GDI to blit from the update info's bitmap into the backing store bitmap.

* WebProcess/WebPage/DrawingAreaImpl.cpp:
(WebKit::DrawingAreaImpl::createGraphicsContext):
Return a GraphicsContext from the ShareableBitmap.
(WebKit::DrawingAreaImpl::display):
Call createGraphicsContext(), and pass the ShareableBitmap.

* WebProcess/WebPage/DrawingAreaImpl.h:
Declare createGraphicsContext(), which on Windows will create a GDI-backed
GraphicsContext.

* WebProcess/WebPage/win/DrawingAreaImplWin.cpp: Added.
(WebKit::DrawingAreaImpl::createGraphicsContext):
Get a Windows context for the bitmap, and create and return a new
GraphicsContext using the DC.

* win/WebKit2.vcproj:
Added new files.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (88977 => 88978)


--- trunk/Source/WebKit2/ChangeLog	2011-06-15 22:11:50 UTC (rev 88977)
+++ trunk/Source/WebKit2/ChangeLog	2011-06-15 22:19:01 UTC (rev 88978)
@@ -1,3 +1,58 @@
+2011-06-14  Jon Honeycutt  <[email protected]>
+
+        REGRESSION(78201): Windowless Flash plug-ins are transparent on some sites
+        https://bugs.webkit.org/show_bug.cgi?id=62690
+        <rdar://problem/9512026>
+
+        Reviewed by Ada Chan.
+
+        The bug arises when mixing CoreGraphics and GDI. When we create a Windows
+        bitmap for a windowless plug-in to draw into, we first fill it with "clear",
+        or all 0s. If the plug-in uses GDI to draw, the GDI calls will ignore the
+        alpha channel, and if we then use CG to blend this bitmap onto the
+        GraphicsContext for the rest of the page, CG will treat the 0-filled
+        alpha channel as being transparent.
+
+        To fix this, on Windows, use a GDI-backed GraphicsContext to paint the
+        page in the WebProcess, and use GDI to blit from the UpdateInfo to the
+        backing store in the UI process.
+
+        * Platform/SharedMemory.h:
+        (WebKit::SharedMemory::handle):
+        Return the handle for the memory.
+
+        * Shared/ShareableBitmap.h:
+        Declared windowsContext() to return a HDC with the bitmap selected into it.
+        Added members to store the HDC and the HBITMAP.
+
+        * Shared/win/ShareableBitmapWin.cpp: Added.
+        (WebKit::ShareableBitmap::windowsContext):
+        Get the screen DC, and create a compatible DC from it. Create a DIB
+        section backed by the shared memory, select it into the context, and
+        return it.
+
+        * UIProcess/win/BackingStoreWin.cpp:
+        (WebKit::BackingStore::incorporateUpdate):
+        Use GDI to blit from the update info's bitmap into the backing store bitmap.
+
+        * WebProcess/WebPage/DrawingAreaImpl.cpp:
+        (WebKit::DrawingAreaImpl::createGraphicsContext):
+        Return a GraphicsContext from the ShareableBitmap.
+        (WebKit::DrawingAreaImpl::display):
+        Call createGraphicsContext(), and pass the ShareableBitmap.
+
+        * WebProcess/WebPage/DrawingAreaImpl.h:
+        Declare createGraphicsContext(), which on Windows will create a GDI-backed
+        GraphicsContext.
+
+        * WebProcess/WebPage/win/DrawingAreaImplWin.cpp: Added.
+        (WebKit::DrawingAreaImpl::createGraphicsContext):
+        Get a Windows context for the bitmap, and create and return a new
+        GraphicsContext using the DC.
+
+        * win/WebKit2.vcproj:
+        Added new files.
+
 2011-06-15  Anders Carlsson  <[email protected]>
 
         Reviewed by Sam Weinig.

Modified: trunk/Source/WebKit2/Platform/SharedMemory.h (88977 => 88978)


--- trunk/Source/WebKit2/Platform/SharedMemory.h	2011-06-15 22:11:50 UTC (rev 88977)
+++ trunk/Source/WebKit2/Platform/SharedMemory.h	2011-06-15 22:19:01 UTC (rev 88978)
@@ -94,6 +94,9 @@
 
     size_t size() const { return m_size; }
     void* data() const { return m_data; }
+#if PLATFORM(WIN)
+    HANDLE handle() const { return m_handle; }
+#endif
 
     // Creates a copy-on-write copy of the first |size| bytes.
     PassRefPtr<SharedMemory> createCopyOnWriteCopy(size_t) const;

Modified: trunk/Source/WebKit2/Shared/ShareableBitmap.h (88977 => 88978)


--- trunk/Source/WebKit2/Shared/ShareableBitmap.h	2011-06-15 22:11:50 UTC (rev 88977)
+++ trunk/Source/WebKit2/Shared/ShareableBitmap.h	2011-06-15 22:19:01 UTC (rev 88978)
@@ -111,6 +111,9 @@
     // This is only safe to use when we know that the contents of the shareable bitmap won't change.
     PassRefPtr<WebCore::Image> createImage();
 
+#if PLATFORM(WIN)
+    HDC windowsContext() const;
+#endif
 #if USE(CG)
     // This creates a copied CGImageRef (most likely a copy-on-write) of the shareable bitmap.
     RetainPtr<CGImageRef> makeCGImageCopy();
@@ -155,6 +158,10 @@
 
     // If the shareable bitmap is backed by fastMalloced memory, this points to the data.
     void* m_data;
+#if PLATFORM(WIN)
+    mutable OwnPtr<HDC> m_windowsContext;
+    mutable OwnPtr<HBITMAP> m_windowsBitmap;
+#endif
 };
 
 } // namespace WebKit

Copied: trunk/Source/WebKit2/Shared/win/ShareableBitmapWin.cpp (from rev 88977, trunk/Source/WebKit2/WebProcess/WebPage/win/DrawingAreaImplWin.cpp) (0 => 88978)


--- trunk/Source/WebKit2/Shared/win/ShareableBitmapWin.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/Shared/win/ShareableBitmapWin.cpp	2011-06-15 22:19:01 UTC (rev 88978)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2011 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. 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 INC. 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 "config.h"
+#include "ShareableBitmap.h"
+
+#include <WebCore/BitmapInfo.h>
+#include <WebCore/GraphicsContext.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+HDC ShareableBitmap::windowsContext() const
+{
+    ASSERT(isBackedBySharedMemory());
+    if (m_windowsContext)
+        return m_windowsContext.get();
+
+    OwnPtr<HDC> screenDC = adoptPtr(::GetDC(0));
+    BitmapInfo bmInfo = BitmapInfo::createBottomUp(m_size);
+
+    m_windowsContext = adoptPtr(::CreateCompatibleDC(screenDC.get()));
+    m_windowsBitmap = adoptPtr(CreateDIBSection(m_windowsContext.get(), &bmInfo, DIB_RGB_COLORS, 0, m_sharedMemory->handle(), 0));
+    ::SelectObject(m_windowsContext.get(), m_windowsBitmap.get());
+
+    return m_windowsContext.get();
+}
+
+} // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/win/BackingStoreWin.cpp (88977 => 88978)


--- trunk/Source/WebKit2/UIProcess/win/BackingStoreWin.cpp	2011-06-15 22:11:50 UTC (rev 88977)
+++ trunk/Source/WebKit2/UIProcess/win/BackingStoreWin.cpp	2011-06-15 22:19:01 UTC (rev 88978)
@@ -84,8 +84,8 @@
 
     IntPoint updateRectLocation = updateInfo.updateRectBounds.location();
 
-    BitmapDC dc(m_bitmap.get(), 0);
-    GraphicsContext graphicsContext(dc);
+    BitmapDC backingStoreDC(m_bitmap.get(), 0);
+    HDC bitmapDC = bitmap->windowsContext();
 
     // Paint all update rects.
     for (size_t i = 0; i < updateInfo.updateRects.size(); ++i) {
@@ -93,7 +93,8 @@
         IntRect srcRect = updateRect;
         srcRect.move(-updateRectLocation.x(), -updateRectLocation.y());
 
-        bitmap->paint(graphicsContext, updateRect.location(), srcRect);
+        ::BitBlt(backingStoreDC, updateRect.location().x(), updateRect.location().y(), updateRect.size().width(), updateRect.size().height(),
+            bitmapDC, srcRect.x(), srcRect.y(), SRCCOPY);
     }
 }
 

Modified: trunk/Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.cpp (88977 => 88978)


--- trunk/Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.cpp	2011-06-15 22:11:50 UTC (rev 88977)
+++ trunk/Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.cpp	2011-06-15 22:19:01 UTC (rev 88978)
@@ -585,6 +585,13 @@
     return wastedSpace <= wastedSpaceThreshold;
 }
 
+#if !PLATFORM(WIN)
+PassOwnPtr<GraphicsContext> DrawingAreaImpl::createGraphicsContext(ShareableBitmap* bitmap)
+{
+    return bitmap->createGraphicsContext();
+}
+#endif
+
 void DrawingAreaImpl::display(UpdateInfo& updateInfo)
 {
     ASSERT(!m_isPaintingSuspended);
@@ -631,8 +638,8 @@
     m_scrollRect = IntRect();
     m_scrollOffset = IntSize();
 
-    OwnPtr<GraphicsContext> graphicsContext = bitmap->createGraphicsContext();
-    
+    OwnPtr<GraphicsContext> graphicsContext = createGraphicsContext(bitmap.get());
+
     updateInfo.updateRectBounds = bounds;
 
     graphicsContext->translate(-bounds.x(), -bounds.y());

Modified: trunk/Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.h (88977 => 88978)


--- trunk/Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.h	2011-06-15 22:11:50 UTC (rev 88977)
+++ trunk/Source/WebKit2/WebProcess/WebPage/DrawingAreaImpl.h	2011-06-15 22:19:01 UTC (rev 88978)
@@ -31,8 +31,13 @@
 #include "Region.h"
 #include "RunLoop.h"
 
+namespace WebCore {
+    class GraphicsContext;
+}
+
 namespace WebKit {
 
+class ShareableBitmap;
 class UpdateInfo;
 
 class DrawingAreaImpl : public DrawingArea {
@@ -83,6 +88,7 @@
     void displayTimerFired();
     void display();
     void display(UpdateInfo&);
+    PassOwnPtr<WebCore::GraphicsContext> createGraphicsContext(ShareableBitmap*);
 
     uint64_t m_backingStoreStateID;
 

Modified: trunk/Source/WebKit2/WebProcess/WebPage/win/DrawingAreaImplWin.cpp (88977 => 88978)


--- trunk/Source/WebKit2/WebProcess/WebPage/win/DrawingAreaImplWin.cpp	2011-06-15 22:11:50 UTC (rev 88977)
+++ trunk/Source/WebKit2/WebProcess/WebPage/win/DrawingAreaImplWin.cpp	2011-06-15 22:19:01 UTC (rev 88978)
@@ -26,10 +26,15 @@
 #include "config.h"
 #include "DrawingAreaImpl.h"
 
+#include "ShareableBitmap.h"
+#include "UpdateInfo.h"
 #include "WebPage.h"
 #include "WebPageProxyMessages.h"
 #include "WindowGeometry.h"
+#include <WebCore/GraphicsContext.h>
 
+using namespace WebCore;
+
 namespace WebKit {
 
 void DrawingAreaImpl::scheduleChildWindowGeometryUpdate(const WindowGeometry& geometry)
@@ -46,4 +51,11 @@
     m_webPage->send(Messages::WebPageProxy::ScheduleChildWindowGeometryUpdate(geometry));
 }
 
+PassOwnPtr<GraphicsContext> DrawingAreaImpl::createGraphicsContext(ShareableBitmap* bitmap)
+{
+    HDC bitmapDC = bitmap->windowsContext();
+    return adoptPtr(new GraphicsContext(bitmapDC, true));
+}
+
 } // namespace WebKit
+

Modified: trunk/Source/WebKit2/win/WebKit2.vcproj (88977 => 88978)


--- trunk/Source/WebKit2/win/WebKit2.vcproj	2011-06-15 22:11:50 UTC (rev 88977)
+++ trunk/Source/WebKit2/win/WebKit2.vcproj	2011-06-15 22:19:01 UTC (rev 88978)
@@ -1214,6 +1214,10 @@
 					>
 				</File>
 				<File
+					RelativePath="..\Shared\win\ShareableBitmapWin.cpp"
+					>
+				</File>
+				<File
 					RelativePath="..\Shared\win\WebCoreArgumentCodersWin.cpp"
 					>
 				</File>
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to