aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/skottie/SkottieJson.h
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2018-05-04 15:10:54 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-05-04 19:58:13 +0000
commitfa7e9a813e44f283b14f686eeb857d0d00735811 (patch)
tree8524acb13c15e157b644379862292f0e2f910a40 /experimental/skottie/SkottieJson.h
parent0b0d93dbe432b6de4fd8df9a84e2ba3f2cc5b07e (diff)
[skottie] Switch to RapidJSON
- pull latest RapidJSON under third_party/externals/rapidjson (note: and older RS version is already pulled as part of angle2, and it is also checked in G3) - add a thin Json porting layer (SkottieJson) to isolate RS idiosyncrasies - convert Skottie to use the new helpers - parse the DOM in-place (based on local experiments this is the fastest method) Ta-da: Skottie now parses JSON ~10x faster! Change-Id: Ida9099638f88ed025fee83055c8cd8680ee27176 Reviewed-on: https://skia-review.googlesource.com/125744 Commit-Queue: Florin Malita <fmalita@chromium.org> Reviewed-by: Mike Reed <reed@google.com>
Diffstat (limited to 'experimental/skottie/SkottieJson.h')
-rw-r--r--experimental/skottie/SkottieJson.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/experimental/skottie/SkottieJson.h b/experimental/skottie/SkottieJson.h
new file mode 100644
index 0000000000..76e17c610e
--- /dev/null
+++ b/experimental/skottie/SkottieJson.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright 2018 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkottieJson_DEFINED
+#define SkottieJson_DEFINED
+
+#include "SkRefCnt.h"
+
+#include "rapidjson/document.h"
+
+class SkData;
+class SkStream;
+class SkString;
+
+namespace skottie {
+
+namespace json {
+
+class ValueRef {
+public:
+ ValueRef() : fValue(nullptr) {}
+ ValueRef(const rapidjson::Value& v) : fValue(v.IsNull() ? nullptr : &v) {}
+
+ bool isNull() const { return !fValue; }
+ bool isObject() const { return fValue && fValue->IsObject(); }
+ bool isArray() const { return fValue && fValue->IsArray(); }
+
+ template <typename T>
+ bool to(T*) const;
+
+ template <typename T>
+ T toDefault(const T& defaultValue) const {
+ T v;
+ if (!this->to<T>(&v)) {
+ v = defaultValue;
+ }
+ return v;
+ }
+
+ size_t size() const;
+ ValueRef operator[](size_t i) const;
+ ValueRef operator[](const char* key) const;
+
+ bool operator==(const ValueRef& other) const { return fValue == other.fValue; }
+ bool operator!=(const ValueRef& other) const { return !(*this == other); }
+
+ const rapidjson::Value* begin() const;
+ const rapidjson::Value* end() const;
+
+ SkString toString() const;
+
+private:
+ const rapidjson::Value* fValue;
+};
+
+// Container for the json DOM
+class Document {
+public:
+ explicit Document(SkStream*);
+
+ ValueRef root() const { return fDocument; }
+
+private:
+ sk_sp<SkData> fData; // raw data
+ rapidjson::Document fDocument; // in-place json DOM
+};
+
+} // namespace json
+
+} // namespace skottie
+
+#endif // SkottieJson_DEFINED