| 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 "GrCommandBuilder.h" | 8 #include "GrInOrderCommandBuilder.h" |
| 9 | 9 |
| 10 #include "GrColor.h" | 10 #include "GrColor.h" |
| 11 #include "GrInOrderDrawBuffer.h" | 11 #include "GrInOrderDrawBuffer.h" |
| 12 #include "GrTemplates.h" | 12 #include "GrTemplates.h" |
| 13 #include "SkPoint.h" | 13 #include "SkPoint.h" |
| 14 | 14 |
| 15 static bool path_fill_type_is_winding(const GrStencilSettings& pathStencilSettin
gs) { | 15 static bool path_fill_type_is_winding(const GrStencilSettings& pathStencilSettin
gs) { |
| 16 static const GrStencilSettings::Face pathFace = GrStencilSettings::kFront_Fa
ce; | 16 static const GrStencilSettings::Face pathFace = GrStencilSettings::kFront_Fa
ce; |
| 17 bool isWinding = kInvert_StencilOp != pathStencilSettings.passOp(pathFace); | 17 bool isWinding = kInvert_StencilOp != pathStencilSettings.passOp(pathFace); |
| 18 if (isWinding) { | 18 if (isWinding) { |
| 19 // Double check that it is in fact winding. | 19 // Double check that it is in fact winding. |
| 20 SkASSERT(kIncClamp_StencilOp == pathStencilSettings.passOp(pathFace)); | 20 SkASSERT(kIncClamp_StencilOp == pathStencilSettings.passOp(pathFace)); |
| 21 SkASSERT(kIncClamp_StencilOp == pathStencilSettings.failOp(pathFace)); | 21 SkASSERT(kIncClamp_StencilOp == pathStencilSettings.failOp(pathFace)); |
| 22 SkASSERT(0x1 != pathStencilSettings.writeMask(pathFace)); | 22 SkASSERT(0x1 != pathStencilSettings.writeMask(pathFace)); |
| 23 SkASSERT(!pathStencilSettings.isTwoSided()); | 23 SkASSERT(!pathStencilSettings.isTwoSided()); |
| 24 } | 24 } |
| 25 return isWinding; | 25 return isWinding; |
| 26 } | 26 } |
| 27 | 27 |
| 28 GrTargetCommands::Cmd* GrCommandBuilder::recordDrawBatch(State* state, GrBatch*
batch) { | 28 GrTargetCommands::Cmd* GrInOrderCommandBuilder::recordDrawBatch(State* state, Gr
Batch* batch) { |
| 29 // Check if there is a Batch Draw we can batch with | 29 // Check if there is a Batch Draw we can batch with |
| 30 if (!this->cmdBuffer()->empty() && | 30 if (!this->cmdBuffer()->empty() && |
| 31 Cmd::kDrawBatch_CmdType == this->cmdBuffer()->back().type()) { | 31 Cmd::kDrawBatch_CmdType == this->cmdBuffer()->back().type()) { |
| 32 DrawBatch* previous = static_cast<DrawBatch*>(&this->cmdBuffer()->back()
); | 32 DrawBatch* previous = static_cast<DrawBatch*>(&this->cmdBuffer()->back()
); |
| 33 if (previous->fState == state && previous->fBatch->combineIfPossible(bat
ch)) { | 33 if (previous->fState == state && previous->fBatch->combineIfPossible(bat
ch)) { |
| 34 return NULL; | 34 return NULL; |
| 35 } | 35 } |
| 36 } | 36 } |
| 37 | 37 |
| 38 return GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawBatch, (state, batch
, | 38 return GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawBatch, (state, batch
, |
| 39 this->batchT
arget())); | 39 this->batchT
arget())); |
| 40 } | 40 } |
| 41 | 41 |
| 42 GrTargetCommands::Cmd* | 42 GrTargetCommands::Cmd* |
| 43 GrCommandBuilder::recordStencilPath(const GrPipelineBuilder& pipelineBuilder, | 43 GrInOrderCommandBuilder::recordStencilPath(const GrPipelineBuilder& pipelineBuil
der, |
| 44 const GrPathProcessor* pathProc, | 44 const GrPathProcessor* pathProc, |
| 45 const GrPath* path, | 45 const GrPath* path, |
| 46 const GrScissorState& scissorState, | 46 const GrScissorState& scissorState, |
| 47 const GrStencilSettings& stencilSettings) { | 47 const GrStencilSettings& stencilSetti
ngs) { |
| 48 StencilPath* sp = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), StencilPath, | 48 StencilPath* sp = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), StencilPath, |
| 49 (path, pipelineBuilder.getRenderT
arget())); | 49 (path, pipelineBuilder.getRenderT
arget())); |
| 50 | 50 |
| 51 sp->fScissor = scissorState; | 51 sp->fScissor = scissorState; |
| 52 sp->fUseHWAA = pipelineBuilder.isHWAntialias(); | 52 sp->fUseHWAA = pipelineBuilder.isHWAntialias(); |
| 53 sp->fViewMatrix = pathProc->viewMatrix(); | 53 sp->fViewMatrix = pathProc->viewMatrix(); |
| 54 sp->fStencil = stencilSettings; | 54 sp->fStencil = stencilSettings; |
| 55 return sp; | 55 return sp; |
| 56 } | 56 } |
| 57 | 57 |
| 58 GrTargetCommands::Cmd* | 58 GrTargetCommands::Cmd* |
| 59 GrCommandBuilder::recordDrawPath(State* state, | 59 GrInOrderCommandBuilder::recordDrawPath(State* state, |
| 60 const GrPathProcessor* pathProc, | 60 const GrPathProcessor* pathProc, |
| 61 const GrPath* path, | 61 const GrPath* path, |
| 62 const GrStencilSettings& stencilSettings) { | 62 const GrStencilSettings& stencilSettings
) { |
| 63 DrawPath* dp = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawPath, (state
, path)); | 63 DrawPath* dp = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawPath, (state
, path)); |
| 64 dp->fStencilSettings = stencilSettings; | 64 dp->fStencilSettings = stencilSettings; |
| 65 return dp; | 65 return dp; |
| 66 } | 66 } |
| 67 | 67 |
| 68 GrTargetCommands::Cmd* | 68 GrTargetCommands::Cmd* |
| 69 GrCommandBuilder::recordDrawPaths(State* state, | 69 GrInOrderCommandBuilder::recordDrawPaths(State* state, |
| 70 GrInOrderDrawBuffer* iodb, | 70 GrInOrderDrawBuffer* iodb, |
| 71 const GrPathProcessor* pathProc, | 71 const GrPathProcessor* pathProc, |
| 72 const GrPathRange* pathRange, | 72 const GrPathRange* pathRange, |
| 73 const void* indexValues, | 73 const void* indexValues, |
| 74 GrDrawTarget::PathIndexType indexType, | 74 GrDrawTarget::PathIndexType indexType, |
| 75 const float transformValues[], | 75 const float transformValues[], |
| 76 GrDrawTarget::PathTransformType transformType, | 76 GrDrawTarget::PathTransformType transfo
rmType, |
| 77 int count, | 77 int count, |
| 78 const GrStencilSettings& stencilSettings, | 78 const GrStencilSettings& stencilSetting
s, |
| 79 const GrDrawTarget::PipelineInfo& pipelineInfo
) { | 79 const GrDrawTarget::PipelineInfo& pipel
ineInfo) { |
| 80 SkASSERT(pathRange); | 80 SkASSERT(pathRange); |
| 81 SkASSERT(indexValues); | 81 SkASSERT(indexValues); |
| 82 SkASSERT(transformValues); | 82 SkASSERT(transformValues); |
| 83 | 83 |
| 84 char* savedIndices; | 84 char* savedIndices; |
| 85 float* savedTransforms; | 85 float* savedTransforms; |
| 86 | 86 |
| 87 iodb->appendIndicesAndTransforms(indexValues, indexType, | 87 iodb->appendIndicesAndTransforms(indexValues, indexType, |
| 88 transformValues, transformType, | 88 transformValues, transformType, |
| 89 count, &savedIndices, &savedTransforms); | 89 count, &savedIndices, &savedTransforms); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 119 | 119 |
| 120 DrawPaths* dp = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawPaths, (sta
te, pathRange)); | 120 DrawPaths* dp = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawPaths, (sta
te, pathRange)); |
| 121 dp->fIndices = savedIndices; | 121 dp->fIndices = savedIndices; |
| 122 dp->fIndexType = indexType; | 122 dp->fIndexType = indexType; |
| 123 dp->fTransforms = savedTransforms; | 123 dp->fTransforms = savedTransforms; |
| 124 dp->fTransformType = transformType; | 124 dp->fTransformType = transformType; |
| 125 dp->fCount = count; | 125 dp->fCount = count; |
| 126 dp->fStencilSettings = stencilSettings; | 126 dp->fStencilSettings = stencilSettings; |
| 127 return dp; | 127 return dp; |
| 128 } | 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 |