GrInOrderDrawBuffer.cpp revision a4f6b10818819a16bc94738e2eda42dfec332c43
1ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 Google Inc. 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 6ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 7ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 8ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 9ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 10ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#include "GrInOrderDrawBuffer.h" 118f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com#include "GrRenderTarget.h" 12ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#include "GrTexture.h" 131c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com#include "GrBufferAllocPool.h" 1486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com#include "GrIndexBuffer.h" 1586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com#include "GrVertexBuffer.h" 16ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#include "GrGpu.h" 17ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 18471d471dcd7422e5dd9c822c1092b2ba4721dcfebsalomon@google.comGrInOrderDrawBuffer::GrInOrderDrawBuffer(const GrGpu* gpu, 19471d471dcd7422e5dd9c822c1092b2ba4721dcfebsalomon@google.com GrVertexBufferAllocPool* vertexPool, 2025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrIndexBufferAllocPool* indexPool) 2197805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com : fAutoFlushTarget(NULL) 2297805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com , fClipSet(true) 236970557055acaed619d7bb89451868e1570249b2robertphillips@google.com , fVertexPool(*vertexPool) 246970557055acaed619d7bb89451868e1570249b2robertphillips@google.com , fIndexPool(*indexPool) 2525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com , fLastRectVertexLayout(0) 2625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com , fQuadIndexBuffer(NULL) 2725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com , fMaxQuads(0) 28c82a8b7aa4ec19fba508c394920a9e88d3e5bd12robertphillips@google.com , fFlushing(false) { 2918c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com 3018c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com fCaps = gpu->getCaps(); 3118c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com 321c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com GrAssert(NULL != vertexPool); 331c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com GrAssert(NULL != indexPool); 3425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 3525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.push_back(); 3625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fUsedPoolVertexBytes = 0; 3725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fUsedPoolIndexBytes = 0; 3825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com#if GR_DEBUG 3925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0; 4025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fPoolStartVertex = ~0; 4125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0; 4225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fPoolStartIndex = ~0; 4325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com#endif 44a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com this->reset(); 45ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 46ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 47ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comGrInOrderDrawBuffer::~GrInOrderDrawBuffer() { 4886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com this->reset(); 494a018bb20bf969a38ec11d9506843f06366dfa7cbsalomon@google.com // This must be called by before the GrDrawTarget destructor 504a018bb20bf969a38ec11d9506843f06366dfa7cbsalomon@google.com this->releaseGeometry(); 5186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com GrSafeUnref(fQuadIndexBuffer); 5297805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com GrSafeUnref(fAutoFlushTarget); 53ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 54ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 5586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.comvoid GrInOrderDrawBuffer::setQuadIndexBuffer(const GrIndexBuffer* indexBuffer) { 5686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com bool newIdxBuffer = fQuadIndexBuffer != indexBuffer; 5786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com if (newIdxBuffer) { 5886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com GrSafeUnref(fQuadIndexBuffer); 5986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com fQuadIndexBuffer = indexBuffer; 6086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com GrSafeRef(fQuadIndexBuffer); 6186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com fCurrQuad = 0; 6286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com fMaxQuads = (NULL == indexBuffer) ? 0 : indexBuffer->maxQuads(); 6386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } else { 64d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com GrAssert((NULL == indexBuffer && 0 == fMaxQuads) || 6586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com (indexBuffer->maxQuads() == fMaxQuads)); 6686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 6786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com} 6886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 69934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com//////////////////////////////////////////////////////////////////////////////// 70934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 71934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.comvoid GrInOrderDrawBuffer::resetDrawTracking() { 72934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com fCurrQuad = 0; 73934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com fInstancedDrawTracker.reset(); 74934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com} 75934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 76d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.comvoid GrInOrderDrawBuffer::drawRect(const GrRect& rect, 7786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com const GrMatrix* matrix, 7839ee0ffa72fbd5df6d3ec6db4fdad0c1bc3946fdbsalomon@google.com StageMask stageMask, 7986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com const GrRect* srcRects[], 8086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com const GrMatrix* srcMatrices[]) { 81d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com 8286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com GrAssert(!(NULL == fQuadIndexBuffer && fCurrQuad)); 8386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com GrAssert(!(fDraws.empty() && fCurrQuad)); 8486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com GrAssert(!(0 != fMaxQuads && NULL == fQuadIndexBuffer)); 8586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 868f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com GrDrawState* drawState = this->drawState(); 878f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com 8886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com // if we have a quad IB then either append to the previous run of 8986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com // rects or start a new run 9086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com if (fMaxQuads) { 91d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com 9286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com bool appendToPreviousDraw = false; 9339ee0ffa72fbd5df6d3ec6db4fdad0c1bc3946fdbsalomon@google.com GrVertexLayout layout = GetRectVertexLayout(stageMask, srcRects); 9486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com AutoReleaseGeometry geo(this, layout, 4, 0); 956513cd06ae34f5d777b3aaea0b4533014d0a10f2bsalomon@google.com if (!geo.succeeded()) { 966513cd06ae34f5d777b3aaea0b4533014d0a10f2bsalomon@google.com GrPrintf("Failed to get space for vertices!\n"); 976513cd06ae34f5d777b3aaea0b4533014d0a10f2bsalomon@google.com return; 986513cd06ae34f5d777b3aaea0b4533014d0a10f2bsalomon@google.com } 998f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com GrMatrix combinedMatrix = drawState->getViewMatrix(); 1003f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // We go to device space so that matrix changes allow us to concat 1013f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // rect draws. When the caller has provided explicit source rects 1023f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // then we don't want to modify the sampler matrices. Otherwise we do 1033f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // we have to account for the view matrix change in the sampler 1043f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // matrices. 1053f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com StageMask devCoordMask = (NULL == srcRects) ? stageMask : 0; 1063f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com GrDrawTarget::AutoDeviceCoordDraw adcd(this, devCoordMask); 10786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com if (NULL != matrix) { 10886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com combinedMatrix.preConcat(*matrix); 10986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 11086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 11186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com SetRectVertices(rect, &combinedMatrix, srcRects, srcMatrices, layout, geo.vertices()); 11286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 11386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com // we don't want to miss an opportunity to batch rects together 11486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com // simply because the clip has changed if the clip doesn't affect 11586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com // the rect. 11686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com bool disabledClip = false; 1178f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com if (drawState->isClipState() && fClip.isRect()) { 118d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com 1190b50b2ed462505c452de8b6d978c4e522e0f9fe1bsalomon@google.com GrRect clipRect = fClip.getRect(0); 12086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com // If the clip rect touches the edge of the viewport, extended it 12186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com // out (close) to infinity to avoid bogus intersections. 122d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com // We might consider a more exact clip to viewport if this 12386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com // conservative test fails. 1248f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com const GrRenderTarget* target = drawState->getRenderTarget(); 12586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com if (0 >= clipRect.fLeft) { 12686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com clipRect.fLeft = GR_ScalarMin; 12786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 12886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com if (target->width() <= clipRect.fRight) { 12986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com clipRect.fRight = GR_ScalarMax; 13086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 13186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com if (0 >= clipRect.top()) { 13286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com clipRect.fTop = GR_ScalarMin; 13386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 13486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com if (target->height() <= clipRect.fBottom) { 13586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com clipRect.fBottom = GR_ScalarMax; 13686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 13786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int stride = VertexSize(layout); 13886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com bool insideClip = true; 13986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com for (int v = 0; v < 4; ++v) { 14086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com const GrPoint& p = *GetVertexPoint(geo.vertices(), v, stride); 14186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com if (!clipRect.contains(p)) { 14286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com insideClip = false; 14386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com break; 14486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 14586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 14686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com if (insideClip) { 1478f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com drawState->disableState(GrDrawState::kClip_StateBit); 14886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com disabledClip = true; 14986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 15086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 151a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com if (!this->needsNewClip() && 152a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com !this->needsNewState() && 153a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com fCurrQuad > 0 && 154a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com fCurrQuad < fMaxQuads && 155a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com layout == fLastRectVertexLayout) { 15686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 15786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int vsize = VertexSize(layout); 158d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com 15986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com Draw& lastDraw = fDraws.back(); 16086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 16186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com GrAssert(lastDraw.fIndexBuffer == fQuadIndexBuffer); 16247059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com GrAssert(kTriangles_GrPrimitiveType == lastDraw.fPrimitiveType); 16386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com GrAssert(0 == lastDraw.fVertexCount % 4); 16486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com GrAssert(0 == lastDraw.fIndexCount % 6); 16586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com GrAssert(0 == lastDraw.fStartIndex); 16686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 16725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.back(); 1686aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com 169a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com appendToPreviousDraw = 170a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com kDraw_Cmd != fCmds.back() && 17125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com lastDraw.fVertexBuffer == poolState.fPoolVertexBuffer && 17225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com (fCurrQuad * 4 + lastDraw.fStartVertex) == poolState.fPoolStartVertex; 17325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 17486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com if (appendToPreviousDraw) { 17586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com lastDraw.fVertexCount += 4; 17686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com lastDraw.fIndexCount += 6; 17786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com fCurrQuad += 1; 17825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // we reserved above, so we should be the first 179a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com // use of this vertex reservation. 18025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrAssert(0 == poolState.fUsedPoolVertexBytes); 18125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fUsedPoolVertexBytes = 4 * vsize; 18286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 18386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 18486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com if (!appendToPreviousDraw) { 18586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com this->setIndexSourceToBuffer(fQuadIndexBuffer); 18647059542e7aa153926377456a6c611e55c8e428cbsalomon@google.com this->drawIndexed(kTriangles_GrPrimitiveType, 0, 0, 4, 6); 18786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com fCurrQuad = 1; 18886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com fLastRectVertexLayout = layout; 18986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 19086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com if (disabledClip) { 1918f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com drawState->enableState(GrDrawState::kClip_StateBit); 19286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 193934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com fInstancedDrawTracker.reset(); 19486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } else { 19539ee0ffa72fbd5df6d3ec6db4fdad0c1bc3946fdbsalomon@google.com INHERITED::drawRect(rect, matrix, stageMask, srcRects, srcMatrices); 19686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 19786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com} 19886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 199934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.comvoid GrInOrderDrawBuffer::drawIndexedInstances(GrPrimitiveType type, 200934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com int instanceCount, 201934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com int verticesPerInstance, 202934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com int indicesPerInstance) { 203934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com if (!verticesPerInstance || !indicesPerInstance) { 204934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com return; 205934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com } 206934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 207934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com const GeometrySrcState& geomSrc = this->getGeomSrc(); 208934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 209934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com // we only attempt to concat the case when reserved verts are used with 210934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com // an index buffer. 211934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com if (kReserved_GeometrySrcType == geomSrc.fVertexSrc && 212934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com kBuffer_GeometrySrcType == geomSrc.fIndexSrc) { 213934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 214a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com if (this->needsNewClip()) { 215a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com this->recordClip(); 216a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com } 217a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com if (this->needsNewState()) { 218a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com this->recordState(); 219a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com } 220a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com 221934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com Draw* draw = NULL; 222934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com // if the last draw used the same indices/vertices per shape then we 223934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com // may be able to append to it. 224a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com if (kDraw_Cmd == fCmds.back() && 225a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com verticesPerInstance == fInstancedDrawTracker.fVerticesPerInstance && 226934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com indicesPerInstance == fInstancedDrawTracker.fIndicesPerInstance) { 227934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com GrAssert(fDraws.count()); 228934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com draw = &fDraws.back(); 229934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com } 230934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 231934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.back(); 232934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com const GrVertexBuffer* vertexBuffer = poolState.fPoolVertexBuffer; 233934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 234934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com // Check whether the draw is compatible with this draw in order to 235934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com // append 236934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com if (NULL == draw || 237934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com draw->fIndexBuffer != geomSrc.fIndexBuffer || 238934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com draw->fPrimitiveType != type || 239934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com draw->fVertexBuffer != vertexBuffer) { 240934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 241a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw = this->recordDraw(); 242934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com draw->fIndexBuffer = geomSrc.fIndexBuffer; 243934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com geomSrc.fIndexBuffer->ref(); 244934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com draw->fVertexBuffer = vertexBuffer; 245934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com vertexBuffer->ref(); 246934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com draw->fPrimitiveType = type; 247934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com draw->fStartIndex = 0; 248934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com draw->fIndexCount = 0; 249934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com draw->fStartVertex = poolState.fPoolStartVertex; 250934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com draw->fVertexCount = 0; 251934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com draw->fVertexLayout = geomSrc.fVertexLayout; 252934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com } else { 253934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com GrAssert(!(draw->fIndexCount % indicesPerInstance)); 254934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com GrAssert(!(draw->fVertexCount % verticesPerInstance)); 255934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com GrAssert(poolState.fPoolStartVertex == draw->fStartVertex + 256934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com draw->fVertexCount); 257934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com } 258934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 259934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com // how many instances can be in a single draw 260934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com int maxInstancesPerDraw = this->indexCountInCurrentSource() / 261934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com indicesPerInstance; 262934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com if (!maxInstancesPerDraw) { 263934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com return; 264934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com } 265934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com // how many instances should be concat'ed onto draw 266934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com int instancesToConcat = maxInstancesPerDraw - draw->fVertexCount / 267934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com verticesPerInstance; 268934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com if (maxInstancesPerDraw > instanceCount) { 269934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com maxInstancesPerDraw = instanceCount; 270934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com if (instancesToConcat > instanceCount) { 271934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com instancesToConcat = instanceCount; 272934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com } 273934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com } 274934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 275934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com // update the amount of reserved data actually referenced in draws 276934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com size_t vertexBytes = instanceCount * verticesPerInstance * 277934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com VertexSize(draw->fVertexLayout); 278934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com poolState.fUsedPoolVertexBytes = 279934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com GrMax(poolState.fUsedPoolVertexBytes, vertexBytes); 280934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 281934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com while (instanceCount) { 282934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com if (!instancesToConcat) { 283934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com int startVertex = draw->fStartVertex + draw->fVertexCount; 284a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw = this->recordDraw(); 285934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com draw->fIndexBuffer = geomSrc.fIndexBuffer; 286934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com geomSrc.fIndexBuffer->ref(); 287934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com draw->fVertexBuffer = vertexBuffer; 288934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com vertexBuffer->ref(); 289934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com draw->fPrimitiveType = type; 290934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com draw->fStartIndex = 0; 291934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com draw->fStartVertex = startVertex; 292934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com draw->fVertexCount = 0; 293934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com draw->fVertexLayout = geomSrc.fVertexLayout; 294934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com instancesToConcat = maxInstancesPerDraw; 295934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com } 296934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com draw->fVertexCount += instancesToConcat * verticesPerInstance; 297934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com draw->fIndexCount += instancesToConcat * indicesPerInstance; 298934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com instanceCount -= instancesToConcat; 299934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com instancesToConcat = 0; 300934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com } 301934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 302934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com // update draw tracking for next draw 303934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com fCurrQuad = 0; 304934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com fInstancedDrawTracker.fVerticesPerInstance = verticesPerInstance; 305934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com fInstancedDrawTracker.fIndicesPerInstance = indicesPerInstance; 306934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com } else { 307934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com this->INHERITED::drawIndexedInstances(type, 308934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com instanceCount, 309934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com verticesPerInstance, 310934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com indicesPerInstance); 311934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com } 312934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 313934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com} 314934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 31525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.comvoid GrInOrderDrawBuffer::onDrawIndexed(GrPrimitiveType primitiveType, 31625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startVertex, 31725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startIndex, 31825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 31925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int indexCount) { 320ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 321ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com if (!vertexCount || !indexCount) { 322ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com return; 323ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 324ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 325934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com this->resetDrawTracking(); 32686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 32725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.back(); 32825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 329a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com if (this->needsNewClip()) { 330a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com this->recordClip(); 33186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 332a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com if (this->needsNewState()) { 333a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com this->recordState(); 33486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 335ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 336a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com Draw* draw = this->recordDraw(); 337a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com 338a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fPrimitiveType = primitiveType; 339a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fStartVertex = startVertex; 340a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fStartIndex = startIndex; 341a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fVertexCount = vertexCount; 342a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fIndexCount = indexCount; 343a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com 344a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fVertexLayout = this->getVertexLayout(); 34525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com switch (this->getGeomSrc().fVertexSrc) { 3461c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com case kBuffer_GeometrySrcType: 347a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fVertexBuffer = this->getGeomSrc().fVertexBuffer; 348ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com break; 34925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com case kReserved_GeometrySrcType: // fallthrough 35025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com case kArray_GeometrySrcType: { 351ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com size_t vertexBytes = (vertexCount + startVertex) * 352a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com VertexSize(draw->fVertexLayout); 35325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fUsedPoolVertexBytes = 35425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrMax(poolState.fUsedPoolVertexBytes, vertexBytes); 355a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fVertexBuffer = poolState.fPoolVertexBuffer; 356a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fStartVertex += poolState.fPoolStartVertex; 357ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com break; 35825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com } 3591c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com default: 3601c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com GrCrash("unknown geom src type"); 361ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 362a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fVertexBuffer->ref(); 363ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 36425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com switch (this->getGeomSrc().fIndexSrc) { 3651c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com case kBuffer_GeometrySrcType: 366a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fIndexBuffer = this->getGeomSrc().fIndexBuffer; 367ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com break; 36825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com case kReserved_GeometrySrcType: // fallthrough 36925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com case kArray_GeometrySrcType: { 370ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com size_t indexBytes = (indexCount + startIndex) * sizeof(uint16_t); 37125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fUsedPoolIndexBytes = 37225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrMax(poolState.fUsedPoolIndexBytes, indexBytes); 373a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fIndexBuffer = poolState.fPoolIndexBuffer; 374a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fStartIndex += poolState.fPoolStartIndex; 375ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com break; 37625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com } 3771c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com default: 3781c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com GrCrash("unknown geom src type"); 379ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 380a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fIndexBuffer->ref(); 381ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 382ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 38325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.comvoid GrInOrderDrawBuffer::onDrawNonIndexed(GrPrimitiveType primitiveType, 38425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int startVertex, 38525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount) { 386ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com if (!vertexCount) { 387ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com return; 388ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 389ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 390934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com this->resetDrawTracking(); 39186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 39225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.back(); 393a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com if (this->needsNewClip()) { 394a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com this->recordClip(); 39586afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 396a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com if (this->needsNewState()) { 397a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com this->recordState(); 39886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 399ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 400a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com Draw* draw = this->recordDraw(); 401a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fPrimitiveType = primitiveType; 402a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fStartVertex = startVertex; 403a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fStartIndex = 0; 404a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fVertexCount = vertexCount; 405a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fIndexCount = 0; 406a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com 407a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fVertexLayout = this->getVertexLayout(); 40825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com switch (this->getGeomSrc().fVertexSrc) { 4091c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com case kBuffer_GeometrySrcType: 410a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fVertexBuffer = this->getGeomSrc().fVertexBuffer; 411ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com break; 41225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com case kReserved_GeometrySrcType: // fallthrough 41325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com case kArray_GeometrySrcType: { 414ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com size_t vertexBytes = (vertexCount + startVertex) * 415a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com VertexSize(draw->fVertexLayout); 41625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fUsedPoolVertexBytes = 41725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrMax(poolState.fUsedPoolVertexBytes, vertexBytes); 418a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fVertexBuffer = poolState.fPoolVertexBuffer; 419a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fStartVertex += poolState.fPoolStartVertex; 420ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com break; 42125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com } 4221c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com default: 4231c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com GrCrash("unknown geom src type"); 424ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 425a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fVertexBuffer->ref(); 426a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fIndexBuffer = NULL; 427ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 428ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 42964aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.comvoid GrInOrderDrawBuffer::onStencilPath(const GrPath&, GrPathFill) { 43064aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com GrCrash("Not implemented yet. Should not get here."); 43164aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com} 43264aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com 433c82a8b7aa4ec19fba508c394920a9e88d3e5bd12robertphillips@google.comvoid GrInOrderDrawBuffer::clear(const GrIRect* rect, 434c82a8b7aa4ec19fba508c394920a9e88d3e5bd12robertphillips@google.com GrColor color, 435c82a8b7aa4ec19fba508c394920a9e88d3e5bd12robertphillips@google.com GrRenderTarget* renderTarget) { 4366aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com GrIRect r; 4376aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com if (NULL == rect) { 4386aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com // We could do something smart and remove previous draws and clears to 4396aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com // the current render target. If we get that smart we have to make sure 4406aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com // those draws aren't read before this clear (render-to-texture). 4416aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com r.setLTRB(0, 0, 4428f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com this->getDrawState().getRenderTarget()->width(), 4438f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com this->getDrawState().getRenderTarget()->height()); 4446aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com rect = &r; 4456aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com } 446a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com Clear* clr = this->recordClear(); 447a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com clr->fColor = color; 448a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com clr->fRect = *rect; 449a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com clr->fRenderTarget = renderTarget; 450a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com GrSafeRef(clr->fRenderTarget); 4510b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com} 4520b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com 453ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comvoid GrInOrderDrawBuffer::reset() { 45425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrAssert(1 == fGeoPoolStateStack.count()); 45525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com this->resetVertexSource(); 45625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com this->resetIndexSource(); 45786afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int numDraws = fDraws.count(); 45886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com for (int d = 0; d < numDraws; ++d) { 45986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com // we always have a VB, but not always an IB 46086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com GrAssert(NULL != fDraws[d].fVertexBuffer); 46186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com fDraws[d].fVertexBuffer->unref(); 46286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com GrSafeUnref(fDraws[d].fIndexBuffer); 46386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 464a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com fCmds.reset(); 465ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com fDraws.reset(); 466ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com fStates.reset(); 4670b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com fClears.reset(); 4681c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com fVertexPool.reset(); 4691c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com fIndexPool.reset(); 470ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com fClips.reset(); 471a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com fClipSet = true; 47286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 473934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com this->resetDrawTracking(); 474a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com 475a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com // we start off with a default clip and state so that we don't have 476a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com // to do count checks on fClips, fStates, or fCmds before checking their 477a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com // last entry. 478a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com this->recordDefaultState(); 479a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com this->recordDefaultClip(); 480ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 481ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 482a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.combool GrInOrderDrawBuffer::playback(GrDrawTarget* target) { 48325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc); 48425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrAssert(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc); 4853f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com 486ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com GrAssert(NULL != target); 487ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com GrAssert(target != this); // not considered and why? 488ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 489a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com int numCmds = fCmds.count(); 490a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com GrAssert(numCmds >= 2); 491a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com if (2 == numCmds) { 492a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com GrAssert(kSetState_Cmd == fCmds[0]); 493a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com GrAssert(kSetClip_Cmd == fCmds[1]); 494a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com return false; 495ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 496ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 4971c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com fVertexPool.unlock(); 4981c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com fIndexPool.unlock(); 499ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 500ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com GrDrawTarget::AutoClipRestore acr(target); 50125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com AutoGeometryPush agp(target); 502a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com GrDrawState* prevDrawState = target->drawState(); 503a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com prevDrawState->ref(); 504ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 505a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com int currState = 0; 506a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com int currClip = 0; 5076a77cc5dde4bc01a0a9ba9ac32140146247d113fbsalomon@google.com int currClear = 0; 508a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com int currDraw = 0; 509a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com 510a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com for (int c = 0; c < numCmds; ++c) { 511a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com switch (fCmds[c]) { 512a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com case kDraw_Cmd: { 513a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com const Draw& draw = fDraws[currDraw]; 514a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com target->setVertexSourceToBuffer(draw.fVertexLayout, draw.fVertexBuffer); 515a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com if (draw.fIndexCount) { 516a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com target->setIndexSourceToBuffer(draw.fIndexBuffer); 517a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com } 518ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 519a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com if (draw.fIndexCount) { 520a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com target->drawIndexed(draw.fPrimitiveType, 521a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw.fStartVertex, 522a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw.fStartIndex, 523a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw.fVertexCount, 524a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw.fIndexCount); 525a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com } else { 526a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com target->drawNonIndexed(draw.fPrimitiveType, 527a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw.fStartVertex, 528a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw.fVertexCount); 529a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com } 530a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com ++currDraw; 531a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com break; 532a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com } 533a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com case kSetState_Cmd: 534a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com target->setDrawState(&fStates[currState]); 535a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com ++currState; 536a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com break; 537a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com case kSetClip_Cmd: 538a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com target->setClip(fClips[currClip]); 539a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com ++currClip; 540a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com break; 541a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com case kClear_Cmd: 542a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com target->clear(&fClears[currClear].fRect, 543a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com fClears[currClear].fColor, 544a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com fClears[currClear].fRenderTarget); 545a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com ++currClear; 546a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com break; 547ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 548ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 549a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com // we should have consumed all the states, clips, etc. 550a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com GrAssert(fStates.count() == currState); 551a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com GrAssert(fClips.count() == currClip); 552a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com GrAssert(fClears.count() == currClear); 553a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com GrAssert(fDraws.count() == currDraw); 554a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com 555a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com target->setDrawState(prevDrawState); 556a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com prevDrawState->unref(); 557a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com return true; 558ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 559ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 56097805382d89b717de3355312a79a957ea4a864c9bsalomon@google.comvoid GrInOrderDrawBuffer::setAutoFlushTarget(GrDrawTarget* target) { 56197805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com GrSafeAssign(fAutoFlushTarget, target); 56297805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com} 56397805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com 56497805382d89b717de3355312a79a957ea4a864c9bsalomon@google.comvoid GrInOrderDrawBuffer::willReserveVertexAndIndexSpace( 56597805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com GrVertexLayout vertexLayout, 56697805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com int vertexCount, 56797805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com int indexCount) { 56897805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com if (NULL != fAutoFlushTarget) { 56997805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com // We use geometryHints() to know whether to flush the draw buffer. We 57097805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com // can't flush if we are inside an unbalanced pushGeometrySource. 57197805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com // Moreover, flushing blows away vertex and index data that was 57297805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com // previously reserved. So if the vertex or index data is pulled from 57397805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com // reserved space and won't be released by this request then we can't 57497805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com // flush. 57597805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com bool insideGeoPush = fGeoPoolStateStack.count() > 1; 57697805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com 57797805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com bool unreleasedVertexSpace = 57897805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com !vertexCount && 57997805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc; 58097805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com 58197805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com bool unreleasedIndexSpace = 58297805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com !indexCount && 58397805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc; 58497805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com 58597805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com // we don't want to finalize any reserved geom on the target since 58697805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com // we don't know that the client has finished writing to it. 58797805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com bool targetHasReservedGeom = 58897805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com fAutoFlushTarget->hasReservedVerticesOrIndices(); 58997805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com 59097805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com int vcount = vertexCount; 59197805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com int icount = indexCount; 59297805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com 59397805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com if (!insideGeoPush && 59497805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com !unreleasedVertexSpace && 59597805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com !unreleasedIndexSpace && 59697805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com !targetHasReservedGeom && 59797805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com this->geometryHints(vertexLayout, &vcount, &icount)) { 59897805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com 59997805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com this->flushTo(fAutoFlushTarget); 60097805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com } 60197805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com } 60297805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com} 60397805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com 604ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.combool GrInOrderDrawBuffer::geometryHints(GrVertexLayout vertexLayout, 6051c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com int* vertexCount, 6061c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com int* indexCount) const { 6071c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com // we will recommend a flush if the data could fit in a single 6081c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com // preallocated buffer but none are left and it can't fit 6091c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com // in the current buffer (which may not be prealloced). 610ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com bool flush = false; 611ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com if (NULL != indexCount) { 6121c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com int32_t currIndices = fIndexPool.currentBufferIndices(); 6131c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com if (*indexCount > currIndices && 6141c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com (!fIndexPool.preallocatedBuffersRemaining() && 6151c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com *indexCount <= fIndexPool.preallocatedBufferIndices())) { 6161c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com 6171c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com flush = true; 6181c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com } 6191c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com *indexCount = currIndices; 620ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 621ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com if (NULL != vertexCount) { 6221c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com int32_t currVertices = fVertexPool.currentBufferVertices(vertexLayout); 6231c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com if (*vertexCount > currVertices && 6241c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com (!fVertexPool.preallocatedBuffersRemaining() && 6251c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexLayout))) { 6261c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com 6271c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com flush = true; 628ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 6291c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com *vertexCount = currVertices; 630ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 631ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com return flush; 632ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 633ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 63425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.combool GrInOrderDrawBuffer::onReserveVertexSpace(GrVertexLayout vertexLayout, 63525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 63625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void** vertices) { 63725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.back(); 63825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrAssert(vertexCount > 0); 63925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrAssert(NULL != vertices); 64025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrAssert(0 == poolState.fUsedPoolVertexBytes); 64125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 64225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com *vertices = fVertexPool.makeSpace(vertexLayout, 64325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com vertexCount, 64425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com &poolState.fPoolVertexBuffer, 64525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com &poolState.fPoolStartVertex); 64625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com return NULL != *vertices; 64725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com} 64825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 64925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.combool GrInOrderDrawBuffer::onReserveIndexSpace(int indexCount, void** indices) { 65025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.back(); 65125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrAssert(indexCount > 0); 65225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrAssert(NULL != indices); 65325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrAssert(0 == poolState.fUsedPoolIndexBytes); 65425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 65525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com *indices = fIndexPool.makeSpace(indexCount, 65625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com &poolState.fPoolIndexBuffer, 65725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com &poolState.fPoolStartIndex); 65825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com return NULL != *indices; 659ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 660ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 66125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.comvoid GrInOrderDrawBuffer::releaseReservedVertexSpace() { 66225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.back(); 66325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com const GeometrySrcState& geoSrc = this->getGeomSrc(); 66425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 66525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrAssert(kReserved_GeometrySrcType == geoSrc.fVertexSrc); 6663f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com 6673f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // When the caller reserved vertex buffer space we gave it back a pointer 6683f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // provided by the vertex buffer pool. At each draw we tracked the largest 6693f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // offset into the pool's pointer that was referenced. Now we return to the 6703f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // pool any portion at the tail of the allocation that no draw referenced. 6713f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com size_t reservedVertexBytes = VertexSize(geoSrc.fVertexLayout) * 67225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com geoSrc.fVertexCount; 67325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com fVertexPool.putBack(reservedVertexBytes - 67425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fUsedPoolVertexBytes); 67525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fUsedPoolVertexBytes = 0; 6763f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com poolState.fPoolVertexBuffer = NULL; 6773f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com poolState.fPoolStartVertex = 0; 67825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com} 679ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 68025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.comvoid GrInOrderDrawBuffer::releaseReservedIndexSpace() { 68125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.back(); 68225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com const GeometrySrcState& geoSrc = this->getGeomSrc(); 6831c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com 68425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrAssert(kReserved_GeometrySrcType == geoSrc.fIndexSrc); 6853f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com 6863f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // Similar to releaseReservedVertexSpace we return any unused portion at 6873f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // the tail 68825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com size_t reservedIndexBytes = sizeof(uint16_t) * geoSrc.fIndexCount; 68925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com fIndexPool.putBack(reservedIndexBytes - poolState.fUsedPoolIndexBytes); 69025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fUsedPoolIndexBytes = 0; 6913f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com poolState.fPoolIndexBuffer = NULL; 6923f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com poolState.fPoolStartIndex = 0; 6931c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com} 69425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 695bcdbbe61e1a3f89545b2c1461164f0f8bf5f0797bsalomon@google.comvoid GrInOrderDrawBuffer::onSetVertexSourceToArray(const void* vertexArray, 696bcdbbe61e1a3f89545b2c1461164f0f8bf5f0797bsalomon@google.com int vertexCount) { 69725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 69825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.back(); 69925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrAssert(0 == poolState.fUsedPoolVertexBytes); 7001c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com#if GR_DEBUG 7011c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com bool success = 7021c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com#endif 703e79c815bca39fa552983b7a8107219aa5084acdbbsalomon@google.com fVertexPool.appendVertices(this->getVertexLayout(), 7041c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com vertexCount, 7051c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com vertexArray, 70625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com &poolState.fPoolVertexBuffer, 70725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com &poolState.fPoolStartVertex); 7081c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com GR_DEBUGASSERT(success); 7091c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com} 7101c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com 711bcdbbe61e1a3f89545b2c1461164f0f8bf5f0797bsalomon@google.comvoid GrInOrderDrawBuffer::onSetIndexSourceToArray(const void* indexArray, 712bcdbbe61e1a3f89545b2c1461164f0f8bf5f0797bsalomon@google.com int indexCount) { 71325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.back(); 71425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrAssert(0 == poolState.fUsedPoolIndexBytes); 7151c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com#if GR_DEBUG 7161c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com bool success = 7171c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com#endif 7181c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com fIndexPool.appendIndices(indexCount, 7191c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com indexArray, 72025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com &poolState.fPoolIndexBuffer, 72125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com &poolState.fPoolStartIndex); 7221c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com GR_DEBUGASSERT(success); 723ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 724ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 7253f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.comvoid GrInOrderDrawBuffer::releaseVertexArray() { 7263f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // When the client provides an array as the vertex source we handled it 7273f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // by copying their array into reserved space. 7283f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com this->GrInOrderDrawBuffer::releaseReservedVertexSpace(); 7293f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com} 7303f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com 7313f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.comvoid GrInOrderDrawBuffer::releaseIndexArray() { 7323f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // When the client provides an array as the index source we handled it 7333f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // by copying their array into reserved space. 7343f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com this->GrInOrderDrawBuffer::releaseReservedIndexSpace(); 7353f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com} 7363f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com 73725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.comvoid GrInOrderDrawBuffer::geometrySourceWillPush() { 73825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.push_back(); 73925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fUsedPoolVertexBytes = 0; 74025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fUsedPoolIndexBytes = 0; 741934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com this->resetDrawTracking(); 74225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com#if GR_DEBUG 74325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0; 74425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fPoolStartVertex = ~0; 74525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0; 74625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fPoolStartIndex = ~0; 74725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com#endif 74825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com} 74925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 75025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.comvoid GrInOrderDrawBuffer::geometrySourceWillPop( 75125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com const GeometrySrcState& restoredState) { 75225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrAssert(fGeoPoolStateStack.count() > 1); 75325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com fGeoPoolStateStack.pop_back(); 75425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.back(); 75525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // we have to assume that any slack we had in our vertex/index data 75625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // is now unreleasable because data may have been appended later in the 75725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // pool. 75825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com if (kReserved_GeometrySrcType == restoredState.fVertexSrc || 75925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kArray_GeometrySrcType == restoredState.fVertexSrc) { 76025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fUsedPoolVertexBytes = 76125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com VertexSize(restoredState.fVertexLayout) * 76225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com restoredState.fVertexCount; 76325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com } 76425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com if (kReserved_GeometrySrcType == restoredState.fIndexSrc || 76525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kArray_GeometrySrcType == restoredState.fIndexSrc) { 7663f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com poolState.fUsedPoolIndexBytes = sizeof(uint16_t) * 76725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com restoredState.fIndexCount; 76825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com } 769934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com this->resetDrawTracking(); 77025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com} 77125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 77286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.combool GrInOrderDrawBuffer::needsNewState() const { 773a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com // we should have recorded a default state in reset() 774a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com GrAssert(!fStates.empty()); 775a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com return fStates.back() != this->getDrawState(); 776ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 777ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 77886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.combool GrInOrderDrawBuffer::needsNewClip() const { 7798f9cbd62ec108d410b91155dcf6a4789c641246fbsalomon@google.com if (this->getDrawState().isClipState()) { 780a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com if (fClipSet && fClips.back() != fClip) { 78186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com return true; 78286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 783ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 784ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com return false; 785ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 786d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com 787a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.comvoid GrInOrderDrawBuffer::recordClip() { 78886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com fClips.push_back() = fClip; 78986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com fClipSet = false; 790a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com fCmds.push_back(kSetClip_Cmd); 791a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com} 792a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com 793a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.comvoid GrInOrderDrawBuffer::recordDefaultClip() { 794a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com fClips.push_back() = GrClip(); 795a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com fCmds.push_back(kSetClip_Cmd); 796a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com} 797a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com 798a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.comvoid GrInOrderDrawBuffer::recordState() { 799a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com fStates.push_back(this->getDrawState()); 800a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com fCmds.push_back(kSetState_Cmd); 801a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com} 802a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com 803a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.comvoid GrInOrderDrawBuffer::recordDefaultState() { 804a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com fStates.push_back(GrDrawState()); 805a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com fCmds.push_back(kSetState_Cmd); 806a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com} 807a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com 808a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.comGrInOrderDrawBuffer::Draw* GrInOrderDrawBuffer::recordDraw() { 809a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com fCmds.push_back(kDraw_Cmd); 810a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com return &fDraws.push_back(); 811a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com} 812a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com 813a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.comGrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() { 814a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com fCmds.push_back(kClear_Cmd); 815a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com return &fClears.push_back(); 81686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com} 817d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com 818dea2f8d86378b791a2de94384a18e29f13f65a3ebsalomon@google.comvoid GrInOrderDrawBuffer::clipWillBeSet(const GrClip& newClip) { 819dea2f8d86378b791a2de94384a18e29f13f65a3ebsalomon@google.com INHERITED::clipWillBeSet(newClip); 82086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com fClipSet = true; 821ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 822