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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
/*
* 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 "GrOpFlushState.h"
#include "GrDrawOpAtlas.h"
#include "GrGpu.h"
#include "GrResourceProvider.h"
#include "GrTexture.h"
GrOpFlushState::GrOpFlushState(GrGpu* gpu, GrResourceProvider* resourceProvider)
: fGpu(gpu)
, fResourceProvider(resourceProvider)
, fCommandBuffer(nullptr)
, fVertexPool(gpu)
, fIndexPool(gpu)
, fOpArgs(nullptr) {}
const GrCaps& GrOpFlushState::caps() const {
return *fGpu->caps();
}
GrGpuRTCommandBuffer* GrOpFlushState::rtCommandBuffer() {
return fCommandBuffer->asRTCommandBuffer();
}
void GrOpFlushState::doUpload(GrDeferredTextureUploadFn& upload) {
GrDeferredTextureUploadWritePixelsFn wp = [this](GrTextureProxy* proxy, int left, int top,
int width, int height, GrPixelConfig config,
const void* buffer, size_t rowBytes) {
GrSurface* surface = proxy->priv().peekSurface();
GrGpu::DrawPreference drawPreference = GrGpu::kNoDraw_DrawPreference;
GrGpu::WritePixelTempDrawInfo tempInfo;
fGpu->getWritePixelsInfo(surface, proxy->origin(), width, height, proxy->config(),
&drawPreference, &tempInfo);
if (GrGpu::kNoDraw_DrawPreference == drawPreference) {
return this->fGpu->writePixels(surface, proxy->origin(), left, top, width, height,
config, buffer, rowBytes);
}
GrSurfaceDesc desc;
desc.fOrigin = proxy->origin();
desc.fWidth = width;
desc.fHeight = height;
desc.fConfig = proxy->config();
sk_sp<GrTexture> temp(this->fResourceProvider->createApproxTexture(
desc, GrResourceProvider::kNoPendingIO_Flag));
if (!temp) {
return false;
}
if (!fGpu->writePixels(temp.get(), proxy->origin(), 0, 0, width, height, desc.fConfig,
buffer, rowBytes)) {
return false;
}
return fGpu->copySurface(surface, proxy->origin(), temp.get(), proxy->origin(),
SkIRect::MakeWH(width, height), {left, top});
};
upload(wp);
}
GrDeferredUploadToken GrOpFlushState::addInlineUpload(GrDeferredTextureUploadFn&& upload) {
SkASSERT(fOpArgs);
SkASSERT(fOpArgs->fOp);
// Here we're dangerously relying on only GrDrawOps calling this method. This gets fixed by
// storing inline uploads on GrOpFlushState and removing GrDrawOp::FlushStateAccess.
auto op = static_cast<GrDrawOp*>(fOpArgs->fOp);
auto token = this->nextDrawToken();
GrDrawOp::FlushStateAccess(op).addInlineUpload(std::move(upload), token);
return token;
}
GrDeferredUploadToken GrOpFlushState::addASAPUpload(GrDeferredTextureUploadFn&& upload) {
fASAPUploads.emplace_back(std::move(upload));
return this->nextTokenToFlush();
}
void GrOpFlushState::draw(const GrGeometryProcessor* gp, const GrPipeline* pipeline,
const GrMesh& mesh) {
SkASSERT(fOpArgs);
SkASSERT(fOpArgs->fOp);
// Here we're dangerously relying on only GrMeshDrawOps calling this method. This gets fixed by
// storing draw data on GrOpFlushState and removing GrMeshDrawOp::FlushStateAccess.
auto op = static_cast<GrMeshDrawOp*>(fOpArgs->fOp);
GrMeshDrawOp::FlushStateAccess fsa(op);
fsa.addMesh(mesh);
GrMeshDrawOp::FlushStateAccess::QueuedDraw* lastDraw = fsa.lastDraw();
if (lastDraw) {
// If the last draw shares a geometry processor and pipeline and there are no intervening
// uploads, add this mesh to it.
if (lastDraw->fGeometryProcessor == gp && lastDraw->fPipeline == pipeline &&
(fsa.lastUploadToken() != this->nextDrawToken())) {
++lastDraw->fMeshCnt;
return;
}
}
GrMeshDrawOp::FlushStateAccess::QueuedDraw* draw = fsa.addDraw();
GrDeferredUploadToken token = this->issueDrawToken();
draw->fGeometryProcessor.reset(gp);
draw->fPipeline = pipeline;
draw->fMeshCnt = 1;
if (!lastDraw) {
fsa.setBaseDrawToken(token);
}
}
void* GrOpFlushState::makeVertexSpace(size_t vertexSize, int vertexCount, const GrBuffer** buffer,
int* startVertex) {
return fVertexPool.makeSpace(vertexSize, vertexCount, buffer, startVertex);
}
uint16_t* GrOpFlushState::makeIndexSpace(int indexCount, const GrBuffer** buffer, int* startIndex) {
return reinterpret_cast<uint16_t*>(fIndexPool.makeSpace(indexCount, buffer, startIndex));
}
void* GrOpFlushState::makeVertexSpaceAtLeast(size_t vertexSize, int minVertexCount,
int fallbackVertexCount, const GrBuffer** buffer,
int* startVertex, int* actualVertexCount) {
return fVertexPool.makeSpaceAtLeast(vertexSize, minVertexCount, fallbackVertexCount, buffer,
startVertex, actualVertexCount);
}
uint16_t* GrOpFlushState::makeIndexSpaceAtLeast(int minIndexCount, int fallbackIndexCount,
const GrBuffer** buffer, int* startIndex,
int* actualIndexCount) {
return reinterpret_cast<uint16_t*>(fIndexPool.makeSpaceAtLeast(
minIndexCount, fallbackIndexCount, buffer, startIndex, actualIndexCount));
}
void GrOpFlushState::putBackIndices(int indexCount) {
fIndexPool.putBack(indexCount * sizeof(uint16_t));
}
void GrOpFlushState::putBackVertices(int vertices, size_t vertexStride) {
fVertexPool.putBack(vertices * vertexStride);
}
GrAppliedClip GrOpFlushState::detachAppliedClip() {
return fOpArgs->fAppliedClip ? std::move(*fOpArgs->fAppliedClip) : GrAppliedClip();
}
|