Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Unified Diff: src/gpu/gl/builders/GrGLSLPrettyPrint.cpp

Issue 929503002: Multi-string shaders (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: windows warning Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/gl/builders/GrGLProgramBuilder.h ('k') | src/gpu/gl/builders/GrGLShaderBuilder.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/gl/builders/GrGLSLPrettyPrint.cpp
diff --git a/src/gpu/gl/builders/GrGLSLPrettyPrint.cpp b/src/gpu/gl/builders/GrGLSLPrettyPrint.cpp
index 27f4b44e66b87258d7f9131a7fed789aefd5485e..02802987c6007f58496920e03410cd6b176ba53b 100644
--- a/src/gpu/gl/builders/GrGLSLPrettyPrint.cpp
+++ b/src/gpu/gl/builders/GrGLSLPrettyPrint.cpp
@@ -12,69 +12,86 @@ class GLSLPrettyPrint {
public:
GLSLPrettyPrint() {}
- SkString prettify(const SkString& input, bool countlines) {
- // setup pretty state
- fIndex = 0;
- fLength = input.size();
- fInput = input;
+ SkString prettify(const char** strings,
+ int* lengths,
+ int count,
+ bool countlines) {
fCountlines = countlines;
fTabs = 0;
fLinecount = 1;
fFreshline = true;
+ // If a string breaks while in the middle 'parse until' we need to continue parsing on the
+ // next string
+ fInParseUntilNewline = false;
+ fInParseUntil = false;
+
int parensDepth = 0;
+
// number 1st line
this->lineNumbering();
- while (fLength > fIndex) {
- /* the heart and soul of our prettification algorithm. The rules should hopefully be
- * self explanatory. For '#' and '//' tokens we parse until we reach a newline.
- *
- * For long style comments like this one, we search for the ending token. We also
- * preserve whitespace in these comments WITH THE CAVEAT that we do the newlines
- * ourselves. This allows us to remain in control of line numbers, and matching tabs
- * Existing tabs in the input string are copied over too, but this will look funny
- *
- * '{' and '}' are handled in basically the same way. We add a newline if we aren't
- * on a fresh line, dirty the line, then add a second newline, ie braces are always
- * on their own lines indented properly. The one funkiness here is structs print with
- * the semicolon on its own line. Its not a problem for a glsl compiler though
- *
- * '(' and ')' are basically ignored, except as a sign we need to ignore ';' ala
- * in for loops.
- *
- * ';' means add a new line
- *
- * '\t' and '\n' are ignored in general parsing for backwards compatability with
- * existing shader code and we also have a special case for handling whitespace
- * at the beginning of fresh lines.
- *
- * Otherwise just add the new character to the pretty string, indenting if necessary.
- */
- if (this->hasToken("#") || this->hasToken("//")) {
- this->parseUntilNewline();
- } else if (this->hasToken("/*")) {
- this->parseUntil("*/");
- } else if ('{' == fInput[fIndex]) {
- this->newline();
- this->appendChar('{');
- fTabs++;
- this->newline();
- } else if ('}' == fInput[fIndex]) {
- fTabs--;
- this->newline();
- this->appendChar('}');
- this->newline();
- } else if (this->hasToken(")")) {
- parensDepth--;
- } else if (this->hasToken("(")) {
- parensDepth++;
- } else if (!parensDepth && this->hasToken(";")) {
- this->newline();
- } else if ('\t' == fInput[fIndex] || '\n' == fInput[fIndex] ||
- (fFreshline && ' ' == fInput[fIndex])) {
- fIndex++;
- } else {
- this->appendChar(input[fIndex]);
+ for (int i = 0; i < count; i++) {
+ // setup pretty state
+ fIndex = 0;
+ fLength = lengths[i];
+ fInput = strings[i];
+
+ while (fLength > fIndex) {
+ /* the heart and soul of our prettification algorithm. The rules should hopefully
+ * be self explanatory. For '#' and '//' tokens we parse until we reach a newline.
+ *
+ * For long style comments like this one, we search for the ending token. We also
+ * preserve whitespace in these comments WITH THE CAVEAT that we do the newlines
+ * ourselves. This allows us to remain in control of line numbers, and matching
+ * tabs Existing tabs in the input string are copied over too, but this will look
+ * funny
+ *
+ * '{' and '}' are handled in basically the same way. We add a newline if we aren't
+ * on a fresh line, dirty the line, then add a second newline, ie braces are always
+ * on their own lines indented properly. The one funkiness here is structs print
+ * with the semicolon on its own line. Its not a problem for a glsl compiler though
+ *
+ * '(' and ')' are basically ignored, except as a sign we need to ignore ';' ala
+ * in for loops.
+ *
+ * ';' means add a new line
+ *
+ * '\t' and '\n' are ignored in general parsing for backwards compatability with
+ * existing shader code and we also have a special case for handling whitespace
+ * at the beginning of fresh lines.
+ *
+ * Otherwise just add the new character to the pretty string, indenting if necessary.
+ */
+ if (fInParseUntilNewline) {
+ this->parseUntilNewline();
+ } else if (fInParseUntil) {
+ this->parseUntil(fInParseUntilToken);
+ } else if (this->hasToken("#") || this->hasToken("//")) {
+ this->parseUntilNewline();
+ } else if (this->hasToken("/*")) {
+ this->parseUntil("*/");
+ } else if ('{' == fInput[fIndex]) {
+ this->newline();
+ this->appendChar('{');
+ fTabs++;
+ this->newline();
+ } else if ('}' == fInput[fIndex]) {
+ fTabs--;
+ this->newline();
+ this->appendChar('}');
+ this->newline();
+ } else if (this->hasToken(")")) {
+ parensDepth--;
+ } else if (this->hasToken("(")) {
+ parensDepth++;
+ } else if (!parensDepth && this->hasToken(";")) {
+ this->newline();
+ } else if ('\t' == fInput[fIndex] || '\n' == fInput[fIndex] ||
+ (fFreshline && ' ' == fInput[fIndex])) {
+ fIndex++;
+ } else {
+ this->appendChar(fInput[fIndex]);
+ }
}
}
return fPretty;
@@ -107,9 +124,11 @@ private:
if ('\n' == fInput[fIndex]) {
fIndex++;
this->newline();
+ fInParseUntilNewline = false;
break;
}
fPretty.appendf("%c", fInput[fIndex++]);
+ fInParseUntilNewline = true;
}
}
@@ -127,10 +146,13 @@ private:
fIndex++;
}
if (this->hasToken(token)) {
+ fInParseUntil = false;
break;
}
fFreshline = false;
fPretty.appendf("%c", fInput[fIndex++]);
+ fInParseUntil = true;
+ fInParseUntilToken = token;
}
}
@@ -162,12 +184,21 @@ private:
bool fCountlines, fFreshline;
int fTabs, fLinecount;
size_t fIndex, fLength;
- SkString fInput, fPretty;
+ const char* fInput;
+ SkString fPretty;
+
+ // Some helpers for parseUntil when we go over a string length
+ bool fInParseUntilNewline;
+ bool fInParseUntil;
+ const char* fInParseUntilToken;
};
-SkString PrettyPrintGLSL(const SkString& input, bool countlines) {
+SkString PrettyPrintGLSL(const char** strings,
+ int* lengths,
+ int count,
+ bool countlines) {
GLSLPrettyPrint pp;
- return pp.prettify(input, countlines);
+ return pp.prettify(strings, lengths, count, countlines);
}
} // end namespace
« no previous file with comments | « src/gpu/gl/builders/GrGLProgramBuilder.h ('k') | src/gpu/gl/builders/GrGLShaderBuilder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698