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

Side by Side Diff: cc/paint/paint_op_buffer.h

Issue 2830243002: cc: Don't perform image analysis if the DisplayItemList has no images. (Closed)
Patch Set: rebase 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
« no previous file with comments | « cc/paint/display_item_list.cc ('k') | cc/paint/paint_op_buffer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 CC_PAINT_PAINT_OP_BUFFER_H_ 5 #ifndef CC_PAINT_PAINT_OP_BUFFER_H_
6 #define CC_PAINT_PAINT_OP_BUFFER_H_ 6 #define CC_PAINT_PAINT_OP_BUFFER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // pointer. 85 // pointer.
86 void Raster(SkCanvas* canvas, const SkMatrix& original_ctm) const; 86 void Raster(SkCanvas* canvas, const SkMatrix& original_ctm) const;
87 bool IsDrawOp() const; 87 bool IsDrawOp() const;
88 88
89 // Only valid for draw ops. 89 // Only valid for draw ops.
90 void RasterWithAlpha(SkCanvas* canvas, uint8_t alpha) const; 90 void RasterWithAlpha(SkCanvas* canvas, uint8_t alpha) const;
91 91
92 int CountSlowPaths() const { return 0; } 92 int CountSlowPaths() const { return 0; }
93 int CountSlowPathsFromFlags() const { return 0; } 93 int CountSlowPathsFromFlags() const { return 0; }
94 94
95 bool HasDiscardableImages() const { return false; }
96 bool HasDiscardableImagesFromFlags() const { return false; }
97
95 // Returns the number of bytes used by this op in referenced sub records 98 // Returns the number of bytes used by this op in referenced sub records
96 // and display lists. This doesn't count other objects like paths or blobs. 99 // and display lists. This doesn't count other objects like paths or blobs.
97 size_t AdditionalBytesUsed() const { return 0; } 100 size_t AdditionalBytesUsed() const { return 0; }
98 101
99 static constexpr bool kIsDrawOp = false; 102 static constexpr bool kIsDrawOp = false;
100 static constexpr bool kHasPaintFlags = false; 103 static constexpr bool kHasPaintFlags = false;
101 static SkRect kUnsetRect; 104 static SkRect kUnsetRect;
102 }; 105 };
103 106
104 struct CC_PAINT_EXPORT PaintOpWithFlags : PaintOp { 107 struct CC_PAINT_EXPORT PaintOpWithFlags : PaintOp {
105 static constexpr bool kHasPaintFlags = true; 108 static constexpr bool kHasPaintFlags = true;
106 109
107 explicit PaintOpWithFlags(const PaintFlags& flags) : flags(flags) {} 110 explicit PaintOpWithFlags(const PaintFlags& flags) : flags(flags) {}
108 111
109 int CountSlowPathsFromFlags() const { return flags.getPathEffect() ? 1 : 0; } 112 int CountSlowPathsFromFlags() const { return flags.getPathEffect() ? 1 : 0; }
113 bool HasDiscardableImagesFromFlags() const {
114 if (!IsDrawOp())
115 return false;
116
117 SkShader* shader = flags.getShader();
118 SkImage* image = shader ? shader->isAImage(nullptr, nullptr) : nullptr;
119 return image && image->isLazyGenerated();
120 }
110 121
111 // Subclasses should provide a static RasterWithFlags() method which is called 122 // Subclasses should provide a static RasterWithFlags() method which is called
112 // from the Raster() method. The RasterWithFlags() should use the PaintFlags 123 // from the Raster() method. The RasterWithFlags() should use the PaintFlags
113 // passed to it, instead of the |flags| member directly, as some callers may 124 // passed to it, instead of the |flags| member directly, as some callers may
114 // provide a modified PaintFlags. The RasterWithFlags() method is static with 125 // provide a modified PaintFlags. The RasterWithFlags() method is static with
115 // a const PaintOpWithFlags* parameter so that it can be used as a function 126 // a const PaintOpWithFlags* parameter so that it can be used as a function
116 // pointer. 127 // pointer.
117 PaintFlags flags; 128 PaintFlags flags;
118 }; 129 };
119 130
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 // Windows wants to generate these when types are exported, so 368 // Windows wants to generate these when types are exported, so
358 // provide them here explicitly so that DisplayItemList doesn't have 369 // provide them here explicitly so that DisplayItemList doesn't have
359 // to be defined in this header. 370 // to be defined in this header.
360 DrawDisplayItemListOp(const DrawDisplayItemListOp& op); 371 DrawDisplayItemListOp(const DrawDisplayItemListOp& op);
361 DrawDisplayItemListOp& operator=(const DrawDisplayItemListOp& op); 372 DrawDisplayItemListOp& operator=(const DrawDisplayItemListOp& op);
362 ~DrawDisplayItemListOp(); 373 ~DrawDisplayItemListOp();
363 static void Raster(const PaintOp* op, 374 static void Raster(const PaintOp* op,
364 SkCanvas* canvas, 375 SkCanvas* canvas,
365 const SkMatrix& original_ctm); 376 const SkMatrix& original_ctm);
366 size_t AdditionalBytesUsed() const; 377 size_t AdditionalBytesUsed() const;
378 bool HasDiscardableImages() const;
367 // TODO(enne): DisplayItemList should know number of slow paths. 379 // TODO(enne): DisplayItemList should know number of slow paths.
368 380
369 scoped_refptr<DisplayItemList> list; 381 scoped_refptr<DisplayItemList> list;
370 }; 382 };
371 383
372 struct CC_PAINT_EXPORT DrawDRRectOp final : PaintOpWithFlags { 384 struct CC_PAINT_EXPORT DrawDRRectOp final : PaintOpWithFlags {
373 static constexpr PaintOpType kType = PaintOpType::DrawDRRect; 385 static constexpr PaintOpType kType = PaintOpType::DrawDRRect;
374 static constexpr bool kIsDrawOp = true; 386 static constexpr bool kIsDrawOp = true;
375 DrawDRRectOp(const SkRRect& outer, 387 DrawDRRectOp(const SkRRect& outer,
376 const SkRRect& inner, 388 const SkRRect& inner,
(...skipping 25 matching lines...) Expand all
402 static void Raster(const PaintOp* op, 414 static void Raster(const PaintOp* op,
403 SkCanvas* canvas, 415 SkCanvas* canvas,
404 const SkMatrix& original_ctm) { 416 const SkMatrix& original_ctm) {
405 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); 417 auto* flags_op = static_cast<const PaintOpWithFlags*>(op);
406 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); 418 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm);
407 } 419 }
408 static void RasterWithFlags(const PaintOpWithFlags* op, 420 static void RasterWithFlags(const PaintOpWithFlags* op,
409 const PaintFlags* flags, 421 const PaintFlags* flags,
410 SkCanvas* canvas, 422 SkCanvas* canvas,
411 const SkMatrix& original_ctm); 423 const SkMatrix& original_ctm);
424 bool HasDiscardableImages() const;
412 425
413 PaintImage image; 426 PaintImage image;
414 SkScalar left; 427 SkScalar left;
415 SkScalar top; 428 SkScalar top;
416 }; 429 };
417 430
418 struct CC_PAINT_EXPORT DrawImageRectOp final : PaintOpWithFlags { 431 struct CC_PAINT_EXPORT DrawImageRectOp final : PaintOpWithFlags {
419 static constexpr PaintOpType kType = PaintOpType::DrawImageRect; 432 static constexpr PaintOpType kType = PaintOpType::DrawImageRect;
420 static constexpr bool kIsDrawOp = true; 433 static constexpr bool kIsDrawOp = true;
421 DrawImageRectOp(const PaintImage& image, 434 DrawImageRectOp(const PaintImage& image,
422 const SkRect& src, 435 const SkRect& src,
423 const SkRect& dst, 436 const SkRect& dst,
424 const PaintFlags* flags, 437 const PaintFlags* flags,
425 PaintCanvas::SrcRectConstraint constraint); 438 PaintCanvas::SrcRectConstraint constraint);
426 ~DrawImageRectOp(); 439 ~DrawImageRectOp();
427 static void Raster(const PaintOp* op, 440 static void Raster(const PaintOp* op,
428 SkCanvas* canvas, 441 SkCanvas* canvas,
429 const SkMatrix& original_ctm) { 442 const SkMatrix& original_ctm) {
430 auto* flags_op = static_cast<const PaintOpWithFlags*>(op); 443 auto* flags_op = static_cast<const PaintOpWithFlags*>(op);
431 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm); 444 RasterWithFlags(flags_op, &flags_op->flags, canvas, original_ctm);
432 } 445 }
433 static void RasterWithFlags(const PaintOpWithFlags* op, 446 static void RasterWithFlags(const PaintOpWithFlags* op,
434 const PaintFlags* flags, 447 const PaintFlags* flags,
435 SkCanvas* canvas, 448 SkCanvas* canvas,
436 const SkMatrix& original_ctm); 449 const SkMatrix& original_ctm);
450 bool HasDiscardableImages() const;
437 451
438 PaintImage image; 452 PaintImage image;
439 SkRect src; 453 SkRect src;
440 SkRect dst; 454 SkRect dst;
441 PaintCanvas::SrcRectConstraint constraint; 455 PaintCanvas::SrcRectConstraint constraint;
442 }; 456 };
443 457
444 struct CC_PAINT_EXPORT DrawIRectOp final : PaintOpWithFlags { 458 struct CC_PAINT_EXPORT DrawIRectOp final : PaintOpWithFlags {
445 static constexpr PaintOpType kType = PaintOpType::DrawIRect; 459 static constexpr PaintOpType kType = PaintOpType::DrawIRect;
446 static constexpr bool kIsDrawOp = true; 460 static constexpr bool kIsDrawOp = true;
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 565
552 struct CC_PAINT_EXPORT DrawRecordOp final : PaintOp { 566 struct CC_PAINT_EXPORT DrawRecordOp final : PaintOp {
553 static constexpr PaintOpType kType = PaintOpType::DrawRecord; 567 static constexpr PaintOpType kType = PaintOpType::DrawRecord;
554 static constexpr bool kIsDrawOp = true; 568 static constexpr bool kIsDrawOp = true;
555 explicit DrawRecordOp(sk_sp<const PaintRecord> record); 569 explicit DrawRecordOp(sk_sp<const PaintRecord> record);
556 ~DrawRecordOp(); 570 ~DrawRecordOp();
557 static void Raster(const PaintOp* op, 571 static void Raster(const PaintOp* op,
558 SkCanvas* canvas, 572 SkCanvas* canvas,
559 const SkMatrix& original_ctm); 573 const SkMatrix& original_ctm);
560 size_t AdditionalBytesUsed() const; 574 size_t AdditionalBytesUsed() const;
575 bool HasDiscardableImages() const;
561 576
562 sk_sp<const PaintRecord> record; 577 sk_sp<const PaintRecord> record;
563 }; 578 };
564 579
565 struct CC_PAINT_EXPORT DrawRectOp final : PaintOpWithFlags { 580 struct CC_PAINT_EXPORT DrawRectOp final : PaintOpWithFlags {
566 static constexpr PaintOpType kType = PaintOpType::DrawRect; 581 static constexpr PaintOpType kType = PaintOpType::DrawRect;
567 static constexpr bool kIsDrawOp = true; 582 static constexpr bool kIsDrawOp = true;
568 DrawRectOp(const SkRect& rect, const PaintFlags& flags) 583 DrawRectOp(const SkRect& rect, const PaintFlags& flags)
569 : PaintOpWithFlags(flags), rect(rect) {} 584 : PaintOpWithFlags(flags), rect(rect) {}
570 static void Raster(const PaintOp* op, 585 static void Raster(const PaintOp* op,
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 779
765 void playback(SkCanvas* canvas) const; 780 void playback(SkCanvas* canvas) const;
766 void playback(SkCanvas* canvas, SkPicture::AbortCallback* callback) const; 781 void playback(SkCanvas* canvas, SkPicture::AbortCallback* callback) const;
767 782
768 // TODO(enne): These are no longer approximate. Rename these. 783 // TODO(enne): These are no longer approximate. Rename these.
769 int approximateOpCount() const { return op_count_; } 784 int approximateOpCount() const { return op_count_; }
770 size_t approximateBytesUsed() const { 785 size_t approximateBytesUsed() const {
771 return sizeof(*this) + reserved_ + subrecord_bytes_used_; 786 return sizeof(*this) + reserved_ + subrecord_bytes_used_;
772 } 787 }
773 int numSlowPaths() const { return num_slow_paths_; } 788 int numSlowPaths() const { return num_slow_paths_; }
789 bool HasDiscardableImages() const { return has_discardable_images_; }
774 790
775 // Resize the PaintOpBuffer to exactly fit the current amount of used space. 791 // Resize the PaintOpBuffer to exactly fit the current amount of used space.
776 void ShrinkToFit(); 792 void ShrinkToFit();
777 793
778 const SkRect& cullRect() const { return cull_rect_; } 794 const SkRect& cullRect() const { return cull_rect_; }
779 795
780 PaintOp* GetFirstOp() const { 796 PaintOp* GetFirstOp() const {
781 return const_cast<PaintOp*>(first_op_.data_as<PaintOp>()); 797 return const_cast<PaintOp*>(first_op_.data_as<PaintOp>());
782 } 798 }
783 799
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 op->skip = skip; 942 op->skip = skip;
927 AnalyzeAddedOp(op); 943 AnalyzeAddedOp(op);
928 return op; 944 return op;
929 } 945 }
930 946
931 template <typename T> 947 template <typename T>
932 void AnalyzeAddedOp(const T* op) { 948 void AnalyzeAddedOp(const T* op) {
933 num_slow_paths_ += op->CountSlowPathsFromFlags(); 949 num_slow_paths_ += op->CountSlowPathsFromFlags();
934 num_slow_paths_ += op->CountSlowPaths(); 950 num_slow_paths_ += op->CountSlowPaths();
935 951
952 has_discardable_images_ |= op->HasDiscardableImages();
953 has_discardable_images_ |= op->HasDiscardableImagesFromFlags();
954
936 subrecord_bytes_used_ += op->AdditionalBytesUsed(); 955 subrecord_bytes_used_ += op->AdditionalBytesUsed();
937 } 956 }
938 957
939 // As a performance optimization because n=1 is an extremely common case just 958 // As a performance optimization because n=1 is an extremely common case just
940 // store the first op in the PaintOpBuffer itself to avoid an extra alloc. 959 // store the first op in the PaintOpBuffer itself to avoid an extra alloc.
941 base::AlignedMemory<sizeof(LargestPaintOp), PaintOpAlign> first_op_; 960 base::AlignedMemory<sizeof(LargestPaintOp), PaintOpAlign> first_op_;
942 std::unique_ptr<char, base::AlignedFreeDeleter> data_; 961 std::unique_ptr<char, base::AlignedFreeDeleter> data_;
943 size_t used_ = 0; 962 size_t used_ = 0;
944 size_t reserved_ = 0; 963 size_t reserved_ = 0;
945 int op_count_ = 0; 964 int op_count_ = 0;
946 965
947 // Record paths for veto-to-msaa for gpu raster. 966 // Record paths for veto-to-msaa for gpu raster.
948 int num_slow_paths_ = 0; 967 int num_slow_paths_ = 0;
949 // Record additional bytes used by referenced sub-records and display lists. 968 // Record additional bytes used by referenced sub-records and display lists.
950 size_t subrecord_bytes_used_ = 0; 969 size_t subrecord_bytes_used_ = 0;
970 bool has_discardable_images_ = false;
951 SkRect cull_rect_; 971 SkRect cull_rect_;
952 972
953 DISALLOW_COPY_AND_ASSIGN(PaintOpBuffer); 973 DISALLOW_COPY_AND_ASSIGN(PaintOpBuffer);
954 }; 974 };
955 975
956 } // namespace cc 976 } // namespace cc
957 977
958 #endif // CC_PAINT_PAINT_OP_BUFFER_H_ 978 #endif // CC_PAINT_PAINT_OP_BUFFER_H_
OLDNEW
« no previous file with comments | « cc/paint/display_item_list.cc ('k') | cc/paint/paint_op_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698