Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: src/gpu/batches/GrAAConvexPathRenderer.cpp

Issue 1327943003: Clean up some lint complaints and fix center_of_mass() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 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 | « src/core/SkPictureShader.cpp ('k') | src/gpu/batches/GrAAConvexTessellator.cpp » ('j') | 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 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 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 "GrAAConvexPathRenderer.h" 9 #include "GrAAConvexPathRenderer.h"
10 10
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // from the origin. 74 // from the origin.
75 p0 = segments[0].endPt(); 75 p0 = segments[0].endPt();
76 SkPoint pi; 76 SkPoint pi;
77 SkPoint pj; 77 SkPoint pj;
78 // the first and last iteration of the below loop would compute 78 // the first and last iteration of the below loop would compute
79 // zeros since the starting / ending point is (0,0). So instead we start 79 // zeros since the starting / ending point is (0,0). So instead we start
80 // at i=1 and make the last iteration i=count-2. 80 // at i=1 and make the last iteration i=count-2.
81 pj = segments[1].endPt() - p0; 81 pj = segments[1].endPt() - p0;
82 for (int i = 1; i < count - 1; ++i) { 82 for (int i = 1; i < count - 1; ++i) {
83 pi = pj; 83 pi = pj;
84 const SkPoint pj = segments[i + 1].endPt() - p0; 84 pj = segments[i + 1].endPt() - p0;
85 85
86 SkScalar t = SkScalarMul(pi.fX, pj.fY) - SkScalarMul(pj.fX, pi.fY); 86 SkScalar t = SkPoint::CrossProduct(pi, pj);
87 area += t; 87 area += t;
88 center.fX += (pi.fX + pj.fX) * t; 88 center.fX += (pi.fX + pj.fX) * t;
89 center.fY += (pi.fY + pj.fY) * t; 89 center.fY += (pi.fY + pj.fY) * t;
90
91 } 90 }
92 } 91 }
92
93 // If the poly has no area then we instead return the average of 93 // If the poly has no area then we instead return the average of
94 // its points. 94 // its points.
95 if (SkScalarNearlyZero(area)) { 95 if (SkScalarNearlyZero(area)) {
96 SkPoint avg; 96 SkPoint avg;
97 avg.set(0, 0); 97 avg.set(0, 0);
98 for (int i = 0; i < count; ++i) { 98 for (int i = 0; i < count; ++i) {
99 const SkPoint& pt = segments[i].endPt(); 99 const SkPoint& pt = segments[i].endPt();
100 avg.fX += pt.fX; 100 avg.fX += pt.fX;
101 avg.fY += pt.fY; 101 avg.fY += pt.fY;
102 } 102 }
103 SkScalar denom = SK_Scalar1 / count; 103 SkScalar denom = SK_Scalar1 / count;
104 avg.scale(denom); 104 avg.scale(denom);
105 *c = avg; 105 *c = avg;
106 } else { 106 } else {
107 area *= 3; 107 area *= 3;
108 area = SkScalarInvert(area); 108 area = SkScalarInvert(area);
109 center.fX = SkScalarMul(center.fX, area); 109 center.scale(area);
110 center.fY = SkScalarMul(center.fY, area);
111 // undo the translate of p0 to the origin. 110 // undo the translate of p0 to the origin.
112 *c = center + p0; 111 *c = center + p0;
113 } 112 }
114 SkASSERT(!SkScalarIsNaN(c->fX) && !SkScalarIsNaN(c->fY)); 113 SkASSERT(!SkScalarIsNaN(c->fX) && !SkScalarIsNaN(c->fY));
115 } 114 }
116 115
117 static void compute_vectors(SegmentArray* segments, 116 static void compute_vectors(SegmentArray* segments,
118 SkPoint* fanPt, 117 SkPoint* fanPt,
119 SkPathPriv::FirstDirection dir, 118 SkPathPriv::FirstDirection dir,
120 int* vCount, 119 int* vCount,
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
909 if (!idxs) { 908 if (!idxs) {
910 SkDebugf("Could not allocate indices\n"); 909 SkDebugf("Could not allocate indices\n");
911 return; 910 return;
912 } 911 }
913 912
914 SkSTArray<kPreallocDrawCnt, Draw, true> draws; 913 SkSTArray<kPreallocDrawCnt, Draw, true> draws;
915 create_vertices(segments, fanPt, &draws, verts, idxs); 914 create_vertices(segments, fanPt, &draws, verts, idxs);
916 915
917 GrVertices vertices; 916 GrVertices vertices;
918 917
919 for (int i = 0; i < draws.count(); ++i) { 918 for (int j = 0; j < draws.count(); ++j) {
920 const Draw& draw = draws[i]; 919 const Draw& draw = draws[j];
921 vertices.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, i ndexBuffer, 920 vertices.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, i ndexBuffer,
922 firstVertex, firstIndex, draw.fVertexCnt, d raw.fIndexCnt); 921 firstVertex, firstIndex, draw.fVertexCnt, d raw.fIndexCnt);
923 target->draw(vertices); 922 target->draw(vertices);
924 firstVertex += draw.fVertexCnt; 923 firstVertex += draw.fVertexCnt;
925 firstIndex += draw.fIndexCnt; 924 firstIndex += draw.fIndexCnt;
926 } 925 }
927 } 926 }
928 } 927 }
929 928
930 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; } 929 SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 DRAW_BATCH_TEST_DEFINE(AAConvexPathBatch) { 1012 DRAW_BATCH_TEST_DEFINE(AAConvexPathBatch) {
1014 AAConvexPathBatch::Geometry geometry; 1013 AAConvexPathBatch::Geometry geometry;
1015 geometry.fColor = GrRandomColor(random); 1014 geometry.fColor = GrRandomColor(random);
1016 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random); 1015 geometry.fViewMatrix = GrTest::TestMatrixInvertible(random);
1017 geometry.fPath = GrTest::TestPathConvex(random); 1016 geometry.fPath = GrTest::TestPathConvex(random);
1018 1017
1019 return AAConvexPathBatch::Create(geometry); 1018 return AAConvexPathBatch::Create(geometry);
1020 } 1019 }
1021 1020
1022 #endif 1021 #endif
OLDNEW
« no previous file with comments | « src/core/SkPictureShader.cpp ('k') | src/gpu/batches/GrAAConvexTessellator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698