OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2011 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 "GrBufferedDrawTarget.h" |
| 9 |
| 10 // We will use the reordering buffer, unless we have NVPR. |
| 11 // TODO move NVPR to batch so we can reorder |
| 12 static inline bool allow_reordering(const GrCaps* caps) { |
| 13 return caps && caps->shaderCaps() && !caps->shaderCaps()->pathRenderingSuppo
rt(); |
| 14 } |
| 15 |
| 16 GrBufferedDrawTarget::GrBufferedDrawTarget(GrDrawContext* dc, GrRenderTarget* rt
, GrContext* context) |
| 17 : INHERITED(dc, rt, context) |
| 18 , fCommands(GrCommandBuilder::Create(context->foo(), context->getGpu(), allo
w_reordering(context->caps()), rt)) |
| 19 , fPathIndexBuffer(kPathIdxBufferMinReserve * sizeof(char)/4) |
| 20 , fPathTransformBuffer(kPathXformBufferMinReserve * sizeof(float)/4) |
| 21 , fPipelineBuffer(kPipelineBufferMinReserve) |
| 22 , fDrawID(0) { |
| 23 } |
| 24 |
| 25 GrBufferedDrawTarget::~GrBufferedDrawTarget() { |
| 26 this->reset(); |
| 27 } |
| 28 |
| 29 void GrBufferedDrawTarget::onDrawBatch(GrBatch* batch) { |
| 30 fCommands->recordDrawBatch(batch, *this->caps()); |
| 31 } |
| 32 |
| 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() { |
| 68 fCommands->flush(this->getGpu(), this->getContext()->resourceProvider()); |
| 69 ++fDrawID; |
| 70 } |
| 71 |
| 72 GrTargetCommands::StateForPathDraw* |
| 73 GrBufferedDrawTarget::createStateForPathDraw(const GrPrimitiveProcessor* primPro
c, |
| 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 } |
OLD | NEW |