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 #include "config.h" |
| 6 #include "core/layout/HitTestCache.h" |
| 7 |
| 8 #include "public/platform/Platform.h" |
| 9 |
| 10 namespace blink { |
| 11 |
| 12 bool HitTestCache::lookupCachedResult(HitTestResult& hitResult, uint64_t domTree
Version) |
| 13 { |
| 14 bool result = false; |
| 15 HitHistogramMetric metric = HitHistogramMetric::MISS; |
| 16 if (hitResult.hitTestRequest().avoidCache()) { |
| 17 metric = HitHistogramMetric::MISS_EXPLICIT_AVOID; |
| 18 // For now we don't support rect based hit results. |
| 19 } else if (domTreeVersion == m_domTreeVersion && !hitResult.hitTestLocation(
).isRectBasedTest()) { |
| 20 for (const auto& cachedItem : m_items) { |
| 21 if (cachedItem.hitTestLocation().point() == hitResult.hitTestLocatio
n().point()) { |
| 22 if (hitResult.hitTestRequest().equalForCacheability(cachedItem.h
itTestRequest())) { |
| 23 metric = HitHistogramMetric::HIT_EXACT_MATCH; |
| 24 result = true; |
| 25 hitResult = cachedItem; |
| 26 break; |
| 27 } |
| 28 metric = HitHistogramMetric::MISS_VALIDITY_RECT_MATCHES; |
| 29 } |
| 30 } |
| 31 } |
| 32 Platform::current()->histogramEnumeration("Event.HitTest", static_cast<int>(
metric), static_cast<int>(HitHistogramMetric::MAX_HIT_METRIC)); |
| 33 return result; |
| 34 } |
| 35 |
| 36 void HitTestCache::verifyCachedResult(const HitTestResult& expected, const HitTe
stResult& actual) |
| 37 { |
| 38 ValidityHistogramMetric metric; |
| 39 if (!actual.equalForCacheability(expected)) { |
| 40 metric = expected.hitTestLocation().isRectBasedTest() ? ValidityHistogra
mMetric::INCORRECT_RECT_BASED_EXACT_MATCH : ValidityHistogramMetric::INCORRECT_P
OINT_EXACT_MATCH; |
| 41 |
| 42 // ASSERT that the cache hit is the same as the actual result. |
| 43 ASSERT_NOT_REACHED(); |
| 44 } else { |
| 45 metric = ValidityHistogramMetric::VALID_EXACT_MATCH; |
| 46 } |
| 47 Platform::current()->histogramEnumeration("Event.HitTestValidity", static_ca
st<int>(metric), static_cast<int>(ValidityHistogramMetric::MAX_VALIDITY_METRIC))
; |
| 48 } |
| 49 |
| 50 void HitTestCache::addCachedResult(const HitTestResult& result, uint64_t domTree
Version) |
| 51 { |
| 52 if (!result.isCacheable()) |
| 53 return; |
| 54 |
| 55 // If the result was a hit test on an LayoutPart and the request allowed |
| 56 // querying of the layout part; then the part hasn't been loaded yet. |
| 57 if (result.isOverWidget() && result.hitTestRequest().allowsChildFrameContent
()) |
| 58 return; |
| 59 |
| 60 // For now don't support rect based or list based requests. |
| 61 if (result.hitTestLocation().isRectBasedTest() || result.hitTestRequest().li
stBased()) |
| 62 return; |
| 63 if (domTreeVersion != m_domTreeVersion) |
| 64 clear(); |
| 65 if (m_items.size() < HIT_TEST_CACHE_SIZE) |
| 66 m_items.resize(m_updateIndex + 1); |
| 67 |
| 68 m_items.at(m_updateIndex).cacheValues(result); |
| 69 m_domTreeVersion = domTreeVersion; |
| 70 |
| 71 m_updateIndex++; |
| 72 if (m_updateIndex >= HIT_TEST_CACHE_SIZE) |
| 73 m_updateIndex = 0; |
| 74 } |
| 75 |
| 76 void HitTestCache::clear() |
| 77 { |
| 78 m_updateIndex = 0; |
| 79 m_items.clear(); |
| 80 } |
| 81 |
| 82 DEFINE_TRACE(HitTestCache) |
| 83 { |
| 84 visitor->trace(m_items); |
| 85 } |
| 86 |
| 87 } // namespace blink |
OLD | NEW |