| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "InstancedRendering.h" | 8 #include "InstancedRendering.h" |
| 9 | 9 |
| 10 #include "GrBatchFlushState.h" | 10 #include "GrBatchFlushState.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 viewMatrix.mapRect(&batch->fBounds, bounds); | 177 viewMatrix.mapRect(&batch->fBounds, bounds); |
| 178 | 178 |
| 179 batch->fInfo.fNonSquare = true; | 179 batch->fInfo.fNonSquare = true; |
| 180 } | 180 } |
| 181 | 181 |
| 182 instance.fColor = color; | 182 instance.fColor = color; |
| 183 | 183 |
| 184 const float* rectAsFloats = localRect.asScalars(); // Ensure SkScalar == flo
at. | 184 const float* rectAsFloats = localRect.asScalars(); // Ensure SkScalar == flo
at. |
| 185 memcpy(&instance.fLocalRect, rectAsFloats, 4 * sizeof(float)); | 185 memcpy(&instance.fLocalRect, rectAsFloats, 4 * sizeof(float)); |
| 186 | 186 |
| 187 batch->fPixelLoad = batch->fBounds.height() * batch->fBounds.width(); |
| 187 return batch; | 188 return batch; |
| 188 } | 189 } |
| 189 | 190 |
| 190 inline bool InstancedRendering::selectAntialiasMode(const SkMatrix& viewMatrix,
bool antialias, | 191 inline bool InstancedRendering::selectAntialiasMode(const SkMatrix& viewMatrix,
bool antialias, |
| 191 const GrInstancedPipelineInf
o& info, | 192 const GrInstancedPipelineInf
o& info, |
| 192 bool* useHWAA, AntialiasMode
* antialiasMode) { | 193 bool* useHWAA, AntialiasMode
* antialiasMode) { |
| 193 SkASSERT(!info.fColorDisabled || info.fDrawingShapeToStencil); | 194 SkASSERT(!info.fColorDisabled || info.fDrawingShapeToStencil); |
| 194 SkASSERT(!info.fIsMixedSampled || info.fIsMultisampled); | 195 SkASSERT(!info.fIsMixedSampled || info.fIsMultisampled); |
| 195 | 196 |
| 196 if (!info.fIsMultisampled || fGpu->caps()->multisampleDisableSupport()) { | 197 if (!info.fIsMultisampled || fGpu->caps()->multisampleDisableSupport()) { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 fInstancedRendering->fTrackedBatches.addToTail(this); | 360 fInstancedRendering->fTrackedBatches.addToTail(this); |
| 360 fIsTracked = true; | 361 fIsTracked = true; |
| 361 } | 362 } |
| 362 | 363 |
| 363 bool InstancedRendering::Batch::onCombineIfPossible(GrBatch* other, const GrCaps
& caps) { | 364 bool InstancedRendering::Batch::onCombineIfPossible(GrBatch* other, const GrCaps
& caps) { |
| 364 Batch* that = static_cast<Batch*>(other); | 365 Batch* that = static_cast<Batch*>(other); |
| 365 SkASSERT(fInstancedRendering == that->fInstancedRendering); | 366 SkASSERT(fInstancedRendering == that->fInstancedRendering); |
| 366 SkASSERT(fTailDraw); | 367 SkASSERT(fTailDraw); |
| 367 SkASSERT(that->fTailDraw); | 368 SkASSERT(that->fTailDraw); |
| 368 | 369 |
| 369 if (!fInfo.canJoin(that->fInfo) || | 370 if (!BatchInfo::CanCombine(fInfo, that->fInfo) || |
| 370 !GrPipeline::CanCombine(*this->pipeline(), this->bounds(), | 371 !GrPipeline::CanCombine(*this->pipeline(), this->bounds(), |
| 371 *that->pipeline(), that->bounds(), caps)) { | 372 *that->pipeline(), that->bounds(), caps)) { |
| 372 return false; | 373 return false; |
| 373 } | 374 } |
| 374 | 375 |
| 376 BatchInfo combinedInfo = fInfo | that->fInfo; |
| 377 if (!combinedInfo.isSimpleRects()) { |
| 378 // This threshold was chosen with the "shapes_mixed" bench on a MacBook
with Intel graphics. |
| 379 // There seems to be a wide range where it doesn't matter if we combine
or not. What matters |
| 380 // is that the itty bitty rects combine with other shapes and the giant
ones don't. |
| 381 constexpr SkScalar kMaxPixelsToGeneralizeRects = 256 * 256; |
| 382 if (fInfo.isSimpleRects() && fPixelLoad > kMaxPixelsToGeneralizeRects) { |
| 383 return false; |
| 384 } |
| 385 if (that->fInfo.isSimpleRects() && that->fPixelLoad > kMaxPixelsToGenera
lizeRects) { |
| 386 return false; |
| 387 } |
| 388 } |
| 389 |
| 375 fBounds.join(that->fBounds); | 390 fBounds.join(that->fBounds); |
| 376 fInfo.join(that->fInfo); | 391 fInfo = combinedInfo; |
| 392 fPixelLoad += that->fPixelLoad; |
| 377 | 393 |
| 378 // Adopt the other batch's draws. | 394 // Adopt the other batch's draws. |
| 379 fNumDraws += that->fNumDraws; | 395 fNumDraws += that->fNumDraws; |
| 380 fNumChangesInGeometry += that->fNumChangesInGeometry; | 396 fNumChangesInGeometry += that->fNumChangesInGeometry; |
| 381 if (fTailDraw->fGeometry != that->fHeadDraw->fGeometry) { | 397 if (fTailDraw->fGeometry != that->fHeadDraw->fGeometry) { |
| 382 ++fNumChangesInGeometry; | 398 ++fNumChangesInGeometry; |
| 383 } | 399 } |
| 384 fTailDraw->fNext = that->fHeadDraw; | 400 fTailDraw->fNext = that->fHeadDraw; |
| 385 fTailDraw = that->fTailDraw; | 401 fTailDraw = that->fTailDraw; |
| 386 | 402 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 } | 481 } |
| 466 | 482 |
| 467 void InstancedRendering::resetGpuResources(ResetType resetType) { | 483 void InstancedRendering::resetGpuResources(ResetType resetType) { |
| 468 fVertexBuffer.reset(); | 484 fVertexBuffer.reset(); |
| 469 fIndexBuffer.reset(); | 485 fIndexBuffer.reset(); |
| 470 fParamsBuffer.reset(); | 486 fParamsBuffer.reset(); |
| 471 this->onResetGpuResources(resetType); | 487 this->onResetGpuResources(resetType); |
| 472 } | 488 } |
| 473 | 489 |
| 474 } | 490 } |
| OLD | NEW |