1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "GrImmediateDrawTarget.h"
#include "GrBatch.h"
#include "GrGpu.h"
#include "GrPipeline.h"
#include "GrRenderTarget.h"
#include "SkRect.h"
#include "SkTypes.h"
GrImmediateDrawTarget::GrImmediateDrawTarget(GrContext* context)
: INHERITED(context)
, fBatchTarget(this->getGpu())
, fDrawID(0) {
}
GrImmediateDrawTarget::~GrImmediateDrawTarget() {
this->reset();
}
void GrImmediateDrawTarget::onDrawBatch(GrBatch* batch,
const PipelineInfo& pipelineInfo) {
SkAlignedSStorage<sizeof(GrPipeline)> pipelineStorage;
GrPipeline* pipeline = reinterpret_cast<GrPipeline*>(pipelineStorage.get());
if (!this->setupPipelineAndShouldDraw(pipeline, pipelineInfo)) {
pipeline->~GrPipeline();
return;
}
batch->initBatchTracker(pipeline->getInitBatchTracker());
fBatchTarget.resetNumberOfDraws();
batch->generateGeometry(&fBatchTarget, pipeline);
batch->setNumberOfDraws(fBatchTarget.numberOfDraws());
fBatchTarget.preFlush();
fBatchTarget.flushNext(batch->numberOfDraws());
fBatchTarget.postFlush();
pipeline->~GrPipeline();
}
void GrImmediateDrawTarget::onClear(const SkIRect* rect, GrColor color,
bool canIgnoreRect, GrRenderTarget* renderTarget) {
this->getGpu()->clear(rect, color, canIgnoreRect, renderTarget);
}
void GrImmediateDrawTarget::clearStencilClip(const SkIRect& rect,
bool insideClip,
GrRenderTarget* renderTarget) {
this->getGpu()->clearStencilClip(rect, insideClip, renderTarget);
}
void GrImmediateDrawTarget::discard(GrRenderTarget* renderTarget) {
if (!this->caps()->discardRenderTargetSupport()) {
return;
}
this->getGpu()->discard(renderTarget);
}
void GrImmediateDrawTarget::onReset() {
fBatchTarget.reset();
}
void GrImmediateDrawTarget::onFlush() {
++fDrawID;
}
bool
GrImmediateDrawTarget::setupPipelineAndShouldDraw(GrPipeline* pipeline,
const GrDrawTarget::PipelineInfo& pipelineInfo) {
this->setupPipeline(pipelineInfo, pipeline);
if (pipeline->mustSkip()) {
return false;
}
this->recordXferBarrierIfNecessary(pipeline);
return true;
}
void GrImmediateDrawTarget::recordXferBarrierIfNecessary(const GrPipeline* pipeline) {
const GrXferProcessor& xp = *pipeline->getXferProcessor();
GrRenderTarget* rt = pipeline->getRenderTarget();
GrXferBarrierType barrierType;
if (xp.willNeedXferBarrier(rt, *this->caps(), &barrierType)) {
this->getGpu()->xferBarrier(rt, barrierType);
}
}
|