Commit 02333c5b authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

[PE] cc::DisplayItemList::TotalOpCount()

I found the reason that SPv175 has 10% less paint_op_count but about
1% more paint_op_memory_usage: we didn't count ops in sub-records.

Add cc::DisplayItemList::TotalOpCount() to count all ops.

Bug: 803867
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I0526ace84cc16775d5691e87b502544e64f5932e
Reviewed-on: https://chromium-review.googlesource.com/996316Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548653}
parent 35c85cc3
......@@ -170,10 +170,10 @@ void RasterizeAndRecordBenchmark::RunOnLayer(PictureLayer* layer) {
if (paint_op_memory_usage) {
// Verify we are recording the same thing each time.
DCHECK_EQ(paint_op_memory_usage, display_list->BytesUsed());
DCHECK_EQ(paint_op_count, display_list->op_count());
DCHECK_EQ(paint_op_count, display_list->TotalOpCount());
} else {
paint_op_memory_usage = display_list->BytesUsed();
paint_op_count = display_list->op_count();
paint_op_count = display_list->TotalOpCount();
}
timer.NextLap();
......
......@@ -141,11 +141,11 @@ void RecordingSource::DetermineIfSolidColor() {
is_solid_color_ = false;
solid_color_ = SK_ColorTRANSPARENT;
if (display_list_->op_count() > kMaxOpsToAnalyzeForLayer)
if (display_list_->TotalOpCount() > kMaxOpsToAnalyzeForLayer)
return;
TRACE_EVENT1("cc", "RecordingSource::DetermineIfSolidColor", "opcount",
display_list_->op_count());
display_list_->TotalOpCount());
is_solid_color_ = display_list_->GetColorIfSolidInRect(
gfx::ScaleToRoundedRect(gfx::Rect(GetSize()), recording_scale_factor_),
&solid_color_, kMaxOpsToAnalyzeForLayer);
......
......@@ -162,7 +162,7 @@ class CC_PAINT_EXPORT DisplayItemList
bool HasNonAAPaint() const { return paint_op_buffer_.HasNonAAPaint(); }
// This gives the total number of PaintOps.
size_t op_count() const { return paint_op_buffer_.size(); }
size_t TotalOpCount() const { return paint_op_buffer_.total_op_count(); }
size_t BytesUsed() const;
const DiscardableImageMap& discardable_image_map() const {
......
......@@ -128,7 +128,7 @@ TEST(DisplayItemListTest, EmptyUnpairedRangeDoesNotAddVisualRect) {
list->EndPaintOfUnpaired(layer_rect);
}
// No ops.
EXPECT_EQ(0u, list->op_count());
EXPECT_EQ(0u, list->TotalOpCount());
{
list->StartPaint();
......@@ -137,7 +137,7 @@ TEST(DisplayItemListTest, EmptyUnpairedRangeDoesNotAddVisualRect) {
list->EndPaintOfUnpaired(layer_rect);
}
// Two ops.
EXPECT_EQ(2u, list->op_count());
EXPECT_EQ(2u, list->TotalOpCount());
}
TEST(DisplayItemListTest, ClipPairedRange) {
......@@ -552,7 +552,7 @@ TEST(DisplayItemListTest, AsValueWithOps) {
TEST(DisplayItemListTest, SizeEmpty) {
auto list = base::MakeRefCounted<DisplayItemList>();
EXPECT_EQ(0u, list->op_count());
EXPECT_EQ(0u, list->TotalOpCount());
}
TEST(DisplayItemListTest, SizeOne) {
......@@ -563,7 +563,7 @@ TEST(DisplayItemListTest, SizeOne) {
list->push<DrawRectOp>(gfx::RectToSkRect(drawing_bounds), PaintFlags());
list->EndPaintOfUnpaired(drawing_bounds);
}
EXPECT_EQ(1u, list->op_count());
EXPECT_EQ(1u, list->TotalOpCount());
}
TEST(DisplayItemListTest, SizeMultiple) {
......@@ -581,7 +581,7 @@ TEST(DisplayItemListTest, SizeMultiple) {
list->push<RestoreOp>();
list->EndPaintOfPairedEnd();
}
EXPECT_EQ(3u, list->op_count());
EXPECT_EQ(3u, list->TotalOpCount());
}
TEST(DisplayItemListTest, AppendVisualRectSimple) {
......@@ -596,7 +596,7 @@ TEST(DisplayItemListTest, AppendVisualRectSimple) {
list->EndPaintOfUnpaired(drawing_bounds);
}
EXPECT_EQ(1u, list->op_count());
EXPECT_EQ(1u, list->TotalOpCount());
EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(0));
}
......@@ -619,7 +619,7 @@ TEST(DisplayItemListTest, AppendVisualRectEmptyBlock) {
list->EndPaintOfPairedEnd();
}
EXPECT_EQ(3u, list->op_count());
EXPECT_EQ(3u, list->TotalOpCount());
EXPECT_RECT_EQ(gfx::Rect(), list->VisualRectForTesting(0));
EXPECT_RECT_EQ(gfx::Rect(), list->VisualRectForTesting(1));
EXPECT_RECT_EQ(gfx::Rect(), list->VisualRectForTesting(2));
......@@ -656,7 +656,7 @@ TEST(DisplayItemListTest, AppendVisualRectEmptyBlockContainingEmptyBlock) {
list->EndPaintOfPairedEnd();
}
EXPECT_EQ(5u, list->op_count());
EXPECT_EQ(5u, list->TotalOpCount());
EXPECT_RECT_EQ(gfx::Rect(), list->VisualRectForTesting(0));
EXPECT_RECT_EQ(gfx::Rect(), list->VisualRectForTesting(1));
EXPECT_RECT_EQ(gfx::Rect(), list->VisualRectForTesting(2));
......@@ -691,7 +691,7 @@ TEST(DisplayItemListTest, AppendVisualRectBlockContainingDrawing) {
list->EndPaintOfPairedEnd();
}
EXPECT_EQ(4u, list->op_count());
EXPECT_EQ(4u, list->TotalOpCount());
EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(0));
EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(1));
EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(2));
......@@ -725,7 +725,7 @@ TEST(DisplayItemListTest, AppendVisualRectBlockContainingEscapedDrawing) {
list->EndPaintOfPairedEnd();
}
EXPECT_EQ(4u, list->op_count());
EXPECT_EQ(4u, list->TotalOpCount());
EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(0));
EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(1));
EXPECT_RECT_EQ(drawing_bounds, list->VisualRectForTesting(2));
......@@ -768,7 +768,7 @@ TEST(DisplayItemListTest,
list->EndPaintOfPairedEnd();
}
EXPECT_EQ(5u, list->op_count());
EXPECT_EQ(5u, list->TotalOpCount());
EXPECT_RECT_EQ(drawing_a_bounds, list->VisualRectForTesting(0));
EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(1));
EXPECT_RECT_EQ(drawing_b_bounds, list->VisualRectForTesting(2));
......@@ -824,7 +824,7 @@ TEST(DisplayItemListTest, AppendVisualRectTwoBlocksTwoDrawings) {
list->EndPaintOfPairedEnd();
}
EXPECT_EQ(8u, list->op_count());
EXPECT_EQ(8u, list->TotalOpCount());
gfx::Rect merged_drawing_bounds = gfx::Rect(drawing_a_bounds);
merged_drawing_bounds.Union(drawing_b_bounds);
EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(0));
......@@ -887,7 +887,7 @@ TEST(DisplayItemListTest,
list->EndPaintOfPairedEnd();
}
EXPECT_EQ(8u, list->op_count());
EXPECT_EQ(8u, list->TotalOpCount());
gfx::Rect merged_drawing_bounds = gfx::Rect(drawing_a_bounds);
merged_drawing_bounds.Union(drawing_b_bounds);
EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(0));
......@@ -950,7 +950,7 @@ TEST(DisplayItemListTest,
list->EndPaintOfPairedEnd();
}
EXPECT_EQ(8u, list->op_count());
EXPECT_EQ(8u, list->TotalOpCount());
gfx::Rect merged_drawing_bounds = gfx::Rect(drawing_a_bounds);
merged_drawing_bounds.Union(drawing_b_bounds);
EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(0));
......@@ -1013,7 +1013,7 @@ TEST(DisplayItemListTest,
list->EndPaintOfPairedEnd();
}
EXPECT_EQ(8u, list->op_count());
EXPECT_EQ(8u, list->TotalOpCount());
gfx::Rect merged_drawing_bounds = gfx::Rect(drawing_a_bounds);
merged_drawing_bounds.Union(drawing_b_bounds);
EXPECT_RECT_EQ(merged_drawing_bounds, list->VisualRectForTesting(0));
......@@ -1051,10 +1051,31 @@ TEST(DisplayItemListTest, VisualRectForPairsEnclosingEmptyPainting) {
list->EndPaintOfPairedEnd();
}
EXPECT_EQ(3u, list->op_count());
EXPECT_EQ(3u, list->TotalOpCount());
EXPECT_RECT_EQ(visual_rect, list->VisualRectForTesting(0));
EXPECT_RECT_EQ(visual_rect, list->VisualRectForTesting(1));
EXPECT_RECT_EQ(visual_rect, list->VisualRectForTesting(2));
}
TEST(DisplayItemListTest, TotalOpCount) {
auto list = base::MakeRefCounted<DisplayItemList>();
auto sub_list = base::MakeRefCounted<DisplayItemList>();
sub_list->StartPaint();
sub_list->push<SaveOp>();
sub_list->push<TranslateOp>(10.f, 20.f);
sub_list->push<DrawRectOp>(SkRect::MakeWH(10, 20), PaintFlags());
sub_list->push<RestoreOp>();
sub_list->EndPaintOfUnpaired(gfx::Rect());
EXPECT_EQ(4u, sub_list->TotalOpCount());
list->StartPaint();
list->push<SaveOp>();
list->push<TranslateOp>(10.f, 20.f);
list->push<DrawRecordOp>(sub_list->ReleaseAsRecord());
list->push<RestoreOp>();
list->EndPaintOfUnpaired(gfx::Rect());
EXPECT_EQ(8u, list->TotalOpCount());
}
} // namespace cc
......@@ -2055,6 +2055,10 @@ size_t DrawRecordOp::AdditionalBytesUsed() const {
return record->bytes_used();
}
size_t DrawRecordOp::AdditionalOpCount() const {
return record->total_op_count();
}
bool DrawRecordOp::HasDiscardableImages() const {
return record->HasDiscardableImages();
}
......@@ -2102,6 +2106,7 @@ void PaintOpBuffer::operator=(PaintOpBuffer&& other) {
op_count_ = other.op_count_;
num_slow_paths_ = other.num_slow_paths_;
subrecord_bytes_used_ = other.subrecord_bytes_used_;
subrecord_op_count_ = other.subrecord_op_count_;
has_non_aa_paint_ = other.has_non_aa_paint_;
has_discardable_images_ = other.has_discardable_images_;
......@@ -2122,6 +2127,7 @@ void PaintOpBuffer::Reset() {
num_slow_paths_ = 0;
has_non_aa_paint_ = false;
subrecord_bytes_used_ = 0;
subrecord_op_count_ = 0;
has_discardable_images_ = false;
}
......@@ -2379,6 +2385,8 @@ bool PaintOpBuffer::operator==(const PaintOpBuffer& other) const {
return false;
if (subrecord_bytes_used_ != other.subrecord_bytes_used_)
return false;
if (subrecord_op_count_ != other.subrecord_op_count_)
return false;
if (has_non_aa_paint_ != other.has_non_aa_paint_)
return false;
if (has_discardable_images_ != other.has_discardable_images_)
......
......@@ -210,6 +210,9 @@ class CC_PAINT_EXPORT PaintOp {
// and display lists. This doesn't count other objects like paths or blobs.
size_t AdditionalBytesUsed() const { return 0; }
// Returns the number of ops in referenced sub records and display lists.
size_t AdditionalOpCount() const { return 0; }
// Run the destructor for the derived op type. Ops are usually contained in
// memory buffers and so don't have their destructors run automatically.
void DestroyThis();
......@@ -601,6 +604,7 @@ class CC_PAINT_EXPORT DrawRecordOp final : public PaintOp {
bool IsValid() const { return true; }
static bool AreEqual(const PaintOp* left, const PaintOp* right);
size_t AdditionalBytesUsed() const;
size_t AdditionalOpCount() const;
bool HasDiscardableImages() const;
int CountSlowPaths() const;
bool HasNonAAPaint() const;
......@@ -863,6 +867,9 @@ class CC_PAINT_EXPORT PaintOpBuffer : public SkRefCnt {
size_t bytes_used() const {
return sizeof(*this) + reserved_ + subrecord_bytes_used_;
}
// Returns the total number of ops including sub-records.
size_t total_op_count() const { return op_count_ + subrecord_op_count_; }
size_t next_op_offset() const { return used_; }
int numSlowPaths() const { return num_slow_paths_; }
bool HasNonAAPaint() const { return has_non_aa_paint_; }
......@@ -927,6 +934,7 @@ class CC_PAINT_EXPORT PaintOpBuffer : public SkRefCnt {
has_discardable_images_ |= op->HasDiscardableImagesFromFlags();
subrecord_bytes_used_ += op->AdditionalBytesUsed();
subrecord_op_count_ += op->AdditionalOpCount();
}
template <typename T>
......@@ -1140,6 +1148,8 @@ class CC_PAINT_EXPORT PaintOpBuffer : public SkRefCnt {
int num_slow_paths_ = 0;
// Record additional bytes used by referenced sub-records and display lists.
size_t subrecord_bytes_used_ = 0;
// Record total op count of referenced sub-record and display lists.
size_t subrecord_op_count_ = 0;
bool has_non_aa_paint_ : 1;
bool has_discardable_images_ : 1;
......
......@@ -3124,4 +3124,20 @@ TEST(PaintOpBufferTest, RecordShadersSerializeScaledImages) {
EXPECT_EQ(scale.height(), 0.8f);
}
TEST(PaintOpBufferTest, TotalOpCount) {
auto record_buffer = sk_make_sp<PaintOpBuffer>();
auto sub_record_buffer = sk_make_sp<PaintOpBuffer>();
auto sub_sub_record_buffer = sk_make_sp<PaintOpBuffer>();
PushDrawRectOps(sub_sub_record_buffer.get());
PushDrawRectOps(sub_record_buffer.get());
PushDrawRectOps(record_buffer.get());
sub_record_buffer->push<DrawRecordOp>(sub_sub_record_buffer);
record_buffer->push<DrawRecordOp>(sub_record_buffer);
size_t len = std::min(test_rects.size(), test_flags.size());
EXPECT_EQ(len, sub_sub_record_buffer->total_op_count());
EXPECT_EQ(2 * len + 1, sub_record_buffer->total_op_count());
EXPECT_EQ(3 * len + 2, record_buffer->total_op_count());
}
} // namespace cc
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment