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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 // Setup GrGeometryProcessor | 202 // Setup GrGeometryProcessor |
203 GrBatchAtlas* atlas = fAtlas; | 203 GrBatchAtlas* atlas = fAtlas; |
204 SkAutoTUnref<GrGeometryProcessor> dfProcessor( | 204 SkAutoTUnref<GrGeometryProcessor> dfProcessor( |
205 GrDistanceFieldPathGeoProc::Create(this->color(), | 205 GrDistanceFieldPathGeoProc::Create(this->color(), |
206 this->viewMatrix(), | 206 this->viewMatrix(), |
207 atlas->getTexture(), | 207 atlas->getTexture(), |
208 params, | 208 params, |
209 flags, | 209 flags, |
210 this->usesLocalCoords())); | 210 this->usesLocalCoords())); |
211 | 211 |
212 target->initDraw(dfProcessor, this->pipeline()); | 212 target->initDraw(dfProcessor); |
213 | 213 |
214 FlushInfo flushInfo; | 214 FlushInfo flushInfo; |
215 | 215 |
216 // allocate vertices | 216 // allocate vertices |
217 size_t vertexStride = dfProcessor->getVertexStride(); | 217 size_t vertexStride = dfProcessor->getVertexStride(); |
218 SkASSERT(vertexStride == 2 * sizeof(SkPoint) + sizeof(GrColor)); | 218 SkASSERT(vertexStride == 2 * sizeof(SkPoint) + sizeof(GrColor)); |
219 | 219 |
220 const GrVertexBuffer* vertexBuffer; | 220 const GrVertexBuffer* vertexBuffer; |
221 void* vertices = target->makeVertexSpace(vertexStride, | 221 void* vertices = target->makeVertexSpace(vertexStride, |
222 kVerticesPerQuad * instanceCoun
t, | 222 kVerticesPerQuad * instanceCoun
t, |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 (const unsigned char*)dst.addr(), | 400 (const unsigned char*)dst.addr(), |
401 dst.width(), dst.height(), dst.rowByt
es()); | 401 dst.width(), dst.height(), dst.rowByt
es()); |
402 | 402 |
403 // add to atlas | 403 // add to atlas |
404 SkIPoint16 atlasLocation; | 404 SkIPoint16 atlasLocation; |
405 GrBatchAtlas::AtlasID id; | 405 GrBatchAtlas::AtlasID id; |
406 bool success = atlas->addToAtlas(&id, target, width, height, dfStorage.g
et(), | 406 bool success = atlas->addToAtlas(&id, target, width, height, dfStorage.g
et(), |
407 &atlasLocation); | 407 &atlasLocation); |
408 if (!success) { | 408 if (!success) { |
409 this->flush(target, flushInfo); | 409 this->flush(target, flushInfo); |
410 target->initDraw(dfProcessor, pipeline); | 410 target->initDraw(dfProcessor); |
411 | 411 |
412 SkDEBUGCODE(success =) atlas->addToAtlas(&id, target, width, height, | 412 SkDEBUGCODE(success =) atlas->addToAtlas(&id, target, width, height, |
413 dfStorage.get(), &atlasLoca
tion); | 413 dfStorage.get(), &atlasLoca
tion); |
414 SkASSERT(success); | 414 SkASSERT(success); |
415 | 415 |
416 } | 416 } |
417 | 417 |
418 // add to cache | 418 // add to cache |
419 pathData->fKey = PathData::Key(genID, dimension, stroke); | 419 pathData->fKey = PathData::Key(genID, dimension, stroke); |
420 pathData->fScale = scale; | 420 pathData->fScale = scale; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 // vertex texture coords | 484 // vertex texture coords |
485 SkPoint* textureCoords = (SkPoint*)(offset + sizeof(SkPoint) + sizeof(Gr
Color)); | 485 SkPoint* textureCoords = (SkPoint*)(offset + sizeof(SkPoint) + sizeof(Gr
Color)); |
486 textureCoords->setRectFan(tx / texture->width(), | 486 textureCoords->setRectFan(tx / texture->width(), |
487 ty / texture->height(), | 487 ty / texture->height(), |
488 (tx + pathData->fBounds.width()) / texture->wi
dth(), | 488 (tx + pathData->fBounds.width()) / texture->wi
dth(), |
489 (ty + pathData->fBounds.height()) / texture->
height(), | 489 (ty + pathData->fBounds.height()) / texture->
height(), |
490 vertexStride); | 490 vertexStride); |
491 } | 491 } |
492 | 492 |
493 void flush(GrVertexBatch::Target* target, FlushInfo* flushInfo) const { | 493 void flush(GrVertexBatch::Target* target, FlushInfo* flushInfo) const { |
494 GrVertices vertices; | 494 GrMesh mesh; |
495 int maxInstancesPerDraw = flushInfo->fIndexBuffer->maxQuads(); | 495 int maxInstancesPerDraw = flushInfo->fIndexBuffer->maxQuads(); |
496 vertices.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuf
fer, | 496 mesh.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer, |
497 flushInfo->fIndexBuffer, flushInfo->fVertexOffset, kVerticesPerQuad, | 497 flushInfo->fIndexBuffer, flushInfo->fVertexOffset, kVerticesPerQuad, |
498 kIndicesPerQuad, flushInfo->fInstancesToFlush, maxInstancesPerDraw); | 498 kIndicesPerQuad, flushInfo->fInstancesToFlush, maxInstancesPerDraw); |
499 target->draw(vertices); | 499 target->draw(mesh); |
500 flushInfo->fVertexOffset += kVerticesPerQuad * flushInfo->fInstancesToFl
ush; | 500 flushInfo->fVertexOffset += kVerticesPerQuad * flushInfo->fInstancesToFl
ush; |
501 flushInfo->fInstancesToFlush = 0; | 501 flushInfo->fInstancesToFlush = 0; |
502 } | 502 } |
503 | 503 |
504 GrColor color() const { return fGeoData[0].fColor; } | 504 GrColor color() const { return fGeoData[0].fColor; } |
505 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } | 505 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } |
506 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } | 506 bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; } |
507 | 507 |
508 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { | 508 bool onCombineIfPossible(GrBatch* t, const GrCaps& caps) override { |
509 AADistanceFieldPathBatch* that = t->cast<AADistanceFieldPathBatch>(); | 509 AADistanceFieldPathBatch* that = t->cast<AADistanceFieldPathBatch>(); |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 geometry.fAntiAlias = random->nextBool(); | 647 geometry.fAntiAlias = random->nextBool(); |
648 geometry.fGenID = random->nextU(); | 648 geometry.fGenID = random->nextU(); |
649 | 649 |
650 return AADistanceFieldPathBatch::Create(geometry, viewMatrix, | 650 return AADistanceFieldPathBatch::Create(geometry, viewMatrix, |
651 gTestStruct.fAtlas, | 651 gTestStruct.fAtlas, |
652 &gTestStruct.fPathCache, | 652 &gTestStruct.fPathCache, |
653 &gTestStruct.fPathList); | 653 &gTestStruct.fPathList); |
654 } | 654 } |
655 | 655 |
656 #endif | 656 #endif |
OLD | NEW |