OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 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. |
| 6 */ |
| 7 |
| 8 #include "GrCommandBuilder.h" |
| 9 |
| 10 #include "GrColor.h" |
| 11 #include "GrInOrderDrawBuffer.h" |
| 12 #include "GrTemplates.h" |
| 13 #include "SkPoint.h" |
| 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* GrCommandBuilder::recordDrawBatch(State* state, GrBatch*
batch) { |
| 29 // Check if there is a Batch Draw we can batch with |
| 30 if (!this->cmdBuffer()->empty() && |
| 31 Cmd::kDrawBatch_CmdType == this->cmdBuffer()->back().type()) { |
| 32 DrawBatch* previous = static_cast<DrawBatch*>(&this->cmdBuffer()->back()
); |
| 33 if (previous->fState == state && previous->fBatch->combineIfPossible(bat
ch)) { |
| 34 return NULL; |
| 35 } |
| 36 } |
| 37 |
| 38 return GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawBatch, (state, batch
, |
| 39 this->batchT
arget())); |
| 40 } |
| 41 |
| 42 GrTargetCommands::Cmd* |
| 43 GrCommandBuilder::recordStencilPath(const GrPipelineBuilder& pipelineBuilder, |
| 44 const GrPathProcessor* pathProc, |
| 45 const GrPath* path, |
| 46 const GrScissorState& scissorState, |
| 47 const GrStencilSettings& stencilSettings) { |
| 48 StencilPath* sp = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), StencilPath, |
| 49 (path, pipelineBuilder.getRenderT
arget())); |
| 50 |
| 51 sp->fScissor = scissorState; |
| 52 sp->fUseHWAA = pipelineBuilder.isHWAntialias(); |
| 53 sp->fViewMatrix = pathProc->viewMatrix(); |
| 54 sp->fStencil = stencilSettings; |
| 55 return sp; |
| 56 } |
| 57 |
| 58 GrTargetCommands::Cmd* |
| 59 GrCommandBuilder::recordDrawPath(State* state, |
| 60 const GrPathProcessor* pathProc, |
| 61 const GrPath* path, |
| 62 const GrStencilSettings& stencilSettings) { |
| 63 DrawPath* dp = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawPath, (state
, path)); |
| 64 dp->fStencilSettings = stencilSettings; |
| 65 return dp; |
| 66 } |
| 67 |
| 68 GrTargetCommands::Cmd* |
| 69 GrCommandBuilder::recordDrawPaths(State* state, |
| 70 GrInOrderDrawBuffer* iodb, |
| 71 const GrPathProcessor* pathProc, |
| 72 const GrPathRange* pathRange, |
| 73 const void* indexValues, |
| 74 GrDrawTarget::PathIndexType indexType, |
| 75 const float transformValues[], |
| 76 GrDrawTarget::PathTransformType transformType, |
| 77 int count, |
| 78 const GrStencilSettings& stencilSettings, |
| 79 const GrDrawTarget::PipelineInfo& pipelineInfo
) { |
| 80 SkASSERT(pathRange); |
| 81 SkASSERT(indexValues); |
| 82 SkASSERT(transformValues); |
| 83 |
| 84 char* savedIndices; |
| 85 float* savedTransforms; |
| 86 |
| 87 iodb->appendIndicesAndTransforms(indexValues, indexType, |
| 88 transformValues, transformType, |
| 89 count, &savedIndices, &savedTransforms); |
| 90 |
| 91 if (!this->cmdBuffer()->empty() && |
| 92 Cmd::kDrawPaths_CmdType == this->cmdBuffer()->back().type()) { |
| 93 // The previous command was also DrawPaths. Try to collapse this call in
to the one |
| 94 // before. Note that stenciling all the paths at once, then covering, ma
y not be |
| 95 // equivalent to two separate draw calls if there is overlap. Blending w
on't work, |
| 96 // and the combined calls may also cancel each other's winding numbers i
n some |
| 97 // places. For now the winding numbers are only an issue if the fill is
even/odd, |
| 98 // because DrawPaths is currently only used for glyphs, and glyphs in th
e same |
| 99 // font tend to all wind in the same direction. |
| 100 DrawPaths* previous = static_cast<DrawPaths*>(&this->cmdBuffer()->back()
); |
| 101 if (pathRange == previous->pathRange() && |
| 102 indexType == previous->fIndexType && |
| 103 transformType == previous->fTransformType && |
| 104 stencilSettings == previous->fStencilSettings && |
| 105 path_fill_type_is_winding(stencilSettings) && |
| 106 !pipelineInfo.willBlendWithDst(pathProc) && |
| 107 previous->fState == state) { |
| 108 const int indexBytes = GrPathRange::PathIndexSizeInBytes(indexTy
pe); |
| 109 const int xformSize = GrPathRendering::PathTransformSize(transfo
rmType); |
| 110 if (&previous->fIndices[previous->fCount*indexBytes] == savedInd
ices && |
| 111 (0 == xformSize || |
| 112 &previous->fTransforms[previous->fCount*xformSize] == saved
Transforms)) { |
| 113 // Fold this DrawPaths call into the one previous. |
| 114 previous->fCount += count; |
| 115 return NULL; |
| 116 } |
| 117 } |
| 118 } |
| 119 |
| 120 DrawPaths* dp = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawPaths, (sta
te, pathRange)); |
| 121 dp->fIndices = savedIndices; |
| 122 dp->fIndexType = indexType; |
| 123 dp->fTransforms = savedTransforms; |
| 124 dp->fTransformType = transformType; |
| 125 dp->fCount = count; |
| 126 dp->fStencilSettings = stencilSettings; |
| 127 return dp; |
| 128 } |
| 129 |
| 130 GrTargetCommands::Cmd* GrCommandBuilder::recordClear(const SkIRect* rect, |
| 131 GrColor color, |
| 132 bool canIgnoreRect, |
| 133 GrRenderTarget* renderTarge
t) { |
| 134 SkASSERT(renderTarget); |
| 135 |
| 136 SkIRect r; |
| 137 if (NULL == rect) { |
| 138 // We could do something smart and remove previous draws and clears to |
| 139 // the current render target. If we get that smart we have to make sure |
| 140 // those draws aren't read before this clear (render-to-texture). |
| 141 r.setLTRB(0, 0, renderTarget->width(), renderTarget->height()); |
| 142 rect = &r; |
| 143 } |
| 144 Clear* clr = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), Clear, (renderTarg
et)); |
| 145 GrColorIsPMAssert(color); |
| 146 clr->fColor = color; |
| 147 clr->fRect = *rect; |
| 148 clr->fCanIgnoreRect = canIgnoreRect; |
| 149 return clr; |
| 150 } |
| 151 |
| 152 GrTargetCommands::Cmd* GrCommandBuilder::recordClearStencilClip(const SkIRect& r
ect, |
| 153 bool insideClip, |
| 154 GrRenderTarget*
renderTarget) { |
| 155 SkASSERT(renderTarget); |
| 156 |
| 157 ClearStencilClip* clr = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), |
| 158 ClearStencilClip, |
| 159 (renderTarget)); |
| 160 clr->fRect = rect; |
| 161 clr->fInsideClip = insideClip; |
| 162 return clr; |
| 163 } |
| 164 |
| 165 GrTargetCommands::Cmd* GrCommandBuilder::recordDiscard(GrRenderTarget* renderTar
get) { |
| 166 SkASSERT(renderTarget); |
| 167 |
| 168 Clear* clr = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), Clear, (renderTarg
et)); |
| 169 clr->fColor = GrColor_ILLEGAL; |
| 170 return clr; |
| 171 } |
| 172 |
| 173 GrTargetCommands::Cmd* GrCommandBuilder::recordCopySurface(GrSurface* dst, |
| 174 GrSurface* src, |
| 175 const SkIRect& srcRec
t, |
| 176 const SkIPoint& dstPo
int) { |
| 177 CopySurface* cs = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), CopySurface,
(dst, src)); |
| 178 cs->fSrcRect = srcRect; |
| 179 cs->fDstPoint = dstPoint; |
| 180 return cs; |
| 181 } |
| 182 |
| 183 GrTargetCommands::Cmd* |
| 184 GrCommandBuilder::recordXferBarrierIfNecessary(const GrPipeline& pipeline, |
| 185 const GrDrawTargetCaps& caps) { |
| 186 const GrXferProcessor& xp = *pipeline.getXferProcessor(); |
| 187 GrRenderTarget* rt = pipeline.getRenderTarget(); |
| 188 |
| 189 GrXferBarrierType barrierType; |
| 190 if (!xp.willNeedXferBarrier(rt, caps, &barrierType)) { |
| 191 return NULL; |
| 192 } |
| 193 |
| 194 XferBarrier* xb = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), XferBarrier,
()); |
| 195 xb->fBarrierType = barrierType; |
| 196 return xb; |
| 197 } |
OLD | NEW |