Enhance GL error checking for non-Ganesh GL calls

https://codereview.appspot.com/7312057/



git-svn-id: http://skia.googlecode.com/svn/trunk@7647 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/bench/BenchGpuTimer_gl.cpp b/bench/BenchGpuTimer_gl.cpp
index 699f5e5..d2de122 100644
--- a/bench/BenchGpuTimer_gl.cpp
+++ b/bench/BenchGpuTimer_gl.cpp
@@ -51,9 +51,16 @@
 
         GrGLint available = 0;
         while (!available) {
-            SK_GL(*fContext, GetQueryObjectiv(fQuery,
+            SK_GL_NOERRCHECK(*fContext, GetQueryObjectiv(fQuery,
                                              GR_GL_QUERY_RESULT_AVAILABLE,
                                              &available));
+            // If GetQueryObjectiv is erroring out we need some alternative
+            // means of breaking out of this loop
+            GrGLenum error;
+            SK_GL_RET_NOERRCHECK(*fContext, error, GetError());
+            if (GR_GL_NO_ERROR != error) {
+                break;
+            }
         }
         GrGLuint64 totalGPUTimeElapsed = 0;
         SK_GL(*fContext, GetQueryObjectui64v(fQuery,
diff --git a/bench/benchmain.cpp b/bench/benchmain.cpp
index 7b1a34e..2142da1 100644
--- a/bench/benchmain.cpp
+++ b/bench/benchmain.cpp
@@ -11,6 +11,7 @@
 
 #if SK_SUPPORT_GPU
 #include "GrContext.h"
+#include "gl/GrGLDefines.h"
 #include "GrRenderTarget.h"
 #if SK_ANGLE
 #include "gl/SkANGLEGLContext.h"
diff --git a/gyp/tools.gyp b/gyp/tools.gyp
index 8148358..121779b 100644
--- a/gyp/tools.gyp
+++ b/gyp/tools.gyp
@@ -144,6 +144,15 @@
         'images.gyp:images',
         'tools.gyp:picture_utils',
       ],
+      'conditions': [
+        ['skia_gpu == 1',
+          {
+            'include_dirs' : [
+              '../src/gpu',
+            ],
+          },
+        ],
+      ],
       'export_dependent_settings': [
         'images.gyp:images',
       ],
diff --git a/include/gpu/gl/SkGLContext.h b/include/gpu/gl/SkGLContext.h
index 3f99eae..9842fc6 100644
--- a/include/gpu/gl/SkGLContext.h
+++ b/include/gpu/gl/SkGLContext.h
@@ -61,9 +61,14 @@
 };
 
 /**
- * Helper macro for using the GL context through the GrGLInterface. Example:
+ * Helper macros for using the GL context through the GrGLInterface. Example:
  * SK_GL(glCtx, GenTextures(1, &texID));
  */
-#define SK_GL(ctx, X) (ctx).gl()->f ## X
+#define SK_GL(ctx, X) (ctx).gl()->f ## X;    \
+                      SkASSERT(GR_GL_NO_ERROR == (ctx).gl()->fGetError())
+#define SK_GL_RET(ctx, RET, X) (RET) = (ctx).gl()->f ## X;    \
+                  SkASSERT(GR_GL_NO_ERROR == (ctx).gl()->fGetError())
+#define SK_GL_NOERRCHECK(ctx, X) (ctx).gl()->f ## X
+#define SK_GL_RET_NOERRCHECK(ctx, RET, X) (RET) = (ctx).gl()->f ## X
 
 #endif
diff --git a/src/gpu/gl/SkGLContext.cpp b/src/gpu/gl/SkGLContext.cpp
index c5069b2..59ac31d 100644
--- a/src/gpu/gl/SkGLContext.cpp
+++ b/src/gpu/gl/SkGLContext.cpp
@@ -40,18 +40,19 @@
 
     fGL = this->createGLContext();
     if (fGL) {
-        fExtensionString =
-            reinterpret_cast<const char*>(SK_GL(*this,
-                                                 GetString(GR_GL_EXTENSIONS)));
-        const char* versionStr =
-            reinterpret_cast<const char*>(SK_GL(*this,
-                                                GetString(GR_GL_VERSION)));
+        const GrGLubyte* temp;
+
+        SK_GL_RET(*this, temp, GetString(GR_GL_EXTENSIONS));
+        fExtensionString = reinterpret_cast<const char*>(temp);
+
+        SK_GL_RET(*this, temp, GetString(GR_GL_VERSION));
+        const char* versionStr = reinterpret_cast<const char*>(temp);
         GrGLVersion version = GrGLGetVersionFromString(versionStr);
 
         // clear any existing GL erorrs
         GrGLenum error;
         do {
-            error = SK_GL(*this, GetError());
+            SK_GL_RET(*this, error, GetError());
         } while (GR_GL_NO_ERROR != error);
 
         GrGLBinding bindingInUse = GrGLGetBindingInUse(this->gl());
@@ -118,9 +119,9 @@
         SK_GL(*this, ClearStencil(0));
         SK_GL(*this, Clear(GR_GL_STENCIL_BUFFER_BIT));
 
-        error = SK_GL(*this, GetError());
-        GrGLenum status =
-            SK_GL(*this, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
+        SK_GL_RET(*this, error, GetError());
+        GrGLenum status;
+        SK_GL_RET(*this, status, CheckFramebufferStatus(GR_GL_FRAMEBUFFER));
 
         if (GR_GL_FRAMEBUFFER_COMPLETE != status ||
             GR_GL_NO_ERROR != error) {
diff --git a/tools/PictureBenchmark.cpp b/tools/PictureBenchmark.cpp
index 8c1a6cc..b6a927b 100644
--- a/tools/PictureBenchmark.cpp
+++ b/tools/PictureBenchmark.cpp
@@ -96,7 +96,7 @@
         while (tiledRenderer->nextTile(x, y)) {
             // There are two timers, which will behave slightly differently:
             // 1) longRunningTimer, along with perTileTimerData, will time how long it takes to draw
-            // one tile fRepeats times, and take the average. As such, it will not respect the
+            // one tile fRepeats times, and take the average. As such, it will not respect thea
             // logPerIter or printMin options, since it does not know the time per iteration. It
             // will also be unable to call flush() for each tile.
             // The goal of this timer is to make up for a system timer that is not precise enough to
@@ -104,10 +104,10 @@
             //
             // 2) perTileTimer, along with perTileTimerData, will record each run separately, and
             // then take the average. As such, it supports logPerIter and printMin options.
-            SkAutoTDelete<BenchTimer> longRunningTimer(this->setupTimer(false));
+            SkAutoTDelete<BenchTimer> longRunningTimer(this->setupTimer());
             TimerData longRunningTimerData(tiledRenderer->getPerIterTimeFormat(),
                                            tiledRenderer->getNormalTimeFormat());
-            SkAutoTDelete<BenchTimer> perTileTimer(this->setupTimer(false));
+            SkAutoTDelete<BenchTimer> perTileTimer(this->setupTimer());
             TimerData perTileTimerData(tiledRenderer->getPerIterTimeFormat(),
                                        tiledRenderer->getNormalTimeFormat());
             longRunningTimer->start();
diff --git a/tools/PictureRenderer.cpp b/tools/PictureRenderer.cpp
index b277232..e2dd5f8 100644
--- a/tools/PictureRenderer.cpp
+++ b/tools/PictureRenderer.cpp
@@ -12,6 +12,7 @@
 #include "SkDevice.h"
 #include "SkGPipe.h"
 #if SK_SUPPORT_GPU
+#include "gl/GrGLDefines.h"
 #include "SkGpuDevice.h"
 #endif
 #include "SkGraphics.h"