Title: [175484] trunk/Source
Revision
175484
Author
timothy_hor...@apple.com
Date
2014-11-03 12:08:22 -0800 (Mon, 03 Nov 2014)

Log Message

Use FrameSnapshotting functions in FindController::getFindIndicatorBitmap
https://bugs.webkit.org/show_bug.cgi?id=138300
<rdar://problem/18855863>

Reviewed by Simon Fraser.

Share more code by using WebCore's FrameSnapshotting::snapshotSelection
in FindController instead of copying it into FindController wholesale.

* WebProcess/WebPage/FindController.cpp:
(WebKit::getFindIndicatorBitmap):
Make getFindIndicatorBitmap static, rename it from getFindIndicatorBitmapAndRect,
and drop the rect argument because only one caller wanted it, and we no longer need
to compute it (this happens in WebCore now).

Use snapshotSelection; all of the removed paint behaviors get added by
code in or underneath snapshotSelection now.

Draw the snapshot into our ShareableBitmap; we could avoid this in a future patch
by refactoring the FrameSnapshotting functions to take GraphicsContexts.

(WebKit::FindController::getImageForFindMatch):
(WebKit::FindController::updateFindIndicator):
Adopt the new getFindIndicatorBitmap.

* WebProcess/WebPage/FindController.h:
Remove getFindIndicatorBitmap(AndRect), which is now static.

* WebCore.exp.in:
* page/FrameSnapshotting.cpp:
(WebCore::snapshotSelection):
Move knowledge that selectionBounds can be empty down to WebCore.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (175483 => 175484)


--- trunk/Source/WebCore/ChangeLog	2014-11-03 20:03:57 UTC (rev 175483)
+++ trunk/Source/WebCore/ChangeLog	2014-11-03 20:08:22 UTC (rev 175484)
@@ -1,3 +1,16 @@
+2014-11-03  Tim Horton  <timothy_hor...@apple.com>
+
+        Use FrameSnapshotting functions in FindController::getFindIndicatorBitmap
+        https://bugs.webkit.org/show_bug.cgi?id=138300
+        <rdar://problem/18855863>
+
+        Reviewed by Simon Fraser.
+
+        * WebCore.exp.in:
+        * page/FrameSnapshotting.cpp:
+        (WebCore::snapshotSelection):
+        Move knowledge that selectionBounds can be empty down to WebCore.
+
 2014-11-03  Joseph Pecoraro  <pecor...@apple.com>
 
         Web Inspector: Show Selector's Specificity

Modified: trunk/Source/WebCore/WebCore.exp.in (175483 => 175484)


--- trunk/Source/WebCore/WebCore.exp.in	2014-11-03 20:03:57 UTC (rev 175483)
+++ trunk/Source/WebCore/WebCore.exp.in	2014-11-03 20:08:22 UTC (rev 175484)
@@ -176,6 +176,7 @@
 __ZN7WebCore11HistoryItemC1ERKNS_3URLERKN3WTF6StringES7_S7_
 __ZN7WebCore11HistoryItemC1Ev
 __ZN7WebCore11HistoryItemD1Ev
+__ZN7WebCore11ImageBufferD1Ev
 __ZN7WebCore11JSDOMWindow6s_infoE
 __ZN7WebCore11MemoryCache11setDisabledEb
 __ZN7WebCore11MemoryCache13getStatisticsEv
@@ -521,6 +522,7 @@
 __ZN7WebCore15GraphicsContext11clearShadowEv
 __ZN7WebCore15GraphicsContext12setFillColorERKNS_5ColorENS_10ColorSpaceE
 __ZN7WebCore15GraphicsContext14setStrokeColorERKNS_5ColorENS_10ColorSpaceE
+__ZN7WebCore15GraphicsContext15drawImageBufferEPNS_11ImageBufferENS_10ColorSpaceERKNS_10FloatPointERKNS_20ImagePaintingOptionsE
 __ZN7WebCore15GraphicsContext15drawNativeImageEP7CGImageRKNS_9FloatSizeENS_10ColorSpaceERKNS_9FloatRectES9_NS_17CompositeOperatorENS_9BlendModeENS_16ImageOrientationE
 __ZN7WebCore15GraphicsContext15setFillGradientEN3WTF7PassRefINS_8GradientEEE
 __ZN7WebCore15GraphicsContext18setShouldAntialiasEb
@@ -779,6 +781,7 @@
 __ZN7WebCore17openTemporaryFileERKN3WTF6StringERi
 __ZN7WebCore17sRGBColorSpaceRefEv
 __ZN7WebCore17setCookiesFromDOMERKNS_21NetworkStorageSessionERKNS_3URLES5_RKN3WTF6StringE
