Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 params, | 205 params, |
| 206 flags, | 206 flags, |
| 207 this->usesLocalCoords())); | 207 this->usesLocalCoords())); |
| 208 | 208 |
| 209 target->initDraw(dfProcessor, this->pipeline()); | 209 target->initDraw(dfProcessor, this->pipeline()); |
| 210 | 210 |
| 211 FlushInfo flushInfo; | 211 FlushInfo flushInfo; |
| 212 | 212 |
| 213 // allocate vertices | 213 // allocate vertices |
| 214 size_t vertexStride = dfProcessor->getVertexStride(); | 214 size_t vertexStride = dfProcessor->getVertexStride(); |
| 215 SkASSERT(vertexStride == 2 * sizeof(SkPoint)); | 215 SkASSERT(vertexStride == 2 * sizeof(SkPoint) + sizeof(GrColor)); |
| 216 | 216 |
| 217 const GrVertexBuffer* vertexBuffer; | 217 const GrVertexBuffer* vertexBuffer; |
| 218 void* vertices = target->makeVertexSpace(vertexStride, | 218 void* vertices = target->makeVertexSpace(vertexStride, |
| 219 kVerticesPerQuad * instanceCoun t, | 219 kVerticesPerQuad * instanceCoun t, |
| 220 &vertexBuffer, | 220 &vertexBuffer, |
| 221 &flushInfo.fVertexOffset); | 221 &flushInfo.fVertexOffset); |
| 222 flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer)); | 222 flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer)); |
| 223 flushInfo.fIndexBuffer.reset(target->resourceProvider()->refQuadIndexBuf fer()); | 223 flushInfo.fIndexBuffer.reset(target->resourceProvider()->refQuadIndexBuf fer()); |
| 224 if (!vertices || !flushInfo.fIndexBuffer) { | 224 if (!vertices || !flushInfo.fIndexBuffer) { |
| 225 SkDebugf("Could not allocate vertices\n"); | 225 SkDebugf("Could not allocate vertices\n"); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 SkDebugf("Can't rasterize path\n"); | 271 SkDebugf("Can't rasterize path\n"); |
| 272 return; | 272 return; |
| 273 } | 273 } |
| 274 } | 274 } |
| 275 | 275 |
| 276 atlas->setLastUseToken(pathData->fID, target->currentToken()); | 276 atlas->setLastUseToken(pathData->fID, target->currentToken()); |
| 277 | 277 |
| 278 // Now set vertices | 278 // Now set vertices |
| 279 intptr_t offset = reinterpret_cast<intptr_t>(vertices); | 279 intptr_t offset = reinterpret_cast<intptr_t>(vertices); |
| 280 offset += i * kVerticesPerQuad * vertexStride; | 280 offset += i * kVerticesPerQuad * vertexStride; |
| 281 SkPoint* positions = reinterpret_cast<SkPoint*>(offset); | |
| 282 this->writePathVertices(target, | 281 this->writePathVertices(target, |
| 283 atlas, | 282 atlas, |
| 284 this->pipeline(), | 283 this->pipeline(), |
| 285 dfProcessor, | 284 dfProcessor, |
| 286 positions, | 285 offset, |
| 286 this->color(), | |
| 287 vertexStride, | 287 vertexStride, |
| 288 this->viewMatrix(), | 288 this->viewMatrix(), |
| 289 args.fPath, | 289 args.fPath, |
| 290 pathData); | 290 pathData); |
| 291 flushInfo.fInstancesToFlush++; | 291 flushInfo.fInstancesToFlush++; |
| 292 } | 292 } |
| 293 | 293 |
| 294 this->flush(target, &flushInfo); | 294 this->flush(target, &flushInfo); |
| 295 } | 295 } |
| 296 | 296 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 430 #ifdef DF_PATH_TRACKING | 430 #ifdef DF_PATH_TRACKING |
| 431 ++g_NumCachedPaths; | 431 ++g_NumCachedPaths; |
| 432 #endif | 432 #endif |
| 433 return true; | 433 return true; |
| 434 } | 434 } |
| 435 | 435 |
| 436 void writePathVertices(GrDrawBatch::Target* target, | 436 void writePathVertices(GrDrawBatch::Target* target, |
| 437 GrBatchAtlas* atlas, | 437 GrBatchAtlas* atlas, |
| 438 const GrPipeline* pipeline, | 438 const GrPipeline* pipeline, |
| 439 const GrGeometryProcessor* gp, | 439 const GrGeometryProcessor* gp, |
| 440 SkPoint* positions, | 440 intptr_t offset, |
| 441 GrColor color, | |
| 441 size_t vertexStride, | 442 size_t vertexStride, |
| 442 const SkMatrix& viewMatrix, | 443 const SkMatrix& viewMatrix, |
| 443 const SkPath& path, | 444 const SkPath& path, |
| 444 const PathData* pathData) const { | 445 const PathData* pathData) const { |
| 445 GrTexture* texture = atlas->getTexture(); | 446 GrTexture* texture = atlas->getTexture(); |
| 446 | 447 |
| 447 SkScalar dx = pathData->fBounds.fLeft; | 448 SkScalar dx = pathData->fBounds.fLeft; |
| 448 SkScalar dy = pathData->fBounds.fTop; | 449 SkScalar dy = pathData->fBounds.fTop; |
| 449 SkScalar width = pathData->fBounds.width(); | 450 SkScalar width = pathData->fBounds.width(); |
| 450 SkScalar height = pathData->fBounds.height(); | 451 SkScalar height = pathData->fBounds.height(); |
| 451 | 452 |
| 452 SkScalar invScale = 1.0f / pathData->fScale; | 453 SkScalar invScale = 1.0f / pathData->fScale; |
| 453 dx *= invScale; | 454 dx *= invScale; |
| 454 dy *= invScale; | 455 dy *= invScale; |
| 455 width *= invScale; | 456 width *= invScale; |
| 456 height *= invScale; | 457 height *= invScale; |
| 457 | 458 |
| 458 SkFixed tx = SkIntToFixed(pathData->fAtlasLocation.fX); | 459 SkFixed tx = SkIntToFixed(pathData->fAtlasLocation.fX); |
| 459 SkFixed ty = SkIntToFixed(pathData->fAtlasLocation.fY); | 460 SkFixed ty = SkIntToFixed(pathData->fAtlasLocation.fY); |
| 460 SkFixed tw = SkScalarToFixed(pathData->fBounds.width()); | 461 SkFixed tw = SkScalarToFixed(pathData->fBounds.width()); |
| 461 SkFixed th = SkScalarToFixed(pathData->fBounds.height()); | 462 SkFixed th = SkScalarToFixed(pathData->fBounds.height()); |
| 462 | 463 |
| 464 SkPoint* positions = reinterpret_cast<SkPoint*>(offset); | |
| 465 | |
| 463 // vertex positions | 466 // vertex positions |
| 464 // TODO make the vertex attributes a struct | 467 // TODO make the vertex attributes a struct |
| 465 SkRect r = SkRect::MakeXYWH(dx, dy, width, height); | 468 SkRect r = SkRect::MakeXYWH(dx, dy, width, height); |
| 466 positions->setRectFan(r.left(), r.top(), r.right(), r.bottom(), vertexSt ride); | 469 positions->setRectFan(r.left(), r.top(), r.right(), r.bottom(), vertexSt ride); |
| 467 | 470 |
| 471 // colors | |
| 472 for (int i = 0; i < kVerticesPerQuad; i++) { | |
| 473 GrColor* colorPtr = (GrColor*)(offset + sizeof(SkPoint) + i * vertex Stride); | |
| 474 *colorPtr = color; | |
| 475 } | |
| 476 | |
| 468 // vertex texture coords | 477 // vertex texture coords |
| 469 SkPoint* textureCoords = positions + 1; | 478 SkPoint* textureCoords = (SkPoint*)(offset + sizeof(SkPoint) + sizeof(Gr Color)); |
| 470 textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normaliz eFixedX(tx)), | 479 textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normaliz eFixedX(tx)), |
| 471 SkFixedToFloat(texture->texturePriv().normaliz eFixedY(ty)), | 480 SkFixedToFloat(texture->texturePriv().normaliz eFixedY(ty)), |
| 472 SkFixedToFloat(texture->texturePriv().normaliz eFixedX(tx + tw)), | 481 SkFixedToFloat(texture->texturePriv().normaliz eFixedX(tx + tw)), |
| 473 SkFixedToFloat(texture->texturePriv().normaliz eFixedY(ty + th)), | 482 SkFixedToFloat(texture->texturePriv().normaliz eFixedY(ty + th)), |
| 474 vertexStride); | 483 vertexStride); |
| 475 } | 484 } |
| 476 | 485 |
| 477 void flush(GrVertexBatch::Target* target, FlushInfo* flushInfo) const { | 486 void flush(GrVertexBatch::Target* target, FlushInfo* flushInfo) const { |
| 478 GrVertices vertices; | 487 GrVertices vertices; |
| 479 int maxInstancesPerDraw = flushInfo->fIndexBuffer->maxQuads(); | 488 int maxInstancesPerDraw = flushInfo->fIndexBuffer->maxQuads(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 490 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 499 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
| 491 | 500 |
| 492 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 501 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
| 493 AADistanceFieldPathBatch* that = t->cast<AADistanceFieldPathBatch>(); | 502 AADistanceFieldPathBatch* that = t->cast<AADistanceFieldPathBatch>(); |
| 494 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi peline(), | 503 if (!GrPipeline::CanCombine(*this->pipeline(), this->bounds(), *that->pi peline(), |
| 495 that->bounds(), caps)) { | 504 that->bounds(), caps)) { |
| 496 return false; | 505 return false; |
| 497 } | 506 } |
| 498 | 507 |
| 499 // TODO we could actually probably do a bunch of this work on the CPU, i e map viewMatrix, | 508 // TODO we could actually probably do a bunch of this work on the CPU, i e map viewMatrix, |
| 500 // maybe upload color via attribute | 509 // maybe upload color via attribute |
|
bsalomon
2015/12/09 02:10:05
To answer my own question, we should delete this.
| |
| 501 if (this->color() != that->color()) { | 510 if (this->color() != that->color()) { |
| 502 return false; | 511 return false; |
| 503 } | 512 } |
| 504 | 513 |
| 505 if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) { | 514 if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) { |
| 506 return false; | 515 return false; |
| 507 } | 516 } |
| 508 | 517 |
| 509 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()) ; | 518 fGeoData.push_back_n(that->geoData()->count(), that->geoData()->begin()) ; |
| 510 this->joinBounds(that->bounds()); | 519 this->joinBounds(that->bounds()); |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 633 geometry.fAntiAlias = random->nextBool(); | 642 geometry.fAntiAlias = random->nextBool(); |
| 634 geometry.fGenID = random->nextU(); | 643 geometry.fGenID = random->nextU(); |
| 635 | 644 |
| 636 return AADistanceFieldPathBatch::Create(geometry, color, viewMatrix, | 645 return AADistanceFieldPathBatch::Create(geometry, color, viewMatrix, |
| 637 gTestStruct.fAtlas, | 646 gTestStruct.fAtlas, |
| 638 &gTestStruct.fPathCache, | 647 &gTestStruct.fPathCache, |
| 639 &gTestStruct.fPathList); | 648 &gTestStruct.fPathList); |
| 640 } | 649 } |
| 641 | 650 |
| 642 #endif | 651 #endif |
| OLD | NEW |