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

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: Fix comments from tdresser 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
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 (size_t i = 0; i < WTF_ARRAY_LENGTH(m_items) && m_items[i].valid; ++ i) {
21 if (m_items[i].result.validityRect().contains(hitResult.hitTestLocat ion().point())) {
22 if (hitResult.hitTestRequest().equalForCacheability(m_items[i].r esult.hitTestRequest())) {
23 metric = hitResult.hitTestLocation().point() == m_items[i].r esult.hitTestLocation().point() ? HitHistogramMetric::HIT_EXACT_MATCH : HitHisto gramMetric::HIT_REGION_MATCH;
24 result = true;
25 hitResult = m_items[i].result;
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::verify(const HitTestResult& expected, const HitTestResult& ac tual)
37 {
38 bool pointMatch = actual.hitTestLocation().point() == expected.hitTestLocati on().point();
39
40 ValidityHistogramMetric metric;
41 if (!actual.equalForCacheability(expected)) {
42 if (pointMatch) {
43 metric = expected.hitTestLocation().isRectBasedTest() ? ValidityHist ogramMetric::INCORRECT_RECT_BASED_EXACT_MATCH : ValidityHistogramMetric::INCORRE CT_POINT_EXACT_MATCH;
44 } else {
45 metric = expected.hitTestLocation().isRectBasedTest() ? ValidityHist ogramMetric::INCORRECT_RECT_BASED_REGION : ValidityHistogramMetric::INCORRECT_PO INT_REGION;
46 }
47
48 // ASSERT that the cache hit is the same as the actual result.
49 ASSERT_NOT_REACHED();
50 } else {
51 metric = pointMatch ? ValidityHistogramMetric::VALID_EXACT_MATCH : Valid ityHistogramMetric::VALID_REGION;
52 }
53 Platform::current()->histogramEnumeration("Event.HitTestValidity", static_ca st<int>(metric), static_cast<int>(ValidityHistogramMetric::MAX_VALIDITY_METRIC)) ;
54 }
55
56 void HitTestCache::addCachedResult(const HitTestResult& result, uint64_t domTree Version)
57 {
58 // For now we don't support rect based hit results.
59 if (result.hitTestLocation().isRectBasedTest()) {
60 return;
61 }
62 if (domTreeVersion != m_domTreeVersion) {
63 clear();
64 }
65
66 m_items[m_updateIndex].result.cacheValues(result);
67 m_items[m_updateIndex].valid = true;
68 m_domTreeVersion = domTreeVersion;
69
70 m_updateIndex++;
71 if (m_updateIndex >= WTF_ARRAY_LENGTH(m_items))
72 m_updateIndex = 0;
73 }
74
75 void HitTestCache::clear()
76 {
77 m_updateIndex = 0;
78 for (size_t i = 0; i < WTF_ARRAY_LENGTH(m_items); ++i) {
esprehn 2015/06/12 05:09:29 We could use a Vector with inline capacity of 2 fo
dtapuska 2015/06/12 15:30:37 Done.
79 if (m_items[i].valid) {
80 m_items[i].valid = false;
81 m_items[i].result = HitTestResult();
82 }
83 }
84 }
85
86 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698