| 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 |
| 36 // Responsible for processing display items as they are produced, and producing | 52 // Responsible for processing display items as they are produced, and producing |
| 37 // a final paint artifact when complete. This class includes logic for caching, | 53 // a final paint artifact when complete. This class includes logic for caching, |
| 38 // cache invalidation, and merging. | 54 // cache invalidation, and merging. |
| 39 class PLATFORM_EXPORT PaintController { | 55 class PLATFORM_EXPORT PaintController { |
| 40 WTF_MAKE_NONCOPYABLE(PaintController); | 56 WTF_MAKE_NONCOPYABLE(PaintController); |
| 41 USING_FAST_MALLOC(PaintController); | 57 USING_FAST_MALLOC(PaintController); |
| 42 | 58 |
| 43 public: | 59 public: |
| 44 static std::unique_ptr<PaintController> Create() { | 60 static std::unique_ptr<PaintController> Create() { |
| 45 return WTF::WrapUnique(new PaintController()); | 61 return WTF::WrapUnique(new PaintController()); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 void SetDisplayItemConstructionIsDisabled(const bool disable) { | 170 void SetDisplayItemConstructionIsDisabled(const bool disable) { |
| 155 construction_disabled_ = disable; | 171 construction_disabled_ = disable; |
| 156 } | 172 } |
| 157 bool SubsequenceCachingIsDisabled() const { | 173 bool SubsequenceCachingIsDisabled() const { |
| 158 return subsequence_caching_disabled_; | 174 return subsequence_caching_disabled_; |
| 159 } | 175 } |
| 160 void SetSubsequenceCachingIsDisabled(bool disable) { | 176 void SetSubsequenceCachingIsDisabled(bool disable) { |
| 161 subsequence_caching_disabled_ = disable; | 177 subsequence_caching_disabled_ = disable; |
| 162 } | 178 } |
| 163 | 179 |
| 164 bool FirstPainted() const { return first_painted_; } | 180 void SetFirstPainted(); |
| 165 void SetFirstPainted() { first_painted_ = true; } | 181 void SetTextPainted(); |
| 166 bool TextPainted() const { return text_painted_; } | 182 void SetImagePainted(); |
| 167 void SetTextPainted() { text_painted_ = true; } | |
| 168 bool ImagePainted() const { return image_painted_; } | |
| 169 void SetImagePainted() { image_painted_ = true; } | |
| 170 | 183 |
| 171 // Returns displayItemList added using createAndAppend() since beginning or | 184 // Returns displayItemList added using createAndAppend() since beginning or |
| 172 // the last commitNewDisplayItems(). Use with care. | 185 // the last commitNewDisplayItems(). Use with care. |
| 173 DisplayItemList& NewDisplayItemList() { return new_display_item_list_; } | 186 DisplayItemList& NewDisplayItemList() { return new_display_item_list_; } |
| 174 | 187 |
| 175 void AppendDebugDrawingAfterCommit( | 188 void AppendDebugDrawingAfterCommit( |
| 176 const DisplayItemClient&, | 189 const DisplayItemClient&, |
| 177 sk_sp<PaintRecord>, | 190 sk_sp<PaintRecord>, |
| 178 const LayoutSize& offset_from_layout_object); | 191 const LayoutSize& offset_from_layout_object); |
| 179 | 192 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 206 void BeginSubsequence(const DisplayItemClient& client) { | 219 void BeginSubsequence(const DisplayItemClient& client) { |
| 207 current_subsequence_clients_.push_back(&client); | 220 current_subsequence_clients_.push_back(&client); |
| 208 BeginShouldKeepAlive(client); | 221 BeginShouldKeepAlive(client); |
| 209 } | 222 } |
| 210 | 223 |
| 211 void EndSubsequence() { current_subsequence_clients_.pop_back(); } | 224 void EndSubsequence() { current_subsequence_clients_.pop_back(); } |
| 212 #endif | 225 #endif |
| 213 | 226 |
| 214 bool LastDisplayItemIsSubsequenceEnd() const; | 227 bool LastDisplayItemIsSubsequenceEnd() const; |
| 215 | 228 |
| 229 void BeginFrame(const void* frame); |
| 230 FrameFirstPaint EndFrame(const void* frame); |
| 231 |
| 216 protected: | 232 protected: |
| 217 PaintController() | 233 PaintController() |
| 218 : new_display_item_list_(0), | 234 : new_display_item_list_(0), |
| 219 construction_disabled_(false), | 235 construction_disabled_(false), |
| 220 subsequence_caching_disabled_(false), | 236 subsequence_caching_disabled_(false), |
| 221 first_painted_(false), | |
| 222 text_painted_(false), | |
| 223 image_painted_(false), | |
| 224 skipping_cache_count_(0), | 237 skipping_cache_count_(0), |
| 225 num_cached_new_items_(0), | 238 num_cached_new_items_(0), |
| 226 current_cached_subsequence_begin_index_in_new_list_(kNotFound), | 239 current_cached_subsequence_begin_index_in_new_list_(kNotFound), |
| 227 #ifndef NDEBUG | 240 #ifndef NDEBUG |
| 228 num_sequential_matches_(0), | 241 num_sequential_matches_(0), |
| 229 num_out_of_order_matches_(0), | 242 num_out_of_order_matches_(0), |
| 230 num_indexed_items_(0), | 243 num_indexed_items_(0), |
| 231 #endif | 244 #endif |
| 232 under_invalidation_checking_begin_(0), | 245 under_invalidation_checking_begin_(0), |
| 233 under_invalidation_checking_end_(0), | 246 under_invalidation_checking_end_(0), |
| 234 last_cached_subsequence_end_(0) { | 247 last_cached_subsequence_end_(0) { |
| 235 ResetCurrentListIndices(); | 248 ResetCurrentListIndices(); |
| 236 SetTracksRasterInvalidations( | 249 SetTracksRasterInvalidations( |
| 237 RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()); | 250 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)); |
| 238 } | 258 } |
| 239 | 259 |
| 240 private: | 260 private: |
| 241 friend class PaintControllerTestBase; | 261 friend class PaintControllerTestBase; |
| 242 friend class PaintControllerPaintTestBase; | 262 friend class PaintControllerPaintTestBase; |
| 243 | 263 |
| 244 bool LastDisplayItemIsNoopBegin() const; | 264 bool LastDisplayItemIsNoopBegin() const; |
| 245 | 265 |
| 246 void EnsureNewDisplayItemListInitialCapacity() { | 266 void EnsureNewDisplayItemListInitialCapacity() { |
| 247 if (new_display_item_list_.IsEmpty()) { | 267 if (new_display_item_list_.IsEmpty()) { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 Vector<size_t> items_moved_into_new_list_; | 357 Vector<size_t> items_moved_into_new_list_; |
| 338 | 358 |
| 339 // Allows display item construction to be disabled to isolate the costs of | 359 // Allows display item construction to be disabled to isolate the costs of |
| 340 // construction in performance metrics. | 360 // construction in performance metrics. |
| 341 bool construction_disabled_; | 361 bool construction_disabled_; |
| 342 | 362 |
| 343 // Allows subsequence caching to be disabled to test the cost of display item | 363 // Allows subsequence caching to be disabled to test the cost of display item |
| 344 // caching. | 364 // caching. |
| 345 bool subsequence_caching_disabled_; | 365 bool subsequence_caching_disabled_; |
| 346 | 366 |
| 347 // The following fields indicate that this PaintController has ever had | 367 // A stack recording current frames' first paints. |
| 348 // first-paint, text or image painted. They are never reset to false. | 368 Vector<FrameFirstPaint> frame_first_paints_; |
| 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_; | |
| 354 | 369 |
| 355 int skipping_cache_count_; | 370 int skipping_cache_count_; |
| 356 | 371 |
| 357 int num_cached_new_items_; | 372 int num_cached_new_items_; |
| 358 | 373 |
| 359 // Stores indices to valid cacheable display items in | 374 // Stores indices to valid cacheable display items in |
| 360 // m_currentPaintArtifact.displayItemList() that have not been matched by | 375 // m_currentPaintArtifact.displayItemList() that have not been matched by |
| 361 // requests of cached display items (using useCachedDrawingIfPossible() and | 376 // requests of cached display items (using useCachedDrawingIfPossible() and |
| 362 // useCachedSubsequenceIfPossible()) during sequential matching. The indexed | 377 // useCachedSubsequenceIfPossible()) during sequential matching. The indexed |
| 363 // items will be matched by later out-of-order requests of cached display | 378 // 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... |
| 434 CachedSubsequenceMap new_cached_subsequences_; | 449 CachedSubsequenceMap new_cached_subsequences_; |
| 435 size_t last_cached_subsequence_end_; | 450 size_t last_cached_subsequence_end_; |
| 436 | 451 |
| 437 FRIEND_TEST_ALL_PREFIXES(PaintControllerTest, CachedSubsequenceSwapOrder); | 452 FRIEND_TEST_ALL_PREFIXES(PaintControllerTest, CachedSubsequenceSwapOrder); |
| 438 FRIEND_TEST_ALL_PREFIXES(PaintControllerTest, CachedNestedSubsequenceUpdate); | 453 FRIEND_TEST_ALL_PREFIXES(PaintControllerTest, CachedNestedSubsequenceUpdate); |
| 439 }; | 454 }; |
| 440 | 455 |
| 441 } // namespace blink | 456 } // namespace blink |
| 442 | 457 |
| 443 #endif // PaintController_h | 458 #endif // PaintController_h |
| OLD | NEW |