diff --git a/ink/strokes/in_progress_stroke.cc b/ink/strokes/in_progress_stroke.cc index d46ca2cd..8f872d9e 100644 --- a/ink/strokes/in_progress_stroke.cc +++ b/ink/strokes/in_progress_stroke.cc @@ -115,6 +115,14 @@ absl::Status InProgressStroke::EnqueueInputs( return absl::OkStatus(); } +bool InProgressStroke::HasQueuedInputs() const { + return !queued_real_inputs_.IsEmpty() || + !queued_predicted_inputs_.IsEmpty() || + // The only thing queued was empty, but a previous prediction was + // cleared as a result. + (queued_inputs_since_last_update_shape_ && PredictedInputCount() > 0); +} + absl::Status InProgressStroke::UpdateShape(Duration32 current_elapsed_time) { if (!brush_.has_value()) { return absl::FailedPreconditionError( @@ -126,11 +134,14 @@ absl::Status InProgressStroke::UpdateShape(Duration32 current_elapsed_time) { !status.ok()) { return status; } - if (inputs_are_finished_ || !queued_real_inputs_.IsEmpty() || - !queued_predicted_inputs_.IsEmpty() || - (queued_inputs_since_last_update_shape_ && PredictedInputCount() > 0)) { + current_elapsed_time_ = current_elapsed_time; + + if (HasQueuedInputs()) { // Erase any old predicted inputs. processed_inputs_.Erase(real_input_count_); + } else if (!ChangesWithTime()) { + // Exit early if no change is needed. + return absl::OkStatus(); } if (absl::Status status = processed_inputs_.Append(queued_real_inputs_); @@ -152,8 +163,6 @@ absl::Status InProgressStroke::UpdateShape(Duration32 current_elapsed_time) { return status; } - current_elapsed_time_ = current_elapsed_time; - input_modeler_.ExtendStroke(queued_real_inputs_, queued_predicted_inputs_, current_elapsed_time); uint32_t num_coats = BrushCoatCount(); @@ -172,12 +181,7 @@ absl::Status InProgressStroke::UpdateShape(Duration32 current_elapsed_time) { } bool InProgressStroke::NeedsUpdate() const { - if (!queued_real_inputs_.IsEmpty() || !queued_predicted_inputs_.IsEmpty() || - // There are processed predicted inputs to be cleared. - (queued_inputs_since_last_update_shape_ && PredictedInputCount() > 0)) { - return true; - } - return ChangesWithTime(); + return HasQueuedInputs() || ChangesWithTime(); } bool InProgressStroke::ChangesWithTime() const { diff --git a/ink/strokes/in_progress_stroke.h b/ink/strokes/in_progress_stroke.h index 32c3adbd..ee019e1e 100644 --- a/ink/strokes/in_progress_stroke.h +++ b/ink/strokes/in_progress_stroke.h @@ -271,6 +271,10 @@ class InProgressStroke { absl::Status ValidateNewElapsedTime(Duration32 current_elapsed_time) const; + // Whether `UpdateShape` might be needed due to a prior call to + // `EnqueueInputs`. + bool HasQueuedInputs() const; + std::optional brush_; // Real and predicted inputs that have been queued by calls to // `EnqueueInputs()` since the last call to `UpdateShape()`.