Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
GrOpFlushState.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 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 */
8
11#include "include/core/SkRect.h"
25
26#include <functional>
27#include <memory>
28
29//////////////////////////////////////////////////////////////////////////////
30
32 skgpu::TokenTracker* tokenTracker,
34 : fVertexPool(gpu, cpuBufferCache)
35 , fIndexPool(gpu, cpuBufferCache)
36 , fDrawIndirectPool(gpu, std::move(cpuBufferCache))
37 , fGpu(gpu)
38 , fResourceProvider(resourceProvider)
39 , fTokenTracker(tokenTracker) {}
40
42 return *fGpu->caps();
43}
44
46 return fGpu->getContext()->priv().threadSafeCache();
47}
48
50 const GrOp* op, const SkRect& chainBounds, const GrPipeline* pipeline,
51 const GrUserStencilSettings* userStencilSettings) {
52 SkASSERT(this->opsRenderPass());
53
54 while (fCurrDraw != fDraws.end() && fCurrDraw->fOp == op) {
55 skgpu::AtlasToken drawToken = fTokenTracker->nextFlushToken();
56 while (fCurrUpload != fInlineUploads.end() &&
57 fCurrUpload->fUploadBeforeToken == drawToken) {
58 this->opsRenderPass()->inlineUpload(this, fCurrUpload->fUpload);
59 ++fCurrUpload;
60 }
61
62 GrProgramInfo programInfo(this->caps(),
63 this->writeView(),
64 this->usesMSAASurface(),
65 pipeline,
66 userStencilSettings,
67 fCurrDraw->fGeometryProcessor,
68 fCurrDraw->fPrimitiveType,
69 this->renderPassBarriers(),
70 this->colorLoadOp());
71
72 this->bindPipelineAndScissorClip(programInfo, chainBounds);
73 this->bindTextures(programInfo.geomProc(), fCurrDraw->fGeomProcProxies,
74 programInfo.pipeline());
75 for (int i = 0; i < fCurrDraw->fMeshCnt; ++i) {
76 this->drawMesh(fCurrDraw->fMeshes[i]);
77 }
78
79 fTokenTracker->issueFlushToken();
80 ++fCurrDraw;
81 }
82}
83
85 fVertexPool.unmap();
86 fIndexPool.unmap();
87 fDrawIndirectPool.unmap();
88 for (auto& upload : fASAPUploads) {
89 this->doUpload(upload);
90 }
91 // Setup execution iterators.
92 fCurrDraw = fDraws.begin();
93 fCurrUpload = fInlineUploads.begin();
94 fGpu->willExecute();
95}
96
98 SkASSERT(fCurrDraw == fDraws.end());
99 SkASSERT(fCurrUpload == fInlineUploads.end());
100 fVertexPool.reset();
101 fIndexPool.reset();
102 fDrawIndirectPool.reset();
103 fArena.reset();
104 fASAPUploads.reset();
105 fInlineUploads.reset();
106 fDraws.reset();
107 fBaseDrawToken = skgpu::AtlasToken::InvalidToken();
108}
109
111 bool shouldPrepareSurfaceForSampling) {
112 GrDeferredTextureUploadWritePixelsFn wp = [this, shouldPrepareSurfaceForSampling](
113 GrTextureProxy* dstProxy,
116 const void* buffer,
117 size_t rowBytes) {
118 GrSurface* dstSurface = dstProxy->peekSurface();
119 if (!fGpu->caps()->surfaceSupportsWritePixels(dstSurface)) {
120 return false;
121 }
123 colorType, dstSurface->backendFormat(), colorType);
124 size_t tightRB = rect.width()*GrColorTypeBytesPerPixel(supportedWrite.fColorType);
125 SkASSERT(rowBytes >= tightRB);
126 std::unique_ptr<char[]> tmpPixels;
127 if (supportedWrite.fColorType != colorType ||
128 (!fGpu->caps()->writePixelsRowBytesSupport() && rowBytes != tightRB)) {
129 tmpPixels.reset(new char[rect.height()*tightRB]);
130 // Use kUnknown to ensure no alpha type conversions or clamping occur.
131 static constexpr auto kAT = kUnknown_SkAlphaType;
132 GrImageInfo srcInfo(colorType, kAT, nullptr, rect.size());
133 GrImageInfo tmpInfo(supportedWrite.fColorType, kAT, nullptr, rect.size());
134 if (!GrConvertPixels( GrPixmap(tmpInfo, tmpPixels.get(), tightRB ),
135 GrCPixmap(srcInfo, buffer, rowBytes))) {
136 return false;
137 }
138 rowBytes = tightRB;
139 buffer = tmpPixels.get();
140 }
141 return this->fGpu->writePixels(dstSurface,
142 rect,
143 colorType,
144 supportedWrite.fColorType,
145 buffer,
146 rowBytes,
147 shouldPrepareSurfaceForSampling);
148 };
149 upload(wp);
150}
151
153 return fInlineUploads.append(&fArena, std::move(upload), fTokenTracker->nextDrawToken())
154 .fUploadBeforeToken;
155}
156
158 fASAPUploads.append(&fArena, std::move(upload));
159 return fTokenTracker->nextFlushToken();
160}
161
163 const GrGeometryProcessor* geomProc,
164 const GrSimpleMesh meshes[],
165 int meshCnt,
166 const GrSurfaceProxy* const geomProcProxies[],
167 GrPrimitiveType primitiveType) {
168 SkASSERT(fOpArgs);
169 SkDEBUGCODE(fOpArgs->validate());
170 bool firstDraw = fDraws.begin() == fDraws.end();
171 auto& draw = fDraws.append(&fArena);
172 skgpu::AtlasToken token = fTokenTracker->issueDrawToken();
173 for (int i = 0; i < geomProc->numTextureSamplers(); ++i) {
174 SkASSERT(geomProcProxies && geomProcProxies[i]);
175 geomProcProxies[i]->ref();
176 }
177 draw.fGeometryProcessor = geomProc;
178 draw.fGeomProcProxies = geomProcProxies;
179 draw.fMeshes = meshes;
180 draw.fMeshCnt = meshCnt;
181 draw.fOp = fOpArgs->op();
182 draw.fPrimitiveType = primitiveType;
183 if (firstDraw) {
184 fBaseDrawToken = token;
185 }
186}
187
188void* GrOpFlushState::makeVertexSpace(size_t vertexSize, int vertexCount,
189 sk_sp<const GrBuffer>* buffer, int* startVertex) {
190 return fVertexPool.makeSpace(vertexSize, vertexCount, buffer, startVertex);
191}
192
194 int* startIndex) {
195 return reinterpret_cast<uint16_t*>(fIndexPool.makeSpace(indexCount, buffer, startIndex));
196}
197
198void* GrOpFlushState::makeVertexSpaceAtLeast(size_t vertexSize, int minVertexCount,
199 int fallbackVertexCount, sk_sp<const GrBuffer>* buffer,
200 int* startVertex, int* actualVertexCount) {
201 return fVertexPool.makeSpaceAtLeast(vertexSize, minVertexCount, fallbackVertexCount, buffer,
202 startVertex, actualVertexCount);
203}
204
205uint16_t* GrOpFlushState::makeIndexSpaceAtLeast(int minIndexCount, int fallbackIndexCount,
206 sk_sp<const GrBuffer>* buffer, int* startIndex,
207 int* actualIndexCount) {
208 return reinterpret_cast<uint16_t*>(fIndexPool.makeSpaceAtLeast(
209 minIndexCount, fallbackIndexCount, buffer, startIndex, actualIndexCount));
210}
211
212void GrOpFlushState::putBackIndices(int indexCount) {
213 fIndexPool.putBack(indexCount * sizeof(uint16_t));
214}
215
216void GrOpFlushState::putBackVertices(int vertices, size_t vertexStride) {
217 fVertexPool.putBack(vertices * vertexStride);
218}
219
221 return fOpArgs->appliedClip() ? std::move(*fOpArgs->appliedClip()) : GrAppliedClip::Disabled();
222}
223
225 return fGpu->getContext()->priv().getStrikeCache();
226}
227
229 return fGpu->getContext()->priv().getAtlasManager();
230}
231
232#if !defined(SK_ENABLE_OPTIMIZE_SIZE)
234 return fGpu->getContext()->priv().getSmallPathAtlasMgr();
235}
236#endif
237
239 SkASSERT(mesh.fIsInitialized);
240 if (!mesh.fIndexBuffer) {
241 this->bindBuffers(nullptr, nullptr, mesh.fVertexBuffer);
242 this->draw(mesh.fVertexCount, mesh.fBaseVertex);
243 } else {
244 this->bindBuffers(mesh.fIndexBuffer, nullptr, mesh.fVertexBuffer, mesh.fPrimitiveRestart);
245 if (0 == mesh.fPatternRepeatCount) {
246 this->drawIndexed(mesh.fIndexCount, mesh.fBaseIndex, mesh.fMinIndexValue,
247 mesh.fMaxIndexValue, mesh.fBaseVertex);
248 } else {
249 this->drawIndexPattern(mesh.fIndexCount, mesh.fPatternRepeatCount,
250 mesh.fMaxPatternRepetitionsInIndexBuffer, mesh.fVertexCount,
251 mesh.fBaseVertex);
252 }
253 }
254}
255
256//////////////////////////////////////////////////////////////////////////////
257
258GrOpFlushState::Draw::~Draw() {
259 for (int i = 0; i < fGeometryProcessor->numTextureSamplers(); ++i) {
260 SkASSERT(fGeomProcProxies && fGeomProcProxies[i]);
261 fGeomProcProxies[i]->unref();
262 }
263}
bool GrConvertPixels(const GrPixmap &dst, const GrCPixmap &src, bool flipY)
std::function< void(GrDeferredTextureUploadWritePixelsFn &)> GrDeferredTextureUploadFn
std::function< bool(GrTextureProxy *, SkIRect, GrColorType srcColorType, const void *, size_t rowBytes)> GrDeferredTextureUploadWritePixelsFn
static constexpr size_t GrColorTypeBytesPerPixel(GrColorType ct)
Definition: GrTypesPriv.h:896
GrPrimitiveType
Definition: GrTypesPriv.h:43
GrColorType
Definition: GrTypesPriv.h:540
@ kUnknown_SkAlphaType
uninitialized
Definition: SkAlphaType.h:27
#define SkASSERT(cond)
Definition: SkAssert.h:116
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
GrGeometryProcessor * fGeometryProcessor
static sk_sp< SkImage > upload(const sk_sp< SkSurface > &surf, SkColor color)
static GrAppliedClip Disabled()
Definition: GrAppliedClip.h:96
void putBack(size_t bytes)
Definition: GrCaps.h:57
virtual SupportedWrite supportedWritePixelsColorType(GrColorType surfaceColorType, const GrBackendFormat &surfaceFormat, GrColorType srcColorType) const =0
bool surfaceSupportsWritePixels(const GrSurface *) const
Definition: GrCaps.cpp:305
bool writePixelsRowBytesSupport() const
Definition: GrCaps.h:354
skgpu::ganesh::SmallPathAtlasMgr * getSmallPathAtlasMgr()
GrAtlasManager * getAtlasManager()
sktext::gpu::StrikeCache * getStrikeCache()
GrDirectContextPriv priv()
Definition: GrGpu.h:62
bool writePixels(GrSurface *surface, SkIRect rect, GrColorType surfaceColorType, GrColorType srcColorType, const GrMipLevel texels[], int mipLevelCount, bool prepForTexSampling=false)
Definition: GrGpu.cpp:461
const GrCaps * caps() const
Definition: GrGpu.h:73
GrDirectContext * getContext()
Definition: GrGpu.h:67
virtual void willExecute()
Definition: GrGpu.h:413
void * makeSpace(int indexCount, sk_sp< const GrBuffer > *buffer, int *startIndex)
void * makeSpaceAtLeast(int minIndexCount, int fallbackIndexCount, sk_sp< const GrBuffer > *buffer, int *startIndex, int *actualIndexCount)
sktext::gpu::StrikeCache * strikeCache() const final
skgpu::ganesh::SmallPathAtlasMgr * smallPathAtlasManager() const final
void drawMesh(const GrSimpleMesh &mesh)
uint16_t * makeIndexSpace(int indexCount, sk_sp< const GrBuffer > *, int *startIndex) final
void bindPipelineAndScissorClip(const GrProgramInfo &programInfo, const SkRect &drawBounds)
GrThreadSafeCache * threadSafeCache() const final
void recordDraw(const GrGeometryProcessor *, const GrSimpleMesh[], int meshCnt, const GrSurfaceProxy *const primProcProxies[], GrPrimitiveType) final
void putBackIndices(int indexCount) final
void * makeVertexSpaceAtLeast(size_t vertexSize, int minVertexCount, int fallbackVertexCount, sk_sp< const GrBuffer > *, int *startVertex, int *actualVertexCount) final
void bindBuffers(sk_sp< const GrBuffer > indexBuffer, sk_sp< const GrBuffer > instanceBuffer, sk_sp< const GrBuffer > vertexBuffer, GrPrimitiveRestart primitiveRestart=GrPrimitiveRestart::kNo)
const GrSurfaceProxyView & writeView() const final
GrOpFlushState(GrGpu *, GrResourceProvider *, skgpu::TokenTracker *, sk_sp< GrBufferAllocPool::CpuBufferCache >=nullptr)
GrAppliedClip detachAppliedClip() final
GrAtlasManager * atlasManager() const final
const GrCaps & caps() const final
skgpu::AtlasToken addInlineUpload(GrDeferredTextureUploadFn &&) final
void drawIndexed(int indexCount, int baseIndex, uint16_t minIndexValue, uint16_t maxIndexValue, int baseVertex)
GrOpsRenderPass * opsRenderPass()
void putBackVertices(int vertices, size_t vertexStride) final
void * makeVertexSpace(size_t vertexSize, int vertexCount, sk_sp< const GrBuffer > *, int *startVertex) final
void executeDrawsAndUploadsForMeshDrawOp(const GrOp *op, const SkRect &chainBounds, const GrPipeline *, const GrUserStencilSettings *)
uint16_t * makeIndexSpaceAtLeast(int minIndexCount, int fallbackIndexCount, sk_sp< const GrBuffer > *, int *startIndex, int *actualIndexCount) final
void bindTextures(const GrGeometryProcessor &geomProc, const GrSurfaceProxy &singleGeomProcTexture, const GrPipeline &pipeline)
void doUpload(GrDeferredTextureUploadFn &, bool shouldPrepareSurfaceForSampling=false)
void draw(int vertexCount, int baseVertex)
bool usesMSAASurface() const final
skgpu::AtlasToken addASAPUpload(GrDeferredTextureUploadFn &&) final
void drawIndexPattern(int patternIndexCount, int patternRepeatCount, int maxPatternRepetitionsInIndexBuffer, int patternVertexCount, int baseVertex)
Definition: GrOp.h:70
virtual void inlineUpload(GrOpFlushState *, GrDeferredTextureUploadFn &)=0
const GrPipeline & pipeline() const
Definition: GrProgramInfo.h:39
const GrGeometryProcessor & geomProc() const
Definition: GrProgramInfo.h:40
GrThreadSafeCache * threadSafeCache()
GrSurface * peekSurface() const
virtual GrBackendFormat backendFormat() const =0
void * makeSpace(size_t vertexSize, int vertexCount, sk_sp< const GrBuffer > *buffer, int *startVertex)
void * makeSpaceAtLeast(size_t vertexSize, int minVertexCount, int fallbackVertexCount, sk_sp< const GrBuffer > *buffer, int *startVertex, int *actualVertexCount)
T & append(SkArenaAlloc *arena, Args... args)
void ref() const
Definition: SkRefCnt.h:176
static AtlasToken InvalidToken()
Definition: AtlasTypes.h:153
AtlasToken nextFlushToken() const
Definition: AtlasTypes.h:207
AtlasToken nextDrawToken() const
Definition: AtlasTypes.h:214
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
SkMesh mesh
Definition: SkRecords.h:345
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
Definition: ref_ptr.h:256
Definition: upload.py:1
GrColorType fColorType
Definition: GrCaps.h:318
GrAppliedClip * appliedClip()
sk_sp< const GrBuffer > fIndexBuffer
Definition: GrSimpleMesh.h:31
sk_sp< const GrBuffer > fVertexBuffer
Definition: GrSimpleMesh.h:40
Definition: SkRect.h:32