Workaround for chrome on mac buffer object performance issue.

Review URL: http://codereview.appspot.com/5713051/



git-svn-id: http://skia.googlecode.com/svn/trunk@3289 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/gpu/gl/GrGLIndexBuffer.cpp b/src/gpu/gl/GrGLIndexBuffer.cpp
index b64668e..f424e78 100644
--- a/src/gpu/gl/GrGLIndexBuffer.cpp
+++ b/src/gpu/gl/GrGLIndexBuffer.cpp
@@ -104,28 +104,38 @@
     }
     this->bind();
     GrGLenum usage = dynamic() ? GR_GL_DYNAMIC_DRAW : GR_GL_STATIC_DRAW;
-#if !GR_GL_USE_BUFFER_DATA_NULL_HINT
-    // Note that we're cheating on the size here. Currently no methods
-    // allow a partial update that preserves contents of non-updated
-    // portions of the buffer (and lock() does a glBufferData(..size, NULL..))
-    GL_CALL(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER, srcSizeInBytes, src, usage));
-#else
-    if (this->sizeInBytes() == srcSizeInBytes) {
-        GL_CALL(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER,
-                            srcSizeInBytes, src, usage));
-    } else {
-        // Before we call glBufferSubData we give the driver a hint using
-        // glBufferData with NULL. This makes the old buffer contents
-        // inaccessible to future draws. The GPU may still be processing draws
-        // that reference the old contents. With this hint it can assign a
-        // different allocation for the new contents to avoid flushing the gpu
-        // past draws consuming the old contents.
-        GL_CALL(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER,
-                           this->sizeInBytes(), NULL, usage));
-        GL_CALL(BufferSubData(GR_GL_ELEMENT_ARRAY_BUFFER,
-                              0, srcSizeInBytes, src));
-    }
+
+    bool doNullHint = GR_GL_USE_BUFFER_DATA_NULL_HINT;
+#if GR_GL_MAC_BUFFER_OBJECT_PERFOMANCE_WORKAROUND
+    GrAssert(!doNullHint);
+    static int N = 0;
+    doNullHint = (0 == N % 1024);
+    ++N;
 #endif
+
+    if (doNullHint) {
+        if (this->sizeInBytes() == srcSizeInBytes) {
+            GL_CALL(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER,
+                                srcSizeInBytes, src, usage));
+        } else {
+            // Before we call glBufferSubData we give the driver a hint using
+            // glBufferData with NULL. This makes the old buffer contents
+            // inaccessible to future draws. The GPU may still be processing
+            // draws that reference the old contents. With this hint it can
+            // assign a different allocation for the new contents to avoid
+            // flushing the gpu past draws consuming the old contents.
+            GL_CALL(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER,
+                               this->sizeInBytes(), NULL, usage));
+            GL_CALL(BufferSubData(GR_GL_ELEMENT_ARRAY_BUFFER,
+                                  0, srcSizeInBytes, src));
+        }
+    } else {
+        // Note that we're cheating on the size here. Currently no methods
+        // allow a partial update that preserves contents of non-updated
+        // portions of the buffer (lock() does a glBufferData(..size, NULL..))
+        GL_CALL(BufferData(GR_GL_ELEMENT_ARRAY_BUFFER, 
+                           srcSizeInBytes, src, usage));
+    }
     return true;
 }