Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: Source/core/layout/LayoutView.cpp

Issue 1142283004: Implement a Hit Test Cache. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed. 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 10 matching lines...) Expand all
21 #include "config.h" 21 #include "config.h"
22 #include "core/layout/LayoutView.h" 22 #include "core/layout/LayoutView.h"
23 23
24 #include "core/dom/Document.h" 24 #include "core/dom/Document.h"
25 #include "core/dom/Element.h" 25 #include "core/dom/Element.h"
26 #include "core/editing/FrameSelection.h" 26 #include "core/editing/FrameSelection.h"
27 #include "core/frame/LocalFrame.h" 27 #include "core/frame/LocalFrame.h"
28 #include "core/html/HTMLFrameOwnerElement.h" 28 #include "core/html/HTMLFrameOwnerElement.h"
29 #include "core/html/HTMLIFrameElement.h" 29 #include "core/html/HTMLIFrameElement.h"
30 #include "core/layout/ColumnInfo.h" 30 #include "core/layout/ColumnInfo.h"
31 #include "core/layout/HitTestResult.h"
32 #include "core/layout/LayoutFlowThread.h" 31 #include "core/layout/LayoutFlowThread.h"
33 #include "core/layout/LayoutGeometryMap.h" 32 #include "core/layout/LayoutGeometryMap.h"
34 #include "core/layout/LayoutPart.h" 33 #include "core/layout/LayoutPart.h"
35 #include "core/layout/LayoutQuote.h" 34 #include "core/layout/LayoutQuote.h"
36 #include "core/layout/LayoutScrollbarPart.h" 35 #include "core/layout/LayoutScrollbarPart.h"
37 #include "core/layout/compositing/DeprecatedPaintLayerCompositor.h" 36 #include "core/layout/compositing/DeprecatedPaintLayerCompositor.h"
38 #include "core/page/Page.h" 37 #include "core/page/Page.h"
39 #include "core/paint/DeprecatedPaintLayer.h" 38 #include "core/paint/DeprecatedPaintLayer.h"
40 #include "core/paint/ViewPainter.h" 39 #include "core/paint/ViewPainter.h"
41 #include "core/svg/SVGDocumentExtensions.h" 40 #include "core/svg/SVGDocumentExtensions.h"
42 #include "platform/TraceEvent.h" 41 #include "platform/TraceEvent.h"
43 #include "platform/geometry/FloatQuad.h" 42 #include "platform/geometry/FloatQuad.h"
44 #include "platform/geometry/TransformState.h" 43 #include "platform/geometry/TransformState.h"
44 #include "platform/graphics/GraphicsLayer.h"
45 #include "platform/graphics/paint/DisplayItemList.h" 45 #include "platform/graphics/paint/DisplayItemList.h"
46 46
47 namespace blink { 47 namespace blink {
48 48
49 LayoutView::LayoutView(Document* document) 49 LayoutView::LayoutView(Document* document)
50 : LayoutBlockFlow(document) 50 : LayoutBlockFlow(document)
51 , m_frameView(document->view()) 51 , m_frameView(document->view())
52 , m_selectionStart(nullptr) 52 , m_selectionStart(nullptr)
53 , m_selectionEnd(nullptr) 53 , m_selectionEnd(nullptr)
54 , m_selectionStartPos(-1) 54 , m_selectionStartPos(-1)
55 , m_selectionEndPos(-1) 55 , m_selectionEndPos(-1)
56 , m_pageLogicalHeight(0) 56 , m_pageLogicalHeight(0)
57 , m_pageLogicalHeightChanged(false) 57 , m_pageLogicalHeightChanged(false)
58 , m_layoutState(0) 58 , m_layoutState(0)
59 , m_layoutQuoteHead(nullptr) 59 , m_layoutQuoteHead(nullptr)
60 , m_layoutCounterCount(0) 60 , m_layoutCounterCount(0)
61 , m_hitTestCount(0) 61 , m_hitTestCount(0)
62 , m_hitTestCacheHits(0)
62 , m_pendingSelection(PendingSelection::create()) 63 , m_pendingSelection(PendingSelection::create())
63 { 64 {
64 // init LayoutObject attributes 65 // init LayoutObject attributes
65 setInline(false); 66 setInline(false);
66 67
67 m_minPreferredLogicalWidth = 0; 68 m_minPreferredLogicalWidth = 0;
68 m_maxPreferredLogicalWidth = 0; 69 m_maxPreferredLogicalWidth = 0;
69 70
70 setPreferredLogicalWidthsDirty(MarkOnlyThis); 71 setPreferredLogicalWidthsDirty(MarkOnlyThis);
71 72
72 setPositionState(AbsolutePosition); // to 0,0 :) 73 setPositionState(AbsolutePosition); // to 0,0 :)
73 } 74 }
74 75
75 LayoutView::~LayoutView() 76 LayoutView::~LayoutView()
76 { 77 {
77 } 78 }
78 79
79 bool LayoutView::hitTest(HitTestResult& result) 80 bool LayoutView::hitTest(HitTestResult& result)
80 { 81 {
81 return hitTest(result.hitTestRequest(), result.hitTestLocation(), result);
82 }
83
84 bool LayoutView::hitTest(const HitTestRequest& request, const HitTestLocation& l ocation, HitTestResult& result)
85 {
86 TRACE_EVENT0("blink", "LayoutView::hitTest"); 82 TRACE_EVENT0("blink", "LayoutView::hitTest");
87 m_hitTestCount++; 83 m_hitTestCount++;
88 84
89 ASSERT(!location.isRectBasedTest() || request.listBased()); 85 ASSERT(!result.hitTestLocation().isRectBasedTest() || result.hitTestRequest( ).listBased());
90 86
91 // We have to recursively update layout/style here because otherwise, when t he hit test recurses 87 // We have to recursively update layout/style here because otherwise, when t he hit test recurses
92 // into a child document, it could trigger a layout on the parent document, which can destroy DeprecatedPaintLayer 88 // into a child document, it could trigger a layout on the parent document, which can destroy DeprecatedPaintLayer
93 // that are higher up in the call stack, leading to crashes. 89 // that are higher up in the call stack, leading to crashes.
94 // Note that Document::updateLayout calls its parent's updateLayout. 90 // Note that Document::updateLayout calls its parent's updateLayout.
95 // FIXME: It should be the caller's responsibility to ensure an up-to-date l ayout. 91 // FIXME: It should be the caller's responsibility to ensure an up-to-date l ayout.
96 frameView()->updateLayoutAndStyleForPainting(); 92 frameView()->updateLayoutAndStyleForPainting();
97 commitPendingSelection(); 93 commitPendingSelection();
98 94
99 bool hitLayer = layer()->hitTest(request, location, result); 95 bool cacheHit = false;
96 // Determine if we should use the hit test cache.
97 if (frameView()->layoutCount() == m_hitTestCacheLayoutCount) {
98 if (!m_hitTestCacheResult.hitTestLocation().isRectBasedTest() && !result .hitTestLocation().isRectBasedTest() && m_hitTestCacheResult.validityRect().cont ains(result.hitTestLocation().point())) {
99 if (result.hitTestRequest().equalForCacheability(m_hitTestCacheResul t.hitTestRequest())) {
100 m_hitTestCacheHits++;
101 cacheHit = true;
102 }
103 }
104 }
105 bool hitLayer = layer()->hitTest(result);
100 106
101 // FrameView scrollbars are not the same as Layer scrollbars tested by Layer ::hitTestOverflowControls, 107 // FrameView scrollbars are not the same as Layer scrollbars tested by Layer ::hitTestOverflowControls,
102 // so we need to test FrameView scrollbars separately here. Note that it's i mportant we do this after 108 // so we need to test FrameView scrollbars separately here. Note that it's i mportant we do this after
103 // the hit test above, because that may overwrite the entire HitTestResult w hen it finds a hit. 109 // the hit test above, because that may overwrite the entire HitTestResult w hen it finds a hit.
104 IntPoint framePoint = frameView()->contentsToFrame(location.roundedPoint()); 110 IntPoint framePoint = frameView()->contentsToFrame(result.hitTestLocation(). roundedPoint());
105 if (Scrollbar* frameScrollbar = frameView()->scrollbarAtFramePoint(framePoin t)) 111 if (Scrollbar* frameScrollbar = frameView()->scrollbarAtFramePoint(framePoin t))
106 result.setScrollbar(frameScrollbar); 112 result.setScrollbar(frameScrollbar);
107 113
114 if (cacheHit) {
115 if (!m_hitTestCacheResult.equalForCacheability(result)) {
116 for (int i = 0; i < 10; ++i) {
117 layer()->hitTest(result);
118 }
119
120 WTF_LOG_ERROR("Hit failure with %lf %lf cache %lf %lf", result.hitTe stLocation().point().x().toDouble(), result.hitTestLocation().point().y().toDoub le(), m_hitTestCacheResult.hitTestLocation().point().x().toDouble(), m_hitTestCa cheResult.hitTestLocation().point().y().toDouble());
121
122 // DCHECK that the cache hit is the same as the actual result
123 ASSERT(false);
124 }
125 }
126 if (hitLayer) {
127 m_hitTestCacheResult = result;
128 m_hitTestCacheLayoutCount = frameView()->layoutCount();
129
130 // TODO(dtapuska): We shouldn't send the hit cache result to the composi tor if
131 // we aren't displaying it in HUD: as it slows everything down.
132 if (layer()->graphicsLayerBacking()) {
133 layer()->graphicsLayerBacking()->platformLayer()->setHitCacheRect(en closingIntRect(m_hitTestCacheResult.validityRect()));
134 }
135 }
136
108 return hitLayer; 137 return hitLayer;
109 } 138 }
110 139
140 void LayoutView::clearHitTestCache()
141 {
142 m_hitTestCacheResult = HitTestResult();
143 m_hitTestCacheLayoutCount = 0;
144 }
145
111 void LayoutView::computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit, Logi calExtentComputedValues& computedValues) const 146 void LayoutView::computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit, Logi calExtentComputedValues& computedValues) const
112 { 147 {
113 computedValues.m_extent = (!shouldUsePrintingLayout() && m_frameView) ? Layo utUnit(viewLogicalHeight()) : logicalHeight; 148 computedValues.m_extent = (!shouldUsePrintingLayout() && m_frameView) ? Layo utUnit(viewLogicalHeight()) : logicalHeight;
114 } 149 }
115 150
116 void LayoutView::updateLogicalWidth() 151 void LayoutView::updateLogicalWidth()
117 { 152 {
118 if (!shouldUsePrintingLayout() && m_frameView) 153 if (!shouldUsePrintingLayout() && m_frameView)
119 setLogicalWidth(viewLogicalWidth()); 154 setLogicalWidth(viewLogicalWidth());
120 } 155 }
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 if (shouldUsePrintingLayout()) 911 if (shouldUsePrintingLayout())
877 return pageLogicalHeight(); 912 return pageLogicalHeight();
878 return viewLogicalHeight(); 913 return viewLogicalHeight();
879 } 914 }
880 915
881 float LayoutView::zoomFactor() const 916 float LayoutView::zoomFactor() const
882 { 917 {
883 return m_frameView->frame().pageZoomFactor(); 918 return m_frameView->frame().pageZoomFactor();
884 } 919 }
885 920
886 void LayoutView::updateHitTestResult(HitTestResult& result, const LayoutPoint& p oint) 921 void LayoutView::updateHitTestResult(HitTestResult& result, const LayoutPoint& p oint, const LayoutRect& rect)
887 { 922 {
888 if (result.innerNode()) 923 if (result.innerNode())
889 return; 924 return;
890 925
926 result.intersectValidityRect(rect);
891 Node* node = document().documentElement(); 927 Node* node = document().documentElement();
892 if (node) { 928 if (node) {
893 LayoutPoint adjustedPoint = point; 929 LayoutPoint adjustedPoint = point;
894 offsetForContents(adjustedPoint); 930 offsetForContents(adjustedPoint);
895 result.setNodeAndPosition(node, adjustedPoint); 931 result.setNodeAndPosition(node, adjustedPoint);
896 } 932 }
897 } 933 }
898 934
899 bool LayoutView::usesCompositing() const 935 bool LayoutView::usesCompositing() const
900 { 936 {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
943 return viewHeight(IncludeScrollbars) / scale; 979 return viewHeight(IncludeScrollbars) / scale;
944 } 980 }
945 981
946 void LayoutView::willBeDestroyed() 982 void LayoutView::willBeDestroyed()
947 { 983 {
948 LayoutBlockFlow::willBeDestroyed(); 984 LayoutBlockFlow::willBeDestroyed();
949 m_compositor.clear(); 985 m_compositor.clear();
950 } 986 }
951 987
952 } // namespace blink 988 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698