Commit b977f3de authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

Use visual rects in DisplayItemList::AreaOfDrawText()

Bug: 1126582
Change-Id: Ie1c29eda2f7c05a96eef708041b15eed9de4d098
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2404398
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarTao Bai <michaelbai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#806064}
parent ce389c1d
...@@ -119,22 +119,26 @@ void DisplayItemList::CaptureContent(const gfx::Rect& rect, ...@@ -119,22 +119,26 @@ void DisplayItemList::CaptureContent(const gfx::Rect& rect,
} }
double DisplayItemList::AreaOfDrawText(const gfx::Rect& rect) const { double DisplayItemList::AreaOfDrawText(const gfx::Rect& rect) const {
double area = 0;
if (!paint_op_buffer_.has_draw_text_ops()) if (!paint_op_buffer_.has_draw_text_ops())
return area; return 0;
std::vector<size_t> offsets; std::vector<size_t> offsets;
std::vector<gfx::Rect> rects; std::vector<gfx::Rect> rects;
rtree_.Search(rect, &offsets, &rects); rtree_.Search(rect, &offsets, &rects);
IterateTextContentByOffsets( DCHECK_EQ(offsets.size(), rects.size());
paint_op_buffer_, offsets, rects,
[&area](const DrawTextBlobOp* op, const gfx::Rect& rect) { double area = 0;
// TODO(wangxianzhu) : crbug.com/1126582 use the visual_rect from size_t index = 0;
// callback. for (auto* op : PaintOpBuffer::OffsetIterator(&paint_op_buffer_, &offsets)) {
// This is not fully accurate, e.g. when there is transform operations, if (op->GetType() == PaintOpType::DrawTextBlob ||
// but is good for statistics purpose. // Don't walk into the record because the visual rect is already the
SkRect bounds = op->blob->bounds(); // bounding box of the sub paint operations. This works for most paint
area += static_cast<double>(bounds.width()) * bounds.height(); // results for text generated by blink.
}); (op->GetType() == PaintOpType::DrawRecord &&
static_cast<DrawRecordOp*>(op)->record->has_draw_text_ops())) {
area += static_cast<double>(rects[index].width()) * rects[index].height();
}
++index;
}
return area; return area;
} }
......
...@@ -1138,14 +1138,15 @@ TEST_F(DisplayItemListTest, AreaOfDrawText) { ...@@ -1138,14 +1138,15 @@ TEST_F(DisplayItemListTest, AreaOfDrawText) {
auto sub_list = base::MakeRefCounted<DisplayItemList>(); auto sub_list = base::MakeRefCounted<DisplayItemList>();
auto text_blob1 = SkTextBlob::MakeFromString("ABCD", SkFont()); auto text_blob1 = SkTextBlob::MakeFromString("ABCD", SkFont());
auto text_blob1_bounds = text_blob1->bounds(); gfx::Size text_blob1_size(ceilf(text_blob1->bounds().width()),
auto text_blob1_area = text_blob1_bounds.width() * text_blob1_bounds.height(); ceilf(text_blob1->bounds().height()));
auto text_blob1_area = text_blob1_size.width() * text_blob1_size.height();
auto text_blob2 = SkTextBlob::MakeFromString("EFG", SkFont()); auto text_blob2 = SkTextBlob::MakeFromString("EFG", SkFont());
auto text_blob2_bounds = text_blob2->bounds(); gfx::Size text_blob2_size(ceilf(text_blob2->bounds().width()),
auto text_blob2_area = text_blob2_bounds.width() * text_blob2_bounds.height(); ceilf(text_blob2->bounds().height()));
auto text_blob2_area = text_blob2_size.width() * text_blob2_size.height();
sub_list->StartPaint(); sub_list->StartPaint();
sub_list->push<DrawRectOp>(SkRect::MakeWH(100, 200), PaintFlags());
sub_list->push<DrawTextBlobOp>(text_blob1, 0, 0, PaintFlags()); sub_list->push<DrawTextBlobOp>(text_blob1, 0, 0, PaintFlags());
sub_list->EndPaintOfUnpaired(gfx::Rect()); sub_list->EndPaintOfUnpaired(gfx::Rect());
auto record = sub_list->ReleaseAsRecord(); auto record = sub_list->ReleaseAsRecord();
...@@ -1155,22 +1156,24 @@ TEST_F(DisplayItemListTest, AreaOfDrawText) { ...@@ -1155,22 +1156,24 @@ TEST_F(DisplayItemListTest, AreaOfDrawText) {
list->push<TranslateOp>(100, 100); list->push<TranslateOp>(100, 100);
list->push<DrawRecordOp>(record); list->push<DrawRecordOp>(record);
list->push<RestoreOp>(); list->push<RestoreOp>();
list->EndPaintOfUnpaired(gfx::Rect(100, 100, 100, 200)); list->EndPaintOfUnpaired(gfx::Rect(gfx::Point(100, 100), text_blob1_size));
list->StartPaint(); list->StartPaint();
list->push<SaveOp>(); list->push<SaveOp>();
list->push<TranslateOp>(100, 400); list->push<TranslateOp>(100, 400);
list->push<DrawRecordOp>(record); list->push<DrawRecordOp>(record);
list->push<RestoreOp>(); list->push<RestoreOp>();
list->EndPaintOfUnpaired(gfx::Rect(100, 400, 100, 200)); list->EndPaintOfUnpaired(gfx::Rect(gfx::Point(100, 400), text_blob1_size));
list->StartPaint(); list->StartPaint();
list->push<DrawRectOp>(SkRect::MakeWH(100, 100), PaintFlags());
list->push<DrawTextBlobOp>(text_blob2, 10, 20, PaintFlags()); list->push<DrawTextBlobOp>(text_blob2, 10, 20, PaintFlags());
list->EndPaintOfUnpaired(gfx::Rect(0, 0, 100, 100)); list->EndPaintOfUnpaired(gfx::Rect(text_blob2_size));
list->StartPaint(); list->StartPaint();
list->push<DrawTextBlobOp>(text_blob2, 400, 100, PaintFlags()); list->push<DrawTextBlobOp>(text_blob2, 400, 100, PaintFlags());
list->EndPaintOfUnpaired(gfx::Rect(gfx::Point(400, 100), text_blob2_size));
list->StartPaint();
list->push<DrawRectOp>(SkRect::MakeXYWH(400, 100, 100, 100), PaintFlags()); list->push<DrawRectOp>(SkRect::MakeXYWH(400, 100, 100, 100), PaintFlags());
list->EndPaintOfUnpaired(gfx::Rect(400, 100, 100, 100)); list->EndPaintOfUnpaired(gfx::Rect(400, 100, 100, 100));
...@@ -1178,10 +1181,10 @@ TEST_F(DisplayItemListTest, AreaOfDrawText) { ...@@ -1178,10 +1181,10 @@ TEST_F(DisplayItemListTest, AreaOfDrawText) {
// This includes the DrawTextBlobOp in the first DrawRecordOp the the first // This includes the DrawTextBlobOp in the first DrawRecordOp the the first
// direct DrawTextBlobOp. // direct DrawTextBlobOp.
EXPECT_EQ(static_cast<int>(text_blob1_area + text_blob2_area), EXPECT_EQ(static_cast<int>(text_blob1_area + text_blob2_area),
static_cast<int>(list->AreaOfDrawText(gfx::Rect(0, 0, 200, 200)))); static_cast<int>(list->AreaOfDrawText(gfx::Rect(200, 200))));
// This includes all DrawTextBlobOps. // This includes all DrawTextBlobOps.
EXPECT_EQ(static_cast<int>(text_blob1_area * 2 + text_blob2_area * 2), EXPECT_EQ(static_cast<int>(text_blob1_area * 2 + text_blob2_area * 2),
static_cast<int>(list->AreaOfDrawText(gfx::Rect(0, 0, 500, 500)))); static_cast<int>(list->AreaOfDrawText(gfx::Rect(500, 500))));
} }
} // namespace cc } // 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