jdk/src/java.desktop/share/classes/sun/java2d/marlin/Stroker.java
changeset 39519 21bfc4452441
parent 36902 bb30d89aa00e
child 40421 d5ee65e2b0fb
equal deleted inserted replaced
39518:cf5567d544b4 39519:21bfc4452441
     1 /*
     1 /*
     2  * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   178      * clean up before reusing this instance
   178      * clean up before reusing this instance
   179      */
   179      */
   180     void dispose() {
   180     void dispose() {
   181         reverse.dispose();
   181         reverse.dispose();
   182 
   182 
   183         if (doCleanDirty) {
   183         if (DO_CLEAN_DIRTY) {
   184             // Force zero-fill dirty arrays:
   184             // Force zero-fill dirty arrays:
   185             Arrays.fill(offset0, 0f);
   185             Arrays.fill(offset0, 0f);
   186             Arrays.fill(offset1, 0f);
   186             Arrays.fill(offset1, 0f);
   187             Arrays.fill(offset2, 0f);
   187             Arrays.fill(offset2, 0f);
   188             Arrays.fill(miter, 0f);
   188             Arrays.fill(miter, 0f);
   224     private void drawRoundJoin(float x, float y,
   224     private void drawRoundJoin(float x, float y,
   225                                float omx, float omy, float mx, float my,
   225                                float omx, float omy, float mx, float my,
   226                                boolean rev,
   226                                boolean rev,
   227                                float threshold)
   227                                float threshold)
   228     {
   228     {
   229         if ((omx == 0 && omy == 0) || (mx == 0 && my == 0)) {
   229         if ((omx == 0f && omy == 0f) || (mx == 0f && my == 0f)) {
   230             return;
   230             return;
   231         }
   231         }
   232 
   232 
   233         float domx = omx - mx;
   233         float domx = omx - mx;
   234         float domy = omy - my;
   234         float domy = omy - my;
   336 
   336 
   337         emitCurveTo(x1, y1, x2, y2, x3, y3, x4, y4, rev);
   337         emitCurveTo(x1, y1, x2, y2, x3, y3, x4, y4, rev);
   338     }
   338     }
   339 
   339 
   340     private void drawRoundCap(float cx, float cy, float mx, float my) {
   340     private void drawRoundCap(float cx, float cy, float mx, float my) {
   341         emitCurveTo(cx+mx-C*my, cy+my+C*mx,
   341         final float Cmx = C * mx;
   342                     cx-my+C*mx, cy+mx+C*my,
   342         final float Cmy = C * my;
   343                     cx-my,      cy+mx);
   343         emitCurveTo(cx + mx - Cmy, cy + my + Cmx,
   344         emitCurveTo(cx-my-C*mx, cy+mx-C*my,
   344                     cx - my + Cmx, cy + mx + Cmy,
   345                     cx-mx-C*my, cy-my+C*mx,
   345                     cx - my,       cy + mx);
   346                     cx-mx,      cy-my);
   346         emitCurveTo(cx - my - Cmx, cy + mx - Cmy,
       
   347                     cx - mx - Cmy, cy - my + Cmx,
       
   348                     cx - mx,       cy - my);
   347     }
   349     }
   348 
   350 
   349     // Put the intersection point of the lines (x0, y0) -> (x1, y1)
   351     // Put the intersection point of the lines (x0, y0) -> (x1, y1)
   350     // and (x0p, y0p) -> (x1p, y1p) in m[off] and m[off+1].
   352     // and (x0p, y0p) -> (x1p, y1p) in m[off] and m[off+1].
   351     // If the lines are parallel, it will put a non finite number in m.
   353     // If the lines are parallel, it will put a non finite number in m.
   410         if (prev == DRAWING_OP_TO) {
   412         if (prev == DRAWING_OP_TO) {
   411             finish();
   413             finish();
   412         }
   414         }
   413         this.sx0 = this.cx0 = x0;
   415         this.sx0 = this.cx0 = x0;
   414         this.sy0 = this.cy0 = y0;
   416         this.sy0 = this.cy0 = y0;
   415         this.cdx = this.sdx = 1;
   417         this.cdx = this.sdx = 1f;
   416         this.cdy = this.sdy = 0;
   418         this.cdy = this.sdy = 0f;
   417         this.prev = MOVE_TO;
   419         this.prev = MOVE_TO;
   418     }
   420     }
   419 
   421 
   420     @Override
   422     @Override
   421     public void lineTo(float x1, float y1) {
   423     public void lineTo(float x1, float y1) {
   450         if (prev != DRAWING_OP_TO) {
   452         if (prev != DRAWING_OP_TO) {
   451             if (prev == CLOSE) {
   453             if (prev == CLOSE) {
   452                 return;
   454                 return;
   453             }
   455             }
   454             emitMoveTo(cx0, cy0 - lineWidth2);
   456             emitMoveTo(cx0, cy0 - lineWidth2);
   455             this.cmx = this.smx = 0;
   457             this.cmx = this.smx = 0f;
   456             this.cmy = this.smy = -lineWidth2;
   458             this.cmy = this.smy = -lineWidth2;
   457             this.cdx = this.sdx = 1;
   459             this.cdx = this.sdx = 1f;
   458             this.cdy = this.sdy = 0;
   460             this.cdy = this.sdy = 0f;
   459             finish();
   461             finish();
   460             return;
   462             return;
   461         }
   463         }
   462 
   464 
   463         if (cx0 != sx0 || cy0 != sy0) {
   465         if (cx0 != sx0 || cy0 != sy0) {
  1230             curves = curves_initial;
  1232             curves = curves_initial;
  1231             curveTypes = curveTypes_initial;
  1233             curveTypes = curveTypes_initial;
  1232             end = 0;
  1234             end = 0;
  1233             numCurves = 0;
  1235             numCurves = 0;
  1234 
  1236 
  1235             if (doStats) {
  1237             if (DO_STATS) {
  1236                 curveTypesUseMark = 0;
  1238                 curveTypesUseMark = 0;
  1237                 curvesUseMark = 0;
  1239                 curvesUseMark = 0;
  1238             }
  1240             }
  1239         }
  1241         }
  1240 
  1242 
  1244          */
  1246          */
  1245         void dispose() {
  1247         void dispose() {
  1246             end = 0;
  1248             end = 0;
  1247             numCurves = 0;
  1249             numCurves = 0;
  1248 
  1250 
  1249             if (doStats) {
  1251             if (DO_STATS) {
  1250                 RendererContext.stats.stat_rdr_poly_stack_types
  1252                 rdrCtx.stats.stat_rdr_poly_stack_types
  1251                     .add(curveTypesUseMark);
  1253                     .add(curveTypesUseMark);
  1252                 RendererContext.stats.stat_rdr_poly_stack_curves
  1254                 rdrCtx.stats.stat_rdr_poly_stack_curves
  1253                     .add(curvesUseMark);
  1255                     .add(curvesUseMark);
  1254                 // reset marks
  1256                 // reset marks
  1255                 curveTypesUseMark = 0;
  1257                 curveTypesUseMark = 0;
  1256                 curvesUseMark = 0;
  1258                 curvesUseMark = 0;
  1257             }
  1259             }
  1270         }
  1272         }
  1271 
  1273 
  1272         private void ensureSpace(final int n) {
  1274         private void ensureSpace(final int n) {
  1273             // use substraction to avoid integer overflow:
  1275             // use substraction to avoid integer overflow:
  1274             if (curves.length - end < n) {
  1276             if (curves.length - end < n) {
  1275                 if (doStats) {
  1277                 if (DO_STATS) {
  1276                     RendererContext.stats.stat_array_stroker_polystack_curves
  1278                     rdrCtx.stats.stat_array_stroker_polystack_curves
  1277                         .add(end + n);
  1279                         .add(end + n);
  1278                 }
  1280                 }
  1279                 curves = rdrCtx.widenDirtyFloatArray(curves, end, end + n);
  1281                 curves = rdrCtx.widenDirtyFloatArray(curves, end, end + n);
  1280             }
  1282             }
  1281             if (curveTypes.length <= numCurves) {
  1283             if (curveTypes.length <= numCurves) {
  1282                 if (doStats) {
  1284                 if (DO_STATS) {
  1283                     RendererContext.stats.stat_array_stroker_polystack_curveTypes
  1285                     rdrCtx.stats.stat_array_stroker_polystack_curveTypes
  1284                         .add(numCurves + 1);
  1286                         .add(numCurves + 1);
  1285                 }
  1287                 }
  1286                 curveTypes = rdrCtx.widenDirtyByteArray(curveTypes,
  1288                 curveTypes = rdrCtx.widenDirtyByteArray(curveTypes,
  1287                                                         numCurves,
  1289                                                         numCurves,
  1288                                                         numCurves + 1);
  1290                                                         numCurves + 1);
  1321             curveTypes[numCurves++] = TYPE_LINETO;
  1323             curveTypes[numCurves++] = TYPE_LINETO;
  1322             curves[end++] = x;    curves[end++] = y;
  1324             curves[end++] = x;    curves[end++] = y;
  1323         }
  1325         }
  1324 
  1326 
  1325         void popAll(PathConsumer2D io) {
  1327         void popAll(PathConsumer2D io) {
  1326             if (doStats) {
  1328             if (DO_STATS) {
  1327                 // update used marks:
  1329                 // update used marks:
  1328                 if (numCurves > curveTypesUseMark) {
  1330                 if (numCurves > curveTypesUseMark) {
  1329                     curveTypesUseMark = numCurves;
  1331                     curveTypesUseMark = numCurves;
  1330                 }
  1332                 }
  1331                 if (end > curvesUseMark) {
  1333                 if (end > curvesUseMark) {