GrInOrderDrawBuffer.cpp revision 9b62aa156bcf1db6f11af9302bf8bb8ef2567142
1ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com/* 2ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Copyright 2011 Google Inc. 3ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * 4ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * Use of this source code is governed by a BSD-style license that can be 5ec3ed6a5ebf6f2c406d7bcf94b6bc34fcaeb976eepoger@google.com * found in the LICENSE file. 6ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com */ 7ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 8ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com#include "GrInOrderDrawBuffer.h" 9fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org 101c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com#include "GrBufferAllocPool.h" 11c26d94fd7dc0b00cd6d0e42d28285f4a38aff021bsalomon@google.com#include "GrDrawTargetCaps.h" 12ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com#include "GrGpu.h" 1386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com#include "GrIndexBuffer.h" 14ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com#include "GrPath.h" 15fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org#include "GrPoint.h" 16ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com#include "GrRenderTarget.h" 176e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com#include "GrTemplates.h" 18ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com#include "GrTexture.h" 1986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com#include "GrVertexBuffer.h" 20ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 216e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.comGrInOrderDrawBuffer::GrInOrderDrawBuffer(GrGpu* gpu, 22471d471dcd7422e5dd9c822c1092b2ba4721dcfebsalomon@google.com GrVertexBufferAllocPool* vertexPool, 2325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GrIndexBufferAllocPool* indexPool) 246e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com : GrDrawTarget(gpu->getContext()) 256e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com , fDstGpu(gpu) 2697805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com , fClipSet(true) 27d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com , fClipProxyState(kUnknown_ClipProxyState) 286970557055acaed619d7bb89451868e1570249b2robertphillips@google.com , fVertexPool(*vertexPool) 296970557055acaed619d7bb89451868e1570249b2robertphillips@google.com , fIndexPool(*indexPool) 30a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org , fFlushing(false) 31a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org , fDrawID(0) { 3218c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com 336e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com fDstGpu->ref(); 34bcce8926524827775539874346dd424a9510dbc9bsalomon@google.com fCaps.reset(SkRef(fDstGpu->caps())); 3518c9c198f571997463d9a7134dbd88298e592ec2bsalomon@google.com 36f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(NULL != vertexPool); 37f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(NULL != indexPool); 3825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 3925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.push_back(); 4025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fUsedPoolVertexBytes = 0; 4125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fUsedPoolIndexBytes = 0; 42515dcd36032997ce335daa0163c6d67e851bcad1commit-bot@chromium.org#ifdef SK_DEBUG 4325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0; 4425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fPoolStartVertex = ~0; 4525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0; 4625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fPoolStartIndex = ~0; 4725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com#endif 48a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com this->reset(); 49ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 50ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 51ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comGrInOrderDrawBuffer::~GrInOrderDrawBuffer() { 5286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com this->reset(); 534a018bb20bf969a38ec11d9506843f06366dfa7cbsalomon@google.com // This must be called by before the GrDrawTarget destructor 544a018bb20bf969a38ec11d9506843f06366dfa7cbsalomon@google.com this->releaseGeometry(); 556e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com fDstGpu->unref(); 56ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 57ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 58934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com//////////////////////////////////////////////////////////////////////////////// 59934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 60d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.comnamespace { 61d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.comvoid get_vertex_bounds(const void* vertices, 62d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com size_t vertexSize, 63d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com int vertexCount, 64d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com SkRect* bounds) { 65f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(vertexSize >= sizeof(GrPoint)); 66f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(vertexCount > 0); 67d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com const GrPoint* point = static_cast<const GrPoint*>(vertices); 68d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com bounds->fLeft = bounds->fRight = point->fX; 69d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com bounds->fTop = bounds->fBottom = point->fY; 70d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com for (int i = 1; i < vertexCount; ++i) { 71d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com point = reinterpret_cast<GrPoint*>(reinterpret_cast<intptr_t>(point) + vertexSize); 72d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com bounds->growToInclude(point->fX, point->fY); 73d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 74d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com} 75934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com} 76934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 779b855c7c95ce9fff7a447e4a6bdf8a469c1f3097jvanverth@google.com 78429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.comnamespace { 799b855c7c95ce9fff7a447e4a6bdf8a469c1f3097jvanverth@google.com 80429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.comextern const GrVertexAttrib kRectPosColorUVAttribs[] = { 81429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, 82429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com {kVec4ub_GrVertexAttribType, sizeof(GrPoint), kColor_GrVertexAttribBinding}, 83c9f3b38f67893b22c3e02a6a934bc676e36c5cfcrmistry@google.com {kVec2f_GrVertexAttribType, sizeof(GrPoint)+sizeof(GrColor), 84429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com kLocalCoord_GrVertexAttribBinding}, 85429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com}; 869b855c7c95ce9fff7a447e4a6bdf8a469c1f3097jvanverth@google.com 87429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.comextern const GrVertexAttrib kRectPosUVAttribs[] = { 88429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com {kVec2f_GrVertexAttribType, 0, kPosition_GrVertexAttribBinding}, 89429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com {kVec2f_GrVertexAttribType, sizeof(GrPoint), kLocalCoord_GrVertexAttribBinding}, 90429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com}; 91054ae99d93711c26e40682a0e3a03a47ea605c53jvanverth@google.com 92429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.comstatic void set_vertex_attributes(GrDrawState* drawState, 93429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com bool hasColor, bool hasUVs, 94429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com int* colorOffset, int* localOffset) { 95429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com *colorOffset = -1; 96429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com *localOffset = -1; 97d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 98d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // Using per-vertex colors allows batching across colors. (A lot of rects in a row differing 99d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // only in color is a common occurrence in tables). However, having per-vertex colors disables 100d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // blending optimizations because we don't know if the color will be solid or not. These 101d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // optimizations help determine whether coverage and color can be blended correctly when 102d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // dual-source blending isn't available. This comes into play when there is coverage. If colors 103d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // were a stage it could take a hint that every vertex's color will be opaque. 104429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com if (hasColor && hasUVs) { 105429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com *colorOffset = sizeof(GrPoint); 106429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com *localOffset = sizeof(GrPoint) + sizeof(GrColor); 107429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com drawState->setVertexAttribs<kRectPosColorUVAttribs>(3); 108429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com } else if (hasColor) { 109429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com *colorOffset = sizeof(GrPoint); 110429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com drawState->setVertexAttribs<kRectPosColorUVAttribs>(2); 111429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com } else if (hasUVs) { 112429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com *localOffset = sizeof(GrPoint); 113429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com drawState->setVertexAttribs<kRectPosUVAttribs>(2); 114429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com } else { 115429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com drawState->setVertexAttribs<kRectPosUVAttribs>(1); 116429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com } 117429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com} 118429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com 119429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com}; 120429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com 121fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.orgvoid GrInOrderDrawBuffer::onDrawRect(const SkRect& rect, 122429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com const SkMatrix* matrix, 123fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org const SkRect* localRect, 124429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com const SkMatrix* localMatrix) { 125429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com GrDrawState::AutoColorRestore acr; 126429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com 127429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com GrDrawState* drawState = this->drawState(); 128429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com 129429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com GrColor color = drawState->getColor(); 130429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com 131429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com int colorOffset, localOffset; 132429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com set_vertex_attributes(drawState, 133429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com this->caps()->dualSourceBlendingSupport() || drawState->hasSolidCoverage(), 134429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com NULL != localRect, 135429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com &colorOffset, &localOffset); 136429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com if (colorOffset >= 0) { 137d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // We set the draw state's color to white here. This is done so that any batching performed 138d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // in our subclass's onDraw() won't get a false from GrDrawState::op== due to a color 139d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // mismatch. TODO: Once vertex layout is owned by GrDrawState it should skip comparing the 140c9f3b38f67893b22c3e02a6a934bc676e36c5cfcrmistry@google.com // constant color in its op== when the kColor layout bit is set and then we can remove 141429033038271147ed66b4bc2675ac98a5ccfa75crobertphillips@google.com // this. 1429b855c7c95ce9fff7a447e4a6bdf8a469c1f3097jvanverth@google.com acr.set(drawState, 0xFFFFFFFF); 143d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 144d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 145b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com AutoReleaseGeometry geo(this, 4, 0); 146d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com if (!geo.succeeded()) { 147d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com GrPrintf("Failed to get space for vertices!\n"); 148d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com return; 149d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 1508b129aa3379ece6c43d9ce2ad0cdeafb089b7eb5robertphillips@google.com 151d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // Go to device coords to allow batching across matrix changes 152d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com SkMatrix combinedMatrix; 153d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com if (NULL != matrix) { 154d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com combinedMatrix = *matrix; 155d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } else { 156d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com combinedMatrix.reset(); 157d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 1589b855c7c95ce9fff7a447e4a6bdf8a469c1f3097jvanverth@google.com combinedMatrix.postConcat(drawState->getViewMatrix()); 1593976825a21532e254311b90b4a9046e25717e335jvanverth@google.com // When the caller has provided an explicit source rect for a stage then we don't want to 160d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // modify that stage's matrix. Otherwise if the effect is generating its source rect from 161d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // the vertex positions then we have to account for the view matrix change. 162137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com GrDrawState::AutoViewMatrixRestore avmr; 163137f1347abaf0bb6a945e91c2f6cb49f0ee69bc3bsalomon@google.com if (!avmr.setIdentity(drawState)) { 164d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com return; 165d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 166d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 1679b855c7c95ce9fff7a447e4a6bdf8a469c1f3097jvanverth@google.com size_t vsize = drawState->getVertexSize(); 168d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 169d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vsize); 170d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com combinedMatrix.mapPointsWithStride(geo.positions(), vsize, 4); 171d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 172d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com SkRect devBounds; 173d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // since we already computed the dev verts, set the bounds hint. This will help us avoid 174d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // unnecessary clipping in our onDraw(). 175d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com get_vertex_bounds(geo.vertices(), vsize, 4, &devBounds); 176d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 177c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com if (localOffset >= 0) { 178c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com GrPoint* coords = GrTCast<GrPoint*>(GrTCast<intptr_t>(geo.vertices()) + localOffset); 179c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com coords->setRectFan(localRect->fLeft, localRect->fTop, 180c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com localRect->fRight, localRect->fBottom, 1819b855c7c95ce9fff7a447e4a6bdf8a469c1f3097jvanverth@google.com vsize); 182c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com if (NULL != localMatrix) { 183c78188896e28a4ae49e406a7422b345ae177dafebsalomon@google.com localMatrix->mapPointsWithStride(coords, vsize, 4); 184e3d3216fe17b6afb2e613271b5246a2766e12df6bsalomon@google.com } 185d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 18686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 187d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com if (colorOffset >= 0) { 188d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + colorOffset); 189d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com for (int i = 0; i < 4; ++i) { 190d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com *vertColor = color; 191d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com vertColor = (GrColor*) ((intptr_t) vertColor + vsize); 192d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 193d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 194d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com 1956e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com this->setIndexSourceToBuffer(this->getContext()->getQuadIndexBuffer()); 196d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com this->drawIndexedInstances(kTriangles_GrPrimitiveType, 1, 4, 6, &devBounds); 1979b855c7c95ce9fff7a447e4a6bdf8a469c1f3097jvanverth@google.com 1989b855c7c95ce9fff7a447e4a6bdf8a469c1f3097jvanverth@google.com // to ensure that stashing the drawState ptr is valid 199f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(this->drawState() == drawState); 200d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com} 201fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 202d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.combool GrInOrderDrawBuffer::quickInsideClip(const SkRect& devBounds) { 203d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com if (!this->getDrawState().isClipState()) { 204d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com return true; 205d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 206d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com if (kUnknown_ClipProxyState == fClipProxyState) { 207d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com SkIRect rect; 208d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com bool iior; 209d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com this->getClip()->getConservativeBounds(this->getDrawState().getRenderTarget(), &rect, &iior); 210d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com if (iior) { 211d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // The clip is a rect. We will remember that in fProxyClip. It is common for an edge (or 212d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // all edges) of the clip to be at the edge of the RT. However, we get that clipping for 213d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // free via the viewport. We don't want to think that clipping must be enabled in this 214d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // case. So we extend the clip outward from the edge to avoid these false negatives. 215d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com fClipProxyState = kValid_ClipProxyState; 2164469938e92d779dff05e745559e67907bbf21e78reed@google.com fClipProxy = SkRect::Make(rect); 217d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 218d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com if (fClipProxy.fLeft <= 0) { 219d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com fClipProxy.fLeft = SK_ScalarMin; 22086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 221d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com if (fClipProxy.fTop <= 0) { 222d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com fClipProxy.fTop = SK_ScalarMin; 22386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 224d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com if (fClipProxy.fRight >= this->getDrawState().getRenderTarget()->width()) { 225d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com fClipProxy.fRight = SK_ScalarMax; 226d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 227d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com if (fClipProxy.fBottom >= this->getDrawState().getRenderTarget()->height()) { 228d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com fClipProxy.fBottom = SK_ScalarMax; 229d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 230d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } else { 231d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com fClipProxyState = kInvalid_ClipProxyState; 23286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 23386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 234d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com if (kValid_ClipProxyState == fClipProxyState) { 235d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com return fClipProxy.contains(devBounds); 236d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 237d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com SkPoint originOffset = {SkIntToScalar(this->getClip()->fOrigin.fX), 238d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com SkIntToScalar(this->getClip()->fOrigin.fY)}; 239d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com SkRect clipSpaceBounds = devBounds; 240d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com clipSpaceBounds.offset(originOffset); 241d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com return this->getClip()->fClipStack->quickContains(clipSpaceBounds); 24286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com} 24386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com 244d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.comint GrInOrderDrawBuffer::concatInstancedDraw(const DrawInfo& info) { 245f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(info.isInstanced()); 246934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 247934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com const GeometrySrcState& geomSrc = this->getGeomSrc(); 248b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com const GrDrawState& drawState = this->getDrawState(); 249934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 250d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // we only attempt to concat the case when reserved verts are used with a client-specified index 251d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // buffer. To make this work with client-specified VBs we'd need to know if the VB was updated 252d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // between draws. 253d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com if (kReserved_GeometrySrcType != geomSrc.fVertexSrc || 254d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com kBuffer_GeometrySrcType != geomSrc.fIndexSrc) { 255d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com return 0; 256d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 257d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // Check if there is a draw info that is compatible that uses the same VB from the pool and 258d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // the same IB 259d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com if (kDraw_Cmd != fCmds.back()) { 260d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com return 0; 261d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 262934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 263d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com DrawRecord* draw = &fDraws.back(); 264d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.back(); 265d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com const GrVertexBuffer* vertexBuffer = poolState.fPoolVertexBuffer; 266d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 267d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com if (!draw->isInstanced() || 268d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com draw->verticesPerInstance() != info.verticesPerInstance() || 269d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com draw->indicesPerInstance() != info.indicesPerInstance() || 270d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com draw->fVertexBuffer != vertexBuffer || 271b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com draw->fIndexBuffer != geomSrc.fIndexBuffer) { 272d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com return 0; 273d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 274d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // info does not yet account for the offset from the start of the pool's VB while the previous 275d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // draw record does. 276d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com int adjustedStartVertex = poolState.fPoolStartVertex + info.startVertex(); 277d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com if (draw->startVertex() + draw->vertexCount() != adjustedStartVertex) { 278d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com return 0; 279d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 280a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com 281f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(poolState.fPoolStartVertex == draw->startVertex() + draw->vertexCount()); 282934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 283d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // how many instances can be concat'ed onto draw given the size of the index buffer 284d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerInstance(); 285d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com instancesToConcat -= draw->instanceCount(); 286d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com instancesToConcat = GrMin(instancesToConcat, info.instanceCount()); 287934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 288d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com // update the amount of reserved vertex data actually referenced in draws 289ae683921ffda9108147a29da7319c7eee4dc9245skia.committer@gmail.com size_t vertexBytes = instancesToConcat * info.verticesPerInstance() * 290b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com drawState.getVertexSize(); 291d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes); 292934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 293d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com draw->adjustInstanceCount(instancesToConcat); 294d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com return instancesToConcat; 295d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com} 296934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 297d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.comclass AutoClipReenable { 298d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.compublic: 299d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com AutoClipReenable() : fDrawState(NULL) {} 300d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com ~AutoClipReenable() { 301d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com if (NULL != fDrawState) { 302d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com fDrawState->enableState(GrDrawState::kClip_StateBit); 303d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 304934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com } 305d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com void set(GrDrawState* drawState) { 306d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com if (drawState->isClipState()) { 307d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com fDrawState = drawState; 308d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com drawState->disableState(GrDrawState::kClip_StateBit); 309d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 310d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 311d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.comprivate: 312d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com GrDrawState* fDrawState; 313d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com}; 314934c570297c1b1f99cb4ca8d012d468a7eddf73fbsalomon@google.com 31574749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.comvoid GrInOrderDrawBuffer::onDraw(const DrawInfo& info) { 316ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 31725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.back(); 318b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com const GrDrawState& drawState = this->getDrawState(); 319d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com AutoClipReenable acr; 320d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com 321b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com if (drawState.isClipState() && 322d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com NULL != info.getDevBounds() && 323d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com this->quickInsideClip(*info.getDevBounds())) { 324d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com acr.set(this->drawState()); 325d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 32625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 327a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com if (this->needsNewClip()) { 328a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com this->recordClip(); 32986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 330a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com if (this->needsNewState()) { 331a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com this->recordState(); 33286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 333ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 334d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com DrawRecord* draw; 335d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com if (info.isInstanced()) { 336d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com int instancesConcated = this->concatInstancedDraw(info); 337d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com if (info.instanceCount() > instancesConcated) { 338d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com draw = this->recordDraw(info); 339d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com draw->adjustInstanceCount(-instancesConcated); 340d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } else { 341d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com return; 342d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 343d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } else { 344d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com draw = this->recordDraw(info); 345d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com } 34674749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com 34725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com switch (this->getGeomSrc().fVertexSrc) { 34874749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com case kBuffer_GeometrySrcType: 34974749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com draw->fVertexBuffer = this->getGeomSrc().fVertexBuffer; 35074749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com break; 35174749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com case kReserved_GeometrySrcType: // fallthrough 35274749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com case kArray_GeometrySrcType: { 353ae683921ffda9108147a29da7319c7eee4dc9245skia.committer@gmail.com size_t vertexBytes = (info.vertexCount() + info.startVertex()) * 354b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com drawState.getVertexSize(); 35574749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com poolState.fUsedPoolVertexBytes = GrMax(poolState.fUsedPoolVertexBytes, vertexBytes); 35674749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com draw->fVertexBuffer = poolState.fPoolVertexBuffer; 357d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com draw->adjustStartVertex(poolState.fPoolStartVertex); 35874749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com break; 35974749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com } 36074749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com default: 36174749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com GrCrash("unknown geom src type"); 362ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 363a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com draw->fVertexBuffer->ref(); 364ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 36574749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com if (info.isIndexed()) { 36674749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com switch (this->getGeomSrc().fIndexSrc) { 36774749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com case kBuffer_GeometrySrcType: 36874749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com draw->fIndexBuffer = this->getGeomSrc().fIndexBuffer; 36974749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com break; 37074749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com case kReserved_GeometrySrcType: // fallthrough 37174749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com case kArray_GeometrySrcType: { 37274749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com size_t indexBytes = (info.indexCount() + info.startIndex()) * sizeof(uint16_t); 37374749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com poolState.fUsedPoolIndexBytes = GrMax(poolState.fUsedPoolIndexBytes, indexBytes); 37474749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com draw->fIndexBuffer = poolState.fPoolIndexBuffer; 375d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com draw->adjustStartIndex(poolState.fPoolStartIndex); 37674749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com break; 37774749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com } 37874749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com default: 37974749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com GrCrash("unknown geom src type"); 38074749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com } 38174749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com draw->fIndexBuffer->ref(); 38274749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com } else { 38374749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com draw->fIndexBuffer = NULL; 384ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 385ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 386ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 38732184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.orgGrInOrderDrawBuffer::StencilPath::StencilPath() {} 38832184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.orgGrInOrderDrawBuffer::DrawPath::DrawPath() {} 3899b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.orgGrInOrderDrawBuffer::DrawPaths::DrawPaths() {} 3909b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.orgGrInOrderDrawBuffer::DrawPaths::~DrawPaths() { 3919b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org if (fTransforms) { 3929b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org SkDELETE_ARRAY(fTransforms); 3939b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org } 3949b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org for (size_t i = 0; i < fPathCount; ++i) { 3959b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org fPaths[i]->unref(); 3969b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org } 3979b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org SkDELETE_ARRAY(fPaths); 3989b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org} 3995f74cf8c49701f514b69dc6f1a8b5c0ffd78af0asugoi@google.com 40032184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.orgvoid GrInOrderDrawBuffer::onStencilPath(const GrPath* path, SkPath::FillType fill) { 401ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com if (this->needsNewClip()) { 402ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com this->recordClip(); 403ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com } 404ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com // Only compare the subset of GrDrawState relevant to path stenciling? 405ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com if (this->needsNewState()) { 406ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com this->recordState(); 407ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com } 408ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com StencilPath* sp = this->recordStencilPath(); 409ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com sp->fPath.reset(path); 410ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com path->ref(); 411ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com sp->fFill = fill; 41264aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com} 41364aef2bacd1f5c25ffd9347aabd6265c9b60c0f4bsalomon@google.com 41432184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.orgvoid GrInOrderDrawBuffer::onDrawPath(const GrPath* path, 415c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org SkPath::FillType fill, const GrDeviceCoordTexture* dstCopy) { 416c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org if (this->needsNewClip()) { 417c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org this->recordClip(); 418c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org } 419c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org // TODO: Only compare the subset of GrDrawState relevant to path covering? 420c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org if (this->needsNewState()) { 421c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org this->recordState(); 422c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org } 42332184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.org DrawPath* cp = this->recordDrawPath(); 424c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org cp->fPath.reset(path); 425c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org path->ref(); 426c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org cp->fFill = fill; 427c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org if (NULL != dstCopy) { 428c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org cp->fDstCopy = *dstCopy; 429c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org } 430c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org} 431c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org 4329b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.orgvoid GrInOrderDrawBuffer::onDrawPaths(size_t pathCount, const GrPath** paths, 4339b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org const SkMatrix* transforms, 4349b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org SkPath::FillType fill, 4359b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org SkStrokeRec::Style stroke, 4369b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org const GrDeviceCoordTexture* dstCopy) { 4379b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org SkASSERT(pathCount); 4389b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org 4399b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org if (this->needsNewClip()) { 4409b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org this->recordClip(); 4419b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org } 4429b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org if (this->needsNewState()) { 4439b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org this->recordState(); 4449b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org } 4459b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org DrawPaths* dp = this->recordDrawPaths(); 4469b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org dp->fPathCount = pathCount; 4479b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org dp->fPaths = SkNEW_ARRAY(const GrPath*, pathCount); 4489b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org memcpy(dp->fPaths, paths, sizeof(GrPath*) * pathCount); 4499b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org for (size_t i = 0; i < pathCount; ++i) { 4509b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org dp->fPaths[i]->ref(); 4519b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org } 4529b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org 4539b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org dp->fTransforms = SkNEW_ARRAY(SkMatrix, pathCount); 4549b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org memcpy(dp->fTransforms, transforms, sizeof(SkMatrix) * pathCount); 4559b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org 4569b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org dp->fFill = fill; 4579b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org dp->fStroke = stroke; 4589b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org 4599b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org if (NULL != dstCopy) { 4609b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org dp->fDstCopy = *dstCopy; 4619b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org } 4629b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org} 4639b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org 46418bb41e9563748fbde07c1540da9314cbb7d1dc8skia.committer@gmail.comvoid GrInOrderDrawBuffer::clear(const SkIRect* rect, GrColor color, 46556ce48ade325f6f49acb0da31d6252806e4ed7efrobertphillips@google.com bool canIgnoreRect, GrRenderTarget* renderTarget) { 466fd03d4a829efe2d77a712fd991927c55f59a2ffecommit-bot@chromium.org SkIRect r; 4671b3ce47c7b6c14c84d7aaee249b33f9d3b473050bsalomon@google.com if (NULL == renderTarget) { 4681b3ce47c7b6c14c84d7aaee249b33f9d3b473050bsalomon@google.com renderTarget = this->drawState()->getRenderTarget(); 469f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(NULL != renderTarget); 4701b3ce47c7b6c14c84d7aaee249b33f9d3b473050bsalomon@google.com } 4716aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com if (NULL == rect) { 4726aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com // We could do something smart and remove previous draws and clears to 4736aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com // the current render target. If we get that smart we have to make sure 4746aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com // those draws aren't read before this clear (render-to-texture). 4751b3ce47c7b6c14c84d7aaee249b33f9d3b473050bsalomon@google.com r.setLTRB(0, 0, renderTarget->width(), renderTarget->height()); 4766aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com rect = &r; 4776aa25c3f555dc2a6711365d14279db3ec909e064bsalomon@google.com } 478a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com Clear* clr = this->recordClear(); 479a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com clr->fColor = color; 480a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com clr->fRect = *rect; 48156ce48ade325f6f49acb0da31d6252806e4ed7efrobertphillips@google.com clr->fCanIgnoreRect = canIgnoreRect; 482a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com clr->fRenderTarget = renderTarget; 4831b3ce47c7b6c14c84d7aaee249b33f9d3b473050bsalomon@google.com renderTarget->ref(); 4840b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com} 4850b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com 486a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.orgvoid GrInOrderDrawBuffer::onInstantGpuTraceEvent(const char* marker) { 487a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org // TODO: adds command to buffer 488a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org} 489a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org 490a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.orgvoid GrInOrderDrawBuffer::onPushGpuTraceEvent(const char* marker) { 491a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org // TODO: adds command to buffer 492a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org} 493a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org 494a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.orgvoid GrInOrderDrawBuffer::onPopGpuTraceEvent() { 495a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org // TODO: adds command to buffer 496a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org} 497a3baf3be0e2a3128fb73bd41d40d130f75a4dc86commit-bot@chromium.org 498ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.comvoid GrInOrderDrawBuffer::reset() { 499f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(1 == fGeoPoolStateStack.count()); 50025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com this->resetVertexSource(); 50125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com this->resetIndexSource(); 50286afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com int numDraws = fDraws.count(); 50386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com for (int d = 0; d < numDraws; ++d) { 50486afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com // we always have a VB, but not always an IB 505f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(NULL != fDraws[d].fVertexBuffer); 50686afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com fDraws[d].fVertexBuffer->unref(); 507a4de8c257ea0be8ff7081f645249b6afe5c48e7ecommit-bot@chromium.org SkSafeUnref(fDraws[d].fIndexBuffer); 50886afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 509a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com fCmds.reset(); 510ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com fDraws.reset(); 511ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com fStencilPaths.reset(); 5129b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org fDrawPath.reset(); 51332184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.org fDrawPaths.reset(); 514ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com fStates.reset(); 5150b335c1ac100aeacf79a4c98a052286fd46661e7bsalomon@google.com fClears.reset(); 5161c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com fVertexPool.reset(); 5171c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com fIndexPool.reset(); 518ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com fClips.reset(); 519beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com fClipOrigins.reset(); 520116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com fCopySurfaces.reset(); 521a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com fClipSet = true; 522ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 523ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 5241267fbd95290f58443652ca8d947bde50b212618robertphillips@google.comvoid GrInOrderDrawBuffer::flush() { 5251267fbd95290f58443652ca8d947bde50b212618robertphillips@google.com if (fFlushing) { 5261267fbd95290f58443652ca8d947bde50b212618robertphillips@google.com return; 5271267fbd95290f58443652ca8d947bde50b212618robertphillips@google.com } 5281267fbd95290f58443652ca8d947bde50b212618robertphillips@google.com 529f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(kReserved_GeometrySrcType != this->getGeomSrc().fVertexSrc); 530f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(kReserved_GeometrySrcType != this->getGeomSrc().fIndexSrc); 5313f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com 532a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com int numCmds = fCmds.count(); 533358e427763f0971af436f07170c641f747b94595bsalomon@google.com if (0 == numCmds) { 5341267fbd95290f58443652ca8d947bde50b212618robertphillips@google.com return; 535ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 5366e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com 5376e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com GrAutoTRestore<bool> flushRestore(&fFlushing); 5386e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com fFlushing = true; 539ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 5401c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com fVertexPool.unlock(); 5411c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com fIndexPool.unlock(); 542ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 5436e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com GrDrawTarget::AutoClipRestore acr(fDstGpu); 5446e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com AutoGeometryAndStatePush agasp(fDstGpu, kPreserve_ASRInit); 545ca43208e4aaac817fbc8265542f995f24a3fb7bfbsalomon@google.com 546ca43208e4aaac817fbc8265542f995f24a3fb7bfbsalomon@google.com GrDrawState playbackState; 5476e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com GrDrawState* prevDrawState = fDstGpu->drawState(); 548a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com prevDrawState->ref(); 5496e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com fDstGpu->setDrawState(&playbackState); 550ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 551beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com GrClipData clipData; 552beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com 553ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com int currState = 0; 554ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com int currClip = 0; 555ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com int currClear = 0; 556ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com int currDraw = 0; 557ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com int currStencilPath = 0; 55832184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.org int currDrawPath = 0; 5599b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org int currDrawPaths = 0; 560116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com int currCopySurface = 0; 561a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com 562a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com for (int c = 0; c < numCmds; ++c) { 563a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com switch (fCmds[c]) { 564a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com case kDraw_Cmd: { 56574749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com const DrawRecord& draw = fDraws[currDraw]; 5666e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com fDstGpu->setVertexSourceToBuffer(draw.fVertexBuffer); 567d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com if (draw.isIndexed()) { 5686e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com fDstGpu->setIndexSourceToBuffer(draw.fIndexBuffer); 569a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com } 5706e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com fDstGpu->executeDraw(draw); 571ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 572a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com ++currDraw; 573a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com break; 574a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com } 575ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com case kStencilPath_Cmd: { 576ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com const StencilPath& sp = fStencilPaths[currStencilPath]; 57732184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.org fDstGpu->stencilPath(sp.fPath.get(), sp.fFill); 578ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com ++currStencilPath; 579ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com break; 580ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com } 58132184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.org case kDrawPath_Cmd: { 5829b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org const DrawPath& cp = fDrawPath[currDrawPath]; 58332184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.org fDstGpu->executeDrawPath(cp.fPath.get(), cp.fFill, 584c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org NULL != cp.fDstCopy.texture() ? &cp.fDstCopy : NULL); 58532184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.org ++currDrawPath; 586c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org break; 587c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org } 5889b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org case kDrawPaths_Cmd: { 5899b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org DrawPaths& dp = fDrawPaths[currDrawPaths]; 5909b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org const GrDeviceCoordTexture* dstCopy = 5919b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org NULL != dp.fDstCopy.texture() ? &dp.fDstCopy : NULL; 5929b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org fDstGpu->executeDrawPaths(dp.fPathCount, dp.fPaths, 5939b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org dp.fTransforms, dp.fFill, dp.fStroke, 5949b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org dstCopy); 5959b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org ++currDrawPaths; 5969b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org break; 5979b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org } 598a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com case kSetState_Cmd: 599ca43208e4aaac817fbc8265542f995f24a3fb7bfbsalomon@google.com fStates[currState].restoreTo(&playbackState); 600a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com ++currState; 601a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com break; 602a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com case kSetClip_Cmd: 603beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com clipData.fClipStack = &fClips[currClip]; 604beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com clipData.fOrigin = fClipOrigins[currClip]; 6056e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com fDstGpu->setClip(&clipData); 606a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com ++currClip; 607a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com break; 608a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com case kClear_Cmd: 6096e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com fDstGpu->clear(&fClears[currClear].fRect, 6106e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com fClears[currClear].fColor, 61156ce48ade325f6f49acb0da31d6252806e4ed7efrobertphillips@google.com fClears[currClear].fCanIgnoreRect, 6126e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com fClears[currClear].fRenderTarget); 613a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com ++currClear; 614a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com break; 615116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com case kCopySurface_Cmd: 616116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com fDstGpu->copySurface(fCopySurfaces[currCopySurface].fDst.get(), 617116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com fCopySurfaces[currCopySurface].fSrc.get(), 618116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com fCopySurfaces[currCopySurface].fSrcRect, 619116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com fCopySurfaces[currCopySurface].fDstPoint); 620116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com ++currCopySurface; 621116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com break; 622ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 623ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 624a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com // we should have consumed all the states, clips, etc. 625f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(fStates.count() == currState); 626f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(fClips.count() == currClip); 627f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(fClipOrigins.count() == currClip); 628f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(fClears.count() == currClear); 629f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(fDraws.count() == currDraw); 630f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(fCopySurfaces.count() == currCopySurface); 631a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com 6326e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com fDstGpu->setDrawState(prevDrawState); 633a5d056ae0b04021dfb44c2c7a3d6a34e060261b8bsalomon@google.com prevDrawState->unref(); 63455e4a2005eae1e4f677ec145c577c615a63cf05dbsalomon@google.com this->reset(); 635a8916ffd90c04dc6cc1fb9ba94af2ff950284fadcommit-bot@chromium.org ++fDrawID; 636ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 637ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 638116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.combool GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, 639116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com GrSurface* src, 640116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com const SkIRect& srcRect, 641116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com const SkIPoint& dstPoint) { 642116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com if (fDstGpu->canCopySurface(dst, src, srcRect, dstPoint)) { 643116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com CopySurface* cs = this->recordCopySurface(); 644116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com cs->fDst.reset(SkRef(dst)); 645116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com cs->fSrc.reset(SkRef(src)); 646116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com cs->fSrcRect = srcRect; 647116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com cs->fDstPoint = dstPoint; 648116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com return true; 649116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com } else { 650116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com return false; 651116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com } 652116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com} 653116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com 654116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.combool GrInOrderDrawBuffer::onCanCopySurface(GrSurface* dst, 655116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com GrSurface* src, 656116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com const SkIRect& srcRect, 657116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com const SkIPoint& dstPoint) { 658116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com return fDstGpu->canCopySurface(dst, src, srcRect, dstPoint); 659116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com} 660116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com 661eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.comvoid GrInOrderDrawBuffer::initCopySurfaceDstDesc(const GrSurface* src, GrTextureDesc* desc) { 662eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com fDstGpu->initCopySurfaceDstDesc(src, desc); 663eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com} 664eb85117c05471e1a55ce387cbc38279f857a4584bsalomon@google.com 6659528bdb0dccee915505bcf99cb10659f85e2604brobertphillips@google.comvoid GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(int vertexCount, 6669528bdb0dccee915505bcf99cb10659f85e2604brobertphillips@google.com int indexCount) { 6676e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com // We use geometryHints() to know whether to flush the draw buffer. We 6686e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com // can't flush if we are inside an unbalanced pushGeometrySource. 6696e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com // Moreover, flushing blows away vertex and index data that was 6706e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com // previously reserved. So if the vertex or index data is pulled from 6716e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com // reserved space and won't be released by this request then we can't 6726e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com // flush. 6736e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com bool insideGeoPush = fGeoPoolStateStack.count() > 1; 6746e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com 6756e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com bool unreleasedVertexSpace = 6766e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com !vertexCount && 6776e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com kReserved_GeometrySrcType == this->getGeomSrc().fVertexSrc; 6786e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com 6796e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com bool unreleasedIndexSpace = 6806e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com !indexCount && 6816e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com kReserved_GeometrySrcType == this->getGeomSrc().fIndexSrc; 6826e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com 6836e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com // we don't want to finalize any reserved geom on the target since 6846e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com // we don't know that the client has finished writing to it. 6856e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com bool targetHasReservedGeom = fDstGpu->hasReservedVerticesOrIndices(); 6866e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com 6876e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com int vcount = vertexCount; 6886e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com int icount = indexCount; 6896e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com 6906e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com if (!insideGeoPush && 6916e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com !unreleasedVertexSpace && 6926e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com !unreleasedIndexSpace && 6936e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com !targetHasReservedGeom && 6946e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com this->geometryHints(&vcount, &icount)) { 6956e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com 6966e4e65066a7c0dbc9bfbfe4b8f5d49c3d8a79b59bsalomon@google.com this->flush(); 69797805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com } 69897805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com} 69997805382d89b717de3355312a79a957ea4a864c9bsalomon@google.com 700b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.combool GrInOrderDrawBuffer::geometryHints(int* vertexCount, 7011c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com int* indexCount) const { 7021c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com // we will recommend a flush if the data could fit in a single 7031c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com // preallocated buffer but none are left and it can't fit 7041c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com // in the current buffer (which may not be prealloced). 705ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com bool flush = false; 706ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com if (NULL != indexCount) { 7071c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com int32_t currIndices = fIndexPool.currentBufferIndices(); 7081c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com if (*indexCount > currIndices && 7091c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com (!fIndexPool.preallocatedBuffersRemaining() && 7101c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com *indexCount <= fIndexPool.preallocatedBufferIndices())) { 7111c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com 7121c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com flush = true; 7131c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com } 7141c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com *indexCount = currIndices; 715ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 716ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com if (NULL != vertexCount) { 717b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com size_t vertexSize = this->getDrawState().getVertexSize(); 718a63389843dd18003382d61c2e4610af09ed07d38jvanverth@google.com int32_t currVertices = fVertexPool.currentBufferVertices(vertexSize); 7191c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com if (*vertexCount > currVertices && 7201c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com (!fVertexPool.preallocatedBuffersRemaining() && 721a63389843dd18003382d61c2e4610af09ed07d38jvanverth@google.com *vertexCount <= fVertexPool.preallocatedBufferVertices(vertexSize))) { 7221c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com 7231c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com flush = true; 724ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 7251c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com *vertexCount = currVertices; 726ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 727ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com return flush; 728ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 729ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 730a63389843dd18003382d61c2e4610af09ed07d38jvanverth@google.combool GrInOrderDrawBuffer::onReserveVertexSpace(size_t vertexSize, 73125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com int vertexCount, 73225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com void** vertices) { 73325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.back(); 734f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(vertexCount > 0); 735f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(NULL != vertices); 736f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(0 == poolState.fUsedPoolVertexBytes); 737fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 738a63389843dd18003382d61c2e4610af09ed07d38jvanverth@google.com *vertices = fVertexPool.makeSpace(vertexSize, 73925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com vertexCount, 74025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com &poolState.fPoolVertexBuffer, 74125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com &poolState.fPoolStartVertex); 74225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com return NULL != *vertices; 74325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com} 744fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 74525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.combool GrInOrderDrawBuffer::onReserveIndexSpace(int indexCount, void** indices) { 74625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.back(); 747f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(indexCount > 0); 748f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(NULL != indices); 749f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(0 == poolState.fUsedPoolIndexBytes); 75025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 75125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com *indices = fIndexPool.makeSpace(indexCount, 75225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com &poolState.fPoolIndexBuffer, 75325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com &poolState.fPoolStartIndex); 75425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com return NULL != *indices; 755ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 756ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 75725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.comvoid GrInOrderDrawBuffer::releaseReservedVertexSpace() { 75825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.back(); 759fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com const GeometrySrcState& geoSrc = this->getGeomSrc(); 760d57d71a5b857c273d9cf834856e10e663c1ccb91bsalomon@google.com 761d57d71a5b857c273d9cf834856e10e663c1ccb91bsalomon@google.com // If we get a release vertex space call then our current source should either be reserved 762d57d71a5b857c273d9cf834856e10e663c1ccb91bsalomon@google.com // or array (which we copied into reserved space). 763f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(kReserved_GeometrySrcType == geoSrc.fVertexSrc || 764d57d71a5b857c273d9cf834856e10e663c1ccb91bsalomon@google.com kArray_GeometrySrcType == geoSrc.fVertexSrc); 7653f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com 7663f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // When the caller reserved vertex buffer space we gave it back a pointer 7673f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // provided by the vertex buffer pool. At each draw we tracked the largest 7683f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // offset into the pool's pointer that was referenced. Now we return to the 7693f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // pool any portion at the tail of the allocation that no draw referenced. 770b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com size_t reservedVertexBytes = geoSrc.fVertexSize * geoSrc.fVertexCount; 771fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com fVertexPool.putBack(reservedVertexBytes - 77225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fUsedPoolVertexBytes); 77325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fUsedPoolVertexBytes = 0; 7743f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com poolState.fPoolVertexBuffer = NULL; 7753f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com poolState.fPoolStartVertex = 0; 77625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com} 777ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 77825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.comvoid GrInOrderDrawBuffer::releaseReservedIndexSpace() { 77925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.back(); 780fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com const GeometrySrcState& geoSrc = this->getGeomSrc(); 7811c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com 782d57d71a5b857c273d9cf834856e10e663c1ccb91bsalomon@google.com // If we get a release index space call then our current source should either be reserved 783d57d71a5b857c273d9cf834856e10e663c1ccb91bsalomon@google.com // or array (which we copied into reserved space). 784f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(kReserved_GeometrySrcType == geoSrc.fIndexSrc || 785d57d71a5b857c273d9cf834856e10e663c1ccb91bsalomon@google.com kArray_GeometrySrcType == geoSrc.fIndexSrc); 7863f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com 7873f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // Similar to releaseReservedVertexSpace we return any unused portion at 7883f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // the tail 78925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com size_t reservedIndexBytes = sizeof(uint16_t) * geoSrc.fIndexCount; 79025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com fIndexPool.putBack(reservedIndexBytes - poolState.fUsedPoolIndexBytes); 79125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fUsedPoolIndexBytes = 0; 7923f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com poolState.fPoolIndexBuffer = NULL; 7933f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com poolState.fPoolStartIndex = 0; 7941c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com} 795fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com 796bcdbbe61e1a3f89545b2c1461164f0f8bf5f0797bsalomon@google.comvoid GrInOrderDrawBuffer::onSetVertexSourceToArray(const void* vertexArray, 797bcdbbe61e1a3f89545b2c1461164f0f8bf5f0797bsalomon@google.com int vertexCount) { 79825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 79925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.back(); 800f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(0 == poolState.fUsedPoolVertexBytes); 801515dcd36032997ce335daa0163c6d67e851bcad1commit-bot@chromium.org#ifdef SK_DEBUG 8021c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com bool success = 8031c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com#endif 804b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com fVertexPool.appendVertices(this->getVertexSize(), 8051c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com vertexCount, 8061c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com vertexArray, 80725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com &poolState.fPoolVertexBuffer, 80825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com &poolState.fPoolStartVertex); 8091c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com GR_DEBUGASSERT(success); 8101c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com} 8111c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com 812bcdbbe61e1a3f89545b2c1461164f0f8bf5f0797bsalomon@google.comvoid GrInOrderDrawBuffer::onSetIndexSourceToArray(const void* indexArray, 813bcdbbe61e1a3f89545b2c1461164f0f8bf5f0797bsalomon@google.com int indexCount) { 81425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.back(); 815f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(0 == poolState.fUsedPoolIndexBytes); 816515dcd36032997ce335daa0163c6d67e851bcad1commit-bot@chromium.org#ifdef SK_DEBUG 8171c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com bool success = 8181c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com#endif 8191c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com fIndexPool.appendIndices(indexCount, 8201c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com indexArray, 82125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com &poolState.fPoolIndexBuffer, 82225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com &poolState.fPoolStartIndex); 8231c13c9668a889e56a0c85b51b9f28139c25b76ffbsalomon@google.com GR_DEBUGASSERT(success); 824ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 825ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 8263f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.comvoid GrInOrderDrawBuffer::releaseVertexArray() { 8273f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // When the client provides an array as the vertex source we handled it 8283f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // by copying their array into reserved space. 8293f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com this->GrInOrderDrawBuffer::releaseReservedVertexSpace(); 8303f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com} 8313f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com 8323f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.comvoid GrInOrderDrawBuffer::releaseIndexArray() { 8333f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // When the client provides an array as the index source we handled it 8343f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com // by copying their array into reserved space. 8353f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com this->GrInOrderDrawBuffer::releaseReservedIndexSpace(); 8363f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com} 8373f5a95e9745c5ea1f960d1454cf7df5942fa5dedbsalomon@google.com 83825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.comvoid GrInOrderDrawBuffer::geometrySourceWillPush() { 83925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.push_back(); 84025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fUsedPoolVertexBytes = 0; 84125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fUsedPoolIndexBytes = 0; 842515dcd36032997ce335daa0163c6d67e851bcad1commit-bot@chromium.org#ifdef SK_DEBUG 84325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fPoolVertexBuffer = (GrVertexBuffer*)~0; 84425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fPoolStartVertex = ~0; 84525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fPoolIndexBuffer = (GrIndexBuffer*)~0; 84625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com poolState.fPoolStartIndex = ~0; 84725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com#endif 84825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com} 84925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 85025fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.comvoid GrInOrderDrawBuffer::geometrySourceWillPop( 85125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com const GeometrySrcState& restoredState) { 852f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(fGeoPoolStateStack.count() > 1); 85325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com fGeoPoolStateStack.pop_back(); 85425fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com GeometryPoolState& poolState = fGeoPoolStateStack.back(); 85525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // we have to assume that any slack we had in our vertex/index data 85625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // is now unreleasable because data may have been appended later in the 85725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com // pool. 85825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com if (kReserved_GeometrySrcType == restoredState.fVertexSrc || 85925fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kArray_GeometrySrcType == restoredState.fVertexSrc) { 860b75b0a0b8492e14c7728e0a0881f87dc64ce60f9jvanverth@google.com poolState.fUsedPoolVertexBytes = restoredState.fVertexSize * restoredState.fVertexCount; 86125fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com } 86225fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com if (kReserved_GeometrySrcType == restoredState.fIndexSrc || 86325fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com kArray_GeometrySrcType == restoredState.fIndexSrc) { 864fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com poolState.fUsedPoolIndexBytes = sizeof(uint16_t) * 86525fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com restoredState.fIndexCount; 86625fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com } 86725fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com} 86825fb21f5df904c6f111bbf8f07e6a6c339416d09bsalomon@google.com 86986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.combool GrInOrderDrawBuffer::needsNewState() const { 870ca43208e4aaac817fbc8265542f995f24a3fb7bfbsalomon@google.com return fStates.empty() || !fStates.back().isEqual(this->getDrawState()); 871ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 872ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com 87386afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.combool GrInOrderDrawBuffer::needsNewClip() const { 874f6de475e5cbd143f348ff7738919e397b7fe7f57tfarina@chromium.org SkASSERT(fClips.count() == fClipOrigins.count()); 875358e427763f0971af436f07170c641f747b94595bsalomon@google.com if (this->getDrawState().isClipState()) { 876fbfcd5602128ec010c82cb733c9cdc0a3254f9f3rmistry@google.com if (fClipSet && 877358e427763f0971af436f07170c641f747b94595bsalomon@google.com (fClips.empty() || 87802ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com fClips.back() != *this->getClip()->fClipStack || 87902ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com fClipOrigins.back() != this->getClip()->fOrigin)) { 88086afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com return true; 88186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com } 882ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com } 883ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com return false; 884ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 885d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com 886a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.comvoid GrInOrderDrawBuffer::recordClip() { 88702ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com fClips.push_back() = *this->getClip()->fClipStack; 88802ddc8b85ace91b15feb329a6a1d5d62b2b846c6bsalomon@google.com fClipOrigins.push_back() = this->getClip()->fOrigin; 88986afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com fClipSet = false; 890a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com fCmds.push_back(kSetClip_Cmd); 891a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com} 892a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com 893a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.comvoid GrInOrderDrawBuffer::recordState() { 894ca43208e4aaac817fbc8265542f995f24a3fb7bfbsalomon@google.com fStates.push_back().saveFrom(this->getDrawState()); 895a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com fCmds.push_back(kSetState_Cmd); 896a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com} 897a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com 89874749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.comGrInOrderDrawBuffer::DrawRecord* GrInOrderDrawBuffer::recordDraw(const DrawInfo& info) { 899d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com fCmds.push_back(kDraw_Cmd); 900d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com return &fDraws.push_back(info); 90174749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com} 90274749cd45c29b4f5300e2518f2c2c765ce8ae208bsalomon@google.com 903ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.comGrInOrderDrawBuffer::StencilPath* GrInOrderDrawBuffer::recordStencilPath() { 904ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com fCmds.push_back(kStencilPath_Cmd); 905ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com return &fStencilPaths.push_back(); 906ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com} 907ded4f4b163f5aa19c22c871178c55ecb34623846bsalomon@google.com 90832184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.orgGrInOrderDrawBuffer::DrawPath* GrInOrderDrawBuffer::recordDrawPath() { 90932184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.org fCmds.push_back(kDrawPath_Cmd); 9109b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org return &fDrawPath.push_back(); 9119b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org} 9129b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org 9139b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.orgGrInOrderDrawBuffer::DrawPaths* GrInOrderDrawBuffer::recordDrawPaths() { 9149b62aa156bcf1db6f11af9302bf8bb8ef2567142commit-bot@chromium.org fCmds.push_back(kDrawPaths_Cmd); 91532184d81629e39809bb9e915286d8fe971a8ed68commit-bot@chromium.org return &fDrawPaths.push_back(); 916c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org} 917c4dc0ad8e252a7e30d19b47d3d0d9f2c69faf854commit-bot@chromium.org 918a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.comGrInOrderDrawBuffer::Clear* GrInOrderDrawBuffer::recordClear() { 919a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com fCmds.push_back(kClear_Cmd); 920a4f6b10818819a16bc94738e2eda42dfec332c43bsalomon@google.com return &fClears.push_back(); 92186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com} 922d302f1401b3c9aea094804bad4e76de98782cfe8bsalomon@google.com 923116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.comGrInOrderDrawBuffer::CopySurface* GrInOrderDrawBuffer::recordCopySurface() { 924116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com fCmds.push_back(kCopySurface_Cmd); 925116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com return &fCopySurfaces.push_back(); 926116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com} 927116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com 928116ad84d3126b0db22b2312ca59ed70e5c56f6fcbsalomon@google.com 929beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.comvoid GrInOrderDrawBuffer::clipWillBeSet(const GrClipData* newClipData) { 930beb1af78d016d2700c350487a383c6bcfa7e2e20robertphillips@google.com INHERITED::clipWillBeSet(newClipData); 93186afc2ae27fec84c01eb0e81a32766bdaf67dca8bsalomon@google.com fClipSet = true; 932d62e88e5af39347a8fc2a5abdf5feb67d7ea256dbsalomon@google.com fClipProxyState = kUnknown_ClipProxyState; 933ac10a2d039c5d52eed66e27cbbc503ab523c1cd5reed@google.com} 934