| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "GrInOrderDrawBuffer.h" | 8 #include "GrBufferedDrawTarget.h" |
| 9 | 9 |
| 10 // We will use the reordering buffer, unless we have NVPR. | 10 // We will use the reordering buffer, unless we have NVPR. |
| 11 // TODO move NVPR to batch so we can reorder | 11 // TODO move NVPR to batch so we can reorder |
| 12 static inline bool allow_reordering(const GrCaps* caps) { | 12 static inline bool allow_reordering(const GrCaps* caps) { |
| 13 return caps && caps->shaderCaps() && !caps->shaderCaps()->pathRenderingSuppo
rt(); | 13 return caps && caps->shaderCaps() && !caps->shaderCaps()->pathRenderingSuppo
rt(); |
| 14 } | 14 } |
| 15 | 15 |
| 16 GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrContext* context) | 16 GrBufferedDrawTarget::GrBufferedDrawTarget(GrContext* context) |
| 17 : INHERITED(context) | 17 : INHERITED(context) |
| 18 , fCommands(GrCommandBuilder::Create(context->getGpu(), allow_reordering(con
text->caps()))) | 18 , fCommands(GrCommandBuilder::Create(context->getGpu(), allow_reordering(con
text->caps()))) |
| 19 , fPathIndexBuffer(kPathIdxBufferMinReserve * sizeof(char)/4) | 19 , fPathIndexBuffer(kPathIdxBufferMinReserve * sizeof(char)/4) |
| 20 , fPathTransformBuffer(kPathXformBufferMinReserve * sizeof(float)/4) | 20 , fPathTransformBuffer(kPathXformBufferMinReserve * sizeof(float)/4) |
| 21 , fPipelineBuffer(kPipelineBufferMinReserve) | 21 , fPipelineBuffer(kPipelineBufferMinReserve) |
| 22 , fDrawID(0) { | 22 , fDrawID(0) { |
| 23 } | 23 } |
| 24 | 24 |
| 25 GrInOrderDrawBuffer::~GrInOrderDrawBuffer() { | 25 GrBufferedDrawTarget::~GrBufferedDrawTarget() { |
| 26 this->reset(); | 26 this->reset(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 void GrInOrderDrawBuffer::onDrawBatch(GrBatch* batch, | 29 void GrBufferedDrawTarget::onDrawBatch(GrBatch* batch, |
| 30 const PipelineInfo& pipelineInfo) { | 30 const PipelineInfo& pipelineInfo) { |
| 31 State* state = this->setupPipelineAndShouldDraw(batch, pipelineInfo); | 31 State* state = this->setupPipelineAndShouldDraw(batch, pipelineInfo); |
| 32 if (!state) { | 32 if (!state) { |
| 33 return; | 33 return; |
| 34 } | 34 } |
| 35 | 35 |
| 36 GrTargetCommands::Cmd* cmd = fCommands->recordDrawBatch(state, batch); | 36 GrTargetCommands::Cmd* cmd = fCommands->recordDrawBatch(state, batch); |
| 37 this->recordTraceMarkersIfNecessary(cmd); | 37 this->recordTraceMarkersIfNecessary(cmd); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void GrInOrderDrawBuffer::onStencilPath(const GrPipelineBuilder& pipelineBuilder
, | 40 void GrBufferedDrawTarget::onStencilPath(const GrPipelineBuilder& pipelineBuilde
r, |
| 41 const GrPathProcessor* pathProc, | 41 const GrPathProcessor* pathProc, |
| 42 const GrPath* path, | 42 const GrPath* path, |
| 43 const GrScissorState& scissorState, | 43 const GrScissorState& scissorState, |
| 44 const GrStencilSettings& stencilSettings
) { | 44 const GrStencilSettings& stencilSetting
s) { |
| 45 GrTargetCommands::Cmd* cmd = fCommands->recordStencilPath(pipelineBuilder, | 45 GrTargetCommands::Cmd* cmd = fCommands->recordStencilPath(pipelineBuilder, |
| 46 pathProc, path, sc
issorState, | 46 pathProc, path, sc
issorState, |
| 47 stencilSettings); | 47 stencilSettings); |
| 48 this->recordTraceMarkersIfNecessary(cmd); | 48 this->recordTraceMarkersIfNecessary(cmd); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void GrInOrderDrawBuffer::onDrawPath(const GrPathProcessor* pathProc, | 51 void GrBufferedDrawTarget::onDrawPath(const GrPathProcessor* pathProc, |
| 52 const GrPath* path, | 52 const GrPath* path, |
| 53 const GrStencilSettings& stencilSettings, | 53 const GrStencilSettings& stencilSettings, |
| 54 const PipelineInfo& pipelineInfo) { | 54 const PipelineInfo& pipelineInfo) { |
| 55 State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo); | 55 State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo); |
| 56 if (!state) { | 56 if (!state) { |
| 57 return; | 57 return; |
| 58 } | 58 } |
| 59 GrTargetCommands::Cmd* cmd = fCommands->recordDrawPath(state, pathProc, path
, stencilSettings); | 59 GrTargetCommands::Cmd* cmd = fCommands->recordDrawPath(state, pathProc, path
, stencilSettings); |
| 60 this->recordTraceMarkersIfNecessary(cmd); | 60 this->recordTraceMarkersIfNecessary(cmd); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void GrInOrderDrawBuffer::onDrawPaths(const GrPathProcessor* pathProc, | 63 void GrBufferedDrawTarget::onDrawPaths(const GrPathProcessor* pathProc, |
| 64 const GrPathRange* pathRange, | 64 const GrPathRange* pathRange, |
| 65 const void* indices, | 65 const void* indices, |
| 66 PathIndexType indexType, | 66 PathIndexType indexType, |
| 67 const float transformValues[], | 67 const float transformValues[], |
| 68 PathTransformType transformType, | 68 PathTransformType transformType, |
| 69 int count, | 69 int count, |
| 70 const GrStencilSettings& stencilSettings, | 70 const GrStencilSettings& stencilSettings, |
| 71 const PipelineInfo& pipelineInfo) { | 71 const PipelineInfo& pipelineInfo) { |
| 72 State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo); | 72 State* state = this->setupPipelineAndShouldDraw(pathProc, pipelineInfo); |
| 73 if (!state) { | 73 if (!state) { |
| 74 return; | 74 return; |
| 75 } | 75 } |
| 76 GrTargetCommands::Cmd* cmd = fCommands->recordDrawPaths(state, this, pathPro
c, pathRange, | 76 GrTargetCommands::Cmd* cmd = fCommands->recordDrawPaths(state, this, pathPro
c, pathRange, |
| 77 indices, indexType,
transformValues, | 77 indices, indexType,
transformValues, |
| 78 transformType, count
, | 78 transformType, count
, |
| 79 stencilSettings, pip
elineInfo); | 79 stencilSettings, pip
elineInfo); |
| 80 this->recordTraceMarkersIfNecessary(cmd); | 80 this->recordTraceMarkersIfNecessary(cmd); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void GrInOrderDrawBuffer::onClear(const SkIRect* rect, GrColor color, | 83 void GrBufferedDrawTarget::onClear(const SkIRect* rect, GrColor color, |
| 84 bool canIgnoreRect, GrRenderTarget* renderTarg
et) { | 84 bool canIgnoreRect, GrRenderTarget* renderTarg
et) { |
| 85 GrTargetCommands::Cmd* cmd = fCommands->recordClear(rect, color, canIgnoreRe
ct, renderTarget); | 85 GrTargetCommands::Cmd* cmd = fCommands->recordClear(rect, color, canIgnoreRe
ct, renderTarget); |
| 86 this->recordTraceMarkersIfNecessary(cmd); | 86 this->recordTraceMarkersIfNecessary(cmd); |
| 87 } | 87 } |
| 88 | 88 |
| 89 void GrInOrderDrawBuffer::clearStencilClip(const SkIRect& rect, | 89 void GrBufferedDrawTarget::clearStencilClip(const SkIRect& rect, |
| 90 bool insideClip, | 90 bool insideClip, |
| 91 GrRenderTarget* renderTarget) { | 91 GrRenderTarget* renderTarget) { |
| 92 GrTargetCommands::Cmd* cmd = fCommands->recordClearStencilClip(rect, insideC
lip, renderTarget); | 92 GrTargetCommands::Cmd* cmd = fCommands->recordClearStencilClip(rect, insideC
lip, renderTarget); |
| 93 this->recordTraceMarkersIfNecessary(cmd); | 93 this->recordTraceMarkersIfNecessary(cmd); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void GrInOrderDrawBuffer::discard(GrRenderTarget* renderTarget) { | 96 void GrBufferedDrawTarget::discard(GrRenderTarget* renderTarget) { |
| 97 if (!this->caps()->discardRenderTargetSupport()) { | 97 if (!this->caps()->discardRenderTargetSupport()) { |
| 98 return; | 98 return; |
| 99 } | 99 } |
| 100 | 100 |
| 101 GrTargetCommands::Cmd* cmd = fCommands->recordDiscard(renderTarget); | 101 GrTargetCommands::Cmd* cmd = fCommands->recordDiscard(renderTarget); |
| 102 this->recordTraceMarkersIfNecessary(cmd); | 102 this->recordTraceMarkersIfNecessary(cmd); |
| 103 } | 103 } |
| 104 | 104 |
| 105 void GrInOrderDrawBuffer::onReset() { | 105 void GrBufferedDrawTarget::onReset() { |
| 106 fCommands->reset(); | 106 fCommands->reset(); |
| 107 fPathIndexBuffer.rewind(); | 107 fPathIndexBuffer.rewind(); |
| 108 fPathTransformBuffer.rewind(); | 108 fPathTransformBuffer.rewind(); |
| 109 fGpuCmdMarkers.reset(); | 109 fGpuCmdMarkers.reset(); |
| 110 | 110 |
| 111 fPrevState.reset(NULL); | 111 fPrevState.reset(NULL); |
| 112 // Note, fPrevState points into fPipelineBuffer's allocation, so we have to
reset first. | 112 // Note, fPrevState points into fPipelineBuffer's allocation, so we have to
reset first. |
| 113 // Furthermore, we have to reset fCommands before fPipelineBuffer too. | 113 // Furthermore, we have to reset fCommands before fPipelineBuffer too. |
| 114 if (fDrawID % kPipelineBufferHighWaterMark) { | 114 if (fDrawID % kPipelineBufferHighWaterMark) { |
| 115 fPipelineBuffer.rewind(); | 115 fPipelineBuffer.rewind(); |
| 116 } else { | 116 } else { |
| 117 fPipelineBuffer.reset(); | 117 fPipelineBuffer.reset(); |
| 118 } | 118 } |
| 119 } | 119 } |
| 120 | 120 |
| 121 void GrInOrderDrawBuffer::onFlush() { | 121 void GrBufferedDrawTarget::onFlush() { |
| 122 fCommands->flush(this); | 122 fCommands->flush(this); |
| 123 ++fDrawID; | 123 ++fDrawID; |
| 124 } | 124 } |
| 125 | 125 |
| 126 void GrInOrderDrawBuffer::onCopySurface(GrSurface* dst, | 126 void GrBufferedDrawTarget::onCopySurface(GrSurface* dst, |
| 127 GrSurface* src, | 127 GrSurface* src, |
| 128 const SkIRect& srcRect, | 128 const SkIRect& srcRect, |
| 129 const SkIPoint& dstPoint) { | 129 const SkIPoint& dstPoint) { |
| 130 GrTargetCommands::Cmd* cmd = fCommands->recordCopySurface(dst, src, srcRect,
dstPoint); | 130 GrTargetCommands::Cmd* cmd = fCommands->recordCopySurface(dst, src, srcRect,
dstPoint); |
| 131 this->recordTraceMarkersIfNecessary(cmd); | 131 this->recordTraceMarkersIfNecessary(cmd); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary(GrTargetCommands::Cmd* c
md) { | 134 void GrBufferedDrawTarget::recordTraceMarkersIfNecessary(GrTargetCommands::Cmd*
cmd) { |
| 135 if (!cmd) { | 135 if (!cmd) { |
| 136 return; | 136 return; |
| 137 } | 137 } |
| 138 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); | 138 const GrTraceMarkerSet& activeTraceMarkers = this->getActiveTraceMarkers(); |
| 139 if (activeTraceMarkers.count() > 0) { | 139 if (activeTraceMarkers.count() > 0) { |
| 140 if (cmd->isTraced()) { | 140 if (cmd->isTraced()) { |
| 141 fGpuCmdMarkers[cmd->markerID()].addSet(activeTraceMarkers); | 141 fGpuCmdMarkers[cmd->markerID()].addSet(activeTraceMarkers); |
| 142 } else { | 142 } else { |
| 143 cmd->setMarkerID(fGpuCmdMarkers.count()); | 143 cmd->setMarkerID(fGpuCmdMarkers.count()); |
| 144 fGpuCmdMarkers.push_back(activeTraceMarkers); | 144 fGpuCmdMarkers.push_back(activeTraceMarkers); |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 GrTargetCommands::State* | 149 GrTargetCommands::State* |
| 150 GrInOrderDrawBuffer::setupPipelineAndShouldDraw(const GrPrimitiveProcessor* prim
Proc, | 150 GrBufferedDrawTarget::setupPipelineAndShouldDraw(const GrPrimitiveProcessor* pri
mProc, |
| 151 const GrDrawTarget::PipelineInfo
& pipelineInfo) { | 151 const GrDrawTarget::PipelineInf
o& pipelineInfo) { |
| 152 State* state = this->allocState(primProc); | 152 State* state = this->allocState(primProc); |
| 153 this->setupPipeline(pipelineInfo, state->pipelineLocation()); | 153 this->setupPipeline(pipelineInfo, state->pipelineLocation()); |
| 154 | 154 |
| 155 if (state->getPipeline()->mustSkip()) { | 155 if (state->getPipeline()->mustSkip()) { |
| 156 this->unallocState(state); | 156 this->unallocState(state); |
| 157 return NULL; | 157 return NULL; |
| 158 } | 158 } |
| 159 | 159 |
| 160 state->fPrimitiveProcessor->initBatchTracker( | 160 state->fPrimitiveProcessor->initBatchTracker( |
| 161 &state->fBatchTracker, state->getPipeline()->infoForPrimitiveProcessor()
); | 161 &state->fBatchTracker, state->getPipeline()->infoForPrimitiveProcessor()
); |
| 162 | 162 |
| 163 if (fPrevState && fPrevState->fPrimitiveProcessor.get() && | 163 if (fPrevState && fPrevState->fPrimitiveProcessor.get() && |
| 164 fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker, | 164 fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker, |
| 165 *state->fPrimitiveProcesso
r, | 165 *state->fPrimitiveProcesso
r, |
| 166 state->fBatchTracker) && | 166 state->fBatchTracker) && |
| 167 fPrevState->getPipeline()->isEqual(*state->getPipeline())) { | 167 fPrevState->getPipeline()->isEqual(*state->getPipeline())) { |
| 168 this->unallocState(state); | 168 this->unallocState(state); |
| 169 } else { | 169 } else { |
| 170 fPrevState.reset(state); | 170 fPrevState.reset(state); |
| 171 } | 171 } |
| 172 | 172 |
| 173 this->recordTraceMarkersIfNecessary( | 173 this->recordTraceMarkersIfNecessary( |
| 174 fCommands->recordXferBarrierIfNecessary(*fPrevState->getPipeline(),
*this->caps())); | 174 fCommands->recordXferBarrierIfNecessary(*fPrevState->getPipeline(),
*this->caps())); |
| 175 return fPrevState; | 175 return fPrevState; |
| 176 } | 176 } |
| 177 | 177 |
| 178 GrTargetCommands::State* | 178 GrTargetCommands::State* |
| 179 GrInOrderDrawBuffer::setupPipelineAndShouldDraw(GrBatch* batch, | 179 GrBufferedDrawTarget::setupPipelineAndShouldDraw(GrBatch* batch, |
| 180 const GrDrawTarget::PipelineInfo
& pipelineInfo) { | 180 const GrDrawTarget::PipelineInf
o& pipelineInfo) { |
| 181 State* state = this->allocState(); | 181 State* state = this->allocState(); |
| 182 this->setupPipeline(pipelineInfo, state->pipelineLocation()); | 182 this->setupPipeline(pipelineInfo, state->pipelineLocation()); |
| 183 | 183 |
| 184 if (state->getPipeline()->mustSkip()) { | 184 if (state->getPipeline()->mustSkip()) { |
| 185 this->unallocState(state); | 185 this->unallocState(state); |
| 186 return NULL; | 186 return NULL; |
| 187 } | 187 } |
| 188 | 188 |
| 189 batch->initBatchTracker(state->getPipeline()->infoForPrimitiveProcessor()); | 189 batch->initBatchTracker(state->getPipeline()->infoForPrimitiveProcessor()); |
| 190 | 190 |
| 191 if (fPrevState && !fPrevState->fPrimitiveProcessor.get() && | 191 if (fPrevState && !fPrevState->fPrimitiveProcessor.get() && |
| 192 fPrevState->getPipeline()->isEqual(*state->getPipeline())) { | 192 fPrevState->getPipeline()->isEqual(*state->getPipeline())) { |
| 193 this->unallocState(state); | 193 this->unallocState(state); |
| 194 } else { | 194 } else { |
| 195 fPrevState.reset(state); | 195 fPrevState.reset(state); |
| 196 } | 196 } |
| 197 | 197 |
| 198 this->recordTraceMarkersIfNecessary( | 198 this->recordTraceMarkersIfNecessary( |
| 199 fCommands->recordXferBarrierIfNecessary(*fPrevState->getPipeline(),
*this->caps())); | 199 fCommands->recordXferBarrierIfNecessary(*fPrevState->getPipeline(),
*this->caps())); |
| 200 return fPrevState; | 200 return fPrevState; |
| 201 } | 201 } |
| OLD | NEW |