OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 RasterInvalidationTracking_h | 5 #ifndef RasterInvalidationTracking_h |
6 #define RasterInvalidationTracking_h | 6 #define RasterInvalidationTracking_h |
7 | 7 |
| 8 #include "platform/RuntimeEnabledFeatures.h" |
8 #include "platform/geometry/IntRect.h" | 9 #include "platform/geometry/IntRect.h" |
9 #include "platform/geometry/Region.h" | 10 #include "platform/geometry/Region.h" |
10 #include "platform/graphics/PaintInvalidationReason.h" | 11 #include "platform/graphics/PaintInvalidationReason.h" |
11 #include "platform/graphics/paint/PaintRecord.h" | 12 #include "platform/graphics/paint/PaintRecord.h" |
12 #include "platform/json/JSONValues.h" | 13 #include "platform/json/JSONValues.h" |
13 #include "platform/wtf/Allocator.h" | 14 #include "platform/wtf/Allocator.h" |
14 #include "platform/wtf/text/WTFString.h" | 15 #include "platform/wtf/text/WTFString.h" |
15 #include "third_party/skia/include/core/SkColor.h" | 16 #include "third_party/skia/include/core/SkColor.h" |
16 | 17 |
17 namespace blink { | 18 namespace blink { |
18 | 19 |
19 class DisplayItemClient; | 20 class DisplayItemClient; |
20 | 21 |
21 struct RasterInvalidationInfo { | 22 struct RasterInvalidationInfo { |
22 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 23 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
23 // This is for comparison only. Don't dereference because the client may have | 24 // This is for comparison only. Don't dereference because the client may have |
24 // died. | 25 // died. |
25 const DisplayItemClient* client; | 26 const DisplayItemClient* client = nullptr; |
26 String client_debug_name; | 27 String client_debug_name; |
27 IntRect rect; | 28 IntRect rect; |
28 PaintInvalidationReason reason; | 29 PaintInvalidationReason reason = kPaintInvalidationFull; |
29 RasterInvalidationInfo() : reason(kPaintInvalidationFull) {} | |
30 }; | 30 }; |
31 | 31 |
32 inline bool operator==(const RasterInvalidationInfo& a, | 32 inline bool operator==(const RasterInvalidationInfo& a, |
33 const RasterInvalidationInfo& b) { | 33 const RasterInvalidationInfo& b) { |
34 return a.rect == b.rect; | 34 return a.rect == b.rect; |
35 } | 35 } |
36 | 36 |
37 struct UnderPaintInvalidation { | 37 struct UnderRasterInvalidation { |
38 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 38 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
39 int x; | 39 int x; |
40 int y; | 40 int y; |
41 SkColor old_pixel; | 41 SkColor old_pixel; |
42 SkColor new_pixel; | 42 SkColor new_pixel; |
43 }; | 43 }; |
44 | 44 |
45 struct PLATFORM_EXPORT RasterInvalidationTracking { | 45 struct PLATFORM_EXPORT RasterInvalidationTracking { |
46 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); | 46 DISALLOW_NEW_EXCEPT_PLACEMENT_NEW(); |
47 Vector<RasterInvalidationInfo> tracked_raster_invalidations; | 47 Vector<RasterInvalidationInfo> tracked_invalidations; |
| 48 |
| 49 // The following fields are for under-raster-invalidation detection. |
48 sk_sp<PaintRecord> last_painted_record; | 50 sk_sp<PaintRecord> last_painted_record; |
49 IntRect last_interest_rect; | 51 IntRect last_interest_rect; |
50 Region raster_invalidation_region_since_last_paint; | 52 Region invalidation_region_since_last_paint; |
51 Vector<UnderPaintInvalidation> under_paint_invalidations; | 53 Vector<UnderRasterInvalidation> under_invalidations; |
52 | 54 |
53 void AsJSON(JSONObject*); | 55 void AsJSON(JSONObject*); |
54 }; | 56 }; |
55 | 57 |
56 template <class TargetClass> | 58 template <class TargetClass> |
57 class PLATFORM_EXPORT RasterInvalidationTrackingMap { | 59 class PLATFORM_EXPORT RasterInvalidationTrackingMap { |
58 public: | 60 public: |
59 void AsJSON(TargetClass* key, JSONObject* json) { | 61 void AsJSON(TargetClass* key, JSONObject* json) { |
60 auto it = invalidation_tracking_map_.find(key); | 62 auto it = map_.find(key); |
61 if (it != invalidation_tracking_map_.end()) | 63 if (it != map_.end()) |
62 it->value.AsJSON(json); | 64 it->value.AsJSON(json); |
63 } | 65 } |
64 | 66 |
65 void Remove(TargetClass* key) { | 67 void Remove(TargetClass* key) { |
66 auto it = invalidation_tracking_map_.find(key); | 68 auto it = map_.find(key); |
67 if (it != invalidation_tracking_map_.end()) | 69 if (it != map_.end()) |
68 invalidation_tracking_map_.erase(it); | 70 map_.erase(it); |
| 71 } |
| 72 |
| 73 void ResetTrackedInvalidations(TargetClass* key) { |
| 74 if (auto* tracking = Find(key)) |
| 75 tracking->tracked_invalidations.clear(); |
69 } | 76 } |
70 | 77 |
71 RasterInvalidationTracking& Add(TargetClass* key) { | 78 RasterInvalidationTracking& Add(TargetClass* key) { |
72 return invalidation_tracking_map_.insert(key, RasterInvalidationTracking()) | 79 return map_.insert(key, RasterInvalidationTracking()).stored_value->value; |
73 .stored_value->value; | 80 } |
| 81 |
| 82 void AddInvalidation(TargetClass* key, const RasterInvalidationInfo& info) { |
| 83 auto& tracking = Add(key); |
| 84 tracking.tracked_invalidations.push_back(info); |
| 85 |
| 86 if (RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()) { |
| 87 // TODO(crbug.com/496260): Some antialiasing effects overflow the paint |
| 88 // invalidation rect. |
| 89 IntRect r = info.rect; |
| 90 r.Inflate(1); |
| 91 tracking.invalidation_region_since_last_paint.Unite(r); |
| 92 } |
74 } | 93 } |
75 | 94 |
76 RasterInvalidationTracking* Find(TargetClass* key) { | 95 RasterInvalidationTracking* Find(TargetClass* key) { |
77 auto it = invalidation_tracking_map_.find(key); | 96 auto it = map_.find(key); |
78 if (it == invalidation_tracking_map_.end()) | 97 if (it == map_.end()) |
79 return nullptr; | 98 return nullptr; |
80 return &it->value; | 99 return &it->value; |
81 } | 100 } |
82 | 101 |
83 private: | 102 private: |
84 typedef HashMap<TargetClass*, RasterInvalidationTracking> | 103 typedef HashMap<TargetClass*, RasterInvalidationTracking> |
85 InvalidationTrackingMap; | 104 InvalidationTrackingMap; |
86 InvalidationTrackingMap invalidation_tracking_map_; | 105 InvalidationTrackingMap map_; |
87 }; | 106 }; |
88 | 107 |
89 } // namespace blink | 108 } // namespace blink |
90 | 109 |
91 #endif // RasterInvalidationTracking_h | 110 #endif // RasterInvalidationTracking_h |
OLD | NEW |