fix issues with simultaneous configs and security jail on skfiddle

BUG=skia:
TBR=jcgregorio

Review URL: https://codereview.chromium.org/688003002
diff --git a/experimental/webtry/main.cpp b/experimental/webtry/main.cpp
index f2a6f26..a83a608 100644
--- a/experimental/webtry/main.cpp
+++ b/experimental/webtry/main.cpp
@@ -120,18 +120,11 @@
     drawAndDump(surface, stream);
 }
 
-static void drawGPU(SkWStream* stream, SkImageInfo info) {
+static void drawGPU(SkWStream* stream, GrContext* gr, SkImageInfo info) {
     SkAutoTUnref<SkSurface> surface;
-    GrContextFactory* grFactory = NULL;
-
-    GrContext::Options grContextOpts;
-    grFactory = new GrContextFactory(grContextOpts);
-    GrContext* gr = grFactory->get(GrContextFactory::kMESA_GLContextType);
     surface.reset(SkSurface::NewRenderTarget(gr,info));
 
     drawAndDump(surface, stream);
-
-    delete grFactory;
 }
 
 static void drawPDF(SkWStream* stream, SkImageInfo info) {
@@ -162,7 +155,7 @@
     // make sure to open any needed output files before we set up the security
     // jail
 
-    SkWStream* streams[3];
+    SkWStream* streams[3] = {NULL, NULL, NULL};
 
     if (FLAGS_raster) {
         SkString outPath;
@@ -182,19 +175,34 @@
 
     SkImageInfo info = SkImageInfo::MakeN32(FLAGS_width, FLAGS_height, kPremul_SkAlphaType);
 
+    GrContext *gr = NULL;
+    GrContextFactory* grFactory = NULL;
+
+    // need to set up the GPU context before we install system call restrictions
+    if (FLAGS_gpu) {
+    
+        GrContext::Options grContextOpts;
+        grFactory = new GrContextFactory(grContextOpts);
+        gr = grFactory->get(GrContextFactory::kMESA_GLContextType);
+    }
+
     setLimits();
 
     if (!install_syscall_filter()) {
         return 1;
     }
 
-    if (FLAGS_raster) {
+    if (NULL != streams[0]) {
         drawRaster(streams[0], info);
     }
-    if (FLAGS_gpu) {
-        drawGPU(streams[1], info);
+    if (NULL != streams[1]) {
+        drawGPU(streams[1], gr, info);
     }
-    if (FLAGS_pdf) {
+    if (NULL != streams[2]) {
         drawPDF(streams[2], info);
     }
+
+    if (gr) {
+        delete grFactory;
+    }
 }
diff --git a/experimental/webtry/webtry.go b/experimental/webtry/webtry.go
index ad0d84e..9b14834 100644
--- a/experimental/webtry/webtry.go
+++ b/experimental/webtry/webtry.go
@@ -948,7 +948,7 @@
 		}
 
 		if request.GPU {
-			png, err := ioutil.ReadFile("../../../inout/" + hash + "_GPU.png")
+			png, err := ioutil.ReadFile("../../../inout/" + hash + "_gpu.png")
 			if err != nil {
 				reportTryError(w, r, err, "Failed to open the GPU-generated PNG.", hash)
 				return