aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/skottie/SkottieValue.cpp
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2018-03-23 13:41:58 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-03-23 18:09:50 +0000
commita6e30f75fcd70636b835c8fb24005b84a1dd0d25 (patch)
treecc85258441e5d11f39591679c790f35f7ad30349 /experimental/skottie/SkottieValue.cpp
parent99501b741c1164fa12581cd06f0e7ab3fbce8792 (diff)
[skottie] Clean up SkottieProperties
Split into Adapter and Value CUs. No real changes, just shuffling things around. TBR= Change-Id: I50eaeb3950f4c59e7d7027955b3f49ca2a346e59 Reviewed-on: https://skia-review.googlesource.com/116186 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'experimental/skottie/SkottieValue.cpp')
-rw-r--r--experimental/skottie/SkottieValue.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/experimental/skottie/SkottieValue.cpp b/experimental/skottie/SkottieValue.cpp
new file mode 100644
index 0000000000..386c8ab623
--- /dev/null
+++ b/experimental/skottie/SkottieValue.cpp
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkottieValue.h"
+
+#include "SkColor.h"
+#include "SkPoint.h"
+#include "SkSize.h"
+
+namespace skottie {
+
+template <>
+size_t ValueTraits<ScalarValue>::Cardinality(const ScalarValue&) {
+ return 1;
+}
+
+template <>
+template <>
+SkScalar ValueTraits<ScalarValue>::As<SkScalar>(const ScalarValue& v) {
+ return v;
+}
+
+template <>
+size_t ValueTraits<VectorValue>::Cardinality(const VectorValue& vec) {
+ return vec.size();
+}
+
+template <>
+template <>
+SkColor ValueTraits<VectorValue>::As<SkColor>(const VectorValue& v) {
+ // best effort to turn this into a color
+ const auto r = v.size() > 0 ? v[0] : 0,
+ g = v.size() > 1 ? v[1] : 0,
+ b = v.size() > 2 ? v[2] : 0,
+ a = v.size() > 3 ? v[3] : 1;
+
+ return SkColorSetARGB(SkTPin<SkScalar>(a, 0, 1) * 255,
+ SkTPin<SkScalar>(r, 0, 1) * 255,
+ SkTPin<SkScalar>(g, 0, 1) * 255,
+ SkTPin<SkScalar>(b, 0, 1) * 255);
+}
+
+template <>
+template <>
+SkPoint ValueTraits<VectorValue>::As<SkPoint>(const VectorValue& vec) {
+ // best effort to turn this into a point
+ const auto x = vec.size() > 0 ? vec[0] : 0,
+ y = vec.size() > 1 ? vec[1] : 0;
+ return SkPoint::Make(x, y);
+}
+
+template <>
+template <>
+SkSize ValueTraits<VectorValue>::As<SkSize>(const VectorValue& vec) {
+ const auto pt = ValueTraits::As<SkPoint>(vec);
+ return SkSize::Make(pt.x(), pt.y());
+}
+
+template <>
+size_t ValueTraits<ShapeValue>::Cardinality(const ShapeValue& path) {
+ return SkTo<size_t>(path.countVerbs());
+}
+
+template <>
+template <>
+SkPath ValueTraits<ShapeValue>::As<SkPath>(const ShapeValue& path) {
+ return path;
+}
+
+} // namespace skottie