+__ZN7WebCore17snapshotSelectionERNS_5FrameEj
 __ZN7WebCore17userVisibleStringEP5NSURL
 __ZN7WebCore18DOMWindowExtensionC1EPNS_5FrameERNS_15DOMWrapperWorldE
 __ZN7WebCore18PlatformCALayerMac18setGeometryFlippedEb

Modified: trunk/Source/WebCore/page/FrameSnapshotting.cpp (175483 => 175484)


--- trunk/Source/WebCore/page/FrameSnapshotting.cpp	2014-11-03 20:03:57 UTC (rev 175483)
+++ trunk/Source/WebCore/page/FrameSnapshotting.cpp	2014-11-03 20:08:22 UTC (rev 175484)
@@ -102,11 +102,19 @@
 
 std::unique_ptr<ImageBuffer> snapshotSelection(Frame& frame, SnapshotOptions options)
 {
-    if (!frame.selection().isRange())
+    auto& selection = frame.selection();
+
+    if (!selection.isRange())
         return nullptr;
 
+    FloatRect selectionBounds = selection.selectionBounds();
+
+    // It is possible for the selection bounds to be empty; see https://bugs.webkit.org/show_bug.cgi?id=56645.
+    if (selectionBounds.isEmpty())
+        return nullptr;
+
     options |= SnapshotOptionsPaintSelectionOnly;
-    return snapshotFrameRect(frame, enclosingIntRect(frame.selection().selectionBounds()), options);
+    return snapshotFrameRect(frame, enclosingIntRect(selectionBounds), options);
 }
 
 std::unique_ptr<ImageBuffer> snapshotNode(Frame& frame, Node& node)

Modified: trunk/Source/WebKit2/ChangeLog (175483 => 175484)


--- trunk/Source/WebKit2/ChangeLog	2014-11-03 20:03:57 UTC (rev 175483)
+++ trunk/Source/WebKit2/ChangeLog	2014-11-03 20:08:22 UTC (rev 175484)
@@ -1,3 +1,33 @@
+2014-11-03  Tim Horton  <timothy_hor...@apple.com>
+
+        Use FrameSnapshotting functions in FindController::getFindIndicatorBitmap
+        https://bugs.webkit.org/show_bug.cgi?id=138300
+        <rdar://problem/18855863>
+
+        Reviewed by Simon Fraser.
+
+        Share more code by using WebCore's FrameSnapshotting::snapshotSelection
+        in FindController instead of copying it into FindController wholesale.
+
+        * WebProcess/WebPage/FindController.cpp:
+        (WebKit::getFindIndicatorBitmap):
+        Make getFindIndicatorBitmap static, rename it from getFindIndicatorBitmapAndRect,
+        and drop the rect argument because only one caller wanted it, and we no longer need
+        to compute it (this happens in WebCore now).
+
+        Use snapshotSelection; all of the removed paint behaviors get added by
+        code in or underneath snapshotSelection now.
+
+        Draw the snapshot into our ShareableBitmap; we could avoid this in a future patch
+        by refactoring the FrameSnapshotting functions to take GraphicsContexts.
+
+        (WebKit::FindController::getImageForFindMatch):
+        (WebKit::FindController::updateFindIndicator):
+        Adopt the new getFindIndicatorBitmap.
+
+        * WebProcess/WebPage/FindController.h:
+        Remove getFindIndicatorBitmap(AndRect), which is now static.
+
 2014-11-03  Csaba Osztrogonác  <o...@webkit.org>
 
         URTBF after r175476 to make GTK and EFL build happy.

Modified: trunk/Source/WebKit2/WebProcess/WebPage/FindController.cpp (175483 => 175484)


--- trunk/Source/WebKit2/WebProcess/WebPage/FindController.cpp	2014-11-03 20:03:57 UTC (rev 175483)
+++ trunk/Source/WebKit2/WebProcess/WebPage/FindController.cpp	2014-11-03 20:08:22 UTC (rev 175484)
@@ -36,8 +36,10 @@
 #include <WebCore/DocumentMarkerController.h>
 #include <WebCore/FloatQuad.h>
 #include <WebCore/FocusController.h>
+#include <WebCore/FrameSnapshotting.h>
 #include <WebCore/FrameView.h>
 #include <WebCore/GraphicsContext.h>
+#include <WebCore/ImageBuffer.h>
 #include <WebCore/MainFrame.h>
 #include <WebCore/Page.h>
 #include <WebCore/PageOverlayController.h>
@@ -257,39 +259,23 @@
     m_webPage->send(Messages::WebPageProxy::DidFindStringMatches(string, matchRects, indexForSelection));
 }
 
