Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions ink/strokes/in_progress_stroke.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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_);
Expand All @@ -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();
Expand All @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions ink/strokes/in_progress_stroke.h
Original file line number Diff line number Diff line change
Expand Up @@ -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> brush_;
// Real and predicted inputs that have been queued by calls to
// `EnqueueInputs()` since the last call to `UpdateShape()`.
Expand Down
Loading