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

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 git cl format mangling 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 #include <base/macros.h>
Rick Byers 2015/06/06 16:12:54 What do you need this for? It's still very rare f
esprehn 2015/06/06 21:14:30 I think you want WTF_ARRAY_SIZE, lets not use base
Rick Byers 2015/06/07 04:44:57 Note that there is at least one non-test use of ba
dtapuska 2015/06/09 18:21:23 it was used for arraysize(...) macro; esprehn poin
dtapuska 2015/06/09 18:21:24 Acknowledged.
dtapuska 2015/06/09 18:21:24 Done.
dtapuska 2015/06/09 18:21:24 Done.
10
11 namespace blink {
12
13 bool HitTestCache::check(HitTestResult& hitResult)
esprehn 2015/06/06 21:14:29 verify() I think is better than check.
Rick Byers 2015/06/07 04:44:57 Verify is below. Maybe call this lookup?
dtapuska 2015/06/09 18:21:23 Acknowledged.
dtapuska 2015/06/09 18:21:24 Changed to lookupCacheValue... to model after the
14 {
15 bool result = false;
16 HitHistogramMetric metric = HitHistogramMetric::MISS;
17 if (hitResult.hitTestRequest().avoidCache()) {
18 metric = HitHistogramMetric::MISS_EXPLICIT_AVOID;
19 // For now we don't support rect based hit results.
Rick Byers 2015/06/06 16:12:54 But list-based tests (like elementsFromPoint) work
20 } else if (!hitResult.hitTestLocation().isRectBasedTest()) {
21 for (size_t i = 0; m_items[i].m_valid && i < arraysize(m_items); ++i) {
Rick Byers 2015/06/06 16:12:54 i < arraysize(m_items) should come before the m_va
dtapuska 2015/06/09 18:21:23 Done.
22 if (m_items[i].m_result.validityRect().contains(hitResult.hitTestLoc ation().point())) {
23 if (hitResult.hitTestRequest().equalForCacheability(m_items[i].m _result.hitTestRequest())) {
24 metric = hitResult.hitTestLocation().point() == m_items[i].m _result.hitTestLocation().point() ? HitHistogramMetric::HIT_EXACT_MATCH : HitHis togramMetric::HIT_REGION_MATCH;
25 result = true;
26 hitResult = m_items[i].m_result;
27 break;
28 }
29 }
30 metric = HitHistogramMetric::MISS_VALIDITY_RECT_MATCHES;
31 }
32 }
33 Platform::current()->histogramEnumeration("Event.HitTest", static_cast<int>( metric), static_cast<int>(HitHistogramMetric::MAX_HIT_METRIC));
34 return result;
35 }
36
37 void HitTestCache::verify(const HitTestResult& result, const HitTestResult& cach eResult)
38 {
39 bool pointMatch = cacheResult.hitTestLocation().point() == result.hitTestLoc ation().point();
40
41 VerifyHistogramMetric metric;
42 if (!cacheResult.equalForCacheability(result)) {
43 if (pointMatch) {
44 metric = result.hitTestLocation().isRectBasedTest() ? VerifyHistogra mMetric::INCORRECT_RECT_BASED_EXACT_MATCH : VerifyHistogramMetric::INCORRECT_POI NT_EXACT_MATCH;
45 } else {
46 metric = result.hitTestLocation().isRectBasedTest() ? VerifyHistogra mMetric::INCORRECT_RECT_BASED_REGION : VerifyHistogramMetric::INCORRECT_POINT_RE GION;
47 }
48
49 // ASSERT that the cache hit is the same as the actual result
50 ASSERT(false);
51 } else {
52 metric = pointMatch ? VerifyHistogramMetric::VALID_EXACT_MATCH : VerifyH istogramMetric::VALID_REGION;
53 }
54 Platform::current()->histogramEnumeration("Event.HitTestVerify", static_cast <int>(metric), static_cast<int>(VerifyHistogramMetric::MAX_VERIFY_METRIC));
55 }
56
57 void HitTestCache::cacheValue(const HitTestResult& result)
esprehn 2015/06/06 21:14:30 addCacheValue, in blink cacheValue() is a getter (
dtapuska 2015/06/09 18:21:23 Done.
58 {
59 // For now we don't support rect based hit results.
60 if (result.hitTestLocation().isRectBasedTest()) {
61 return;
62 }
63 m_items[m_updateIndex].m_result.cacheValues(result);
64 m_items[m_updateIndex].m_valid = true;
65
66 m_updateIndex++;
67 if (m_updateIndex >= arraysize(m_items))
68 m_updateIndex = 0;
69 }
70
71 void HitTestCache::clear()
72 {
73 m_updateIndex = 0;
74 for (size_t i = 0; i < arraysize(m_items); ++i) {
75 if (m_items[i].m_valid) {
76 m_items[i].m_valid = false;
77 m_items[i].m_result = HitTestResult();
78 }
79 }
80 }
81
82 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698