Fix GL shader sources getting truncated by ADB log
authorcsmartdalton <csmartdalton@google.com>
Wed, 13 Jul 2016 15:47:54 +0000 (08:47 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 13 Jul 2016 15:47:54 +0000 (08:47 -0700)
Prints the shaders one line at a time so they don't get truncated by
the ADB log.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2142223003

Review-Url: https://codereview.chromium.org/2142223003

src/gpu/gl/builders/GrGLShaderStringBuilder.cpp

index 52915b6..b4ce282 100644 (file)
@@ -17,6 +17,8 @@
 SK_CONF_DECLARE(bool, c_PrintShaders, "gpu.printShaders", false,
                 "Print the source code for all shaders generated.");
 
+static void print_shader_source(const char** strings, int* lengths, int count);
+
 GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx,
                                     GrGLuint programId,
                                     GrGLenum type,
@@ -71,8 +73,7 @@ GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx,
                 // buffer param validation.
                 GrGLsizei length = GR_GL_INIT_ZERO;
                 GR_GL_CALL(gli, GetShaderInfoLog(shaderId, infoLen+1, &length, (char*)log.get()));
-                SkDebugf("%s", GrGLSLPrettyPrint::PrettyPrintGLSL(strings, lengths, count, true).c_str());
-                SkDebugf("\n%s", log.get());
+                print_shader_source(strings, lengths, count);
             }
             SkDEBUGFAIL("Shader compilation failed!");
             GR_GL_CALL(gli, DeleteShader(shaderId));
@@ -81,8 +82,7 @@ GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx,
     }
 
     if (c_PrintShaders) {
-        SkDebugf("%s", GrGLSLPrettyPrint::PrettyPrintGLSL(strings, lengths, count, true).c_str());
-        SkDebugf("\n");
+        print_shader_source(strings, lengths, count);
     }
 
     // Attach the shader, but defer deletion until after we have linked the program.
@@ -93,3 +93,13 @@ GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx,
 
     return shaderId;
 }
+
+static void print_shader_source(const char** strings, int* lengths, int count) {
+    const SkString& pretty = GrGLSLPrettyPrint::PrettyPrintGLSL(strings, lengths, count, true);
+    SkTArray<SkString> lines;
+    SkStrSplit(pretty.c_str(), "\n", &lines);
+    for (const SkString& line : lines) {
+        // Print the shader one line at the time so it doesn't get truncated by the adb log.
+        SkDebugf("%s\n", line.c_str());
+    }
+}