| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef HitTestCache_h | 5 #ifndef HitTestCache_h |
| 6 #define HitTestCache_h | 6 #define HitTestCache_h |
| 7 | 7 |
| 8 #include "core/layout/HitTestResult.h" | 8 #include "core/layout/HitTestResult.h" |
| 9 #include "platform/heap/Handle.h" | |
| 10 #include "wtf/Vector.h" | 9 #include "wtf/Vector.h" |
| 11 | 10 |
| 12 namespace blink { | 11 namespace blink { |
| 13 | 12 |
| 14 // This object implements a cache for storing successful hit tests to DOM nodes | 13 // 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, | 14 // in the visible viewport. The cache is cleared on dom modifications, |
| 16 // scrolling, CSS style modifications. | 15 // scrolling, CSS style modifications. |
| 17 // | 16 // |
| 18 // Multiple hit tests can occur when processing events. Typically the DOM doesn'
t | 17 // 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 | 18 // 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 | 19 // 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) | 20 // 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 | 21 // 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. | 22 // and use the result for the targetting of each event. |
| 24 // | 23 // |
| 25 // Some of the related design, motivation can be found in: | 24 // Some of the related design, motivation can be found in: |
| 26 // https://docs.google.com/document/d/1b0NYAD4S9BJIpHGa4JD2HLmW28f2rUh1jlqrgpU3z
VU/ | 25 // https://docs.google.com/document/d/1b0NYAD4S9BJIpHGa4JD2HLmW28f2rUh1jlqrgpU3z
VU/ |
| 27 // | 26 // |
| 28 | 27 |
| 29 // A cache size of 2 is used because it is relatively cheap to store; | 28 // 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 | 29 // and the ping-pong behaviour of some of the HitTestRequest flags during |
| 31 // Mouse/Touch/Pointer events can generate increased cache misses with | 30 // Mouse/Touch/Pointer events can generate increased cache misses with |
| 32 // size of 1. | 31 // size of 1. |
| 33 #define HIT_TEST_CACHE_SIZE (2) | 32 #define HIT_TEST_CACHE_SIZE (2) |
| 34 | 33 |
| 35 class HitTestCache final : public NoBaseWillBeGarbageCollectedFinalized<HitTestC
ache> { | 34 class HitTestCache { |
| 36 public: | 35 public: |
| 37 static PassOwnPtrWillBeRawPtr<HitTestCache> create() | 36 HitTestCache() = default; |
| 38 { | |
| 39 return adoptPtrWillBeNoop(new HitTestCache); | |
| 40 } | |
| 41 | 37 |
| 42 // Check the cache for a possible hit and update |result| if | 38 // Check the cache for a possible hit and update |result| if |
| 43 // hit encountered; returning true. Otherwise false. | 39 // hit encountered; returning true. Otherwise false. |
| 44 bool lookupCachedResult(HitTestResult&, uint64_t domTreeVersion); | 40 bool lookupCachedResult(HitTestResult&, uint64_t domTreeVersion); |
| 45 | 41 |
| 46 void clear(); | 42 void clear(); |
| 47 | 43 |
| 48 // Verify that the |actual| object matches the |expected| object; and | 44 // Verify that the |actual| object matches the |expected| object; and |
| 49 // log UMA metrics indicating the result. | 45 // log UMA metrics indicating the result. |
| 50 static void verifyCachedResult(const HitTestResult& expected, const HitTestR
esult& actual); | 46 static void verifyCachedResult(const HitTestResult& expected, const HitTestR
esult& actual); |
| 51 | 47 |
| 52 // Adds a HitTestResult to the cache. | 48 // Adds a HitTestResult to the cache. |
| 53 void addCachedResult(const HitTestResult&, uint64_t domTreeVersion); | 49 void addCachedResult(const HitTestResult&, uint64_t domTreeVersion); |
| 54 | 50 |
| 55 DECLARE_TRACE(); | |
| 56 | |
| 57 private: | 51 private: |
| 58 HitTestCache() = default; | |
| 59 | |
| 60 // These values are reported in UMA as the "EventHitTest" enumeration. | 52 // These values are reported in UMA as the "EventHitTest" enumeration. |
| 61 // Do not reorder, append new values at the end, deprecate old | 53 // Do not reorder, append new values at the end, deprecate old |
| 62 // values and update histograms.xml. | 54 // values and update histograms.xml. |
| 63 enum class HitHistogramMetric { | 55 enum class HitHistogramMetric { |
| 64 MISS, // Miss, not found in cache. | 56 MISS, // Miss, not found in cache. |
| 65 MISS_EXPLICIT_AVOID, // Miss, calle asked to explicitly avoid cache. | 57 MISS_EXPLICIT_AVOID, // Miss, calle asked to explicitly avoid cache. |
| 66 MISS_VALIDITY_RECT_MATCHES, // Miss, validity region matches, type doesn
't. | 58 MISS_VALIDITY_RECT_MATCHES, // Miss, validity region matches, type doesn
't. |
| 67 HIT_EXACT_MATCH, // Hit, exact point matches. | 59 HIT_EXACT_MATCH, // Hit, exact point matches. |
| 68 HIT_REGION_MATCH, // Hit, validity region matches. | 60 HIT_REGION_MATCH, // Hit, validity region matches. |
| 69 MAX_HIT_METRIC = HIT_REGION_MATCH, | 61 MAX_HIT_METRIC = HIT_REGION_MATCH, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 83 }; | 75 }; |
| 84 | 76 |
| 85 unsigned m_updateIndex = 0; | 77 unsigned m_updateIndex = 0; |
| 86 WillBeHeapVector<HitTestResult, HIT_TEST_CACHE_SIZE> m_items; | 78 WillBeHeapVector<HitTestResult, HIT_TEST_CACHE_SIZE> m_items; |
| 87 uint64_t m_domTreeVersion = 0; | 79 uint64_t m_domTreeVersion = 0; |
| 88 }; | 80 }; |
| 89 | 81 |
| 90 } // namespace blink | 82 } // namespace blink |
| 91 | 83 |
| 92 #endif // HitTestCache_h | 84 #endif // HitTestCache_h |
| OLD | NEW |