-bool FindController::getFindIndicatorBitmapAndRect(Frame& frame, ShareableBitmap::Handle& handle, IntRect& selectionRect)
+static bool getFindIndicatorBitmap(Frame& frame, ShareableBitmap::Handle& handle)
 {
-    selectionRect = enclosingIntRect(frame.selection().selectionBounds());
-
-    // Selection rect can be empty for matches that are currently obscured from view.
-    if (selectionRect.isEmpty())
+    std::unique_ptr<ImageBuffer> snapshot = snapshotSelection(frame, WebCore::SnapshotOptionsForceBlackText);
+    if (!snapshot)
         return false;
 
-    IntSize backingStoreSize = selectionRect.size();
-    float deviceScaleFactor = m_webPage->corePage()->deviceScaleFactor();
-    backingStoreSize.scale(deviceScaleFactor);
-
-    // Create a backing store and paint the find indicator text into it.
-    RefPtr<ShareableBitmap> findIndicatorTextBackingStore = ShareableBitmap::createShareable(backingStoreSize, ShareableBitmap::SupportsAlpha);
+    RefPtr<ShareableBitmap> findIndicatorTextBackingStore = ShareableBitmap::createShareable(snapshot->internalSize(), ShareableBitmap::SupportsAlpha);
     if (!findIndicatorTextBackingStore)
         return false;
 
     // FIXME: We should consider using subpixel antialiasing for the snapshot
     // if we're compositing this image onto a solid color (the modern find indicator style).
     auto graphicsContext = findIndicatorTextBackingStore->createGraphicsContext();
+    float deviceScaleFactor = frame.page()->deviceScaleFactor();
     graphicsContext->scale(FloatSize(deviceScaleFactor, deviceScaleFactor));
+    graphicsContext->drawImageBuffer(snapshot.get(), ColorSpaceDeviceRGB, FloatPoint());
 
-    IntRect paintRect = selectionRect;
-    paintRect.move(frame.view()->frameRect().x(), frame.view()->frameRect().y());
-    paintRect.move(-frame.view()->scrollOffset());
-
-    graphicsContext->translate(-paintRect.x(), -paintRect.y());
-    frame.view()->setPaintBehavior(PaintBehaviorSelectionOnly | PaintBehaviorForceBlackText | PaintBehaviorFlattenCompositingLayers);
-    frame.document()->updateLayout();
-
-    frame.view()->paint(graphicsContext.get(), paintRect);
-    frame.view()->setPaintBehavior(PaintBehaviorNormal);
-
     if (!findIndicatorTextBackingStore->createHandle(handle))
         return false;
     return true;
@@ -306,9 +292,8 @@
     VisibleSelection oldSelection = frame->selection().selection();
     frame->selection().setSelection(VisibleSelection(m_findMatches[matchIndex].get()));
 
-    IntRect selectionRect;
     ShareableBitmap::Handle handle;
-    getFindIndicatorBitmapAndRect(*frame, handle, selectionRect);
+    getFindIndicatorBitmap(*frame, handle);
 
     frame->selection().setSelection(oldSelection);
 
@@ -347,9 +332,9 @@
 #if !PLATFORM(IOS)
 bool FindController::updateFindIndicator(Frame& selectedFrame, bool isShowingOverlay, bool shouldAnimate)
 {
-    IntRect selectionRect;
+    IntRect selectionRect = enclosingIntRect(selectedFrame.selection().selectionBounds());
     ShareableBitmap::Handle handle;
-    if (!getFindIndicatorBitmapAndRect(selectedFrame, handle, selectionRect))
+    if (!getFindIndicatorBitmap(selectedFrame, handle))
         return false;
 
     // We want the selection rect in window coordinates.

Modified: trunk/Source/WebKit2/WebProcess/WebPage/FindController.h (175483 => 175484)


--- trunk/Source/WebKit2/WebProcess/WebPage/FindController.h	2014-11-03 20:03:57 UTC (rev 175483)
+++ trunk/Source/WebKit2/WebProcess/WebPage/FindController.h	2014-11-03 20:08:22 UTC (rev 175484)
@@ -77,7 +77,6 @@
     virtual void drawRect(WebCore::PageOverlay&, WebCore::GraphicsContext&, const WebCore::IntRect& dirtyRect);
 
     Vector<WebCore::IntRect> rectsForTextMatches();
-    bool getFindIndicatorBitmapAndRect(WebCore::Frame&, ShareableBitmap::Handle&, WebCore::IntRect& selectionRect);
     bool updateFindIndicator(WebCore::Frame& selectedFrame, bool isShowingOverlay, bool shouldAnimate = true);
 
     void updateFindUIAfterPageScroll(bool found, const String&, FindOptions, unsigned maxMatchCount);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to