aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/sksl/SkSLUtil.cpp
diff options
context:
space:
mode:
authorGravatar Ethan Nicholas <ethannicholas@google.com>2017-03-30 18:42:48 +0000
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-30 18:42:59 +0000
commitbcf35f86d50b784b165de703b404998dd4299f6a (patch)
tree9fcd85326b1a5dbda864da9431a878bb62f65191 /src/sksl/SkSLUtil.cpp
parent7833466da45bfa1e078427c4a6db94d41c5c1535 (diff)
Revert "skslc can now be compiled with no Skia dependencies, in preparation for"
This reverts commit 7833466da45bfa1e078427c4a6db94d41c5c1535. Reason for revert: Vulkan assertion failure Original change's description: > skslc can now be compiled with no Skia dependencies, in preparation for > its eventual role in Skia's build process. > > Bug: skia: > Change-Id: Iaa9933f4fc4a64bec60aa897c509a3513f457a78 > Reviewed-on: https://skia-review.googlesource.com/10282 > Commit-Queue: Ethan Nicholas <ethannicholas@google.com> > Reviewed-by: Ben Wagner <benjaminwagner@google.com> > TBR=egdaniel@google.com,benjaminwagner@google.com,ethannicholas@google.com,reviews@skia.org NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Change-Id: Ic64cac2395abb406116885ddd725f74a434c8c49 Reviewed-on: https://skia-review.googlesource.com/10758 Reviewed-by: Ethan Nicholas <ethannicholas@google.com> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/sksl/SkSLUtil.cpp')
-rw-r--r--src/sksl/SkSLUtil.cpp107
1 files changed, 100 insertions, 7 deletions
diff --git a/src/sksl/SkSLUtil.cpp b/src/sksl/SkSLUtil.cpp
index c715cf1d09..e93a953990 100644
--- a/src/sksl/SkSLUtil.cpp
+++ b/src/sksl/SkSLUtil.cpp
@@ -10,24 +10,117 @@
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
+#include <cinttypes>
+#include <locale>
+#include <sstream>
+#include <string>
namespace SkSL {
-#ifdef SKSL_STANDALONE
-StandaloneShaderCaps standaloneCaps;
+SkString to_string(double value) {
+#ifdef SK_BUILD_FOR_WIN
+ #define SNPRINTF _snprintf
+#else
+ #define SNPRINTF snprintf
#endif
+#define MAX_DOUBLE_CHARS 25
+ char buffer[MAX_DOUBLE_CHARS];
+ SkDEBUGCODE(int len = )SNPRINTF(buffer, sizeof(buffer), "%.17g", value);
+ ASSERT(len < MAX_DOUBLE_CHARS);
+ SkString result(buffer);
+ if (!strchr(buffer, '.') && !strchr(buffer, 'e')) {
+ result += ".0";
+ }
+ return result;
+#undef SNPRINTF
+#undef MAX_DOUBLE_CHARS
+}
+
+SkString to_string(int32_t value) {
+ return SkStringPrintf("%d", value);
+}
+
+SkString to_string(uint32_t value) {
+ return SkStringPrintf("%u", value);
+}
+
+SkString to_string(int64_t value) {
+ return SkStringPrintf("%" PRId64, value);
+}
+
+SkString to_string(uint64_t value) {
+ return SkStringPrintf("%" PRIu64, value);
+}
+
+int stoi(SkString s) {
+ if (s.size() > 2 && s[0] == '0' && s[1] == 'x') {
+ char* p;
+ int result = strtoul(s.c_str() + 2, &p, 16);
+ ASSERT(*p == 0);
+ return result;
+ }
+ return atoi(s.c_str());
+}
+
+double stod(SkString s) {
+ double result;
+ std::string str(s.c_str(), s.size());
+ std::stringstream buffer(str);
+ buffer.imbue(std::locale::classic());
+ buffer >> result;
+ return result;
+}
+
+long stol(SkString s) {
+ if (s.size() > 2 && s[0] == '0' && s[1] == 'x') {
+ char* p;
+ long result = strtoul(s.c_str() + 2, &p, 16);
+ ASSERT(*p == 0);
+ return result;
+ }
+ return atol(s.c_str());
+}
void sksl_abort() {
-#ifdef SKSL_STANDALONE
- abort();
-#else
+#ifdef SKIA
sk_abort_no_print();
exit(1);
+#else
+ abort();
#endif
}
-void write_stringstream(const StringStream& s, OutputStream& out) {
- out.write(s.data(), s.size());
+void write_data(const SkData& data, SkWStream& out) {
+ out.write(data.data(), data.size());
+}
+
+SkString operator+(const SkString& s, const char* c) {
+ SkString result(s);
+ result += c;
+ return result;
+}
+
+SkString operator+(const char* c, const SkString& s) {
+ SkString result(c);
+ result += s;
+ return result;
}
+SkString operator+(const SkString& s1, const SkString& s2) {
+ SkString result(s1);
+ result += s2;
+ return result;
+}
+
+bool operator==(const SkString& s1, const char* s2) {
+ return !strcmp(s1.c_str(), s2);
+}
+
+bool operator!=(const SkString& s1, const char* s2) {
+ return strcmp(s1.c_str(), s2);
+}
+
+bool operator!=(const char* s1, const SkString& s2) {
+ return strcmp(s1, s2.c_str());
+}
} // namespace