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

Unified 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: Remove stray file Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/layout/LayoutView.cpp
diff --git a/Source/core/layout/LayoutView.cpp b/Source/core/layout/LayoutView.cpp
index c1790151cc635db4c78a5b810bc41ca3bbf8b1be..da2ca2c52aa80843ac5ed2d73705b7b34818dcd4 100644
--- a/Source/core/layout/LayoutView.cpp
+++ b/Source/core/layout/LayoutView.cpp
@@ -43,6 +43,7 @@
#include "platform/TracedValue.h"
#include "platform/geometry/FloatQuad.h"
#include "platform/geometry/TransformState.h"
+#include "platform/graphics/GraphicsLayer.h"
#include "platform/graphics/paint/DisplayItemList.h"
#include <inttypes.h>
@@ -61,6 +62,7 @@ LayoutView::LayoutView(Document* document)
, m_layoutQuoteHead(nullptr)
, m_layoutCounterCount(0)
, m_hitTestCount(0)
+ , m_hitTestCacheHits(0)
, m_pendingSelection(PendingSelection::create())
{
// init LayoutObject attributes
@@ -78,15 +80,12 @@ LayoutView::~LayoutView()
{
}
-bool LayoutView::hitTest(HitTestResult& result)
-{
- return hitTest(result.hitTestRequest(), result.hitTestLocation(), result);
-}
-
namespace {
-PassRefPtr<TracedValue> hitTestInfo(const HitTestRequest& request, const HitTestLocation& location, const HitTestResult& result)
+PassRefPtr<TracedValue> hitTestInfo(const HitTestResult& result)
{
+ const HitTestRequest& request = result.hitTestRequest();
+ const HitTestLocation& location = result.hitTestLocation();
RefPtr<TracedValue> value(TracedValue::create());
value->setInteger("x", location.roundedPoint().x());
value->setInteger("y", location.roundedPoint().y());
@@ -112,12 +111,12 @@ PassRefPtr<TracedValue> hitTestInfo(const HitTestRequest& request, const HitTest
} // anonymous namespace
-bool LayoutView::hitTest(const HitTestRequest& request, const HitTestLocation& location, HitTestResult& result)
+bool LayoutView::hitTest(HitTestResult& result)
{
TRACE_EVENT_BEGIN0("blink", "LayoutView::hitTest");
m_hitTestCount++;
- ASSERT(!location.isRectBasedTest() || request.listBased());
+ ASSERT(!result.hitTestLocation().isRectBasedTest() || result.hitTestRequest().listBased());
// We have to recursively update layout/style here because otherwise, when the hit test recurses
// into a child document, it could trigger a layout on the parent document, which can destroy DeprecatedPaintLayer
@@ -127,16 +126,32 @@ bool LayoutView::hitTest(const HitTestRequest& request, const HitTestLocation& l
frameView()->updateLayoutAndStyleForPainting();
commitPendingSelection();
- bool hitLayer = layer()->stackingNode()->hitTest(request, location, result);
+ uint64_t domTreeVersion = document().domTreeVersion();
+ HitTestResult cacheResult = result;
+ bool cacheHit = m_hitTestCache.lookupCachedResult(cacheResult, domTreeVersion);
+ bool hitLayer = layer()->stackingNode()->hitTest(result);
// FrameView scrollbars are not the same as Layer scrollbars tested by Layer::hitTestOverflowControls,
// so we need to test FrameView scrollbars separately here. Note that it's important we do this after
// the hit test above, because that may overwrite the entire HitTestResult when it finds a hit.
- IntPoint framePoint = frameView()->contentsToFrame(location.roundedPoint());
+ IntPoint framePoint = frameView()->contentsToFrame(result.hitTestLocation().roundedPoint());
if (Scrollbar* frameScrollbar = frameView()->scrollbarAtFramePoint(framePoint))
result.setScrollbar(frameScrollbar);
- TRACE_EVENT_END1("blink", "LayoutView::hitTest", "info", hitTestInfo(request, location, result));
+ if (cacheHit) {
+ m_hitTestCacheHits++;
+ m_hitTestCache.verify(result, cacheResult);
+ }
+
+ if (hitLayer) {
+ m_hitTestCache.addCachedResult(result, domTreeVersion);
+
+ if (layer()->graphicsLayerBacking()) {
+ layer()->graphicsLayerBacking()->platformLayer()->setHitCacheRect(enclosingIntRect(result.validityRect()));
+ }
+ }
+
+ TRACE_EVENT_END1("blink", "LayoutView::hitTest", "info", hitTestInfo(result));
return hitLayer;
}

Powered by Google App Engine
This is Rietveld 408576698