0

[PDF Ink Signatures] Modify timing to drop Ink input snapshot

The change in https://crrev.com/1433897 to avoid flashing after stroke
completion can still sometimes have a flash.  Be more aggressive in the
retainment of the Ink input snapshot, and only drop it once a call to
PdfViewWebPlugin::Paint() confirms that it is not needed.

Bug: 380057101
Change-Id: Iacfe3cc29f16461fdadb7b33fccdbced9694d0b9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6367699
Commit-Queue: Alan Screen <awscreen@chromium.org>
Reviewed-by: Andy Phan <andyphan@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1434635}
This commit is contained in:
Alan Screen
2025-03-19 00:31:31 -07:00
committed by Chromium LUCI CQ
parent 12f4a46ba0
commit 252b68222a
3 changed files with 21 additions and 9 deletions

@ -356,6 +356,10 @@ class PdfViewWebPlugin::PdfInkModuleClientImpl : public PdfInkModuleClient {
InkStrokeId id,
const ink::Stroke& stroke) override {
plugin_->engine_->ApplyStroke(page_index, id, stroke);
// `snapshot_` is now stale, since its content doesn't contain this newly
// added stroke.
plugin_->snapshot_needs_update_for_ink_input_ = true;
}
void StrokeFinished() override {
@ -627,10 +631,15 @@ void PdfViewWebPlugin::Paint(cc::PaintCanvas* canvas, const gfx::Rect& rect) {
.TakePaintImage();
canvas->drawImage(snapshot_ink_inputs_.value(), 0, 0);
} else if (snapshot_ink_inputs_.has_value()) {
// Waiting on `snapshot_` to get refreshed to reflect the change for an
// added stroke, so reapply the last Ink inputs snapshot to avoid a flash
// of a recently added stroke temporarily disappearing.
canvas->drawImage(snapshot_ink_inputs_.value(), 0, 0);
if (snapshot_needs_update_for_ink_input_) {
// Still waiting on `snapshot_` to get refreshed to reflect the change
// for an added stroke, so reapply the last Ink inputs snapshot to avoid
// a flash of a recently added stroke temporarily disappearing.
canvas->drawImage(snapshot_ink_inputs_.value(), 0, 0);
} else {
// Now safe to discard the previous Ink inputs snapshot.
snapshot_ink_inputs_.reset();
}
}
#endif // BUILDFLAG(ENABLE_PDF_INK2)
}
@ -2276,9 +2285,8 @@ void PdfViewWebPlugin::UpdateSnapshot(sk_sp<SkImage> snapshot) {
#if BUILDFLAG(ENABLE_PDF_INK2)
// `paint_manager_` updates the snapshot after it has completed painting,
// which uses `engine_` in `DoPaint()`. Any newly added Ink stroke will now
// be applied in the snapshot, so there is no need to retain any prior
// `snapshot_ink_inputs_`.
snapshot_ink_inputs_.reset();
// be applied in the snapshot.
snapshot_needs_update_for_ink_input_ = false;
#endif
if (!plugin_rect_.IsEmpty())

@ -775,6 +775,10 @@ class PdfViewWebPlugin final : public PDFiumEngineClient,
#if BUILDFLAG(ENABLE_PDF_INK2)
// The last saved image snapshot for rendering of Ink inputs.
std::optional<cc::PaintImage> snapshot_ink_inputs_;
// Tracks if `snapshot_` still needs to be updated to reflect a newly
// added Ink stroke.
bool snapshot_needs_update_for_ink_input_ = false;
#endif
// Translate from snapshot to device pixels.

@ -3025,10 +3025,10 @@ TEST_F(PdfViewWebPluginInkTest, DrawInProgressStroke) {
// not include the last Ink stroke. This results in the most recent stroke
// disappearing, causing a flash for the user unless the snapshot from the
// most recent stroke is reused.
EXPECT_TRUE(plugin_->HasInkInputsSnapshotForTesting());
plugin_->Paint(canvas_.sk_canvas(), kScreenRect);
EXPECT_TRUE(MatchesPngFile(canvas_.GetBitmap().asImage().get(),
stroked_image_png_file));
EXPECT_TRUE(plugin_->HasInkInputsSnapshotForTesting());
// Simulate how the snapshot eventually gets updated, after all necessary
// tasks that normally happen from the PaintManager finally complete. That
@ -3038,10 +3038,10 @@ TEST_F(PdfViewWebPluginInkTest, DrawInProgressStroke) {
// engine.
plugin_->UpdateSnapshot(CreateSkiaImageForTesting(
plugin_->GetPluginRectForTesting().size(), SK_ColorWHITE));
EXPECT_FALSE(plugin_->HasInkInputsSnapshotForTesting());
plugin_->Paint(canvas_.sk_canvas(), kScreenRect);
EXPECT_TRUE(cc::MatchesBitmap(canvas_.GetBitmap(), blank_bitmap,
cc::ExactPixelComparator()));
EXPECT_FALSE(plugin_->HasInkInputsSnapshotForTesting());
}
class PdfViewWebPluginInk2SaveTest : public PdfViewWebPluginSaveTest {