Chromium Code Reviews| OLD | NEW |
|---|---|
| (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/ | |
| 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 |exepcted| object; otherwise | |
|
tdresser
2015/06/10 13:35:21
exepcted -> expected
dtapuska
2015/06/10 14:04:48
Done.
| |
| 37 // log UMA metrics indicating failure. | |
|
tdresser
2015/06/10 13:35:21
This is a bit misleading, in that we log UMA metri
dtapuska
2015/06/10 14:04:48
Done.
| |
| 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. Try not to reorder/modify. | |
|
tdresser
2015/06/10 13:35:21
Don't you need a few more constraints here (and be
dtapuska
2015/06/10 14:04:48
Done.
| |
| 45 enum class HitHistogramMetric { | |
| 46 MISS, // A cache miss. | |
| 47 MISS_EXPLICIT_AVOID, // Explicitly asked by caller to avoid cache. | |
| 48 MISS_VALIDITY_RECT_MATCHES, // Region matches but request type doesn't. | |
| 49 HIT_EXACT_MATCH, // Exact point/rect hit. | |
| 50 HIT_REGION_MATCH, // Region match. | |
| 51 MAX_HIT_METRIC = HIT_REGION_MATCH, | |
| 52 }; | |
| 53 | |
| 54 // These values are reported in UMA. Try not to reorder/modify. | |
| 55 enum class ValidityHistogramMetric { | |
| 56 VALID_EXACT_MATCH, // Correct node for exact point test. | |
| 57 VALID_REGION, // Correct node for region check. | |
| 58 INCORRECT_RECT_BASED_EXACT_MATCH, // Wrong node returned for cache hit w ith point was exact match and rect based test. | |
| 59 INCORRECT_POINT_EXACT_MATCH, // Wrong node returned for cache hit with e xact point match and was explicit point test. | |
| 60 INCORRECT_RECT_BASED_REGION, // Wrong node returned for rect with region matching and was rect based test. | |
| 61 INCORRECT_POINT_REGION, // Wrong node returned for point with region mat ching and was explicit point test. | |
| 62 MAX_VALIDITY_METRIC = INCORRECT_POINT_REGION, | |
| 63 }; | |
| 64 | |
| 65 struct CacheItem { | |
| 66 bool valid = false; | |
| 67 HitTestResult result; | |
| 68 }; | |
| 69 | |
| 70 unsigned m_updateIndex = 0; | |
| 71 | |
| 72 // A cache size of 2 is used because it is relatively cheap to store; | |
| 73 // and the ping-pong behaviour of some of the HitTestRequest flags during | |
| 74 // Mouse/Touch/Pointer events can generate incrased cache misses with | |
|
tdresser
2015/06/10 13:35:21
incrased -> increased
dtapuska
2015/06/10 14:04:48
Done.
| |
| 75 // size of 1. | |
| 76 CacheItem m_items[2]; | |
|
tdresser
2015/06/10 13:35:21
Once this is in, it would be interesting to run an
dtapuska
2015/06/10 14:04:48
Acknowledged.
| |
| 77 uint64_t m_domTreeVersion = 0; | |
| 78 }; | |
| 79 | |
| 80 } // namespace blink | |
| 81 | |
| 82 #endif // HitTestCache_h | |
| OLD | NEW |