| 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 |
| 11 #include "GrBatchFlushState.h" | 11 #include "GrBatchFlushState.h" |
| 12 #include "GrBatchTest.h" | 12 #include "GrBatchTest.h" |
| 13 #include "GrBuffer.h" |
| 13 #include "GrContext.h" | 14 #include "GrContext.h" |
| 14 #include "GrPipelineBuilder.h" | 15 #include "GrPipelineBuilder.h" |
| 15 #include "GrResourceProvider.h" | 16 #include "GrResourceProvider.h" |
| 16 #include "GrSurfacePriv.h" | 17 #include "GrSurfacePriv.h" |
| 17 #include "GrSWMaskHelper.h" | 18 #include "GrSWMaskHelper.h" |
| 18 #include "GrTexturePriv.h" | 19 #include "GrTexturePriv.h" |
| 19 #include "GrVertexBuffer.h" | |
| 20 #include "batches/GrVertexBatch.h" | 20 #include "batches/GrVertexBatch.h" |
| 21 #include "effects/GrDistanceFieldGeoProc.h" | 21 #include "effects/GrDistanceFieldGeoProc.h" |
| 22 | 22 |
| 23 #include "SkDistanceFieldGen.h" | 23 #include "SkDistanceFieldGen.h" |
| 24 #include "SkRTConf.h" | 24 #include "SkRTConf.h" |
| 25 | 25 |
| 26 #define ATLAS_TEXTURE_WIDTH 2048 | 26 #define ATLAS_TEXTURE_WIDTH 2048 |
| 27 #define ATLAS_TEXTURE_HEIGHT 2048 | 27 #define ATLAS_TEXTURE_HEIGHT 2048 |
| 28 #define PLOT_WIDTH 512 | 28 #define PLOT_WIDTH 512 |
| 29 #define PLOT_HEIGHT 256 | 29 #define PLOT_HEIGHT 256 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 GrVertexBuffer> fVertexBuffer; | 180 SkAutoTUnref<const GrBuffer> fVertexBuffer; |
| 181 SkAutoTUnref<const GrIndexBuffer> fIndexBuffer; | 181 SkAutoTUnref<const GrBuffer> fIndexBuffer; |
| 182 int fVertexOffset; | 182 int fVertexOffset; |
| 183 int fInstancesToFlush; | 183 int fInstancesToFlush; |
| 184 }; | 184 }; |
| 185 | 185 |
| 186 void onPrepareDraws(Target* target) const override { | 186 void onPrepareDraws(Target* target) const override { |
| 187 int instanceCount = fGeoData.count(); | 187 int instanceCount = fGeoData.count(); |
| 188 | 188 |
| 189 SkMatrix invert; | 189 SkMatrix invert; |
| 190 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { | 190 if (this->usesLocalCoords() && !this->viewMatrix().invert(&invert)) { |
| 191 SkDebugf("Could not invert viewmatrix\n"); | 191 SkDebugf("Could not invert viewmatrix\n"); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 210 this->usesLocalCoords())); | 210 this->usesLocalCoords())); |
| 211 | 211 |
| 212 target->initDraw(dfProcessor); | 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 GrBuffer* vertexBuffer; |
| 221 void* vertices = target->makeVertexSpace(vertexStride, | 221 void* vertices = target->makeVertexSpace(vertexStride, |
| 222 kVerticesPerQuad * instanceCoun
t, | 222 kVerticesPerQuad * instanceCoun
t, |
| 223 &vertexBuffer, | 223 &vertexBuffer, |
| 224 &flushInfo.fVertexOffset); | 224 &flushInfo.fVertexOffset); |
| 225 flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer)); | 225 flushInfo.fVertexBuffer.reset(SkRef(vertexBuffer)); |
| 226 flushInfo.fIndexBuffer.reset(target->resourceProvider()->refQuadIndexBuf
fer()); | 226 flushInfo.fIndexBuffer.reset(target->resourceProvider()->refQuadIndexBuf
fer()); |
| 227 if (!vertices || !flushInfo.fIndexBuffer) { | 227 if (!vertices || !flushInfo.fIndexBuffer) { |
| 228 SkDebugf("Could not allocate vertices\n"); | 228 SkDebugf("Could not allocate vertices\n"); |
| 229 return; | 229 return; |
| 230 } | 230 } |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 GrMesh mesh; | 494 GrMesh mesh; |
| 495 int maxInstancesPerDraw = flushInfo->fIndexBuffer->maxQuads(); | 495 int maxInstancesPerDraw = |
| 496 static_cast<int>(flushInfo->fIndexBuffer->gpuMemorySize() / sizeof(u
int16_t) / 6); |
| 496 mesh.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer, | 497 mesh.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer, |
| 497 flushInfo->fIndexBuffer, flushInfo->fVertexOffset, kVerticesPerQuad, | 498 flushInfo->fIndexBuffer, flushInfo->fVertexOffset, kVerticesPerQuad, |
| 498 kIndicesPerQuad, flushInfo->fInstancesToFlush, maxInstancesPerDraw); | 499 kIndicesPerQuad, flushInfo->fInstancesToFlush, maxInstancesPerDraw); |
| 499 target->draw(mesh); | 500 target->draw(mesh); |
| 500 flushInfo->fVertexOffset += kVerticesPerQuad * flushInfo->fInstancesToFl
ush; | 501 flushInfo->fVertexOffset += kVerticesPerQuad * flushInfo->fInstancesToFl
ush; |
| 501 flushInfo->fInstancesToFlush = 0; | 502 flushInfo->fInstancesToFlush = 0; |
| 502 } | 503 } |
| 503 | 504 |
| 504 GrColor color() const { return fGeoData[0].fColor; } | 505 GrColor color() const { return fGeoData[0].fColor; } |
| 505 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } | 506 const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 647 geometry.fAntiAlias = random->nextBool(); | 648 geometry.fAntiAlias = random->nextBool(); |
| 648 geometry.fGenID = random->nextU(); | 649 geometry.fGenID = random->nextU(); |
| 649 | 650 |
| 650 return AADistanceFieldPathBatch::Create(geometry, viewMatrix, | 651 return AADistanceFieldPathBatch::Create(geometry, viewMatrix, |
| 651 gTestStruct.fAtlas, | 652 gTestStruct.fAtlas, |
| 652 &gTestStruct.fPathCache, | 653 &gTestStruct.fPathCache, |
| 653 &gTestStruct.fPathList); | 654 &gTestStruct.fPathList); |
| 654 } | 655 } |
| 655 | 656 |
| 656 #endif | 657 #endif |
| OLD | NEW |