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

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

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 #ifndef HitTestCache_h
6 #define HitTestCache_h
7
8 #include "core/layout/HitTestResult.h"
9
10 namespace blink {
11
12 // This object implements a cache for storing successful hit tests to DOM nodes
13 // in the visible viewport. The cache is cleared on dom modifications,
14 // scrolling, CSS style modifications.
15 //
16 // Multiple hit tests can occur when processing events. Typically the DOM doesn' t
17 // change when each event is processed so in order to decrease the time spent
18 // processing the events a hit cache is useful. For example a GestureTap event
19 // will generate a series of simulated mouse events (move, down, up, click)
20 // with the same co-ordinates and ideally we'd like to do the hit test once
21 // and use the result for the targetting of each event.
22 //
23 // Some of the related design, motivation can be found in:
24 // https://docs.google.com/document/d/1b0NYAD4S9BJIpHGa4JD2HLmW28f2rUh1jlqrgpU3z VU/
esprehn 2015/06/12 05:09:30 Comments! You're a hero
dtapuska 2015/06/12 15:30:37 Acknowledged.
25 //
26 class HitTestCache {
27 public:
28 HitTestCache() = default;
29
30 // Check the cache for a possible hit and update |result| if
31 // hit encountered; returning true. Otherwise false.
32 bool lookupCachedResult(HitTestResult&, uint64_t domTreeVersion);
33
34 void clear();
35
36 // Verify that the |actual| object matches the |expected| object; and
37 // log UMA metrics indicating the result.
38 static void verify(const HitTestResult& expected, const HitTestResult& actua l);
39
40 // Adds a HitTestResult to the cache.
41 void addCachedResult(const HitTestResult&, uint64_t domTreeVersion);
42
43 private:
44 // These values are reported in UMA as the "EventHitTest" enumeration.
45 // Do not reorder, append new values at the end, deprecate old
46 // values and update histograms.xml.
47 enum class HitHistogramMetric {
48 MISS, // Miss, not found in cache.
49 MISS_EXPLICIT_AVOID, // Miss, calle asked to explicitly avoid cache.
50 MISS_VALIDITY_RECT_MATCHES, // Miss, validity region matches, type doesn 't.
51 HIT_EXACT_MATCH, // Hit, exact point matches.
52 HIT_REGION_MATCH, // Hit, validity region matches.
53 MAX_HIT_METRIC = HIT_REGION_MATCH,
54 };
55
56 // These values are reported in UMA as the "EventHitTestValidity"
57 // enumeration. Do not reorder, append new values at the end,
58 // deprecate old values and update histograms.xml.
59 enum class ValidityHistogramMetric {
60 VALID_EXACT_MATCH, // Correct node for exact point test.
61 VALID_REGION, // Correct node for region check.
62 INCORRECT_RECT_BASED_EXACT_MATCH, // Wrong node returned for cache hit w ith point was exact match and rect based test.
63 INCORRECT_POINT_EXACT_MATCH, // Wrong node returned for cache hit with e xact point match and was explicit point test.
64 INCORRECT_RECT_BASED_REGION, // Wrong node returned for rect with region matching and was rect based test.
65 INCORRECT_POINT_REGION, // Wrong node returned for point with region mat ching and was explicit point test.
66 MAX_VALIDITY_METRIC = INCORRECT_POINT_REGION,
67 };
68
69 struct CacheItem {
70 bool valid = false;
71 HitTestResult result;
72 };
73
74 unsigned m_updateIndex = 0;
75
76 // A cache size of 2 is used because it is relatively cheap to store;
77 // and the ping-pong behaviour of some of the HitTestRequest flags during
78 // Mouse/Touch/Pointer events can generate increased cache misses with
79 // size of 1.
80 CacheItem m_items[2];
81 uint64_t m_domTreeVersion = 0;
82 };
83
84 } // namespace blink
85
86 #endif // HitTestCache_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698