0

[PDF Ink Signatures] Minimize drawing overhead if no in-progress stroke

Since https://crrev.com/1380766 landed, PdfInkModule::Draw() only has
work to do if there is an in-progress stroke.  Rendering for all
previous strokes are handled as objects within the PDF document.

Introduce a new query so that callers can determine if there is
anything for PdfInkModule to draw.  This allows the caller to reduce
the overhead for drawing in the common case where there is currently
no active stroke being drawn.

Also update the PdfInkModule::Draw() API comment to reflect what it
currently draws, and also its requirements given that it can now expect
only to be called for an in-progress stroke.

Bug: 391666319
Change-Id: Ie6a89cfde9a3893e05ac10852f91550c64b9f093
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6191591
Reviewed-by: Lei Zhang <thestig@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Commit-Queue: Alan Screen <awscreen@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1410558}
This commit is contained in:
Alan Screen
2025-01-23 14:24:30 -08:00
committed by Chromium LUCI CQ
parent 126a7d1c29
commit aed5f66971
3 changed files with 16 additions and 6 deletions

@ -142,6 +142,15 @@ PdfInkModule::PdfInkModule(PdfInkModuleClient& client)
PdfInkModule::~PdfInkModule() = default;
bool PdfInkModule::HasInputsToDraw() const {
if (!enabled_ || !is_drawing_stroke()) {
return false;
}
const DrawingStrokeState& state = drawing_stroke_state();
return !state.inputs.empty();
}
void PdfInkModule::Draw(SkCanvas& canvas) {
ink::SkiaRenderer skia_renderer;
@ -150,9 +159,7 @@ void PdfInkModule::Draw(SkCanvas& canvas) {
const float zoom = client_->GetZoom();
auto in_progress_stroke = CreateInProgressStrokeSegmentsFromInputs();
if (in_progress_stroke.empty()) {
return;
}
CHECK(!in_progress_stroke.empty());
DrawingStrokeState& state = drawing_stroke_state();

@ -133,8 +133,11 @@ class PdfInkModule {
bool enabled() const { return enabled_; }
// Draws `strokes_` and `inputs_` into `canvas`. Here, `canvas` covers the
// visible content area, so this only draws strokes for visible pages.
// Determines if there are any `drawing_stroke_state().inputs` to be drawn.
bool HasInputsToDraw() const;
// Draws `drawing_stroke_state().inputs` into `canvas`. Must be in a drawing
// stroke state with non-empty `drawing_stroke_state().inputs`.
void Draw(SkCanvas& canvas);
// Draws `strokes_` for `page_index` into `canvas`. Here, `canvas` only covers

@ -595,7 +595,7 @@ void PdfViewWebPlugin::Paint(cc::PaintCanvas* canvas, const gfx::Rect& rect) {
canvas->drawImage(snapshot_, 0, 0);
#if BUILDFLAG(ENABLE_PDF_INK2)
if (ink_module_) {
if (ink_module_ && ink_module_->HasInputsToDraw()) {
SkBitmap sk_bitmap;
sk_bitmap.allocPixels(
SkImageInfo::MakeN32Premul(rect.width(), rect.height()));