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