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 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 SkScalar dy = pathData->fBounds.fTop; | 454 SkScalar dy = pathData->fBounds.fTop; |
455 SkScalar width = pathData->fBounds.width(); | 455 SkScalar width = pathData->fBounds.width(); |
456 SkScalar height = pathData->fBounds.height(); | 456 SkScalar height = pathData->fBounds.height(); |
457 | 457 |
458 SkScalar invScale = 1.0f / pathData->fScale; | 458 SkScalar invScale = 1.0f / pathData->fScale; |
459 dx *= invScale; | 459 dx *= invScale; |
460 dy *= invScale; | 460 dy *= invScale; |
461 width *= invScale; | 461 width *= invScale; |
462 height *= invScale; | 462 height *= invScale; |
463 | 463 |
464 SkFixed tx = SkIntToFixed(pathData->fAtlasLocation.fX); | |
465 SkFixed ty = SkIntToFixed(pathData->fAtlasLocation.fY); | |
466 SkFixed tw = SkScalarToFixed(pathData->fBounds.width()); | |
467 SkFixed th = SkScalarToFixed(pathData->fBounds.height()); | |
468 | |
469 SkPoint* positions = reinterpret_cast<SkPoint*>(offset); | 464 SkPoint* positions = reinterpret_cast<SkPoint*>(offset); |
470 | 465 |
471 // vertex positions | 466 // vertex positions |
472 // TODO make the vertex attributes a struct | 467 // TODO make the vertex attributes a struct |
473 SkRect r = SkRect::MakeXYWH(dx, dy, width, height); | 468 SkRect r = SkRect::MakeXYWH(dx, dy, width, height); |
474 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); |
475 | 470 |
476 // colors | 471 // colors |
477 for (int i = 0; i < kVerticesPerQuad; i++) { | 472 for (int i = 0; i < kVerticesPerQuad; i++) { |
478 GrColor* colorPtr = (GrColor*)(offset + sizeof(SkPoint) + i * vertex
Stride); | 473 GrColor* colorPtr = (GrColor*)(offset + sizeof(SkPoint) + i * vertex
Stride); |
479 *colorPtr = color; | 474 *colorPtr = color; |
480 } | 475 } |
481 | 476 |
| 477 const SkScalar tx = SkIntToScalar(pathData->fAtlasLocation.fX); |
| 478 const SkScalar ty = SkIntToScalar(pathData->fAtlasLocation.fY); |
| 479 |
482 // vertex texture coords | 480 // vertex texture coords |
483 SkPoint* textureCoords = (SkPoint*)(offset + sizeof(SkPoint) + sizeof(Gr
Color)); | 481 SkPoint* textureCoords = (SkPoint*)(offset + sizeof(SkPoint) + sizeof(Gr
Color)); |
484 textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normaliz
eFixedX(tx)), | 482 textureCoords->setRectFan(tx / texture->width(), |
485 SkFixedToFloat(texture->texturePriv().normaliz
eFixedY(ty)), | 483 ty / texture->height(), |
486 SkFixedToFloat(texture->texturePriv().normaliz
eFixedX(tx + tw)), | 484 (tx + pathData->fBounds.width()) / texture->wi
dth(), |
487 SkFixedToFloat(texture->texturePriv().normaliz
eFixedY(ty + th)), | 485 (ty + pathData->fBounds.height()) / texture->
height(), |
488 vertexStride); | 486 vertexStride); |
489 } | 487 } |
490 | 488 |
491 void flush(GrVertexBatch::Target* target, FlushInfo* flushInfo) const { | 489 void flush(GrVertexBatch::Target* target, FlushInfo* flushInfo) const { |
492 GrVertices vertices; | 490 GrVertices vertices; |
493 int maxInstancesPerDraw = flushInfo->fIndexBuffer->maxQuads(); | 491 int maxInstancesPerDraw = flushInfo->fIndexBuffer->maxQuads(); |
494 vertices.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuf
fer, | 492 vertices.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuf
fer, |
495 flushInfo->fIndexBuffer, flushInfo->fVertexOffset, kVerticesPerQuad, | 493 flushInfo->fIndexBuffer, flushInfo->fVertexOffset, kVerticesPerQuad, |
496 kIndicesPerQuad, flushInfo->fInstancesToFlush, maxInstancesPerDraw); | 494 kIndicesPerQuad, flushInfo->fInstancesToFlush, maxInstancesPerDraw); |
497 target->draw(vertices); | 495 target->draw(vertices); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 geometry.fAntiAlias = random->nextBool(); | 643 geometry.fAntiAlias = random->nextBool(); |
646 geometry.fGenID = random->nextU(); | 644 geometry.fGenID = random->nextU(); |
647 | 645 |
648 return AADistanceFieldPathBatch::Create(geometry, viewMatrix, | 646 return AADistanceFieldPathBatch::Create(geometry, viewMatrix, |
649 gTestStruct.fAtlas, | 647 gTestStruct.fAtlas, |
650 &gTestStruct.fPathCache, | 648 &gTestStruct.fPathCache, |
651 &gTestStruct.fPathList); | 649 &gTestStruct.fPathList); |
652 } | 650 } |
653 | 651 |
654 #endif | 652 #endif |
OLD | NEW |