changeset 57087:eadd3fef2443

8236616: Polyline drawing is incorrect
author aghaisas
date Fri, 03 Jan 2020 16:13:00 +0530
parents 09b8eb38bbfa
children 2e3d5e1ba69d
files src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderer.m
diffstat 1 files changed, 11 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderer.m	Wed Dec 25 02:25:33 2019 +0300
+++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLRenderer.m	Fri Jan 03 16:13:00 2020 +0530
@@ -141,17 +141,21 @@
         struct Vertex verts[POLYLINE_BUF_SIZE];
     } pointsChunk;
 
+    // We intend to submit draw commands in batches of POLYLINE_BUF_SIZE vertices at a time
+    // Subsequent batches need to be connected - so end point in one batch is repeated as first point in subsequent batch
+    // This inflates the total number of points by a factor of number of batches of size POLYLINE_BUF_SIZE
+    nPoints += (nPoints/POLYLINE_BUF_SIZE);
+
     jint prevX = *(xPoints++);
     jint prevY = *(yPoints++);
-    --nPoints;
     const jint firstX = prevX;
     const jint firstY = prevY;
     while (nPoints > 0) {
+        const bool isLastChunk = nPoints <= POLYLINE_BUF_SIZE;
+        __block int chunkSize = isLastChunk ? nPoints : POLYLINE_BUF_SIZE;
+
         fillVertex(pointsChunk.verts, prevX + transX, prevY + transY);
 
-        const bool isLastChunk = nPoints + 1 <= POLYLINE_BUF_SIZE;
-        __block int chunkSize = isLastChunk ? nPoints : POLYLINE_BUF_SIZE - 1;
-
         for (int i = 1; i < chunkSize; i++) {
             prevX = *(xPoints++);
             prevY = *(yPoints++);
@@ -173,12 +177,14 @@
             return;
 
         [mtlEncoder setVertexBytes:pointsChunk.verts length:sizeof(pointsChunk.verts) atIndex:MeshVertexBuffer];
-        [mtlEncoder drawPrimitives:MTLPrimitiveTypeLineStrip vertexStart:0 vertexCount:chunkSize + 1];
+        [mtlEncoder drawPrimitives:MTLPrimitiveTypeLineStrip vertexStart:0 vertexCount:chunkSize];
+
         if (drawCloseSegment) {
             struct Vertex vertices[2] = {
                     {{prevX + transX, prevY + transY}},
                     {{firstX + transX, firstY + transY}},
             };
+
             [mtlEncoder setVertexBytes:vertices length:sizeof(vertices) atIndex:MeshVertexBuffer];
             [mtlEncoder drawPrimitives:MTLPrimitiveTypeLine vertexStart:0 vertexCount:2];
         }