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/CoreExport.h" | |
8 #include "core/layout/HitTestResult.h" | 9 #include "core/layout/HitTestResult.h" |
9 #include "platform/heap/Handle.h" | 10 #include "platform/heap/Handle.h" |
10 #include "wtf/Vector.h" | 11 #include "wtf/Vector.h" |
11 | 12 |
12 namespace blink { | 13 namespace blink { |
13 | 14 |
14 // This object implements a cache for storing successful hit tests to DOM nodes | 15 // 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 // in the visible viewport. The cache is cleared on dom modifications, |
16 // scrolling, CSS style modifications. | 17 // scrolling, CSS style modifications. |
17 // | 18 // |
18 // Multiple hit tests can occur when processing events. Typically the DOM doesn' t | 19 // 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 // 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 // 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 // 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 // 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 // and use the result for the targetting of each event. |
24 // | 25 // |
25 // Some of the related design, motivation can be found in: | 26 // Some of the related design, motivation can be found in: |
26 // https://docs.google.com/document/d/1b0NYAD4S9BJIpHGa4JD2HLmW28f2rUh1jlqrgpU3z VU/ | 27 // https://docs.google.com/document/d/1b0NYAD4S9BJIpHGa4JD2HLmW28f2rUh1jlqrgpU3z VU/ |
27 // | 28 // |
28 | 29 |
29 // A cache size of 2 is used because it is relatively cheap to store; | 30 // 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 // and the ping-pong behaviour of some of the HitTestRequest flags during |
31 // Mouse/Touch/Pointer events can generate increased cache misses with | 32 // Mouse/Touch/Pointer events can generate increased cache misses with |
32 // size of 1. | 33 // size of 1. |
33 #define HIT_TEST_CACHE_SIZE (2) | 34 #define HIT_TEST_CACHE_SIZE (2) |
34 | 35 |
35 class HitTestCache final : public NoBaseWillBeGarbageCollectedFinalized<HitTestC ache> { | 36 class CORE_EXPORT HitTestCache final : public NoBaseWillBeGarbageCollectedFinali zed<HitTestCache> { |
36 public: | 37 public: |
37 static PassOwnPtrWillBeRawPtr<HitTestCache> create() | 38 static PassOwnPtrWillBeRawPtr<HitTestCache> create() |
38 { | 39 { |
39 return adoptPtrWillBeNoop(new HitTestCache); | 40 return adoptPtrWillBeNoop(new HitTestCache); |
40 } | 41 } |
41 | 42 |
42 // Check the cache for a possible hit and update |result| if | 43 // Check the cache for a possible hit and update |result| if |
43 // hit encountered; returning true. Otherwise false. | 44 // hit encountered; returning true. Otherwise false. |
44 bool lookupCachedResult(HitTestResult&, uint64_t domTreeVersion); | 45 bool lookupCachedResult(HitTestResult&, uint64_t domTreeVersion); |
45 | 46 |
46 void clear(); | 47 void clear(); |
47 | 48 |
48 // Verify that the |actual| object matches the |expected| object; and | 49 // Verify that the |actual| object matches the |expected| object; and |
49 // log UMA metrics indicating the result. | 50 // log UMA metrics indicating the result. |
50 static void verifyCachedResult(const HitTestResult& expected, const HitTestR esult& actual); | 51 static void verifyCachedResult(const HitTestResult& expected, const HitTestR esult& actual); |
51 | 52 |
52 // Adds a HitTestResult to the cache. | 53 // Adds a HitTestResult to the cache. |
53 void addCachedResult(const HitTestResult&, uint64_t domTreeVersion); | 54 void addCachedResult(const HitTestResult&, uint64_t domTreeVersion); |
54 | 55 |
55 DECLARE_TRACE(); | 56 DECLARE_TRACE(); |
56 | 57 |
57 private: | 58 private: |
58 HitTestCache() = default; | 59 HitTestCache() |
60 : m_updateIndex(0) | |
61 , m_domTreeVersion(0) { } | |
59 | 62 |
60 // The below UMA values reference a validity region. This code has not | 63 // The below UMA values reference a validity region. This code has not |
61 // been written yet; and exact matches are only supported but the | 64 // been written yet; and exact matches are only supported but the |
62 // UMA enumerations have been added for future support. | 65 // UMA enumerations have been added for future support. |
63 | 66 |
64 // These values are reported in UMA as the "EventHitTest" enumeration. | 67 // These values are reported in UMA as the "EventHitTest" enumeration. |
65 // Do not reorder, append new values at the end, deprecate old | 68 // Do not reorder, append new values at the end, deprecate old |
66 // values and update histograms.xml. | 69 // values and update histograms.xml. |
67 enum class HitHistogramMetric { | 70 enum class HitHistogramMetric { |
68 MISS, // Miss, not found in cache. | 71 MISS, // Miss, not found in cache. |
(...skipping 10 matching lines...) Expand all Loading... | |
79 enum class ValidityHistogramMetric { | 82 enum class ValidityHistogramMetric { |
80 VALID_EXACT_MATCH, // Correct node for exact point test. | 83 VALID_EXACT_MATCH, // Correct node for exact point test. |
81 VALID_REGION, // Correct node for region check. | 84 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. | 85 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. | 86 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. | 87 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. | 88 INCORRECT_POINT_REGION, // Wrong node returned for point with region mat ching and was explicit point test. |
86 MAX_VALIDITY_METRIC = INCORRECT_POINT_REGION, | 89 MAX_VALIDITY_METRIC = INCORRECT_POINT_REGION, |
87 }; | 90 }; |
88 | 91 |
89 unsigned m_updateIndex = 0; | 92 unsigned m_updateIndex; |
tkent
2015/07/02 23:25:48
Do class member initializers prevent the component
| |
90 WillBeHeapVector<HitTestResult, HIT_TEST_CACHE_SIZE> m_items; | 93 WillBeHeapVector<HitTestResult, HIT_TEST_CACHE_SIZE> m_items; |
91 uint64_t m_domTreeVersion = 0; | 94 uint64_t m_domTreeVersion; |
92 }; | 95 }; |
93 | 96 |
94 } // namespace blink | 97 } // namespace blink |
95 | 98 |
96 #endif // HitTestCache_h | 99 #endif // HitTestCache_h |
OLD | NEW |