reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 8 | #include "GrInOrderDrawBuffer.h" |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 9 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 10 | #include "GrBufferAllocPool.h" |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 11 | #include "GrDefaultGeoProcFactory.h" |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 12 | #include "GrDrawTargetCaps.h" |
bsalomon@google.com | ded4f4b | 2012-06-28 18:48:06 +0000 | [diff] [blame] | 13 | #include "GrGpu.h" |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 14 | #include "GrTemplates.h" |
jvanverth | 787cdf9 | 2014-12-04 10:46:50 -0800 | [diff] [blame] | 15 | #include "GrFontCache.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 16 | #include "GrTexture.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 17 | |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 18 | GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrGpu* gpu, |
bsalomon@google.com | 471d471 | 2011-08-23 15:45:25 +0000 | [diff] [blame] | 19 | GrVertexBufferAllocPool* vertexPool, |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 20 | GrIndexBufferAllocPool* indexPool) |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 21 | : INHERITED(gpu, vertexPool, indexPool) |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 22 | , fCmdBuffer(kCmdBufferInitialSizeInBytes) |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 23 | , fPrevState(NULL) |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 24 | , fDrawID(0) |
| 25 | , fBatchTarget(gpu, vertexPool, indexPool) |
| 26 | , fDrawBatch(NULL) { |
bsalomon@google.com | 18c9c19 | 2011-09-22 21:01:31 +0000 | [diff] [blame] | 27 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 28 | SkASSERT(vertexPool); |
| 29 | SkASSERT(indexPool); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 30 | |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 31 | fPathIndexBuffer.setReserve(kPathIdxBufferMinReserve); |
| 32 | fPathTransformBuffer.setReserve(kPathXformBufferMinReserve); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | GrInOrderDrawBuffer::~GrInOrderDrawBuffer() { |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 36 | this->reset(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 37 | } |
| 38 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 39 | //////////////////////////////////////////////////////////////////////////////// |
| 40 | |
joshualitt | 6ae1b11 | 2015-02-23 07:35:35 -0800 | [diff] [blame^] | 41 | namespace { |
| 42 | void get_vertex_bounds(const void* vertices, |
| 43 | size_t vertexSize, |
| 44 | int vertexCount, |
| 45 | SkRect* bounds) { |
| 46 | SkASSERT(vertexSize >= sizeof(SkPoint)); |
| 47 | SkASSERT(vertexCount > 0); |
| 48 | const SkPoint* point = static_cast<const SkPoint*>(vertices); |
| 49 | bounds->fLeft = bounds->fRight = point->fX; |
| 50 | bounds->fTop = bounds->fBottom = point->fY; |
| 51 | for (int i = 1; i < vertexCount; ++i) { |
| 52 | point = reinterpret_cast<SkPoint*>(reinterpret_cast<intptr_t>(point) + vertexSize); |
| 53 | bounds->growToInclude(point->fX, point->fY); |
| 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 58 | /** We always use per-vertex colors so that rects can be batched across color changes. Sometimes we |
| 59 | have explicit local coords and sometimes not. We *could* always provide explicit local coords |
| 60 | and just duplicate the positions when the caller hasn't provided a local coord rect, but we |
| 61 | haven't seen a use case which frequently switches between local rect and no local rect draws. |
| 62 | |
| 63 | The color param is used to determine whether the opaque hint can be set on the draw state. |
| 64 | The caller must populate the vertex colors itself. |
| 65 | |
| 66 | The vertex attrib order is always pos, color, [local coords]. |
| 67 | */ |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 68 | static const GrGeometryProcessor* create_rect_gp(bool hasExplicitLocalCoords, |
| 69 | GrColor color, |
| 70 | const SkMatrix* localMatrix) { |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 71 | uint32_t flags = GrDefaultGeoProcFactory::kPosition_GPType | |
| 72 | GrDefaultGeoProcFactory::kColor_GPType; |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 73 | flags |= hasExplicitLocalCoords ? GrDefaultGeoProcFactory::kLocalCoord_GPType : 0; |
| 74 | if (localMatrix) { |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 75 | return GrDefaultGeoProcFactory::Create(flags, color, SkMatrix::I(), *localMatrix, |
| 76 | GrColorIsOpaque(color)); |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 77 | } else { |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 78 | return GrDefaultGeoProcFactory::Create(flags, color, SkMatrix::I(), SkMatrix::I(), |
| 79 | GrColorIsOpaque(color)); |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 80 | } |
bsalomon | 62c447d | 2014-08-08 08:08:50 -0700 | [diff] [blame] | 81 | } |
robertphillips@google.com | 4290330 | 2013-04-20 12:26:07 +0000 | [diff] [blame] | 82 | |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 83 | static bool path_fill_type_is_winding(const GrStencilSettings& pathStencilSettings) { |
| 84 | static const GrStencilSettings::Face pathFace = GrStencilSettings::kFront_Face; |
| 85 | bool isWinding = kInvert_StencilOp != pathStencilSettings.passOp(pathFace); |
| 86 | if (isWinding) { |
| 87 | // Double check that it is in fact winding. |
| 88 | SkASSERT(kIncClamp_StencilOp == pathStencilSettings.passOp(pathFace)); |
| 89 | SkASSERT(kIncClamp_StencilOp == pathStencilSettings.failOp(pathFace)); |
| 90 | SkASSERT(0x1 != pathStencilSettings.writeMask(pathFace)); |
| 91 | SkASSERT(!pathStencilSettings.isTwoSided()); |
| 92 | } |
| 93 | return isWinding; |
| 94 | } |
| 95 | |
| 96 | template<typename T> static void reset_data_buffer(SkTDArray<T>* buffer, int minReserve) { |
| 97 | // Assume the next time this buffer fills up it will use approximately the same amount |
| 98 | // of space as last time. Only resize if we're using less than a third of the |
| 99 | // allocated space, and leave enough for 50% growth over last time. |
| 100 | if (3 * buffer->count() < buffer->reserved() && buffer->reserved() > minReserve) { |
| 101 | int reserve = SkTMax(minReserve, buffer->count() * 3 / 2); |
| 102 | buffer->reset(); |
| 103 | buffer->setReserve(reserve); |
| 104 | } else { |
| 105 | buffer->rewind(); |
| 106 | } |
| 107 | } |
| 108 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 109 | void GrInOrderDrawBuffer::onDrawRect(GrPipelineBuilder* pipelineBuilder, |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 110 | GrColor color, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 111 | const SkMatrix& viewMatrix, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 112 | const SkRect& rect, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 113 | const SkRect* localRect, |
bsalomon@google.com | 0406b9e | 2013-04-02 21:00:15 +0000 | [diff] [blame] | 114 | const SkMatrix* localMatrix) { |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 115 | GrPipelineBuilder::AutoRestoreEffects are(pipelineBuilder); |
joshualitt | 6ae1b11 | 2015-02-23 07:35:35 -0800 | [diff] [blame^] | 116 | |
| 117 | // Go to device coords to allow batching across matrix changes |
| 118 | SkMatrix invert = SkMatrix::I(); |
| 119 | |
| 120 | // if we have a local rect, then we apply the localMatrix directly to the localRect to generate |
| 121 | // vertex local coords |
| 122 | bool hasExplicitLocalCoords = SkToBool(localRect); |
| 123 | if (!hasExplicitLocalCoords) { |
| 124 | if (!viewMatrix.isIdentity() && !viewMatrix.invert(&invert)) { |
| 125 | SkDebugf("Could not invert\n"); |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | if (localMatrix) { |
| 130 | invert.preConcat(*localMatrix); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | SkAutoTUnref<const GrGeometryProcessor> gp(create_rect_gp(hasExplicitLocalCoords, |
| 135 | color, |
| 136 | &invert)); |
| 137 | |
| 138 | size_t vstride = gp->getVertexStride(); |
| 139 | SkASSERT(vstride == sizeof(SkPoint) + sizeof(GrColor) + (SkToBool(localRect) ? sizeof(SkPoint) : |
| 140 | 0)); |
| 141 | AutoReleaseGeometry geo(this, 4, vstride, 0); |
| 142 | if (!geo.succeeded()) { |
| 143 | SkDebugf("Failed to get space for vertices!\n"); |
| 144 | return; |
| 145 | } |
| 146 | |
| 147 | geo.positions()->setRectFan(rect.fLeft, rect.fTop, rect.fRight, rect.fBottom, vstride); |
| 148 | viewMatrix.mapPointsWithStride(geo.positions(), vstride, 4); |
| 149 | |
| 150 | // When the caller has provided an explicit source rect for a stage then we don't want to |
| 151 | // modify that stage's matrix. Otherwise if the effect is generating its source rect from |
| 152 | // the vertex positions then we have to account for the view matrix |
| 153 | SkRect devBounds; |
| 154 | |
| 155 | // since we already computed the dev verts, set the bounds hint. This will help us avoid |
| 156 | // unnecessary clipping in our onDraw(). |
| 157 | get_vertex_bounds(geo.vertices(), vstride, 4, &devBounds); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 158 | |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 159 | if (localRect) { |
joshualitt | 6ae1b11 | 2015-02-23 07:35:35 -0800 | [diff] [blame^] | 160 | static const int kLocalOffset = sizeof(SkPoint) + sizeof(GrColor); |
| 161 | SkPoint* coords = GrTCast<SkPoint*>(GrTCast<intptr_t>(geo.vertices()) + kLocalOffset); |
| 162 | coords->setRectFan(localRect->fLeft, localRect->fTop, |
| 163 | localRect->fRight, localRect->fBottom, |
| 164 | vstride); |
| 165 | if (localMatrix) { |
| 166 | localMatrix->mapPointsWithStride(coords, vstride, 4); |
| 167 | } |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 168 | } |
| 169 | |
joshualitt | 6ae1b11 | 2015-02-23 07:35:35 -0800 | [diff] [blame^] | 170 | static const int kColorOffset = sizeof(SkPoint); |
| 171 | GrColor* vertColor = GrTCast<GrColor*>(GrTCast<intptr_t>(geo.vertices()) + kColorOffset); |
| 172 | for (int i = 0; i < 4; ++i) { |
| 173 | *vertColor = color; |
| 174 | vertColor = (GrColor*) ((intptr_t) vertColor + vstride); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 175 | } |
| 176 | |
joshualitt | 6ae1b11 | 2015-02-23 07:35:35 -0800 | [diff] [blame^] | 177 | this->setIndexSourceToBuffer(this->getContext()->getQuadIndexBuffer()); |
| 178 | this->drawIndexedInstances(pipelineBuilder, gp, kTriangles_GrPrimitiveType, 1, 4, 6, |
| 179 | &devBounds); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 180 | } |
| 181 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 182 | int GrInOrderDrawBuffer::concatInstancedDraw(const DrawInfo& info) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 183 | SkASSERT(!fCmdBuffer.empty()); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 184 | SkASSERT(info.isInstanced()); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 185 | |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 186 | const GeometrySrcState& geomSrc = this->getGeomSrc(); |
| 187 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 188 | // we only attempt to concat the case when reserved verts are used with a client-specified index |
| 189 | // buffer. To make this work with client-specified VBs we'd need to know if the VB was updated |
| 190 | // between draws. |
| 191 | if (kReserved_GeometrySrcType != geomSrc.fVertexSrc || |
| 192 | kBuffer_GeometrySrcType != geomSrc.fIndexSrc) { |
| 193 | return 0; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 194 | } |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 195 | // Check if there is a draw info that is compatible that uses the same VB from the pool and |
| 196 | // the same IB |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 197 | if (Cmd::kDraw_Cmd != fCmdBuffer.back().type()) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 198 | return 0; |
| 199 | } |
| 200 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 201 | Draw* draw = static_cast<Draw*>(&fCmdBuffer.back()); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 202 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 203 | if (!draw->fInfo.isInstanced() || |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 204 | draw->fInfo.primitiveType() != info.primitiveType() || |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 205 | draw->fInfo.verticesPerInstance() != info.verticesPerInstance() || |
| 206 | draw->fInfo.indicesPerInstance() != info.indicesPerInstance() || |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 207 | draw->fInfo.vertexBuffer() != info.vertexBuffer() || |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 208 | draw->fInfo.indexBuffer() != geomSrc.fIndexBuffer) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 209 | return 0; |
| 210 | } |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 211 | if (draw->fInfo.startVertex() + draw->fInfo.vertexCount() != info.startVertex()) { |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 212 | return 0; |
| 213 | } |
| 214 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 215 | // how many instances can be concat'ed onto draw given the size of the index buffer |
| 216 | int instancesToConcat = this->indexCountInCurrentSource() / info.indicesPerInstance(); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 217 | instancesToConcat -= draw->fInfo.instanceCount(); |
commit-bot@chromium.org | 972f9cd | 2014-03-28 17:58:28 +0000 | [diff] [blame] | 218 | instancesToConcat = SkTMin(instancesToConcat, info.instanceCount()); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 219 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 220 | draw->fInfo.adjustInstanceCount(instancesToConcat); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 221 | |
| 222 | // update last fGpuCmdMarkers to include any additional trace markers that have been added |
| 223 | if (this->getActiveTraceMarkers().count() > 0) { |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 224 | if (draw->isTraced()) { |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 225 | fGpuCmdMarkers.back().addSet(this->getActiveTraceMarkers()); |
| 226 | } else { |
| 227 | fGpuCmdMarkers.push_back(this->getActiveTraceMarkers()); |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 228 | draw->makeTraced(); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 232 | return instancesToConcat; |
bsalomon@google.com | 934c570 | 2012-03-20 21:17:58 +0000 | [diff] [blame] | 233 | } |
| 234 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 235 | void GrInOrderDrawBuffer::onDraw(const GrGeometryProcessor* gp, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 236 | const DrawInfo& info, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 237 | const PipelineInfo& pipelineInfo) { |
joshualitt | 7eb8c7b | 2014-11-18 14:24:27 -0800 | [diff] [blame] | 238 | SkASSERT(info.vertexBuffer() && (!info.isIndexed() || info.indexBuffer())); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 239 | this->closeBatch(); |
| 240 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 241 | if (!this->setupPipelineAndShouldDraw(gp, pipelineInfo)) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 242 | return; |
| 243 | } |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 244 | |
bsalomon | b3e3a95 | 2014-09-19 11:10:40 -0700 | [diff] [blame] | 245 | Draw* draw; |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 246 | if (info.isInstanced()) { |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 247 | int instancesConcated = this->concatInstancedDraw(info); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 248 | if (info.instanceCount() > instancesConcated) { |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 249 | draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 250 | draw->fInfo.adjustInstanceCount(-instancesConcated); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 251 | } else { |
| 252 | return; |
| 253 | } |
| 254 | } else { |
joshualitt | 54e0c12 | 2014-11-19 09:38:51 -0800 | [diff] [blame] | 255 | draw = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Draw, (info)); |
bsalomon@google.com | d62e88e | 2013-02-01 14:19:27 +0000 | [diff] [blame] | 256 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 257 | this->recordTraceMarkersIfNecessary(); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 258 | } |
sugoi@google.com | 5f74cf8 | 2012-12-17 21:16:45 +0000 | [diff] [blame] | 259 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 260 | void GrInOrderDrawBuffer::onDrawBatch(GrBatch* batch, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 261 | const PipelineInfo& pipelineInfo) { |
| 262 | if (!this->setupPipelineAndShouldDraw(batch, pipelineInfo)) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 263 | return; |
| 264 | } |
| 265 | |
| 266 | // Check if there is a Batch Draw we can batch with |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 267 | if (Cmd::kDrawBatch_Cmd != fCmdBuffer.back().type()) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 268 | fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch)); |
| 269 | return; |
| 270 | } |
| 271 | |
| 272 | DrawBatch* draw = static_cast<DrawBatch*>(&fCmdBuffer.back()); |
| 273 | if (draw->fBatch->combineIfPossible(batch)) { |
| 274 | return; |
| 275 | } else { |
| 276 | this->closeBatch(); |
| 277 | fDrawBatch = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch)); |
| 278 | } |
| 279 | this->recordTraceMarkersIfNecessary(); |
| 280 | } |
| 281 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 282 | void GrInOrderDrawBuffer::onStencilPath(const GrPipelineBuilder& pipelineBuilder, |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 283 | const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 284 | const GrPath* path, |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 285 | const GrScissorState& scissorState, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 286 | const GrStencilSettings& stencilSettings) { |
joshualitt | 70f0004 | 2015-02-06 15:53:59 -0800 | [diff] [blame] | 287 | this->closeBatch(); |
| 288 | |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 289 | StencilPath* sp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, StencilPath, |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 290 | (path, pipelineBuilder.getRenderTarget())); |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 291 | sp->fScissor = scissorState; |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 292 | sp->fUseHWAA = pipelineBuilder.isHWAntialias(); |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 293 | sp->fViewMatrix = pathProc->viewMatrix(); |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 294 | sp->fStencil = stencilSettings; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 295 | this->recordTraceMarkersIfNecessary(); |
bsalomon@google.com | 64aef2b | 2012-06-11 15:36:13 +0000 | [diff] [blame] | 296 | } |
| 297 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 298 | void GrInOrderDrawBuffer::onDrawPath(const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 299 | const GrPath* path, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 300 | const GrStencilSettings& stencilSettings, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 301 | const PipelineInfo& pipelineInfo) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 302 | this->closeBatch(); |
| 303 | |
egdaniel | 8dd688b | 2015-01-22 10:16:09 -0800 | [diff] [blame] | 304 | // TODO: Only compare the subset of GrPipelineBuilder relevant to path covering? |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 305 | if (!this->setupPipelineAndShouldDraw(pathProc, pipelineInfo)) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 306 | return; |
| 307 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 308 | DrawPath* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPath, (path)); |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 309 | dp->fStencilSettings = stencilSettings; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 310 | this->recordTraceMarkersIfNecessary(); |
commit-bot@chromium.org | c4dc0ad | 2013-10-09 14:11:33 +0000 | [diff] [blame] | 311 | } |
| 312 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 313 | void GrInOrderDrawBuffer::onDrawPaths(const GrPathProcessor* pathProc, |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 314 | const GrPathRange* pathRange, |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 315 | const void* indices, |
| 316 | PathIndexType indexType, |
| 317 | const float transformValues[], |
| 318 | PathTransformType transformType, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 319 | int count, |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 320 | const GrStencilSettings& stencilSettings, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 321 | const PipelineInfo& pipelineInfo) { |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 322 | SkASSERT(pathRange); |
| 323 | SkASSERT(indices); |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 324 | SkASSERT(transformValues); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 325 | this->closeBatch(); |
| 326 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 327 | if (!this->setupPipelineAndShouldDraw(pathProc, pipelineInfo)) { |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 328 | return; |
| 329 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 330 | |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 331 | int indexBytes = GrPathRange::PathIndexSizeInBytes(indexType); |
| 332 | if (int misalign = fPathIndexBuffer.count() % indexBytes) { |
| 333 | // Add padding to the index buffer so the indices are aligned properly. |
| 334 | fPathIndexBuffer.append(indexBytes - misalign); |
| 335 | } |
| 336 | |
| 337 | char* savedIndices = fPathIndexBuffer.append(count * indexBytes, |
| 338 | reinterpret_cast<const char*>(indices)); |
| 339 | float* savedTransforms = fPathTransformBuffer.append( |
| 340 | count * GrPathRendering::PathTransformSize(transformType), |
| 341 | transformValues); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 342 | |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 343 | if (Cmd::kDrawPaths_Cmd == fCmdBuffer.back().type()) { |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 344 | // The previous command was also DrawPaths. Try to collapse this call into the one |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 345 | // before. Note that stenciling all the paths at once, then covering, may not be |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 346 | // equivalent to two separate draw calls if there is overlap. Blending won't work, |
| 347 | // and the combined calls may also cancel each other's winding numbers in some |
| 348 | // places. For now the winding numbers are only an issue if the fill is even/odd, |
| 349 | // because DrawPaths is currently only used for glyphs, and glyphs in the same |
| 350 | // font tend to all wind in the same direction. |
| 351 | DrawPaths* previous = static_cast<DrawPaths*>(&fCmdBuffer.back()); |
| 352 | if (pathRange == previous->pathRange() && |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 353 | indexType == previous->fIndexType && |
| 354 | transformType == previous->fTransformType && |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 355 | stencilSettings == previous->fStencilSettings && |
| 356 | path_fill_type_is_winding(stencilSettings) && |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 357 | !pipelineInfo.willBlendWithDst(pathProc)) { |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 358 | // Fold this DrawPaths call into the one previous. |
| 359 | previous->fCount += count; |
| 360 | return; |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | DrawPaths* dp = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawPaths, (pathRange)); |
bsalomon | ef3fcd8 | 2014-12-12 08:51:38 -0800 | [diff] [blame] | 365 | dp->fIndicesLocation = SkToU32(savedIndices - fPathIndexBuffer.begin()); |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 366 | dp->fIndexType = indexType; |
bsalomon | ef3fcd8 | 2014-12-12 08:51:38 -0800 | [diff] [blame] | 367 | dp->fTransformsLocation = SkToU32(savedTransforms - fPathTransformBuffer.begin()); |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 368 | dp->fTransformType = transformType; |
| 369 | dp->fCount = count; |
joshualitt | 2c93efe | 2014-11-06 12:57:13 -0800 | [diff] [blame] | 370 | dp->fStencilSettings = stencilSettings; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 371 | |
| 372 | this->recordTraceMarkersIfNecessary(); |
commit-bot@chromium.org | 9b62aa1 | 2014-03-25 11:59:40 +0000 | [diff] [blame] | 373 | } |
| 374 | |
bsalomon | 63b2196 | 2014-11-05 07:05:34 -0800 | [diff] [blame] | 375 | void GrInOrderDrawBuffer::onClear(const SkIRect* rect, GrColor color, |
| 376 | bool canIgnoreRect, GrRenderTarget* renderTarget) { |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 377 | SkASSERT(renderTarget); |
joshualitt | 70f0004 | 2015-02-06 15:53:59 -0800 | [diff] [blame] | 378 | this->closeBatch(); |
| 379 | |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 380 | SkIRect r; |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 381 | if (NULL == rect) { |
| 382 | // We could do something smart and remove previous draws and clears to |
| 383 | // the current render target. If we get that smart we have to make sure |
| 384 | // those draws aren't read before this clear (render-to-texture). |
bsalomon@google.com | 1b3ce47 | 2012-08-17 13:43:08 +0000 | [diff] [blame] | 385 | r.setLTRB(0, 0, renderTarget->width(), renderTarget->height()); |
bsalomon@google.com | 6aa25c3 | 2011-04-27 19:55:29 +0000 | [diff] [blame] | 386 | rect = &r; |
| 387 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 388 | Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget)); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 389 | GrColorIsPMAssert(color); |
bsalomon@google.com | a4f6b10 | 2012-06-26 21:04:22 +0000 | [diff] [blame] | 390 | clr->fColor = color; |
| 391 | clr->fRect = *rect; |
robertphillips@google.com | 56ce48a | 2013-10-31 21:44:25 +0000 | [diff] [blame] | 392 | clr->fCanIgnoreRect = canIgnoreRect; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 393 | this->recordTraceMarkersIfNecessary(); |
bsalomon@google.com | 0b335c1 | 2011-04-25 19:17:44 +0000 | [diff] [blame] | 394 | } |
| 395 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 396 | void GrInOrderDrawBuffer::clearStencilClip(const SkIRect& rect, |
| 397 | bool insideClip, |
| 398 | GrRenderTarget* renderTarget) { |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 399 | SkASSERT(renderTarget); |
joshualitt | 70f0004 | 2015-02-06 15:53:59 -0800 | [diff] [blame] | 400 | this->closeBatch(); |
| 401 | |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 402 | ClearStencilClip* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, ClearStencilClip, (renderTarget)); |
| 403 | clr->fRect = rect; |
| 404 | clr->fInsideClip = insideClip; |
| 405 | this->recordTraceMarkersIfNecessary(); |
| 406 | } |
| 407 | |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 408 | void GrInOrderDrawBuffer::discard(GrRenderTarget* renderTarget) { |
bsalomon | 89c6298 | 2014-11-03 12:08:42 -0800 | [diff] [blame] | 409 | SkASSERT(renderTarget); |
joshualitt | 70f0004 | 2015-02-06 15:53:59 -0800 | [diff] [blame] | 410 | this->closeBatch(); |
| 411 | |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 412 | if (!this->caps()->discardRenderTargetSupport()) { |
| 413 | return; |
| 414 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 415 | Clear* clr = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, Clear, (renderTarget)); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 416 | clr->fColor = GrColor_ILLEGAL; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 417 | this->recordTraceMarkersIfNecessary(); |
commit-bot@chromium.org | 28361fa | 2014-03-28 16:08:05 +0000 | [diff] [blame] | 418 | } |
| 419 | |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 420 | void GrInOrderDrawBuffer::onReset() { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 421 | fCmdBuffer.reset(); |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 422 | fPrevState = NULL; |
cdalton | 3fc6a2f | 2014-11-13 11:54:20 -0800 | [diff] [blame] | 423 | reset_data_buffer(&fPathIndexBuffer, kPathIdxBufferMinReserve); |
| 424 | reset_data_buffer(&fPathTransformBuffer, kPathXformBufferMinReserve); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 425 | fGpuCmdMarkers.reset(); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 426 | fDrawBatch = NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 427 | } |
| 428 | |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 429 | void GrInOrderDrawBuffer::onFlush() { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 430 | if (fCmdBuffer.empty()) { |
robertphillips@google.com | 1267fbd | 2013-07-03 18:37:27 +0000 | [diff] [blame] | 431 | return; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 432 | } |
bsalomon@google.com | 6e4e650 | 2013-02-25 20:12:45 +0000 | [diff] [blame] | 433 | |
joshualitt | c2893c5 | 2015-01-28 06:54:30 -0800 | [diff] [blame] | 434 | // Updated every time we find a set state cmd to reflect the current state in the playback |
| 435 | // stream. |
| 436 | SetState* currentState = NULL; |
| 437 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 438 | // TODO this is temporary while batch is being rolled out |
| 439 | this->closeBatch(); |
| 440 | this->getVertexAllocPool()->unmap(); |
| 441 | this->getIndexAllocPool()->unmap(); |
| 442 | fBatchTarget.preFlush(); |
| 443 | |
| 444 | currentState = NULL; |
| 445 | CmdBuffer::Iter iter(fCmdBuffer); |
| 446 | |
| 447 | int currCmdMarker = 0; |
| 448 | |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 449 | int i = 0; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 450 | while (iter.next()) { |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 451 | i++; |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 452 | GrGpuTraceMarker newMarker("", -1); |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 453 | SkString traceString; |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 454 | if (iter->isTraced()) { |
egdaniel | d78a168 | 2014-07-09 10:41:26 -0700 | [diff] [blame] | 455 | traceString = fGpuCmdMarkers[currCmdMarker].toString(); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 456 | newMarker.fMarker = traceString.c_str(); |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 457 | this->getGpu()->addGpuTraceMarker(&newMarker); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 458 | ++currCmdMarker; |
| 459 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 460 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 461 | // TODO temporary hack |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 462 | if (Cmd::kDrawBatch_Cmd == iter->type()) { |
joshualitt | 7bc18b7 | 2015-02-03 16:41:41 -0800 | [diff] [blame] | 463 | DrawBatch* db = reinterpret_cast<DrawBatch*>(iter.get()); |
| 464 | fBatchTarget.flushNext(db->fBatch->numberOfDraws()); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 465 | continue; |
| 466 | } |
| 467 | |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 468 | if (Cmd::kSetState_Cmd == iter->type()) { |
joshualitt | 9853cce | 2014-11-17 14:22:48 -0800 | [diff] [blame] | 469 | SetState* ss = reinterpret_cast<SetState*>(iter.get()); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 470 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 471 | // TODO sometimes we have a prim proc, othertimes we have a GrBatch. Eventually we will |
| 472 | // only have GrBatch and we can delete this |
| 473 | if (ss->fPrimitiveProcessor) { |
| 474 | this->getGpu()->buildProgramDesc(&ss->fDesc, *ss->fPrimitiveProcessor, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 475 | *ss->getPipeline(), |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 476 | ss->fBatchTracker); |
| 477 | } |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 478 | currentState = ss; |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 479 | } else { |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 480 | iter->execute(this, currentState); |
joshualitt | d53a827 | 2014-11-10 16:03:14 -0800 | [diff] [blame] | 481 | } |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 482 | |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 483 | if (iter->isTraced()) { |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 484 | this->getGpu()->removeGpuTraceMarker(&newMarker); |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 485 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 486 | } |
mtklein | f439c77 | 2014-10-14 14:29:30 -0700 | [diff] [blame] | 487 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 488 | // TODO see copious notes about hack |
| 489 | fBatchTarget.postFlush(); |
| 490 | |
commit-bot@chromium.org | 2a05de0 | 2014-03-25 15:17:32 +0000 | [diff] [blame] | 491 | SkASSERT(fGpuCmdMarkers.count() == currCmdMarker); |
commit-bot@chromium.org | a8916ff | 2013-08-16 15:53:46 +0000 | [diff] [blame] | 492 | ++fDrawID; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 493 | } |
| 494 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 495 | void GrInOrderDrawBuffer::Draw::execute(GrInOrderDrawBuffer* buf, const SetState* state) { |
| 496 | SkASSERT(state); |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 497 | DrawArgs args(state->fPrimitiveProcessor.get(), state->getPipeline(), &state->fDesc, |
joshualitt | 17e7314 | 2015-01-21 11:52:36 -0800 | [diff] [blame] | 498 | &state->fBatchTracker); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 499 | buf->getGpu()->draw(args, fInfo); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 500 | } |
| 501 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 502 | void GrInOrderDrawBuffer::StencilPath::execute(GrInOrderDrawBuffer* buf, const SetState*) { |
bsalomon | 3e79124 | 2014-12-17 13:43:13 -0800 | [diff] [blame] | 503 | GrGpu::StencilPathState state; |
| 504 | state.fRenderTarget = fRenderTarget.get(); |
| 505 | state.fScissor = &fScissor; |
| 506 | state.fStencil = &fStencil; |
| 507 | state.fUseHWAA = fUseHWAA; |
| 508 | state.fViewMatrix = &fViewMatrix; |
| 509 | |
| 510 | buf->getGpu()->stencilPath(this->path(), state); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 511 | } |
| 512 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 513 | void GrInOrderDrawBuffer::DrawPath::execute(GrInOrderDrawBuffer* buf, const SetState* state) { |
| 514 | SkASSERT(state); |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 515 | DrawArgs args(state->fPrimitiveProcessor.get(), state->getPipeline(), &state->fDesc, |
joshualitt | 17e7314 | 2015-01-21 11:52:36 -0800 | [diff] [blame] | 516 | &state->fBatchTracker); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 517 | buf->getGpu()->drawPath(args, this->path(), fStencilSettings); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 518 | } |
| 519 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 520 | void GrInOrderDrawBuffer::DrawPaths::execute(GrInOrderDrawBuffer* buf, const SetState* state) { |
| 521 | SkASSERT(state); |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 522 | DrawArgs args(state->fPrimitiveProcessor.get(), state->getPipeline(), &state->fDesc, |
joshualitt | 17e7314 | 2015-01-21 11:52:36 -0800 | [diff] [blame] | 523 | &state->fBatchTracker); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 524 | buf->getGpu()->drawPaths(args, this->pathRange(), |
cdalton | 55b24af | 2014-11-25 11:00:56 -0800 | [diff] [blame] | 525 | &buf->fPathIndexBuffer[fIndicesLocation], fIndexType, |
| 526 | &buf->fPathTransformBuffer[fTransformsLocation], fTransformType, |
| 527 | fCount, fStencilSettings); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 528 | } |
| 529 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 530 | void GrInOrderDrawBuffer::DrawBatch::execute(GrInOrderDrawBuffer* buf, const SetState* state) { |
| 531 | SkASSERT(state); |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 532 | fBatch->generateGeometry(buf->getBatchTarget(), state->getPipeline()); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 533 | } |
| 534 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 535 | void GrInOrderDrawBuffer::SetState::execute(GrInOrderDrawBuffer*, const SetState*) {} |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 536 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 537 | void GrInOrderDrawBuffer::Clear::execute(GrInOrderDrawBuffer* buf, const SetState*) { |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 538 | if (GrColor_ILLEGAL == fColor) { |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 539 | buf->getGpu()->discard(this->renderTarget()); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 540 | } else { |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 541 | buf->getGpu()->clear(&fRect, fColor, fCanIgnoreRect, this->renderTarget()); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 542 | } |
| 543 | } |
| 544 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 545 | void GrInOrderDrawBuffer::ClearStencilClip::execute(GrInOrderDrawBuffer* buf, const SetState*) { |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 546 | buf->getGpu()->clearStencilClip(fRect, fInsideClip, this->renderTarget()); |
joshualitt | 6db519c | 2014-10-29 08:48:18 -0700 | [diff] [blame] | 547 | } |
| 548 | |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 549 | void GrInOrderDrawBuffer::CopySurface::execute(GrInOrderDrawBuffer* buf, const SetState*) { |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 550 | buf->getGpu()->copySurface(this->dst(), this->src(), fSrcRect, fDstPoint); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 551 | } |
| 552 | |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 553 | bool GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, |
| 554 | GrSurface* src, |
| 555 | const SkIRect& srcRect, |
| 556 | const SkIPoint& dstPoint) { |
bsalomon | 371bcbc | 2014-12-01 08:19:34 -0800 | [diff] [blame] | 557 | if (getGpu()->canCopySurface(dst, src, srcRect, dstPoint)) { |
joshualitt | 95964c6 | 2015-02-11 13:45:50 -0800 | [diff] [blame] | 558 | this->closeBatch(); |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 559 | CopySurface* cs = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, CopySurface, (dst, src)); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 560 | cs->fSrcRect = srcRect; |
| 561 | cs->fDstPoint = dstPoint; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 562 | this->recordTraceMarkersIfNecessary(); |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 563 | return true; |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 564 | } |
bsalomon | f90a02b | 2014-11-26 12:28:00 -0800 | [diff] [blame] | 565 | return false; |
bsalomon@google.com | 116ad84 | 2013-04-09 15:38:19 +0000 | [diff] [blame] | 566 | } |
| 567 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 568 | bool GrInOrderDrawBuffer::setupPipelineAndShouldDraw(const GrPrimitiveProcessor* primProc, |
| 569 | const PipelineInfo& pipelineInfo) { |
| 570 | SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, (primProc)); |
| 571 | this->setupPipeline(pipelineInfo, ss->pipelineLocation()); |
| 572 | |
| 573 | if (ss->getPipeline()->mustSkip()) { |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 574 | fCmdBuffer.pop_back(); |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 575 | return false; |
| 576 | } |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 577 | |
| 578 | ss->fPrimitiveProcessor->initBatchTracker(&ss->fBatchTracker, |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 579 | ss->getPipeline()->getInitBatchTracker()); |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 580 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 581 | if (fPrevState && fPrevState->fPrimitiveProcessor.get() && |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 582 | fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker, |
| 583 | *ss->fPrimitiveProcessor, |
| 584 | ss->fBatchTracker) && |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 585 | fPrevState->getPipeline()->isEqual(*ss->getPipeline())) { |
bsalomon | 932f866 | 2014-11-24 06:47:48 -0800 | [diff] [blame] | 586 | fCmdBuffer.pop_back(); |
| 587 | } else { |
joshualitt | 873ad0e | 2015-01-20 09:08:51 -0800 | [diff] [blame] | 588 | fPrevState = ss; |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 589 | this->recordTraceMarkersIfNecessary(); |
bsalomon | 838f62d | 2014-08-05 07:15:57 -0700 | [diff] [blame] | 590 | } |
bsalomon | ae59b77 | 2014-11-19 08:23:49 -0800 | [diff] [blame] | 591 | return true; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 592 | } |
| 593 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 594 | bool GrInOrderDrawBuffer::setupPipelineAndShouldDraw(GrBatch* batch, |
| 595 | const PipelineInfo& pipelineInfo) { |
| 596 | SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, ()); |
| 597 | this->setupPipeline(pipelineInfo, ss->pipelineLocation()); |
| 598 | |
| 599 | if (ss->getPipeline()->mustSkip()) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 600 | fCmdBuffer.pop_back(); |
| 601 | return false; |
| 602 | } |
| 603 | |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 604 | batch->initBatchTracker(ss->getPipeline()->getInitBatchTracker()); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 605 | |
| 606 | if (fPrevState && !fPrevState->fPrimitiveProcessor.get() && |
egdaniel | e36914c | 2015-02-13 09:00:33 -0800 | [diff] [blame] | 607 | fPrevState->getPipeline()->isEqual(*ss->getPipeline())) { |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 608 | fCmdBuffer.pop_back(); |
| 609 | } else { |
| 610 | this->closeBatch(); |
| 611 | fPrevState = ss; |
| 612 | this->recordTraceMarkersIfNecessary(); |
| 613 | } |
| 614 | return true; |
| 615 | } |
| 616 | |
cdalton | 6819df3 | 2014-10-15 13:43:48 -0700 | [diff] [blame] | 617 | void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() { |
| 618 | SkASSERT(!fCmdBuffer.empty()); |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 619 | SkASSERT(!fCmdBuffer.back().isTraced()); |
mtklein | f439c77 | 2014-10-14 14:29:30 -0700 | [diff] [blame] | 620 | const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); |
| 621 | if (activeTraceMarkers.count() > 0) { |
robertphillips | e5e72f1 | 2015-02-17 09:14:33 -0800 | [diff] [blame] | 622 | fCmdBuffer.back().makeTraced(); |
mtklein | f439c77 | 2014-10-14 14:29:30 -0700 | [diff] [blame] | 623 | fGpuCmdMarkers.push_back(activeTraceMarkers); |
mtklein | 07894c4 | 2014-10-13 14:00:42 -0700 | [diff] [blame] | 624 | } |
mtklein | 07894c4 | 2014-10-13 14:00:42 -0700 | [diff] [blame] | 625 | } |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 626 | |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 627 | void GrInOrderDrawBuffer::willReserveVertexAndIndexSpace(int vertexCount, |
| 628 | size_t vertexStride, |
| 629 | int indexCount) { |
| 630 | this->closeBatch(); |
| 631 | |
robertphillips | 54fac8b | 2015-02-16 09:35:50 -0800 | [diff] [blame] | 632 | this->INHERITED::willReserveVertexAndIndexSpace(vertexCount, vertexStride, indexCount); |
joshualitt | 4d8da81 | 2015-01-28 12:53:54 -0800 | [diff] [blame] | 633 | } |