| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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 "GrInOrderCommandBuilder.h" | 8 #include "GrInOrderCommandBuilder.h" |
| 9 | 9 |
| 10 #include "GrBufferedDrawTarget.h" | 10 #include "GrBufferedDrawTarget.h" |
| 11 | 11 |
| 12 #include "GrColor.h" | 12 #include "GrColor.h" |
| 13 #include "SkPoint.h" | 13 #include "SkPoint.h" |
| 14 | 14 |
| 15 static bool path_fill_type_is_winding(const GrStencilSettings& pathStencilSettin
gs) { | |
| 16 static const GrStencilSettings::Face pathFace = GrStencilSettings::kFront_Fa
ce; | |
| 17 bool isWinding = kInvert_StencilOp != pathStencilSettings.passOp(pathFace); | |
| 18 if (isWinding) { | |
| 19 // Double check that it is in fact winding. | |
| 20 SkASSERT(kIncClamp_StencilOp == pathStencilSettings.passOp(pathFace)); | |
| 21 SkASSERT(kIncClamp_StencilOp == pathStencilSettings.failOp(pathFace)); | |
| 22 SkASSERT(0x1 != pathStencilSettings.writeMask(pathFace)); | |
| 23 SkASSERT(!pathStencilSettings.isTwoSided()); | |
| 24 } | |
| 25 return isWinding; | |
| 26 } | |
| 27 | |
| 28 GrTargetCommands::Cmd* GrInOrderCommandBuilder::recordDrawBatch(GrBatch* batch, | 15 GrTargetCommands::Cmd* GrInOrderCommandBuilder::recordDrawBatch(GrBatch* batch, |
| 29 const GrCaps& ca
ps) { | 16 const GrCaps& ca
ps) { |
| 30 GrBATCH_INFO("In-Recording (%s, %u)\n", batch->name(), batch->uniqueID()); | 17 GrBATCH_INFO("In-Recording (%s, %u)\n", batch->name(), batch->uniqueID()); |
| 31 if (!this->cmdBuffer()->empty() && | 18 if (!this->cmdBuffer()->empty() && |
| 32 Cmd::kDrawBatch_CmdType == this->cmdBuffer()->back().type()) { | 19 Cmd::kDrawBatch_CmdType == this->cmdBuffer()->back().type()) { |
| 33 DrawBatch* previous = static_cast<DrawBatch*>(&this->cmdBuffer()->back()
); | 20 DrawBatch* previous = static_cast<DrawBatch*>(&this->cmdBuffer()->back()
); |
| 34 if (previous->batch()->combineIfPossible(batch, caps)) { | 21 if (previous->batch()->combineIfPossible(batch, caps)) { |
| 35 GrBATCH_INFO("\tBatching with (%s, %u)\n", | 22 GrBATCH_INFO("\tBatching with (%s, %u)\n", |
| 36 previous->batch()->name(), previous->batch()->uniqueID(
)); | 23 previous->batch()->name(), previous->batch()->uniqueID(
)); |
| 37 return nullptr; | 24 return nullptr; |
| 38 } | 25 } |
| 39 } | 26 } |
| 40 | 27 |
| 41 return GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawBatch, (batch)); | 28 return GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawBatch, (batch)); |
| 42 } | 29 } |
| 43 | |
| 44 GrTargetCommands::Cmd* | |
| 45 GrInOrderCommandBuilder::recordDrawPaths(State* state, | |
| 46 GrBufferedDrawTarget* bufferedDrawTarge
t, | |
| 47 const GrPathProcessor* pathProc, | |
| 48 const GrPathRange* pathRange, | |
| 49 const void* indexValues, | |
| 50 GrDrawTarget::PathIndexType indexType, | |
| 51 const float transformValues[], | |
| 52 GrDrawTarget::PathTransformType transfo
rmType, | |
| 53 int count, | |
| 54 const GrStencilSettings& stencilSetting
s, | |
| 55 const GrPipelineOptimizations& opts) { | |
| 56 SkASSERT(pathRange); | |
| 57 SkASSERT(indexValues); | |
| 58 SkASSERT(transformValues); | |
| 59 | |
| 60 char* savedIndices; | |
| 61 float* savedTransforms; | |
| 62 | |
| 63 bufferedDrawTarget->appendIndicesAndTransforms(indexValues, indexType, | |
| 64 transformValues, transformTyp
e, | |
| 65 count, &savedIndices, &savedT
ransforms); | |
| 66 | |
| 67 if (!this->cmdBuffer()->empty() && | |
| 68 Cmd::kDrawPaths_CmdType == this->cmdBuffer()->back().type()) { | |
| 69 // Try to combine this call with the previous DrawPaths. We do this by s
tenciling all the | |
| 70 // paths together and then covering them in a single pass. This is not e
quivalent to two | |
| 71 // separate draw calls, so we can only do it if there is no blending (no
overlap would also | |
| 72 // work). Note that it's also possible for overlapping paths to cancel e
ach other's winding | |
| 73 // numbers, and we only partially account for this by not allowing even/
odd paths to be | |
| 74 // combined. (Glyphs in the same font tend to wind the same direction so
it works out OK.) | |
| 75 DrawPaths* previous = static_cast<DrawPaths*>(&this->cmdBuffer()->back()
); | |
| 76 if (pathRange == previous->pathRange() && | |
| 77 indexType == previous->fIndexType && | |
| 78 transformType == previous->fTransformType && | |
| 79 stencilSettings == previous->fStencilSettings && | |
| 80 path_fill_type_is_winding(stencilSettings) && | |
| 81 previous->fState == state && | |
| 82 !opts.willColorBlendWithDst()) { | |
| 83 | |
| 84 const int indexBytes = GrPathRange::PathIndexSizeInBytes(indexType); | |
| 85 const int xformSize = GrPathRendering::PathTransformSize(transformTy
pe); | |
| 86 if (&previous->fIndices[previous->fCount * indexBytes] == savedIndic
es && | |
| 87 (0 == xformSize || | |
| 88 &previous->fTransforms[previous->fCount * xformSize] == savedTr
ansforms)) { | |
| 89 // Combine this DrawPaths call with the one previous. | |
| 90 previous->fCount += count; | |
| 91 return nullptr; | |
| 92 } | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 DrawPaths* dp = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawPaths, (sta
te, pathRange)); | |
| 97 dp->fIndices = savedIndices; | |
| 98 dp->fIndexType = indexType; | |
| 99 dp->fTransforms = savedTransforms; | |
| 100 dp->fTransformType = transformType; | |
| 101 dp->fCount = count; | |
| 102 dp->fStencilSettings = stencilSettings; | |
| 103 return dp; | |
| 104 } | |
| OLD | NEW |