OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 PaintController_h | 5 #ifndef PaintController_h |
6 #define PaintController_h | 6 #define PaintController_h |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 #include "platform/PlatformExport.h" | 10 #include "platform/PlatformExport.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "platform/wtf/PtrUtil.h" | 26 #include "platform/wtf/PtrUtil.h" |
27 #include "platform/wtf/Vector.h" | 27 #include "platform/wtf/Vector.h" |
28 #include "third_party/skia/include/core/SkRefCnt.h" | 28 #include "third_party/skia/include/core/SkRefCnt.h" |
29 | 29 |
30 namespace blink { | 30 namespace blink { |
31 | 31 |
32 static const size_t kInitialDisplayItemListCapacityBytes = 512; | 32 static const size_t kInitialDisplayItemListCapacityBytes = 512; |
33 | 33 |
34 template class RasterInvalidationTrackingMap<const PaintChunk>; | 34 template class RasterInvalidationTrackingMap<const PaintChunk>; |
35 | 35 |
36 // FrameFirstPaint stores first-paint, text or image painted for the | |
37 // corresponding frame. They are never reset to false. First-paint is defined in | |
38 // https://github.com/WICG/paint-timing. It excludes default background paint. | |
39 struct FrameFirstPaint { | |
40 FrameFirstPaint(const void* frame) | |
41 : frame(frame), | |
42 first_painted(false), | |
43 text_painted(false), | |
44 image_painted(false) {} | |
45 | |
46 const void* frame; | |
47 bool first_painted : 1; | |
48 bool text_painted : 1; | |
49 bool image_painted : 1; | |
50 }; | |
51 | |
52 // Responsible for processing display items as they are produced, and producing | 36 // Responsible for processing display items as they are produced, and producing |
53 // a final paint artifact when complete. This class includes logic for caching, | 37 // a final paint artifact when complete. This class includes logic for caching, |
54 // cache invalidation, and merging. | 38 // cache invalidation, and merging. |
55 class PLATFORM_EXPORT PaintController { | 39 class PLATFORM_EXPORT PaintController { |
56 WTF_MAKE_NONCOPYABLE(PaintController); | 40 WTF_MAKE_NONCOPYABLE(PaintController); |
57 USING_FAST_MALLOC(PaintController); | 41 USING_FAST_MALLOC(PaintController); |
58 | 42 |
59 public: | 43 public: |
60 static std::unique_ptr<PaintController> Create() { | 44 static std::unique_ptr<PaintController> Create() { |
61 return WTF::WrapUnique(new PaintController()); | 45 return WTF::WrapUnique(new PaintController()); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 void SetDisplayItemConstructionIsDisabled(const bool disable) { | 154 void SetDisplayItemConstructionIsDisabled(const bool disable) { |
171 construction_disabled_ = disable; | 155 construction_disabled_ = disable; |
172 } | 156 } |
173 bool SubsequenceCachingIsDisabled() const { | 157 bool SubsequenceCachingIsDisabled() const { |
174 return subsequence_caching_disabled_; | 158 return subsequence_caching_disabled_; |
175 } | 159 } |
176 void SetSubsequenceCachingIsDisabled(bool disable) { | 160 void SetSubsequenceCachingIsDisabled(bool disable) { |
177 subsequence_caching_disabled_ = disable; | 161 subsequence_caching_disabled_ = disable; |
178 } | 162 } |
179 | 163 |
180 void SetFirstPainted(); | 164 bool FirstPainted() const { return first_painted_; } |
181 void SetTextPainted(); | 165 void SetFirstPainted() { first_painted_ = true; } |
182 void SetImagePainted(); | 166 bool TextPainted() const { return text_painted_; } |
| 167 void SetTextPainted() { text_painted_ = true; } |
| 168 bool ImagePainted() const { return image_painted_; } |
| 169 void SetImagePainted() { image_painted_ = true; } |
183 | 170 |
184 // Returns displayItemList added using createAndAppend() since beginning or | 171 // Returns displayItemList added using createAndAppend() since beginning or |
185 // the last commitNewDisplayItems(). Use with care. | 172 // the last commitNewDisplayItems(). Use with care. |
186 DisplayItemList& NewDisplayItemList() { return new_display_item_list_; } | 173 DisplayItemList& NewDisplayItemList() { return new_display_item_list_; } |
187 | 174 |
188 void AppendDebugDrawingAfterCommit( | 175 void AppendDebugDrawingAfterCommit( |
189 const DisplayItemClient&, | 176 const DisplayItemClient&, |
190 sk_sp<PaintRecord>, | 177 sk_sp<PaintRecord>, |
191 const LayoutSize& offset_from_layout_object); | 178 const LayoutSize& offset_from_layout_object); |
192 | 179 |
(...skipping 26 matching lines...) Expand all Loading... |
219 void BeginSubsequence(const DisplayItemClient& client) { | 206 void BeginSubsequence(const DisplayItemClient& client) { |
220 current_subsequence_clients_.push_back(&client); | 207 current_subsequence_clients_.push_back(&client); |
221 BeginShouldKeepAlive(client); | 208 BeginShouldKeepAlive(client); |
222 } | 209 } |
223 | 210 |
224 void EndSubsequence() { current_subsequence_clients_.pop_back(); } | 211 void EndSubsequence() { current_subsequence_clients_.pop_back(); } |
225 #endif | 212 #endif |
226 | 213 |
227 bool LastDisplayItemIsSubsequenceEnd() const; | 214 bool LastDisplayItemIsSubsequenceEnd() const; |
228 | 215 |
229 void BeginFrame(const void* frame); | |
230 FrameFirstPaint EndFrame(const void* frame); | |
231 | |
232 protected: | 216 protected: |
233 PaintController() | 217 PaintController() |
234 : new_display_item_list_(0), | 218 : new_display_item_list_(0), |
235 construction_disabled_(false), | 219 construction_disabled_(false), |
236 subsequence_caching_disabled_(false), | 220 subsequence_caching_disabled_(false), |
| 221 first_painted_(false), |
| 222 text_painted_(false), |
| 223 image_painted_(false), |
237 skipping_cache_count_(0), | 224 skipping_cache_count_(0), |
238 num_cached_new_items_(0), | 225 num_cached_new_items_(0), |
239 current_cached_subsequence_begin_index_in_new_list_(kNotFound), | 226 current_cached_subsequence_begin_index_in_new_list_(kNotFound), |
240 #ifndef NDEBUG | 227 #ifndef NDEBUG |
241 num_sequential_matches_(0), | 228 num_sequential_matches_(0), |
242 num_out_of_order_matches_(0), | 229 num_out_of_order_matches_(0), |
243 num_indexed_items_(0), | 230 num_indexed_items_(0), |
244 #endif | 231 #endif |
245 under_invalidation_checking_begin_(0), | 232 under_invalidation_checking_begin_(0), |
246 under_invalidation_checking_end_(0), | 233 under_invalidation_checking_end_(0), |
247 last_cached_subsequence_end_(0) { | 234 last_cached_subsequence_end_(0) { |
248 ResetCurrentListIndices(); | 235 ResetCurrentListIndices(); |
249 SetTracksRasterInvalidations( | 236 SetTracksRasterInvalidations( |
250 RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()); | 237 RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()); |
251 | |
252 // frame_first_paints_ should have one null frame since the beginning, so | |
253 // that PaintController is robust even if it paints outside of BeginFrame | |
254 // and EndFrame cycles. It will also enable us to combine the first paint | |
255 // data in this PaintController into another PaintController on which we | |
256 // replay the recorded results in the future. | |
257 frame_first_paints_.push_back(FrameFirstPaint(nullptr)); | |
258 } | 238 } |
259 | 239 |
260 private: | 240 private: |
261 friend class PaintControllerTestBase; | 241 friend class PaintControllerTestBase; |
262 friend class PaintControllerPaintTestBase; | 242 friend class PaintControllerPaintTestBase; |
263 | 243 |
264 bool LastDisplayItemIsNoopBegin() const; | 244 bool LastDisplayItemIsNoopBegin() const; |
265 | 245 |
266 void EnsureNewDisplayItemListInitialCapacity() { | 246 void EnsureNewDisplayItemListInitialCapacity() { |
267 if (new_display_item_list_.IsEmpty()) { | 247 if (new_display_item_list_.IsEmpty()) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 Vector<size_t> items_moved_into_new_list_; | 337 Vector<size_t> items_moved_into_new_list_; |
358 | 338 |
359 // Allows display item construction to be disabled to isolate the costs of | 339 // Allows display item construction to be disabled to isolate the costs of |
360 // construction in performance metrics. | 340 // construction in performance metrics. |
361 bool construction_disabled_; | 341 bool construction_disabled_; |
362 | 342 |
363 // Allows subsequence caching to be disabled to test the cost of display item | 343 // Allows subsequence caching to be disabled to test the cost of display item |
364 // caching. | 344 // caching. |
365 bool subsequence_caching_disabled_; | 345 bool subsequence_caching_disabled_; |
366 | 346 |
367 // A stack recording current frames' first paints. | 347 // The following fields indicate that this PaintController has ever had |
368 Vector<FrameFirstPaint> frame_first_paints_; | 348 // first-paint, text or image painted. They are never reset to false. |
| 349 // First-paint is defined in https://github.com/WICG/paint-timing. It excludes |
| 350 // default background paint. |
| 351 bool first_painted_; |
| 352 bool text_painted_; |
| 353 bool image_painted_; |
369 | 354 |
370 int skipping_cache_count_; | 355 int skipping_cache_count_; |
371 | 356 |
372 int num_cached_new_items_; | 357 int num_cached_new_items_; |
373 | 358 |
374 // Stores indices to valid cacheable display items in | 359 // Stores indices to valid cacheable display items in |
375 // m_currentPaintArtifact.displayItemList() that have not been matched by | 360 // m_currentPaintArtifact.displayItemList() that have not been matched by |
376 // requests of cached display items (using useCachedDrawingIfPossible() and | 361 // requests of cached display items (using useCachedDrawingIfPossible() and |
377 // useCachedSubsequenceIfPossible()) during sequential matching. The indexed | 362 // useCachedSubsequenceIfPossible()) during sequential matching. The indexed |
378 // items will be matched by later out-of-order requests of cached display | 363 // items will be matched by later out-of-order requests of cached display |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 CachedSubsequenceMap new_cached_subsequences_; | 434 CachedSubsequenceMap new_cached_subsequences_; |
450 size_t last_cached_subsequence_end_; | 435 size_t last_cached_subsequence_end_; |
451 | 436 |
452 FRIEND_TEST_ALL_PREFIXES(PaintControllerTest, CachedSubsequenceSwapOrder); | 437 FRIEND_TEST_ALL_PREFIXES(PaintControllerTest, CachedSubsequenceSwapOrder); |
453 FRIEND_TEST_ALL_PREFIXES(PaintControllerTest, CachedNestedSubsequenceUpdate); | 438 FRIEND_TEST_ALL_PREFIXES(PaintControllerTest, CachedNestedSubsequenceUpdate); |
454 }; | 439 }; |
455 | 440 |
456 } // namespace blink | 441 } // namespace blink |
457 | 442 |
458 #endif // PaintController_h | 443 #endif // PaintController_h |
OLD | NEW |