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

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

Powered by Google App Engine
This is Rietveld 408576698