Changeset 172864 in webkit


Ignore:
Timestamp:
Aug 22, 2014 12:07:17 PM (10 years ago)
Author:
Simon Fraser
Message:

Implement paint flashing via GraphicsLayers in the WK2 inspector overlay
https://bugs.webkit.org/show_bug.cgi?id=136136

Reviewed by Sam Weinig, Joseph Pecoraro.
Source/WebCore:

Allow InspectorClient to have a custom implementation of showPaintRect(). For
WebKit2's WebInspectorClient, implement this by creating a set of GraphicsLayers
which are parented in a document overlay, with 0.25s fade-out animations.

Also change InspectorInstrumentation::didPaintImpl() to no longer take a GraphicsContext;
it makes no sense to paint the paint rects directly into the context of the web page.
Now that the paint rects are painted into an overlay, the rectangles need to be converted
to root document coordinates, which is done in InspectorInstrumentation::didPaintImpl().

Remove the generic InspectorOverlay::drawOutline()-based indicators; they will
be reimplemented in a later patch.

  • WebCore.exp.in:
  • inspector/InspectorClient.h:

(WebCore::InspectorClient::showPaintRect):

  • inspector/InspectorInstrumentation.cpp:

(WebCore::InspectorInstrumentation::didPaintImpl):

  • inspector/InspectorInstrumentation.h:

(WebCore::InspectorInstrumentation::didPaint):

  • inspector/InspectorPageAgent.cpp:

(WebCore::InspectorPageAgent::didPaint):

  • inspector/InspectorPageAgent.h:
  • page/FrameView.cpp:

(WebCore::FrameView::didPaintContents):

  • rendering/RenderLayerBacking.cpp:

(WebCore::RenderLayerBacking::paintContents):

Source/WebKit2:

Allow InspectorClient to have a custom implementation of showPaintRect(). For
WebKit2's WebInspectorClient, implement this by creating a set of GraphicsLayers
which are parented in a document overlay, with 0.25s fade-out animations.

Also change InspectorInstrumentation::didPaintImpl() to no longer take a GraphicsContext;
it makes no sense to paint the paint rects directly into the context of the web page.
Now that the paint rects are painted into an overlay, the rectangles need to be converted
to root document coordinates, which is done in InspectorInstrumentation::didPaintImpl().

Remove the generic InspectorOverlay::drawOutline()-based indicators; they will
be reimplemented in a later patch.

  • WebProcess/WebCoreSupport/WebInspectorClient.cpp:

(WebKit::RepaintIndicatorLayerClient::RepaintIndicatorLayerClient):
(WebKit::RepaintIndicatorLayerClient::~RepaintIndicatorLayerClient):
(WebKit::RepaintIndicatorLayerClient::notifyAnimationEnded):
(WebKit::WebInspectorClient::WebInspectorClient):
(WebKit::WebInspectorClient::~WebInspectorClient):
(WebKit::WebInspectorClient::showPaintRect):
(WebKit::WebInspectorClient::animationEndedForLayer):

  • WebProcess/WebCoreSupport/WebInspectorClient.h:

(WebKit::WebInspectorClient::WebInspectorClient): Deleted.

