| 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 "GrBufferedDrawTarget.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 GrBufferedDrawTarget::GrBufferedDrawTarget(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) | |
| 20 , fPathTransformBuffer(kPathXformBufferMinReserve * sizeof(float)/4) | |
| 21 , fPipelineBuffer(kPipelineBufferMinReserve) | |
| 22 , fDrawID(0) { | 19 , fDrawID(0) { |
| 23 } | 20 } |
| 24 | 21 |
| 25 GrBufferedDrawTarget::~GrBufferedDrawTarget() { | 22 GrBufferedDrawTarget::~GrBufferedDrawTarget() { |
| 26 this->reset(); | 23 this->reset(); |
| 27 } | 24 } |
| 28 | 25 |
| 29 void GrBufferedDrawTarget::onDrawBatch(GrBatch* batch) { | 26 void GrBufferedDrawTarget::onDrawBatch(GrBatch* batch) { |
| 30 fCommands->recordDrawBatch(batch, *this->caps()); | 27 fCommands->recordDrawBatch(batch, *this->caps()); |
| 31 } | 28 } |
| 32 | 29 |
| 33 void GrBufferedDrawTarget::onDrawPaths(const GrPathProcessor* pathProc, | |
| 34 const GrPathRange* pathRange, | |
| 35 const void* indices, | |
| 36 PathIndexType indexType, | |
| 37 const float transformValues[], | |
| 38 PathTransformType transformType, | |
| 39 int count, | |
| 40 const GrStencilSettings& stencilSettings, | |
| 41 const PipelineInfo& pipelineInfo) { | |
| 42 GrPipelineOptimizations opts; | |
| 43 StateForPathDraw* state = this->createStateForPathDraw(pathProc, pipelineInf
o, &opts); | |
| 44 if (!state) { | |
| 45 return; | |
| 46 } | |
| 47 fCommands->recordDrawPaths(state, this, pathProc, pathRange, indices, indexT
ype, | |
| 48 transformValues, transformType, count, stencilSet
tings, | |
| 49 opts); | |
| 50 } | |
| 51 | |
| 52 void GrBufferedDrawTarget::onReset() { | |
| 53 fCommands->reset(); | |
| 54 fPathIndexBuffer.rewind(); | |
| 55 fPathTransformBuffer.rewind(); | |
| 56 | |
| 57 fPrevState.reset(nullptr); | |
| 58 // Note, fPrevState points into fPipelineBuffer's allocation, so we have to
reset first. | |
| 59 // Furthermore, we have to reset fCommands before fPipelineBuffer too. | |
| 60 if (fDrawID % kPipelineBufferHighWaterMark) { | |
| 61 fPipelineBuffer.rewind(); | |
| 62 } else { | |
| 63 fPipelineBuffer.reset(); | |
| 64 } | |
| 65 } | |
| 66 | |
| 67 void GrBufferedDrawTarget::onFlush() { | 30 void GrBufferedDrawTarget::onFlush() { |
| 68 fCommands->flush(this->getGpu(), this->getContext()->resourceProvider()); | 31 fCommands->flush(this->getGpu(), this->getContext()->resourceProvider()); |
| 69 ++fDrawID; | 32 ++fDrawID; |
| 70 } | 33 } |
| 71 | 34 |
| 72 GrTargetCommands::StateForPathDraw* | 35 void GrBufferedDrawTarget::onReset() { |
| 73 GrBufferedDrawTarget::createStateForPathDraw(const GrPrimitiveProcessor* primPro
c, | 36 fCommands->reset(); |
| 74 const GrDrawTarget::PipelineInfo& p
ipelineInfo, | |
| 75 GrPipelineOptimizations* opts) { | |
| 76 StateForPathDraw* state = this->allocState(primProc); | |
| 77 if (!GrPipeline::CreateAt(state->pipelineLocation(), pipelineInfo.pipelineCr
eateArgs(), opts)) { | |
| 78 this->unallocState(state); | |
| 79 return nullptr; | |
| 80 } | |
| 81 | |
| 82 state->fPrimitiveProcessor->initBatchTracker(&state->fBatchTracker, *opts); | |
| 83 | |
| 84 if (fPrevState && fPrevState->fPrimitiveProcessor.get() && | |
| 85 fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker, | |
| 86 *state->fPrimitiveProcesso
r, | |
| 87 state->fBatchTracker) && | |
| 88 GrPipeline::AreEqual(*fPrevState->getPipeline(), *state->getPipeline(),
false)) { | |
| 89 this->unallocState(state); | |
| 90 } else { | |
| 91 fPrevState.reset(state); | |
| 92 } | |
| 93 | |
| 94 return fPrevState; | |
| 95 } | 37 } |
| OLD | NEW |