Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Side by Side Diff: third_party/WebKit/Source/platform/graphics/paint/PaintController.h

Issue 2872793002: Notify paint for each frame (Closed)
Patch Set: review fix Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 24 matching lines...) Expand all
204 void BeginSubsequence(const DisplayItemClient& client) { 217 void BeginSubsequence(const DisplayItemClient& client) {
205 current_subsequence_clients_.push_back(&client); 218 current_subsequence_clients_.push_back(&client);
206 BeginShouldKeepAlive(client); 219 BeginShouldKeepAlive(client);
207 } 220 }
208 221
209 void EndSubsequence() { current_subsequence_clients_.pop_back(); } 222 void EndSubsequence() { current_subsequence_clients_.pop_back(); }
210 #endif 223 #endif
211 224
212 bool LastDisplayItemIsSubsequenceEnd() const; 225 bool LastDisplayItemIsSubsequenceEnd() const;
213 226
227 void BeginFrame(const void* frame);
228 FrameFirstPaint EndFrame(const void* frame);
229
214 protected: 230 protected:
215 PaintController() 231 PaintController()
216 : new_display_item_list_(0), 232 : new_display_item_list_(0),
217 construction_disabled_(false), 233 construction_disabled_(false),
218 subsequence_caching_disabled_(false), 234 subsequence_caching_disabled_(false),
219 first_painted_(false),
220 text_painted_(false),
221 image_painted_(false),
222 skipping_cache_count_(0), 235 skipping_cache_count_(0),
223 num_cached_new_items_(0), 236 num_cached_new_items_(0),
224 current_cached_subsequence_begin_index_in_new_list_(kNotFound), 237 current_cached_subsequence_begin_index_in_new_list_(kNotFound),
225 #ifndef NDEBUG 238 #ifndef NDEBUG
226 num_sequential_matches_(0), 239 num_sequential_matches_(0),
227 num_out_of_order_matches_(0), 240 num_out_of_order_matches_(0),
228 num_indexed_items_(0), 241 num_indexed_items_(0),
229 #endif 242 #endif
230 under_invalidation_checking_begin_(0), 243 under_invalidation_checking_begin_(0),
231 under_invalidation_checking_end_(0), 244 under_invalidation_checking_end_(0),
232 last_cached_subsequence_end_(0) { 245 last_cached_subsequence_end_(0) {
233 ResetCurrentListIndices(); 246 ResetCurrentListIndices();
234 SetTracksRasterInvalidations( 247 SetTracksRasterInvalidations(
235 RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled()); 248 RuntimeEnabledFeatures::paintUnderInvalidationCheckingEnabled());
249 frame_first_paints_.push_back(FrameFirstPaint(nullptr));
Xianzhu 2017/05/09 23:13:08 Please add a comment to explain the reason.
Zhen Wang 2017/05/09 23:26:24 Done.
236 } 250 }
237 251
238 private: 252 private:
239 friend class PaintControllerTestBase; 253 friend class PaintControllerTestBase;
240 friend class PaintControllerPaintTestBase; 254 friend class PaintControllerPaintTestBase;
241 255
242 bool LastDisplayItemIsNoopBegin() const; 256 bool LastDisplayItemIsNoopBegin() const;
243 257
244 void EnsureNewDisplayItemListInitialCapacity() { 258 void EnsureNewDisplayItemListInitialCapacity() {
245 if (new_display_item_list_.IsEmpty()) { 259 if (new_display_item_list_.IsEmpty()) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 Vector<size_t> items_moved_into_new_list_; 347 Vector<size_t> items_moved_into_new_list_;
334 348
335 // Allows display item construction to be disabled to isolate the costs of 349 // Allows display item construction to be disabled to isolate the costs of
336 // construction in performance metrics. 350 // construction in performance metrics.
337 bool construction_disabled_; 351 bool construction_disabled_;
338 352
339 // Allows subsequence caching to be disabled to test the cost of display item 353 // Allows subsequence caching to be disabled to test the cost of display item
340 // caching. 354 // caching.
341 bool subsequence_caching_disabled_; 355 bool subsequence_caching_disabled_;
342 356
343 // The following fields indicate that this PaintController has ever had 357 // A stack recording current frames' first paints.
344 // first-paint, text or image painted. They are never reset to false. 358 Vector<FrameFirstPaint> frame_first_paints_;
345 // First-paint is defined in https://github.com/WICG/paint-timing. It excludes
346 // default background paint.
347 bool first_painted_;
348 bool text_painted_;
349 bool image_painted_;
350 359
351 int skipping_cache_count_; 360 int skipping_cache_count_;
352 361
353 int num_cached_new_items_; 362 int num_cached_new_items_;
354 363
355 // Stores indices to valid cacheable display items in 364 // Stores indices to valid cacheable display items in
356 // m_currentPaintArtifact.displayItemList() that have not been matched by 365 // m_currentPaintArtifact.displayItemList() that have not been matched by
357 // requests of cached display items (using useCachedDrawingIfPossible() and 366 // requests of cached display items (using useCachedDrawingIfPossible() and
358 // useCachedSubsequenceIfPossible()) during sequential matching. The indexed 367 // useCachedSubsequenceIfPossible()) during sequential matching. The indexed
359 // items will be matched by later out-of-order requests of cached display 368 // items will be matched by later out-of-order requests of cached display
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 CachedSubsequenceMap new_cached_subsequences_; 433 CachedSubsequenceMap new_cached_subsequences_;
425 size_t last_cached_subsequence_end_; 434 size_t last_cached_subsequence_end_;
426 435
427 FRIEND_TEST_ALL_PREFIXES(PaintControllerTest, CachedSubsequenceSwapOrder); 436 FRIEND_TEST_ALL_PREFIXES(PaintControllerTest, CachedSubsequenceSwapOrder);
428 FRIEND_TEST_ALL_PREFIXES(PaintControllerTest, CachedNestedSubsequenceUpdate); 437 FRIEND_TEST_ALL_PREFIXES(PaintControllerTest, CachedNestedSubsequenceUpdate);
429 }; 438 };
430 439
431 } // namespace blink 440 } // namespace blink
432 441
433 #endif // PaintController_h 442 #endif // PaintController_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698