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