< prev index next >

src/java.desktop/share/classes/sun/java2d/marlin/DRenderer.java

Print this page




  29 import jdk.internal.misc.Unsafe;
  30 
  31 final class DRenderer implements DPathConsumer2D, MarlinRenderer {
  32 
  33     static final boolean DISABLE_RENDER = false;
  34 
  35     static final boolean ENABLE_BLOCK_FLAGS = MarlinProperties.isUseTileFlags();
  36     static final boolean ENABLE_BLOCK_FLAGS_HEURISTICS = MarlinProperties.isUseTileFlagsWithHeuristics();
  37 
  38     private static final int ALL_BUT_LSB = 0xFFFFFFFE;
  39     private static final int ERR_STEP_MAX = 0x7FFFFFFF; // = 2^31 - 1
  40 
  41     private static final double POWER_2_TO_32 = 0x1.0p32d;
  42 
  43     // use double to make tosubpix methods faster (no int to double conversion)
  44     static final double SUBPIXEL_SCALE_X = SUBPIXEL_POSITIONS_X;
  45     static final double SUBPIXEL_SCALE_Y = SUBPIXEL_POSITIONS_Y;
  46     static final int SUBPIXEL_MASK_X = SUBPIXEL_POSITIONS_X - 1;
  47     static final int SUBPIXEL_MASK_Y = SUBPIXEL_POSITIONS_Y - 1;
  48 



  49     // number of subpixels corresponding to a tile line
  50     private static final int SUBPIXEL_TILE
  51         = TILE_H << SUBPIXEL_LG_POSITIONS_Y;
  52 
  53     // 2048 (pixelSize) pixels (height) x 8 subpixels = 64K
  54     static final int INITIAL_BUCKET_ARRAY
  55         = INITIAL_PIXEL_DIM * SUBPIXEL_POSITIONS_Y;
  56 
  57     // crossing capacity = edges count / 4 ~ 1024
  58     static final int INITIAL_CROSSING_COUNT = INITIAL_EDGES_COUNT >> 2;
  59 
  60     public static final int WIND_EVEN_ODD = 0;
  61     public static final int WIND_NON_ZERO = 1;
  62 
  63     // common to all types of input path segments.
  64     // OFFSET as bytes
  65     // only integer values:
  66     public static final long OFF_CURX_OR  = 0;
  67     public static final long OFF_ERROR    = OFF_CURX_OR  + SIZE_INT;
  68     public static final long OFF_BUMP_X   = OFF_ERROR    + SIZE_INT;
  69     public static final long OFF_BUMP_ERR = OFF_BUMP_X   + SIZE_INT;
  70     public static final long OFF_NEXT     = OFF_BUMP_ERR + SIZE_INT;
  71     public static final long OFF_YMAX     = OFF_NEXT     + SIZE_INT;
  72 
  73     // size of one edge in bytes
  74     public static final int SIZEOF_EDGE_BYTES = (int)(OFF_YMAX + SIZE_INT);
  75 
  76     // curve break into lines
  77     // cubic error in subpixels to decrement step
  78     private static final double CUB_DEC_ERR_SUBPIX
  79         = MarlinProperties.getCubicDecD2() * (NORM_SUBPIXELS / 8.0d); // 1 pixel
  80     // cubic error in subpixels to increment step
  81     private static final double CUB_INC_ERR_SUBPIX
  82         = MarlinProperties.getCubicIncD1() * (NORM_SUBPIXELS / 8.0d); // 0.4 pixel


 651             // Force zero-fill dirty arrays:
 652             edges.fill(BYTE_0);
 653         }
 654         if (DO_MONITORS) {
 655             rdrCtx.stats.mon_rdr_endRendering.stop();
 656         }
 657         // recycle the RendererContext instance
 658         DMarlinRenderingEngine.returnRendererContext(rdrCtx);
 659     }
 660 
 661     private static double tosubpixx(final double pix_x) {
 662         return SUBPIXEL_SCALE_X * pix_x;
 663     }
 664 
 665     private static double tosubpixy(final double pix_y) {
 666         // shift y by -0.5 for fast ceil(y - 0.5):
 667         return SUBPIXEL_SCALE_Y * pix_y - 0.5d;
 668     }
 669 
 670     @Override
 671     public void moveTo(double pix_x0, double pix_y0) {
 672         closePath();
 673         final double sx = tosubpixx(pix_x0);
 674         final double sy = tosubpixy(pix_y0);
 675         this.sx0 = sx;
 676         this.sy0 = sy;
 677         this.x0 = sx;
 678         this.y0 = sy;
 679     }
 680 
 681     @Override
 682     public void lineTo(double pix_x1, double pix_y1) {
 683         final double x1 = tosubpixx(pix_x1);
 684         final double y1 = tosubpixy(pix_y1);
 685         addLine(x0, y0, x1, y1);
 686         x0 = x1;
 687         y0 = y1;
 688     }
 689 
 690     @Override
 691     public void curveTo(double x1, double y1,
 692                         double x2, double y2,
 693                         double x3, double y3)
 694     {
 695         final double xe = tosubpixx(x3);
 696         final double ye = tosubpixy(y3);
 697         curve.set(x0, y0, tosubpixx(x1), tosubpixy(y1),
 698                           tosubpixx(x2), tosubpixy(y2), xe, ye);
 699         curveBreakIntoLinesAndAdd(x0, y0, curve, xe, ye);
 700         x0 = xe;
 701         y0 = ye;
 702     }
 703 
 704     @Override
 705     public void quadTo(double x1, double y1, double x2, double y2) {
 706         final double xe = tosubpixx(x2);
 707         final double ye = tosubpixy(y2);
 708         curve.set(x0, y0, tosubpixx(x1), tosubpixy(y1), xe, ye);


 709         quadBreakIntoLinesAndAdd(x0, y0, curve, xe, ye);
 710         x0 = xe;
 711         y0 = ye;
 712     }
 713 
 714     @Override
 715     public void closePath() {
 716         addLine(x0, y0, sx0, sy0);
 717         x0 = sx0;
 718         y0 = sy0;


 719     }
 720 
 721     @Override
 722     public void pathDone() {
 723         closePath();
 724     }
 725 
 726     @Override
 727     public long getNativeConsumer() {
 728         throw new InternalError("Renderer does not use a native consumer.");
 729     }
 730 
 731     private void _endRendering(final int ymin, final int ymax) {
 732         if (DISABLE_RENDER) {
 733             return;
 734         }
 735 
 736         // Get X bounds as true pixel boundaries to compute correct pixel coverage:
 737         final int bboxx0 = bbox_spminX;
 738         final int bboxx1 = bbox_spmaxX;




  29 import jdk.internal.misc.Unsafe;
  30 
  31 final class DRenderer implements DPathConsumer2D, MarlinRenderer {
  32 
  33     static final boolean DISABLE_RENDER = false;
  34 
  35     static final boolean ENABLE_BLOCK_FLAGS = MarlinProperties.isUseTileFlags();
  36     static final boolean ENABLE_BLOCK_FLAGS_HEURISTICS = MarlinProperties.isUseTileFlagsWithHeuristics();
  37 
  38     private static final int ALL_BUT_LSB = 0xFFFFFFFE;
  39     private static final int ERR_STEP_MAX = 0x7FFFFFFF; // = 2^31 - 1
  40 
  41     private static final double POWER_2_TO_32 = 0x1.0p32d;
  42 
  43     // use double to make tosubpix methods faster (no int to double conversion)
  44     static final double SUBPIXEL_SCALE_X = SUBPIXEL_POSITIONS_X;
  45     static final double SUBPIXEL_SCALE_Y = SUBPIXEL_POSITIONS_Y;
  46     static final int SUBPIXEL_MASK_X = SUBPIXEL_POSITIONS_X - 1;
  47     static final int SUBPIXEL_MASK_Y = SUBPIXEL_POSITIONS_Y - 1;
  48 
  49     static final double RDR_OFFSET_X = 0.5d / SUBPIXEL_SCALE_X;
  50     static final double RDR_OFFSET_Y = 0.5d / SUBPIXEL_SCALE_Y;
  51 
  52     // number of subpixels corresponding to a tile line
  53     private static final int SUBPIXEL_TILE
  54         = TILE_H << SUBPIXEL_LG_POSITIONS_Y;
  55 
  56     // 2048 (pixelSize) pixels (height) x 8 subpixels = 64K
  57     static final int INITIAL_BUCKET_ARRAY
  58         = INITIAL_PIXEL_DIM * SUBPIXEL_POSITIONS_Y;
  59 
  60     // crossing capacity = edges count / 4 ~ 1024
  61     static final int INITIAL_CROSSING_COUNT = INITIAL_EDGES_COUNT >> 2;
  62 



  63     // common to all types of input path segments.
  64     // OFFSET as bytes
  65     // only integer values:
  66     public static final long OFF_CURX_OR  = 0;
  67     public static final long OFF_ERROR    = OFF_CURX_OR  + SIZE_INT;
  68     public static final long OFF_BUMP_X   = OFF_ERROR    + SIZE_INT;
  69     public static final long OFF_BUMP_ERR = OFF_BUMP_X   + SIZE_INT;
  70     public static final long OFF_NEXT     = OFF_BUMP_ERR + SIZE_INT;
  71     public static final long OFF_YMAX     = OFF_NEXT     + SIZE_INT;
  72 
  73     // size of one edge in bytes
  74     public static final int SIZEOF_EDGE_BYTES = (int)(OFF_YMAX + SIZE_INT);
  75 
  76     // curve break into lines
  77     // cubic error in subpixels to decrement step
  78     private static final double CUB_DEC_ERR_SUBPIX
  79         = MarlinProperties.getCubicDecD2() * (NORM_SUBPIXELS / 8.0d); // 1 pixel
  80     // cubic error in subpixels to increment step
  81     private static final double CUB_INC_ERR_SUBPIX
  82         = MarlinProperties.getCubicIncD1() * (NORM_SUBPIXELS / 8.0d); // 0.4 pixel


 651             // Force zero-fill dirty arrays:
 652             edges.fill(BYTE_0);
 653         }
 654         if (DO_MONITORS) {
 655             rdrCtx.stats.mon_rdr_endRendering.stop();
 656         }
 657         // recycle the RendererContext instance
 658         DMarlinRenderingEngine.returnRendererContext(rdrCtx);
 659     }
 660 
 661     private static double tosubpixx(final double pix_x) {
 662         return SUBPIXEL_SCALE_X * pix_x;
 663     }
 664 
 665     private static double tosubpixy(final double pix_y) {
 666         // shift y by -0.5 for fast ceil(y - 0.5):
 667         return SUBPIXEL_SCALE_Y * pix_y - 0.5d;
 668     }
 669 
 670     @Override
 671     public void moveTo(final double pix_x0, final double pix_y0) {
 672         closePath();
 673         final double sx = tosubpixx(pix_x0);
 674         final double sy = tosubpixy(pix_y0);
 675         this.sx0 = sx;
 676         this.sy0 = sy;
 677         this.x0 = sx;
 678         this.y0 = sy;
 679     }
 680 
 681     @Override
 682     public void lineTo(final double pix_x1, final double pix_y1) {
 683         final double x1 = tosubpixx(pix_x1);
 684         final double y1 = tosubpixy(pix_y1);
 685         addLine(x0, y0, x1, y1);
 686         x0 = x1;
 687         y0 = y1;
 688     }
 689 
 690     @Override
 691     public void curveTo(final double pix_x1, final double pix_y1,
 692                         final double pix_x2, final double pix_y2,
 693                         final double pix_x3, final double pix_y3)
 694     {
 695         final double xe = tosubpixx(pix_x3);
 696         final double ye = tosubpixy(pix_y3);
 697         curve.set(x0, y0, tosubpixx(pix_x1), tosubpixy(pix_y1),
 698                   tosubpixx(pix_x2), tosubpixy(pix_y2), xe, ye);
 699         curveBreakIntoLinesAndAdd(x0, y0, curve, xe, ye);
 700         x0 = xe;
 701         y0 = ye;
 702     }
 703 
 704     @Override
 705     public void quadTo(final double pix_x1, final double pix_y1,
 706                        final double pix_x2, final double pix_y2)
 707     {
 708         final double xe = tosubpixx(pix_x2);
 709         final double ye = tosubpixy(pix_y2);
 710         curve.set(x0, y0, tosubpixx(pix_x1), tosubpixy(pix_y1), xe, ye);
 711         quadBreakIntoLinesAndAdd(x0, y0, curve, xe, ye);
 712         x0 = xe;
 713         y0 = ye;
 714     }
 715 
 716     @Override
 717     public void closePath() {
 718         if (x0 != sx0 || y0 != sy0) {
 719             addLine(x0, y0, sx0, sy0);
 720             x0 = sx0;
 721             y0 = sy0;
 722         }
 723     }
 724 
 725     @Override
 726     public void pathDone() {
 727         closePath();
 728     }
 729 
 730     @Override
 731     public long getNativeConsumer() {
 732         throw new InternalError("Renderer does not use a native consumer.");
 733     }
 734 
 735     private void _endRendering(final int ymin, final int ymax) {
 736         if (DISABLE_RENDER) {
 737             return;
 738         }
 739 
 740         // Get X bounds as true pixel boundaries to compute correct pixel coverage:
 741         final int bboxx0 = bbox_spminX;
 742         final int bboxx1 = bbox_spmaxX;


< prev index next >