Commit 17ae1743 authored by ckitagawa's avatar ckitagawa Committed by Commit Bot

[Paint Preview] Account for scroll offset in subframes

Scroll position isn't accounted for in the clip rect for subframes. It
needs to be manually corrected via the tracker when serializing.

Bug: 1090920
Change-Id: I93e316016832132cbfdfec833249ed454c060b9c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2228577Reviewed-by: default avatarMehran Mahmoudi <mahmoudi@chromium.org>
Commit-Queue: Calder Kitagawa <ckitagawa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#775098}
parent 2f382570
......@@ -51,7 +51,8 @@ uint32_t PaintPreviewTracker::CreateContentForRemoteFrame(
const gfx::Rect& rect,
const base::UnguessableToken& embedding_token) {
sk_sp<SkPicture> pic = SkPicture::MakePlaceholder(
SkRect::MakeXYWH(rect.x(), rect.y(), rect.width(), rect.height()));
SkRect::MakeXYWH(rect.x() + scroll_.width(), rect.y() + scroll_.height(),
rect.width(), rect.height()));
const uint32_t content_id = pic->uniqueID();
DCHECK(!base::Contains(content_id_to_embedding_token_, content_id));
content_id_to_embedding_token_[content_id] = embedding_token;
......@@ -59,6 +60,10 @@ uint32_t PaintPreviewTracker::CreateContentForRemoteFrame(
return content_id;
}
void PaintPreviewTracker::SetScrollForFrame(const SkISize& scroll) {
scroll_ = scroll;
}
void PaintPreviewTracker::AddGlyphs(const SkTextBlob* blob) {
if (!blob)
return;
......
......@@ -50,6 +50,9 @@ class PaintPreviewTracker {
const gfx::Rect& rect,
const base::UnguessableToken& embedding_token);
// Sets the scroll position for the top layer frame.
void SetScrollForFrame(const SkISize& scroll);
// Adds the glyphs in |blob| to the glyph usage tracker for the |blob|'s
// associated typface.
void AddGlyphs(const SkTextBlob* blob);
......@@ -83,6 +86,8 @@ class PaintPreviewTracker {
const base::Optional<base::UnguessableToken> embedding_token_;
const bool is_main_frame_;
SkISize scroll_;
std::vector<mojom::LinkDataPtr> links_;
PictureSerializationContext content_id_to_embedding_token_;
TypefaceUsageMap typeface_glyph_usage_;
......
......@@ -61,6 +61,33 @@ TEST(PaintPreviewTrackerTest, TestRemoteFramePlaceholderPicture) {
// underlying private picture record.
}
TEST(PaintPreviewTrackerTest, TestRemoteFramePlaceholderPictureWithScroll) {
const base::UnguessableToken kDocToken = base::UnguessableToken::Create();
const base::UnguessableToken kEmbeddingToken =
base::UnguessableToken::Create();
PaintPreviewTracker tracker(kDocToken, kEmbeddingToken, true);
tracker.SetScrollForFrame(SkISize::Make(10, 20));
const base::UnguessableToken kEmbeddingTokenChild =
base::UnguessableToken::Create();
gfx::Rect rect(50, 40, 30, 20);
uint32_t content_id =
tracker.CreateContentForRemoteFrame(rect, kEmbeddingTokenChild);
PictureSerializationContext* context =
tracker.GetPictureSerializationContext();
EXPECT_TRUE(context->count(content_id));
EXPECT_EQ((*context)[content_id], kEmbeddingTokenChild);
SkPictureRecorder recorder;
SkCanvas* canvas = recorder.beginRecording(100, 100);
tracker.CustomDataToSkPictureCallback(canvas, content_id);
sk_sp<SkPicture> pic = recorder.finishRecordingAsPicture();
// TODO(crbug/1009552): find a good way to check that a filler picture was
// actually inserted into |pic|. This is difficult without using the
// underlying private picture record.
}
TEST(PaintPreviewTrackerTest, TestGlyphRunList) {
const base::UnguessableToken kEmbeddingToken =
base::UnguessableToken::Create();
......
......@@ -155,9 +155,12 @@ void PaintPreviewRecorderImpl::CapturePaintPreviewInternal(
bounds = gfx::Rect(params->clip_rect.size());
}
cc::PaintRecorder recorder;
auto tracker = std::make_unique<PaintPreviewTracker>(
params->guid, frame->GetEmbeddingToken(), is_main_frame_);
auto size = frame->GetScrollOffset();
tracker->SetScrollForFrame(SkISize::Make(size.width, size.height));
cc::PaintRecorder recorder;
cc::PaintCanvas* canvas =
recorder.beginRecording(bounds.width(), bounds.height());
canvas->SetPaintPreviewTracker(tracker.get());
......
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