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