Add canvas clear service boundary

This commit is contained in:
2026-06-03 13:13:43 +02:00
parent 7c76703355
commit a6306c2759
7 changed files with 145 additions and 11 deletions

View File

@@ -17,6 +17,13 @@ struct DocumentCanvasClearPlan {
bool no_op = true;
};
class DocumentCanvasClearServices {
public:
virtual ~DocumentCanvasClearServices() = default;
virtual void clear_current_canvas(float r, float g, float b, float a) = 0;
};
[[nodiscard]] inline pp::foundation::Status validate_clear_color_channel(float value) noexcept
{
if (!std::isfinite(value)) {
@@ -55,4 +62,24 @@ struct DocumentCanvasClearPlan {
return pp::foundation::Result<DocumentCanvasClearPlan>::success(plan);
}
[[nodiscard]] inline pp::foundation::Status execute_document_canvas_clear_plan(
const DocumentCanvasClearPlan& plan,
DocumentCanvasClearServices& services)
{
const float channels[] { plan.r, plan.g, plan.b, plan.a };
for (const float channel : channels) {
const auto status = validate_clear_color_channel(channel);
if (!status.ok()) {
return status;
}
}
if (plan.no_op || !plan.clears_canvas) {
return pp::foundation::Status::success();
}
services.clear_current_canvas(plan.r, plan.g, plan.b, plan.a);
return pp::foundation::Status::success();
}
} // namespace pp::app