Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/gpu/batches/GrAADistanceFieldPathRenderer.cpp

Issue 1835283002: Simplify GrDrawBatch uploads and token uage. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrAADistanceFieldPathRenderer.h" 9 #include "GrAADistanceFieldPathRenderer.h"
10 10
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } 170 }
171 overrides.getOverrideColorIfSet(&fGeoData[0].fColor); 171 overrides.getOverrideColorIfSet(&fGeoData[0].fColor);
172 172
173 // setup batch properties 173 // setup batch properties
174 fBatch.fColorIgnored = !overrides.readsColor(); 174 fBatch.fColorIgnored = !overrides.readsColor();
175 fBatch.fUsesLocalCoords = overrides.readsLocalCoords(); 175 fBatch.fUsesLocalCoords = overrides.readsLocalCoords();
176 fBatch.fCoverageIgnored = !overrides.readsCoverage(); 176 fBatch.fCoverageIgnored = !overrides.readsCoverage();
177 } 177 }
178 178
179 struct FlushInfo { 179 struct FlushInfo {
180 SkAutoTUnref<const GrBuffer> fVertexBuffer; 180 SkAutoTUnref<const GrBuffer> fVertexBuffer;
181 SkAutoTUnref<const GrBuffer> fIndexBuffer; 181 SkAutoTUnref<const GrBuffer> fIndexBuffer;
182 SkAutoTUnref<const GrGeometryProcessor> fGeometryProcessor;
182 int fVertexOffset; 183 int fVertexOffset;
183 int fInstancesToFlush; 184 int fInstancesToFlush;
184 }; 185 };
185 186
186 void onPrepareDraws(Target* target) const override { 187 void onPrepareDraws(Target* target) const override {
187 int instanceCount = fGeoData.count(); 188 int instanceCount = fGeoData.count();
188 189
189 SkMatrix invert; 190 SkMatrix invert;
190 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { 191 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) {
191 SkDebugf("Could not invert viewmatrix\n"); 192 SkDebugf("Could not invert viewmatrix\n");
192 return; 193 return;
193 } 194 }
194 195
195 const SkMatrix& ctm = this->viewMatrix(); 196 const SkMatrix& ctm = this->viewMatrix();
196 uint32_t flags = 0; 197 uint32_t flags = 0;
197 flags |= ctm.isScaleTranslate() ? kScaleOnly_DistanceFieldEffectFlag : 0 ; 198 flags |= ctm.isScaleTranslate() ? kScaleOnly_DistanceFieldEffectFlag : 0 ;
198 flags |= ctm.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0; 199 flags |= ctm.isSimilarity() ? kSimilarity_DistanceFieldEffectFlag : 0;
199 200
200 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBil erp_FilterMode); 201 GrTextureParams params(SkShader::kRepeat_TileMode, GrTextureParams::kBil erp_FilterMode);
201 202
203 FlushInfo flushInfo;
204
202 // Setup GrGeometryProcessor 205 // Setup GrGeometryProcessor
203 GrBatchAtlas* atlas = fAtlas; 206 GrBatchAtlas* atlas = fAtlas;
204 SkAutoTUnref<GrGeometryProcessor> dfProcessor( 207 flushInfo.fGeometryProcessor.reset(
205 GrDistanceFieldPathGeoProc::Create(this->color(), 208 GrDistanceFieldPathGeoProc::Create(this->color(),
206 this->viewMatrix(), 209 this->viewMatrix(),
207 atlas->getTexture(), 210 atlas->getTexture(),
208 params, 211 params,
209 flags, 212 flags,
210 this->usesLocalCoords())); 213 this->usesLocalCoords()));
211 214
212 target->initDraw(dfProcessor);
213
214 FlushInfo flushInfo;
215
216 // allocate vertices 215 // allocate vertices
217 size_t vertexStride = dfProcessor->getVertexStride(); 216 size_t vertexStride = flushInfo.fGeometryProcessor->getVertexStride();
218 SkASSERT(vertexStride == 2 * sizeof(SkPoint) + sizeof(GrColor)); 217 SkASSERT(vertexStride == 2 * sizeof(SkPoint) + sizeof(GrColor));
219 218
220 const GrBuffer* vertexBuffer; 219 const GrBuffer* vertexBuffer;
221 void* vertices = target->makeVertexSpace(vertexStride, 220 void* vertices = target->makeVertexSpace(vertexStride,
222 kVerticesPerQuad * instanceCoun t, 221 kVerticesPerQuad * instanceCoun t,
223 &vertexBuffer, 222 &vertexBuffer,
224 &flushInfo.fVertexOffset); 223 &flushInfo.fVertexOffset);
225 flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer)); 224 flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer));
226 flushInfo.fIndexBuffer.reset(target->resourceProvider()->refQuadIndexBuf fer()); 225 flushInfo.fIndexBuffer.reset(target->resourceProvider()->refQuadIndexBuf fer());
227 if (!vertices || !flushInfo.fIndexBuffer) { 226 if (!vertices || !flushInfo.fIndexBuffer) {
(...skipping 25 matching lines...) Expand all
253 if (nullptr == pathData || !atlas->hasID(pathData->fID)) { 252 if (nullptr == pathData || !atlas->hasID(pathData->fID)) {
254 // Remove the stale cache entry 253 // Remove the stale cache entry
255 if (pathData) { 254 if (pathData) {
256 fPathCache->remove(pathData->fKey); 255 fPathCache->remove(pathData->fKey);
257 fPathList->remove(pathData); 256 fPathList->remove(pathData);
258 delete pathData; 257 delete pathData;
259 } 258 }
260 SkScalar scale = desiredDimension/maxDim; 259 SkScalar scale = desiredDimension/maxDim;
261 pathData = new PathData; 260 pathData = new PathData;
262 if (!this->addPathToAtlas(target, 261 if (!this->addPathToAtlas(target,
263 dfProcessor,
264 this->pipeline(),
265 &flushInfo, 262 &flushInfo,
266 atlas, 263 atlas,
267 pathData, 264 pathData,
268 args.fPath, 265 args.fPath,
269 args.fGenID, 266 args.fGenID,
270 args.fStroke, 267 args.fStroke,
271 args.fAntiAlias, 268 args.fAntiAlias,
272 desiredDimension, 269 desiredDimension,
273 scale)) { 270 scale)) {
274 SkDebugf("Can't rasterize path\n"); 271 SkDebugf("Can't rasterize path\n");
275 return; 272 return;
276 } 273 }
277 } 274 }
278 275
279 atlas->setLastUseToken(pathData->fID, target->currentToken()); 276 atlas->setLastUseToken(pathData->fID, target->nextDrawToken());
280 277
281 // Now set vertices 278 // Now set vertices
282 intptr_t offset = reinterpret_cast<intptr_t>(vertices); 279 intptr_t offset = reinterpret_cast<intptr_t>(vertices);
283 offset += i * kVerticesPerQuad * vertexStride; 280 offset += i * kVerticesPerQuad * vertexStride;
284 this->writePathVertices(target, 281 this->writePathVertices(target,
285 atlas, 282 atlas,
286 this->pipeline(),
287 dfProcessor,
288 offset, 283 offset,
289 args.fColor, 284 args.fColor,
290 vertexStride, 285 vertexStride,
291 this->viewMatrix(), 286 this->viewMatrix(),
292 args.fPath, 287 args.fPath,
293 pathData); 288 pathData);
294 flushInfo.fInstancesToFlush++; 289 flushInfo.fInstancesToFlush++;
295 } 290 }
296 291
297 this->flush(target, &flushInfo); 292 this->flush(target, &flushInfo);
(...skipping 12 matching lines...) Expand all
310 fAtlas = atlas; 305 fAtlas = atlas;
311 fPathCache = pathCache; 306 fPathCache = pathCache;
312 fPathList = pathList; 307 fPathList = pathList;
313 308
314 // Compute bounds 309 // Compute bounds
315 fBounds = geometry.fPath.getBounds(); 310 fBounds = geometry.fPath.getBounds();
316 viewMatrix.mapRect(&fBounds); 311 viewMatrix.mapRect(&fBounds);
317 } 312 }
318 313
319 bool addPathToAtlas(GrVertexBatch::Target* target, 314 bool addPathToAtlas(GrVertexBatch::Target* target,
320 const GrGeometryProcessor* dfProcessor,
321 const GrPipeline* pipeline,
322 FlushInfo* flushInfo, 315 FlushInfo* flushInfo,
323 GrBatchAtlas* atlas, 316 GrBatchAtlas* atlas,
324 PathData* pathData, 317 PathData* pathData,
325 const SkPath& path, 318 const SkPath& path,
326 uint32_t genID, 319 uint32_t genID,
327 const SkStrokeRec& stroke, 320 const SkStrokeRec& stroke,
328 bool antiAlias, 321 bool antiAlias,
329 uint32_t dimension, 322 uint32_t dimension,
330 SkScalar scale) const { 323 SkScalar scale) const {
331 const SkRect& bounds = path.getBounds(); 324 const SkRect& bounds = path.getBounds();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 (const unsigned char*)dst.addr(), 393 (const unsigned char*)dst.addr(),
401 dst.width(), dst.height(), dst.rowByt es()); 394 dst.width(), dst.height(), dst.rowByt es());
402 395
403 // add to atlas 396 // add to atlas
404 SkIPoint16 atlasLocation; 397 SkIPoint16 atlasLocation;
405 GrBatchAtlas::AtlasID id; 398 GrBatchAtlas::AtlasID id;
406 bool success = atlas->addToAtlas(&id, target, width, height, dfStorage.g et(), 399 bool success = atlas->addToAtlas(&id, target, width, height, dfStorage.g et(),
407 &atlasLocation); 400 &atlasLocation);
408 if (!success) { 401 if (!success) {
409 this->flush(target, flushInfo); 402 this->flush(target, flushInfo);
410 target->initDraw(dfProcessor);
411 403
412 SkDEBUGCODE(success =) atlas->addToAtlas(&id, target, width, height, 404 SkDEBUGCODE(success =) atlas->addToAtlas(&id, target, width, height,
413 dfStorage.get(), &atlasLoca tion); 405 dfStorage.get(), &atlasLoca tion);
414 SkASSERT(success); 406 SkASSERT(success);
415 407
416 } 408 }
417 409
418 // add to cache 410 // add to cache
419 pathData->fKey = PathData::Key(genID, dimension, stroke); 411 pathData->fKey = PathData::Key(genID, dimension, stroke);
420 pathData->fScale = scale; 412 pathData->fScale = scale;
(...skipping 16 matching lines...) Expand all
437 fPathCache->add(pathData); 429 fPathCache->add(pathData);
438 fPathList->addToTail(pathData); 430 fPathList->addToTail(pathData);
439 #ifdef DF_PATH_TRACKING 431 #ifdef DF_PATH_TRACKING
440 ++g_NumCachedPaths; 432 ++g_NumCachedPaths;
441 #endif 433 #endif
442 return true; 434 return true;
443 } 435 }
444 436
445 void writePathVertices(GrDrawBatch::Target* target, 437 void writePathVertices(GrDrawBatch::Target* target,
446 GrBatchAtlas* atlas, 438 GrBatchAtlas* atlas,
447 const GrPipeline* pipeline,
448 const GrGeometryProcessor* gp,
449 intptr_t offset, 439 intptr_t offset,
450 GrColor color, 440 GrColor color,
451 size_t vertexStride, 441 size_t vertexStride,
452 const SkMatrix& viewMatrix, 442 const SkMatrix& viewMatrix,
453 const SkPath& path, 443 const SkPath& path,
454 const PathData* pathData) const { 444 const PathData* pathData) const {
455 GrTexture* texture = atlas->getTexture(); 445 GrTexture* texture = atlas->getTexture();
456 446
457 SkScalar dx = pathData->fBounds.fLeft; 447 SkScalar dx = pathData->fBounds.fLeft;
458 SkScalar dy = pathData->fBounds.fTop; 448 SkScalar dy = pathData->fBounds.fTop;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 vertexStride); 480 vertexStride);
491 } 481 }
492 482
493 void flush(GrVertexBatch::Target* target, FlushInfo* flushInfo) const { 483 void flush(GrVertexBatch::Target* target, FlushInfo* flushInfo) const {
494 GrMesh mesh; 484 GrMesh mesh;
495 int maxInstancesPerDraw = 485 int maxInstancesPerDraw =
496 static_cast<int>(flushInfo->fIndexBuffer->gpuMemorySize() / sizeof(u int16_t) / 6); 486 static_cast<int>(flushInfo->fIndexBuffer->gpuMemorySize() / sizeof(u int16_t) / 6);
497 mesh.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer, 487 mesh.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer,
498 flushInfo->fIndexBuffer, flushInfo->fVertexOffset, kVerticesPerQuad, 488 flushInfo->fIndexBuffer, flushInfo->fVertexOffset, kVerticesPerQuad,
499 kIndicesPerQuad, flushInfo->fInstancesToFlush, maxInstancesPerDraw); 489 kIndicesPerQuad, flushInfo->fInstancesToFlush, maxInstancesPerDraw);
500 target->draw(mesh); 490 target->draw(flushInfo->fGeometryProcessor, mesh);
501 flushInfo->fVertexOffset += kVerticesPerQuad * flushInfo->fInstancesToFl ush; 491 flushInfo->fVertexOffset += kVerticesPerQuad * flushInfo->fInstancesToFl ush;
502 flushInfo->fInstancesToFlush = 0; 492 flushInfo->fInstancesToFlush = 0;
503 } 493 }
504 494
505 GrColor color() const { return fGeoData[0].fColor; } 495 GrColor color() const { return fGeoData[0].fColor; }
506 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } 496 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; }
507 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } 497 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; }
508 498
509 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { 499 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override {
510 AADistanceFieldPathBatch* that = t->cast<AADistanceFieldPathBatch>(); 500 AADistanceFieldPathBatch* that = t->cast<AADistanceFieldPathBatch>();
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
648 geometry.fAntiAlias = random->nextBool(); 638 geometry.fAntiAlias = random->nextBool();
649 geometry.fGenID = random->nextU(); 639 geometry.fGenID = random->nextU();
650 640
651 return AADistanceFieldPathBatch::Create(geometry, viewMatrix, 641 return AADistanceFieldPathBatch::Create(geometry, viewMatrix,
652 gTestStruct.fAtlas, 642 gTestStruct.fAtlas,
653 &gTestStruct.fPathCache, 643 &gTestStruct.fPathCache,
654 &gTestStruct.fPathList); 644 &gTestStruct.fPathList);
655 } 645 }
656 646
657 #endif 647 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698