Add variation of GetConstantValueForVariable which handles ownership.

The new function `MakeConstantValueForVariable` behaves the same, except
it takes unique_ptrs as inputs and returns a unique_ptr as output.
We already had this behavior coded up in two places and I realized I
could use this functionality in other spots as well.

Change-Id: I2f0c43e8555a3c89bf9a1eef7030b422355ec2a3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/405680
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
diff --git a/src/sksl/SkSLConstantFolder.cpp b/src/sksl/SkSLConstantFolder.cpp
index 6573d3f..83d4ebb 100644
--- a/src/sksl/SkSLConstantFolder.cpp
+++ b/src/sksl/SkSLConstantFolder.cpp
@@ -233,6 +233,15 @@
     return &inExpr;
 }
 
+std::unique_ptr<Expression> ConstantFolder::MakeConstantValueForVariable(
+        std::unique_ptr<Expression> expr) {
+    const Expression* constantExpr = GetConstantValueForVariable(*expr);
+    if (constantExpr != expr.get()) {
+        expr = constantExpr->clone();
+    }
+    return expr;
+}
+
 static std::unique_ptr<Expression> simplify_no_op_arithmetic(const Context& context,
                                                              const Expression& left,
                                                              Operator op,