git-svn-id: http://skia.googlecode.com/svn/trunk@783 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/src/GrGpuGLFixed.cpp b/gpu/src/GrGpuGLFixed.cpp
index 3fd8d5c..a028cba 100644
--- a/gpu/src/GrGpuGLFixed.cpp
+++ b/gpu/src/GrGpuGLFixed.cpp
@@ -263,44 +263,9 @@
                                                     oldTexCoordOffsets,
                                                     &oldColorOffset);
 
-    const GLvoid* posPtr = (GLvoid*)(newStride * startVertex);
-
-    if (kBuffer_GeometrySrcType == fGeometrySrc.fVertexSrc) {
-        GrAssert(NULL != fGeometrySrc.fVertexBuffer);
-        GrAssert(!fGeometrySrc.fVertexBuffer->isLocked());
-        if (fHWGeometryState.fVertexBuffer != fGeometrySrc.fVertexBuffer) {
-            GrGLVertexBuffer* buf =
-                            (GrGLVertexBuffer*)fGeometrySrc.fVertexBuffer;
-            GR_GL(BindBuffer(GL_ARRAY_BUFFER, buf->bufferID()));
-            fHWGeometryState.fVertexBuffer = fGeometrySrc.fVertexBuffer;
-        }
-    } else {
-        if (kArray_GeometrySrcType == fGeometrySrc.fVertexSrc) {
-            posPtr = (void*)((intptr_t)fGeometrySrc.fVertexArray +
-                             (intptr_t)posPtr);
-        } else {
-            GrAssert(kReserved_GeometrySrcType == fGeometrySrc.fVertexSrc);
-            posPtr = (void*)((intptr_t)fVertices.get() + (intptr_t)posPtr);
-        }
-        if (NULL != fHWGeometryState.fVertexBuffer) {
-            GR_GL(BindBuffer(GL_ARRAY_BUFFER, 0));
-            fHWGeometryState.fVertexBuffer = NULL;
-        }
-    }
-
-    if (kBuffer_GeometrySrcType == fGeometrySrc.fIndexSrc) {
-        GrAssert(NULL != fGeometrySrc.fIndexBuffer);
-        GrAssert(!fGeometrySrc.fIndexBuffer->isLocked());
-        if (fHWGeometryState.fIndexBuffer != fGeometrySrc.fIndexBuffer) {
-            GrGLIndexBuffer* buf =
-            (GrGLIndexBuffer*)fGeometrySrc.fIndexBuffer;
-            GR_GL(BindBuffer(GL_ELEMENT_ARRAY_BUFFER, buf->bufferID()));
-            fHWGeometryState.fIndexBuffer = fGeometrySrc.fIndexBuffer;
-        }
-    } else if (NULL != fHWGeometryState.fIndexBuffer) {
-        GR_GL(BindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0));
-        fHWGeometryState.fIndexBuffer = NULL;
-    }
+    const GLvoid* posPtr = setBuffersAndGetVertexStart(newStride, startVertex,
+                                                       startIndex, vertexCount,
+                                                       indexCount);
 
     GLenum scalarType;
     if (fGeometrySrc.fVertexLayout & kTextFormat_VertexLayoutBit) {
@@ -317,7 +282,7 @@
     bool strideChange = newStride != oldStride;
     bool posChange = baseChange || scalarChange || strideChange;
 
-    if (posChange) {
+    if (posChange || fHWGeometryState.fArrayPtrsDirty) {
         GR_GL(VertexPointer(2, scalarType, newStride, posPtr));
         fHWGeometryState.fPositionPtr = posPtr;
     }
@@ -330,8 +295,9 @@
             if (oldTexCoordOffsets[s] < 0) {
                 GR_GL(ClientActiveTexture(GL_TEXTURE0+s));
                 GR_GL(EnableClientState(GL_TEXTURE_COORD_ARRAY));
-            }
-            if (posChange || newTexCoordOffsets[s] != oldTexCoordOffsets[s]) {
+                GR_GL(TexCoordPointer(2, scalarType, newStride, texCoordPtr));
+            } else if (fHWGeometryState.fArrayPtrsDirty || posChange ||
+                       newTexCoordOffsets[s] != oldTexCoordOffsets[s]) {
                 GR_GL(ClientActiveTexture(GL_TEXTURE0+s));
                 GR_GL(TexCoordPointer(2, scalarType, newStride, texCoordPtr));
             }
@@ -345,8 +311,9 @@
         GLvoid* colorPtr = (int8_t*)posPtr + newColorOffset;
         if (oldColorOffset <= 0) {
             GR_GL(EnableClientState(GL_COLOR_ARRAY));
-        }
-        if (posChange || newColorOffset != oldColorOffset) {
+            GR_GL(ColorPointer(4, GL_UNSIGNED_BYTE, newStride, colorPtr));
+        } else if (fHWGeometryState.fArrayPtrsDirty || posChange ||
+                   newColorOffset != oldColorOffset) {
             GR_GL(ColorPointer(4, GL_UNSIGNED_BYTE, newStride, colorPtr));
         }
     } else if (oldColorOffset > 0) {
@@ -354,6 +321,7 @@
     }
 
     fHWGeometryState.fVertexLayout = fGeometrySrc.fVertexLayout;
+    fHWGeometryState.fArrayPtrsDirty = false;
 }
 
 #endif