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