Fail draws when can't get geom into vb/ib.

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



git-svn-id: http://skia.googlecode.com/svn/trunk@2053 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/gpu/include/GrContext_impl.h b/gpu/include/GrContext_impl.h
index df16c8c..8596491 100644
--- a/gpu/include/GrContext_impl.h
+++ b/gpu/include/GrContext_impl.h
@@ -37,7 +37,7 @@
     int indexCount = (NULL != idxSrc) ? idxSrc->count() : 0;
 
     if (!geo.set(target, layout, vertexCount, indexCount)) {
-        GrPrintf("Failed to get space for vertices!");
+        GrPrintf("Failed to get space for vertices!\n");
         return;
     }
 
diff --git a/gpu/include/GrDrawTarget.h b/gpu/include/GrDrawTarget.h
index 4431dc0..8196beb 100644
--- a/gpu/include/GrDrawTarget.h
+++ b/gpu/include/GrDrawTarget.h
@@ -938,10 +938,10 @@
                  int            vertexCount,
                  int            indexCount);
         bool succeeded() const { return NULL != fTarget; }
-        void* vertices() const { return fVertices; }
-        void* indices() const { return fIndices; }
+        void* vertices() const { GrAssert(this->succeeded()); return fVertices; }
+        void* indices() const { GrAssert(this->succeeded()); return fIndices; }
         GrPoint* positions() const {
-            return static_cast<GrPoint*>(fVertices);
+            return static_cast<GrPoint*>(this->vertices());
         }
 
     private:
diff --git a/gpu/src/GrBufferAllocPool.cpp b/gpu/src/GrBufferAllocPool.cpp
index efe2017..5b49350 100644
--- a/gpu/src/GrBufferAllocPool.cpp
+++ b/gpu/src/GrBufferAllocPool.cpp
@@ -220,7 +220,12 @@
         if (bytes >= bytesUsed) {
             bytes -= bytesUsed;
             fBytesInUse -= bytesUsed;
-            destroyBlock();
+            // if we locked a vb to satisfy the make space and we're releasing
+            // beyond it, then unlock it.
+            if (block.fBuffer->isLocked()) {
+                block.fBuffer->unlock();
+            }
+            this->destroyBlock();
         } else {
             block.fBytesFree += bytes;
             fBytesInUse -= bytes;
diff --git a/gpu/src/GrContext.cpp b/gpu/src/GrContext.cpp
index 10ff206..bfae62e 100644
--- a/gpu/src/GrContext.cpp
+++ b/gpu/src/GrContext.cpp
@@ -955,6 +955,10 @@
     size_t vsize = GrDrawTarget::VertexSize(layout);
 
     GrDrawTarget::AutoReleaseGeometry geo(target, layout, 8, 0);
+    if (!geo.succeeded()) {
+        GrPrintf("Failed to get space for vertices!\n");
+        return;
+    }
 
     intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices());
 
@@ -1008,6 +1012,10 @@
     size_t vsize = GrDrawTarget::VertexSize(layout);
 
     GrDrawTarget::AutoReleaseGeometry geo(target, layout, 16, 0);
+    if (!geo.succeeded()) {
+        GrPrintf("Failed to get space for vertices!\n");
+        return;
+    }
 
     intptr_t verts = reinterpret_cast<intptr_t>(geo.vertices());
 
@@ -1149,6 +1157,7 @@
         GrDrawTarget::AutoReleaseGeometry geo(target, layout, worstCaseVertCount, 0);
 
         if (!geo.succeeded()) {
+            GrPrintf("Failed to get space for vertices!\n");
             return;
         }
 
@@ -1182,9 +1191,12 @@
     } else {
         #if GR_STATIC_RECT_VB
             GrVertexLayout layout = PaintStageVertexLayoutBits(paint, NULL);
-
-            target->setVertexSourceToBuffer(layout,
-                                            fGpu->getUnitSquareVertexBuffer());
+            const GrVertexBuffer* sqVB = fGpu->getUnitSquareVertexBuffer();
+            if (NULL == sqVB) {
+                GrPrintf("Failed to create static rect vb.\n");
+                return;
+            }
+            target->setVertexSourceToBuffer(layout, sqVB);
             GrDrawTarget::AutoViewMatrixRestore avmr(target);
             GrMatrix m;
             m.setAll(rect.width(),    0,             rect.fLeft,
@@ -1251,7 +1263,12 @@
     }
     target->preConcatSamplerMatrix(GrPaint::kFirstTextureStage, m);
 
-    target->setVertexSourceToBuffer(layout, fGpu->getUnitSquareVertexBuffer());
+    const GrVertexBuffer* sqVB = fGpu->getUnitSquareVertexBuffer();
+    if (NULL == sqVB) {
+        GrPrintf("Failed to create static rect vb.\n");
+        return;
+    }
+    target->setVertexSourceToBuffer(layout, sqVB);
     target->drawNonIndexed(kTriangleFan_PrimitiveType, 0, 4);
 #else
 
@@ -1299,7 +1316,7 @@
 
     if (sizeof(GrPoint) != vertexSize) {
         if (!geo.set(target, layout, vertexCount, 0)) {
-            GrPrintf("Failed to get space for vertices!");
+            GrPrintf("Failed to get space for vertices!\n");
             return;
         }
         int texOffsets[GrDrawTarget::kMaxTexCoords];
@@ -1517,9 +1534,10 @@
 
     GrVertexLayout layout = GrDrawTarget::StagePosAsTexCoordVertexLayoutBit(0);
     static const int VCOUNT = 4;
-
+    // TODO: Use GrGpu::drawRect here
     GrDrawTarget::AutoReleaseGeometry geo(fGpu, layout, VCOUNT, 0);
     if (!geo.succeeded()) {
+        GrPrintf("Failed to get space for vertices!\n");
         return;
     }
     ((GrPoint*)geo.vertices())->setIRectFan(0, 0, width, height);
diff --git a/gpu/src/GrDrawTarget.cpp b/gpu/src/GrDrawTarget.cpp
index ad066d8..1dd750d 100644
--- a/gpu/src/GrDrawTarget.cpp
+++ b/gpu/src/GrDrawTarget.cpp
@@ -768,6 +768,10 @@
     GrVertexLayout layout = GetRectVertexLayout(stageEnableBitfield, srcRects);
 
     AutoReleaseGeometry geo(this, layout, 4, 0);
+    if (!geo.succeeded()) {
+        GrPrintf("Failed to get space for vertices!\n");
+        return;
+    }
 
     SetRectVertices(rect, matrix, srcRects, 
                     srcMatrices, layout, geo.vertices());
diff --git a/gpu/src/GrInOrderDrawBuffer.cpp b/gpu/src/GrInOrderDrawBuffer.cpp
index a8eb1f5..39bf275 100644
--- a/gpu/src/GrInOrderDrawBuffer.cpp
+++ b/gpu/src/GrInOrderDrawBuffer.cpp
@@ -87,6 +87,10 @@
         bool appendToPreviousDraw = false;
         GrVertexLayout layout = GetRectVertexLayout(stageEnableBitfield, srcRects);
         AutoReleaseGeometry geo(this, layout, 4, 0);
+        if (!geo.succeeded()) {
+            GrPrintf("Failed to get space for vertices!\n");
+            return;
+        }
         AutoViewMatrixRestore avmr(this);
         GrMatrix combinedMatrix = this->getViewMatrix();
         this->setViewMatrix(GrMatrix::I());