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

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

Issue 1142283004: Implement a Hit Test Cache. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Remove validity rect as per Elliott's request 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 unified diff | Download patch
« no previous file with comments | « Source/core/layout/HitTestCache.h ('k') | Source/core/layout/HitTestRequest.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "core/layout/HitTestCache.h"
7
8 #include "public/platform/Platform.h"
9
10 namespace blink {
11
12 bool HitTestCache::lookupCachedResult(HitTestResult& hitResult, uint64_t domTree Version)
13 {
14 bool result = false;
15 HitHistogramMetric metric = HitHistogramMetric::MISS;
16 if (hitResult.hitTestRequest().avoidCache()) {
17 metric = HitHistogramMetric::MISS_EXPLICIT_AVOID;
18 // For now we don't support rect based hit results.
19 } else if (domTreeVersion == m_domTreeVersion && !hitResult.hitTestLocation( ).isRectBasedTest()) {
20 for (const auto& cachedItem : m_items) {
21 if (cachedItem.hitTestLocation().point() == hitResult.hitTestLocatio n().point()) {
22 if (hitResult.hitTestRequest().equalForCacheability(cachedItem.h itTestRequest())) {
23 metric = HitHistogramMetric::HIT_EXACT_MATCH;
24 result = true;
25 hitResult = cachedItem;
26 break;
27 }
28 metric = HitHistogramMetric::MISS_VALIDITY_RECT_MATCHES;
29 }
30 }
31 }
32 Platform::current()->histogramEnumeration("Event.HitTest", static_cast<int>( metric), static_cast<int>(HitHistogramMetric::MAX_HIT_METRIC));
33 return result;
34 }
35
36 void HitTestCache::verifyCachedResult(const HitTestResult& expected, const HitTe stResult& actual)
37 {
38 ValidityHistogramMetric metric;
39 if (!actual.equalForCacheability(expected)) {
40 metric = expected.hitTestLocation().isRectBasedTest() ? ValidityHistogra mMetric::INCORRECT_RECT_BASED_EXACT_MATCH : ValidityHistogramMetric::INCORRECT_P OINT_EXACT_MATCH;
41
42 // ASSERT that the cache hit is the same as the actual result.
43 ASSERT_NOT_REACHED();
44 } else {
45 metric = ValidityHistogramMetric::VALID_EXACT_MATCH;
46 }
47 Platform::current()->histogramEnumeration("Event.HitTestValidity", static_ca st<int>(metric), static_cast<int>(ValidityHistogramMetric::MAX_VALIDITY_METRIC)) ;
48 }
49
50 void HitTestCache::addCachedResult(const HitTestResult& result, uint64_t domTree Version)
51 {
52 if (!result.isCacheable())
53 return;
54
55 // If the result was a hit test on an LayoutPart and the request allowed
56 // querying of the layout part; then the part hasn't been loaded yet.
57 if (result.isOverWidget() && result.hitTestRequest().allowsChildFrameContent ())
58 return;
59
60 // For now don't support rect based or list based requests.
61 if (result.hitTestLocation().isRectBasedTest() || result.hitTestRequest().li stBased())
62 return;
63 if (domTreeVersion != m_domTreeVersion)
64 clear();
65 if (m_items.size() < HIT_TEST_CACHE_SIZE)
66 m_items.resize(m_updateIndex + 1);
67
68 m_items.at(m_updateIndex).cacheValues(result);
69 m_domTreeVersion = domTreeVersion;
70
71 m_updateIndex++;
72 if (m_updateIndex >= HIT_TEST_CACHE_SIZE)
73 m_updateIndex = 0;
74 }
75
76 void HitTestCache::clear()
77 {
78 m_updateIndex = 0;
79 m_items.clear();
80 }
81
82 DEFINE_TRACE(HitTestCache)
83 {
84 visitor->trace(m_items);
85 }
86
87 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/layout/HitTestCache.h ('k') | Source/core/layout/HitTestRequest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698