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 "GrCommandBuilder.h" |
9 | 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, | 10 GrTargetCommands::Cmd* GrCommandBuilder::recordClear(const SkIRect* rect, |
131 GrColor color, | 11 GrColor color, |
132 bool canIgnoreRect, | 12 bool canIgnoreRect, |
133 GrRenderTarget* renderTarge
t) { | 13 GrRenderTarget* renderTarge
t) { |
134 SkASSERT(renderTarget); | 14 SkASSERT(renderTarget); |
135 | 15 |
136 SkIRect r; | 16 SkIRect r; |
137 if (NULL == rect) { | 17 if (NULL == rect) { |
138 // We could do something smart and remove previous draws and clears to | 18 // 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 | 19 // the current render target. If we get that smart we have to make sure |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 68 |
189 GrXferBarrierType barrierType; | 69 GrXferBarrierType barrierType; |
190 if (!xp.willNeedXferBarrier(rt, caps, &barrierType)) { | 70 if (!xp.willNeedXferBarrier(rt, caps, &barrierType)) { |
191 return NULL; | 71 return NULL; |
192 } | 72 } |
193 | 73 |
194 XferBarrier* xb = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), XferBarrier,
()); | 74 XferBarrier* xb = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), XferBarrier,
()); |
195 xb->fBarrierType = barrierType; | 75 xb->fBarrierType = barrierType; |
196 return xb; | 76 return xb; |
197 } | 77 } |
OLD | NEW |