Location:
trunk/Source
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r172862 r172864  
     12014-08-22  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Implement paint flashing via GraphicsLayers in the WK2 inspector overlay
     4        https://bugs.webkit.org/show_bug.cgi?id=136136
     5
     6        Reviewed by Sam Weinig, Joseph Pecoraro.
     7
     8        Allow InspectorClient to have a custom implementation of showPaintRect(). For
     9        WebKit2's WebInspectorClient, implement this by creating a set of GraphicsLayers
     10        which are parented in a document overlay, with 0.25s fade-out animations.
     11       
     12        Also change InspectorInstrumentation::didPaintImpl() to no longer take a GraphicsContext;
     13        it makes no sense to paint the paint rects directly into the context of the web page.
     14        Now that the paint rects are painted into an overlay, the rectangles need to be converted
     15        to root document coordinates, which is done in InspectorInstrumentation::didPaintImpl().
     16       
     17        Remove the generic InspectorOverlay::drawOutline()-based indicators; they will
     18        be reimplemented in a later patch.
     19
     20        * WebCore.exp.in:
     21        * inspector/InspectorClient.h:
     22        (WebCore::InspectorClient::showPaintRect):
     23        * inspector/InspectorInstrumentation.cpp:
     24        (WebCore::InspectorInstrumentation::didPaintImpl):
     25        * inspector/InspectorInstrumentation.h:
     26        (WebCore::InspectorInstrumentation::didPaint):
     27        * inspector/InspectorPageAgent.cpp:
     28        (WebCore::InspectorPageAgent::didPaint):
     29        * inspector/InspectorPageAgent.h:
     30        * page/FrameView.cpp:
     31        (WebCore::FrameView::didPaintContents):
     32        * rendering/RenderLayerBacking.cpp:
     33        (WebCore::RenderLayerBacking::paintContents):
     34
    1352014-08-22  Commit Queue  <commit-queue@webkit.org>
    236
  • trunk/Source/WebCore/WebCore.exp.in

    r172854 r172864  
    760760__ZN7WebCore17HistoryController33restoreScrollPositionAndViewStateEv
    761761__ZN7WebCore17JSDOMGlobalObject6s_infoE
     762__ZN7WebCore17KeyframeValueList6insertEN3WTF10PassOwnPtrIKNS_14AnimationValueEEE
    762763__ZN7WebCore17MouseRelatedEvent7offsetXEv
    763764__ZN7WebCore17MouseRelatedEvent7offsetYEv
     
    13781379__ZN7WebCore8toUInt16EPN3JSC9ExecStateENS0_7JSValueENS_30IntegerConversionConfigurationE
    13791380__ZN7WebCore8toUInt64EPN3JSC9ExecStateENS0_7JSValueENS_30IntegerConversionConfigurationE
     1381__ZN7WebCore9AnimationC1Ev
     1382__ZN7WebCore9AnimationD1Ev
    13801383__ZN7WebCore9DOMWindow30dispatchAllPendingUnloadEventsEv
    13811384__ZN7WebCore9DOMWindow36dispatchAllPendingBeforeUnloadEventsEv
  • trunk/Source/WebCore/inspector/InspectorClient.h

    r172862 r172864  
    3535namespace WebCore {
    3636
     37class FloatRect;
     38class Frame;
    3739class InspectorController;
    38 class Frame;
    3940class Page;
    4041
     
    6162    virtual void clearBrowserCookies() { }
    6263
    63     virtual bool overridesShowPaintRects() { return false; }
     64    virtual bool overridesShowPaintRects() const { return false; }
    6465    virtual void setShowPaintRects(bool) { }
     66    virtual void showPaintRect(const FloatRect&) { }
    6567
    6668    virtual bool canShowDebugBorders() { return false; }
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp

    r171195 r172864  
    486486}
    487487
    488 void InspectorInstrumentation::didPaintImpl(InstrumentingAgents*  instrumentingAgents, RenderObject* renderer, GraphicsContext* context, const LayoutRect& rect)
     488void InspectorInstrumentation::didPaintImpl(InstrumentingAgents* instrumentingAgents, RenderObject* renderer, const LayoutRect& rect)
    489489{
    490490    if (InspectorTimelineAgent* timelineAgent = instrumentingAgents->inspectorTimelineAgent())
    491491        timelineAgent->didPaint(renderer, rect);
     492
    492493    if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent())
    493         pageAgent->didPaint(context, rect);
     494        pageAgent->didPaint(renderer, rect);
    494495}
    495496
  • trunk/Source/WebCore/inspector/InspectorInstrumentation.h

    r172862 r172864  
    167167    static void didScrollLayer(Frame*);
    168168    static void willPaint(RenderObject*);
    169     static void didPaint(RenderObject*, GraphicsContext*, const LayoutRect&);
     169    static void didPaint(RenderObject*, const LayoutRect&);
    170170    static InspectorInstrumentationCookie willRecalculateStyle(Document*);
    171171    static void didRecalculateStyle(const InspectorInstrumentationCookie&);
     
    365365    static void didScrollLayerImpl(InstrumentingAgents*);
    366366    static void willPaintImpl(InstrumentingAgents*, RenderObject*);
    367     static void didPaintImpl(InstrumentingAgents*, RenderObject*, GraphicsContext*, const LayoutRect&);
     367    static void didPaintImpl(InstrumentingAgents*, RenderObject*, const LayoutRect&);
    368368    static InspectorInstrumentationCookie willRecalculateStyleImpl(InstrumentingAgents*, Frame*);
    369369    static void didRecalculateStyleImpl(const InspectorInstrumentationCookie&);
     
    11221122}
    11231123
    1124 inline void InspectorInstrumentation::didPaint(RenderObject* renderer, GraphicsContext* context, const LayoutRect& rect)
     1124inline void InspectorInstrumentation::didPaint(RenderObject* renderer, const LayoutRect& rect)
    11251125{
    11261126#if ENABLE(INSPECTOR)
    11271127    FAST_RETURN_IF_NO_FRONTENDS(void());
    11281128    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForRenderer(renderer))
    1129         didPaintImpl(instrumentingAgents, renderer, context, rect);
     1129        didPaintImpl(instrumentingAgents, renderer, rect);
    11301130#else
    11311131    UNUSED_PARAM(renderer);
    1132     UNUSED_PARAM(context);
    11331132    UNUSED_PARAM(rect);
    11341133#endif
  • trunk/Source/WebCore/inspector/InspectorPageAgent.cpp

    r172790 r172864  
    881881}
    882882
    883 void InspectorPageAgent::didPaint(GraphicsContext* context, const LayoutRect& rect)
    884 {
    885     if (!m_enabled || m_client->overridesShowPaintRects() || !m_showPaintRects)
    886         return;
    887 
    888     static int colorSelector = 0;
    889     const Color colors[] = {
    890         Color(0xFF, 0, 0, 0x3F),
    891         Color(0xFF, 0, 0xFF, 0x3F),
    892         Color(0, 0, 0xFF, 0x3F),
    893     };
    894 
    895     LayoutRect inflatedRect(rect);
    896     inflatedRect.inflate(-1);
    897     m_overlay->drawOutline(context, inflatedRect, colors[colorSelector++ % WTF_ARRAY_LENGTH(colors)]);
     883void InspectorPageAgent::didPaint(RenderObject* renderer, const LayoutRect& rect)
     884{
     885    if (!m_enabled || !m_showPaintRects)
     886        return;
     887
     888    LayoutRect absoluteRect = LayoutRect(renderer->localToAbsoluteQuad(FloatRect(rect)).boundingBox());
     889    FrameView* view = renderer->document().view();
     890   
     891    LayoutRect rootRect = absoluteRect;
     892    if (!view->frame().isMainFrame()) {
     893        IntRect rootViewRect = view->contentsToRootView(pixelSnappedIntRect(absoluteRect));
     894        rootRect = view->frame().mainFrame().view()->rootViewToContents(rootViewRect);
     895    }
     896   
     897    if (m_client->overridesShowPaintRects()) {
     898        m_client->showPaintRect(rect);
     899        return;
     900    }
     901
     902    // FIXME: the overlay needs to accumulate paint rects and draw them itself.
    898903}
    899904
  • trunk/Source/WebCore/inspector/InspectorPageAgent.h

    r172655 r172864  
    5656class Frame;
    5757class Frontend;
    58 class GraphicsContext;
    5958class InspectorClient;
    6059class InspectorOverlay;
     
    6261class URL;
    6362class Page;
     63class RenderObject;
    6464class SharedBuffer;
    6565class TextResourceDecoder;
     
    141141    void didRunJavaScriptDialog();
    142142    void applyEmulatedMedia(String*);
    143     void didPaint(GraphicsContext*, const LayoutRect&);
     143    void didPaint(RenderObject*, const LayoutRect&);
    144144    void didLayout();
    145145    void didScroll();
  • trunk/Source/WebCore/page/FrameView.cpp

    r172854 r172864  
    36703670
    36713671    if (!context->paintingDisabled()) {
    3672         InspectorInstrumentation::didPaint(renderView(), context, dirtyRect);
     3672        InspectorInstrumentation::didPaint(renderView(), dirtyRect);
    36733673        // FIXME: should probably not fire milestones for snapshot painting. https://bugs.webkit.org/show_bug.cgi?id=117623
    36743674        firePaintRelatedMilestonesIfNeeded();
  • trunk/Source/WebCore/rendering/RenderLayerBacking.cpp

    r172836 r172864  
    21992199        paintIntoLayer(graphicsLayer, &context, dirtyRect, PaintBehaviorNormal, paintingPhase);
    22002200
    2201         InspectorInstrumentation::didPaint(&renderer(), &context, dirtyRect);
     2201        InspectorInstrumentation::didPaint(&renderer(), dirtyRect);
    22022202    } else if (graphicsLayer == layerForHorizontalScrollbar()) {
    22032203        paintScrollbar(m_owningLayer.horizontalScrollbar(), context, dirtyRect);
  • trunk/Source/WebKit2/ChangeLog

    r172860 r172864  
     12014-08-22  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Implement paint flashing via GraphicsLayers in the WK2 inspector overlay
     4        https://bugs.webkit.org/show_bug.cgi?id=136136
     5
     6        Reviewed by Sam Weinig, Joseph Pecoraro.
     7       
     8        Allow InspectorClient to have a custom implementation of showPaintRect(). For
     9        WebKit2's WebInspectorClient, implement this by creating a set of GraphicsLayers
     10        which are parented in a document overlay, with 0.25s fade-out animations.
     11       
     12        Also change InspectorInstrumentation::didPaintImpl() to no longer take a GraphicsContext;
     13        it makes no sense to paint the paint rects directly into the context of the web page.
     14        Now that the paint rects are painted into an overlay, the rectangles need to be converted
     15        to root document coordinates, which is done in InspectorInstrumentation::didPaintImpl().
     16       
     17        Remove the generic InspectorOverlay::drawOutline()-based indicators; they will
     18        be reimplemented in a later patch.
     19
     20        * WebProcess/WebCoreSupport/WebInspectorClient.cpp:
     21        (WebKit::RepaintIndicatorLayerClient::RepaintIndicatorLayerClient):
     22        (WebKit::RepaintIndicatorLayerClient::~RepaintIndicatorLayerClient):
     23        (WebKit::RepaintIndicatorLayerClient::notifyAnimationEnded):
     24        (WebKit::WebInspectorClient::WebInspectorClient):
     25        (WebKit::WebInspectorClient::~WebInspectorClient):
     26        (WebKit::WebInspectorClient::showPaintRect):
     27        (WebKit::WebInspectorClient::animationEndedForLayer):
     28        * WebProcess/WebCoreSupport/WebInspectorClient.h:
     29        (WebKit::WebInspectorClient::WebInspectorClient): Deleted.
     30
    1312014-08-22  Jon Lee  <jonlee@apple.com>
    232
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebInspectorClient.cpp

    r170445 r172864  
    2929#if ENABLE(INSPECTOR)
    3030
     31#include "DrawingArea.h"
    3132#include "WebInspector.h"
    3233#include "WebPage.h"
    3334#include <WebCore/InspectorController.h>
    3435#include <WebCore/Page.h>
     36#include <wtf/CurrentTime.h>
    3537
    3638#if PLATFORM(IOS)
     
    4143
    4244namespace WebKit {
     45
     46class RepaintIndicatorLayerClient final : public GraphicsLayerClient {
     47public:
     48    RepaintIndicatorLayerClient(WebInspectorClient& inspectorClient)
     49        : m_inspectorClient(inspectorClient)
     50    {
     51    }
     52    virtual ~RepaintIndicatorLayerClient() { }
     53private:
     54    virtual void notifyAnimationEnded(const GraphicsLayer* layer, const String&) override
     55    {
     56        m_inspectorClient.animationEndedForLayer(layer);
     57    }
     58   
     59    WebInspectorClient& m_inspectorClient;
     60};
     61
     62WebInspectorClient::WebInspectorClient(WebPage* page)
     63    : m_page(page)
     64    , m_highlightOverlay(nullptr)
     65{
     66}
     67
     68WebInspectorClient::~WebInspectorClient()
     69{
     70    for (auto layer : m_paintRectLayers) {
     71        layer->removeFromParent();
     72        delete layer;
     73    }
     74
     75    if (m_paintRectOverlay)
     76        m_page->uninstallPageOverlay(m_paintRectOverlay.get());
     77}
    4378
    4479void WebInspectorClient::inspectorDestroyed()
     
    101136}
    102137
     138void WebInspectorClient::showPaintRect(const FloatRect& rect)
     139{
     140    if (!m_paintRectOverlay) {
     141        m_paintRectOverlay = PageOverlay::create(this, PageOverlay::OverlayType::Document);
     142        m_page->installPageOverlay(m_paintRectOverlay, PageOverlay::FadeMode::DoNotFade);
     143    }
     144
     145    if (!m_paintIndicatorLayerClient)
     146        m_paintIndicatorLayerClient = std::make_unique<RepaintIndicatorLayerClient>(*this);
     147
     148    std::unique_ptr<GraphicsLayer> paintLayer = GraphicsLayer::create(m_page->drawingArea()->graphicsLayerFactory(), *m_paintIndicatorLayerClient);
     149   
     150    paintLayer->setAnchorPoint(FloatPoint3D());
     151    paintLayer->setPosition(rect.location());
     152    paintLayer->setSize(rect.size());
     153    paintLayer->setBackgroundColor(Color(1.0f, 0.0f, 0.0f, 0.2f));
     154
     155    KeyframeValueList fadeKeyframes(AnimatedPropertyOpacity);
     156    OwnPtr<AnimationValue> intialValue = FloatAnimationValue::create(0, 1);
     157    fadeKeyframes.insert(intialValue.release());
     158
     159    OwnPtr<AnimationValue> finalValue = FloatAnimationValue::create(0.25, 0);
     160    fadeKeyframes.insert(finalValue.release());
     161   
     162    RefPtr<Animation> opacityAnimation = Animation::create();
     163    opacityAnimation->setDuration(0.25);
     164
     165    paintLayer->addAnimation(fadeKeyframes, FloatSize(), opacityAnimation.get(), ASCIILiteral("opacity"), 0);
     166   
     167    m_paintRectLayers.add(paintLayer.get());
     168
     169    GraphicsLayer* overlayRootLayer = m_paintRectOverlay->layer();
     170    overlayRootLayer->addChild(paintLayer.release());
     171}
     172
     173void WebInspectorClient::animationEndedForLayer(const GraphicsLayer* layer)
     174{
     175    const_cast<GraphicsLayer*>(layer)->removeFromParent();
     176    m_paintRectLayers.remove(const_cast<GraphicsLayer*>(layer));
     177    delete layer;
     178}
     179
    103180#if PLATFORM(IOS)
    104181void WebInspectorClient::showInspectorIndication()
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebInspectorClient.h

    r170445 r172864  
    3333#include <WebCore/InspectorClient.h>
    3434#include <WebCore/InspectorForwarding.h>
     35#include <wtf/HashSet.h>
    3536
    3637namespace WebCore {
    3738class GraphicsContext;
     39class GraphicsLayer;
    3840class IntRect;
    3941}
     
    4244
    4345class WebPage;
     46class RepaintIndicatorLayerClient;
    4447
    4548class WebInspectorClient : public WebCore::InspectorClient, public WebCore::InspectorFrontendChannel, private PageOverlay::Client {
     49friend class RepaintIndicatorLayerClient;
    4650public:
    47     WebInspectorClient(WebPage* page)
    48         : m_page(page)
    49         , m_highlightOverlay(0)
    50     {
    51     }
     51    WebInspectorClient(WebPage*);
     52    virtual ~WebInspectorClient();
    5253
    5354private:
     
    6970#endif
    7071
     72    virtual bool overridesShowPaintRects() const override { return true; }
     73    virtual void showPaintRect(const WebCore::FloatRect&) override;
     74
    7175    virtual bool sendMessageToFrontend(const String&) override;
    7276
     
    8084    virtual bool mouseEvent(PageOverlay*, const WebMouseEvent&) override;
    8185
     86    void animationEndedForLayer(const WebCore::GraphicsLayer*);
     87
    8288    WebPage* m_page;
    8389    PageOverlay* m_highlightOverlay;
     90   
     91    RefPtr<PageOverlay> m_paintRectOverlay;
     92    std::unique_ptr<RepaintIndicatorLayerClient> m_paintIndicatorLayerClient;
     93    HashSet<WebCore::GraphicsLayer*> m_paintRectLayers; // Ideally this would be HashSet<std::unique_ptr<GraphicsLayer>> but that doesn't work yet. webkit.org/b/136166
    8494};
    8595
Note: See TracChangeset for help on using the changeset viewer.