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/GrTessellatingPathRenderer.cpp

Issue 1128083004: Tesellating path renderer: typecast cleanup; logging build fix. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrTessellatingPathRenderer.h" 8 #include "GrTessellatingPathRenderer.h"
9 9
10 #include "GrBatch.h" 10 #include "GrBatch.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 } 178 }
179 179
180 bool sweep_gt_horiz(const SkPoint& a, const SkPoint& b) { 180 bool sweep_gt_horiz(const SkPoint& a, const SkPoint& b) {
181 return a.fX == b.fX ? a.fY < b.fY : a.fX > b.fX; 181 return a.fX == b.fX ? a.fY < b.fY : a.fX > b.fX;
182 } 182 }
183 183
184 bool sweep_gt_vert(const SkPoint& a, const SkPoint& b) { 184 bool sweep_gt_vert(const SkPoint& a, const SkPoint& b) {
185 return a.fY == b.fY ? a.fX > b.fX : a.fY > b.fY; 185 return a.fY == b.fY ? a.fX > b.fX : a.fY > b.fY;
186 } 186 }
187 187
188 inline void* emit_vertex(Vertex* v, void* data) { 188 inline SkPoint* emit_vertex(Vertex* v, SkPoint* data) {
189 SkPoint* d = static_cast<SkPoint*>(data); 189 *data++ = v->fPoint;
190 *d++ = v->fPoint; 190 return data;
191 return d;
192 } 191 }
193 192
194 void* emit_triangle(Vertex* v0, Vertex* v1, Vertex* v2, void* data) { 193 SkPoint* emit_triangle(Vertex* v0, Vertex* v1, Vertex* v2, SkPoint* data) {
195 #if WIREFRAME 194 #if WIREFRAME
196 data = emit_vertex(v0, data); 195 data = emit_vertex(v0, data);
197 data = emit_vertex(v1, data); 196 data = emit_vertex(v1, data);
198 data = emit_vertex(v1, data); 197 data = emit_vertex(v1, data);
199 data = emit_vertex(v2, data); 198 data = emit_vertex(v2, data);
200 data = emit_vertex(v2, data); 199 data = emit_vertex(v2, data);
201 data = emit_vertex(v0, data); 200 data = emit_vertex(v0, data);
202 #else 201 #else
203 data = emit_vertex(v0, data); 202 data = emit_vertex(v0, data);
204 data = emit_vertex(v1, data); 203 data = emit_vertex(v1, data);
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 fTail->fNext = newV; 352 fTail->fNext = newV;
354 fTail = newV; 353 fTail = newV;
355 } else { 354 } else {
356 newV->fNext = fHead; 355 newV->fNext = fHead;
357 fHead->fPrev = newV; 356 fHead->fPrev = newV;
358 fHead = newV; 357 fHead = newV;
359 } 358 }
360 return done; 359 return done;
361 } 360 }
362 361
363 void* emit(void* data) { 362 SkPoint* emit(SkPoint* data) {
364 Vertex* first = fHead; 363 Vertex* first = fHead;
365 Vertex* v = first->fNext; 364 Vertex* v = first->fNext;
366 while (v != fTail) { 365 while (v != fTail) {
367 SkASSERT(v && v->fPrev && v->fNext); 366 SkASSERT(v && v->fPrev && v->fNext);
368 Vertex* prev = v->fPrev; 367 Vertex* prev = v->fPrev;
369 Vertex* curr = v; 368 Vertex* curr = v;
370 Vertex* next = v->fNext; 369 Vertex* next = v->fNext;
371 double ax = static_cast<double>(curr->fPoint.fX) - prev->fPoint. fX; 370 double ax = static_cast<double>(curr->fPoint.fX) - prev->fPoint. fX;
372 double ay = static_cast<double>(curr->fPoint.fY) - prev->fPoint. fY; 371 double ay = static_cast<double>(curr->fPoint.fY) - prev->fPoint. fY;
373 double bx = static_cast<double>(next->fPoint.fX) - curr->fPoint. fX; 372 double bx = static_cast<double>(next->fPoint.fX) - curr->fPoint. fX;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 fCount++; 420 fCount++;
422 return poly; 421 return poly;
423 } 422 }
424 void end(Vertex* v, SkChunkAlloc& alloc) { 423 void end(Vertex* v, SkChunkAlloc& alloc) {
425 LOG("end() %d at %g, %g\n", fID, v->fPoint.fX, v->fPoint.fY); 424 LOG("end() %d at %g, %g\n", fID, v->fPoint.fX, v->fPoint.fY);
426 if (fPartner) { 425 if (fPartner) {
427 fPartner = fPartner->fPartner = NULL; 426 fPartner = fPartner->fPartner = NULL;
428 } 427 }
429 addVertex(v, fActive->fSide == kLeft_Side ? kRight_Side : kLeft_Side, al loc); 428 addVertex(v, fActive->fSide == kLeft_Side ? kRight_Side : kLeft_Side, al loc);
430 } 429 }
431 void* emit(void *data) { 430 SkPoint* emit(SkPoint *data) {
432 if (fCount < 3) { 431 if (fCount < 3) {
433 return data; 432 return data;
434 } 433 }
435 LOG("emit() %d, size %d\n", fID, fCount); 434 LOG("emit() %d, size %d\n", fID, fCount);
436 for (MonotonePoly* m = fHead; m != NULL; m = m->fNext) { 435 for (MonotonePoly* m = fHead; m != NULL; m = m->fNext) {
437 data = m->emit(data); 436 data = m->emit(data);
438 } 437 }
439 return data; 438 return data;
440 } 439 }
441 int fWinding; 440 int fWinding;
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 if (winding != 0) { 1269 if (winding != 0) {
1271 Poly* poly = new_poly(&polys, v, winding, alloc); 1270 Poly* poly = new_poly(&polys, v, winding, alloc);
1272 leftEdge->fRightPoly = rightEdge->fLeftPoly = poly; 1271 leftEdge->fRightPoly = rightEdge->fLeftPoly = poly;
1273 } 1272 }
1274 leftEdge = rightEdge; 1273 leftEdge = rightEdge;
1275 } 1274 }
1276 v->fLastEdgeBelow->fRightPoly = rightPoly; 1275 v->fLastEdgeBelow->fRightPoly = rightPoly;
1277 } 1276 }
1278 #if LOGGING_ENABLED 1277 #if LOGGING_ENABLED
1279 LOG("\nactive edges:\n"); 1278 LOG("\nactive edges:\n");
1280 for (Edge* e = activeEdges->fHead; e != NULL; e = e->fRight) { 1279 for (Edge* e = activeEdges.fHead; e != NULL; e = e->fRight) {
1281 LOG("%g -> %g, lpoly %d, rpoly %d\n", e->fTop->fID, e->fBottom->fID, 1280 LOG("%g -> %g, lpoly %d, rpoly %d\n", e->fTop->fID, e->fBottom->fID,
1282 e->fLeftPoly ? e->fLeftPoly->fID : -1, e->fRightPoly ? e->fRight Poly->fID : -1); 1281 e->fLeftPoly ? e->fLeftPoly->fID : -1, e->fRightPoly ? e->fRight Poly->fID : -1);
1283 } 1282 }
1284 #endif 1283 #endif
1285 } 1284 }
1286 return polys; 1285 return polys;
1287 } 1286 }
1288 1287
1289 // This is a driver function which calls stages 2-5 in turn. 1288 // This is a driver function which calls stages 2-5 in turn.
1290 1289
(...skipping 22 matching lines...) Expand all
1313 static float gID = 0.0f; 1312 static float gID = 0.0f;
1314 v->fID = gID++; 1313 v->fID = gID++;
1315 } 1314 }
1316 #endif 1315 #endif
1317 simplify(vertices, c, alloc); 1316 simplify(vertices, c, alloc);
1318 return tessellate(vertices, alloc); 1317 return tessellate(vertices, alloc);
1319 } 1318 }
1320 1319
1321 // Stage 6: Triangulate the monotone polygons into a vertex buffer. 1320 // Stage 6: Triangulate the monotone polygons into a vertex buffer.
1322 1321
1323 void* polys_to_triangles(Poly* polys, SkPath::FillType fillType, void* data) { 1322 SkPoint* polys_to_triangles(Poly* polys, SkPath::FillType fillType, SkPoint* dat a) {
1324 void* d = data; 1323 SkPoint* d = data;
1325 for (Poly* poly = polys; poly; poly = poly->fNext) { 1324 for (Poly* poly = polys; poly; poly = poly->fNext) {
1326 if (apply_fill_type(fillType, poly->fWinding)) { 1325 if (apply_fill_type(fillType, poly->fWinding)) {
1327 d = poly->emit(d); 1326 d = poly->emit(d);
1328 } 1327 }
1329 } 1328 }
1330 return d; 1329 return d;
1331 } 1330 }
1332 1331
1333 }; 1332 };
1334 1333
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1431 for (Poly* poly = polys; poly; poly = poly->fNext) { 1430 for (Poly* poly = polys; poly; poly = poly->fNext) {
1432 if (apply_fill_type(fillType, poly->fWinding) && poly->fCount >= 3) { 1431 if (apply_fill_type(fillType, poly->fWinding) && poly->fCount >= 3) {
1433 count += (poly->fCount - 2) * (WIREFRAME ? 6 : 3); 1432 count += (poly->fCount - 2) * (WIREFRAME ? 6 : 3);
1434 } 1433 }
1435 } 1434 }
1436 if (0 == count) { 1435 if (0 == count) {
1437 return; 1436 return;
1438 } 1437 }
1439 1438
1440 size_t stride = gp->getVertexStride(); 1439 size_t stride = gp->getVertexStride();
1440 SkASSERT(stride == sizeof(SkPoint));
1441 const GrVertexBuffer* vertexBuffer; 1441 const GrVertexBuffer* vertexBuffer;
1442 int firstVertex; 1442 int firstVertex;
1443 void* verts = batchTarget->makeVertSpace(stride, count, &vertexBuffer, & firstVertex); 1443 SkPoint* verts = static_cast<SkPoint*>(
1444 batchTarget->makeVertSpace(stride, count, &vertexBuffer, &firstVerte x));
1444 if (!verts) { 1445 if (!verts) {
1445 SkDebugf("Could not allocate vertices\n"); 1446 SkDebugf("Could not allocate vertices\n");
1446 return; 1447 return;
1447 } 1448 }
1448 1449
1449 LOG("emitting %d verts\n", count); 1450 LOG("emitting %d verts\n", count);
1450 void* end = polys_to_triangles(polys, fillType, verts); 1451 SkPoint* end = polys_to_triangles(polys, fillType, verts);
1451 int actualCount = static_cast<int>( 1452 int actualCount = static_cast<int>(end - verts);
1452 (static_cast<char*>(end) - static_cast<char*>(verts)) / stride);
1453 LOG("actual count: %d\n", actualCount); 1453 LOG("actual count: %d\n", actualCount);
1454 SkASSERT(actualCount <= count); 1454 SkASSERT(actualCount <= count);
1455 1455
1456 GrPrimitiveType primitiveType = WIREFRAME ? kLines_GrPrimitiveType 1456 GrPrimitiveType primitiveType = WIREFRAME ? kLines_GrPrimitiveType
1457 : kTriangles_GrPrimitiveType; 1457 : kTriangles_GrPrimitiveType;
1458 GrVertices vertices; 1458 GrVertices vertices;
1459 vertices.init(primitiveType, vertexBuffer, firstVertex, actualCount); 1459 vertices.init(primitiveType, vertexBuffer, firstVertex, actualCount);
1460 batchTarget->draw(vertices); 1460 batchTarget->draw(vertices);
1461 1461
1462 batchTarget->putBackVertices((size_t)(count - actualCount), stride); 1462 batchTarget->putBackVertices((size_t)(count - actualCount), stride);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
1528 SkMatrix vmi; 1528 SkMatrix vmi;
1529 bool result = viewMatrix.invert(&vmi); 1529 bool result = viewMatrix.invert(&vmi);
1530 if (!result) { 1530 if (!result) {
1531 SkFAIL("Cannot invert matrix\n"); 1531 SkFAIL("Cannot invert matrix\n");
1532 } 1532 }
1533 vmi.mapRect(&clipBounds); 1533 vmi.mapRect(&clipBounds);
1534 return TessellatingPathBatch::Create(color, path, viewMatrix, clipBounds); 1534 return TessellatingPathBatch::Create(color, path, viewMatrix, clipBounds);
1535 } 1535 }
1536 1536
1537 #endif 1537 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698