< prev index next >

modules/javafx.graphics/src/main/java/javafx/scene/canvas/GraphicsContext.java

Print this page




 689         if (xPoints == null || yPoints == null) return;
 690         GrowableDataBuffer buf = getBuffer();
 691         buf.putByte(NGCanvas.PATHSTART);
 692         int pos = 0;
 693         byte polycmd = NGCanvas.MOVETO;
 694         for (int i = 0; i < nPoints; i++) {
 695             if (pos >= polybuf.length) {
 696                 flushPolyBuf(buf, polybuf, pos, polycmd);
 697                 pos = 0;
 698                 polycmd = NGCanvas.LINETO;
 699             }
 700             polybuf[pos++] = (float) xPoints[i];
 701             polybuf[pos++] = (float) yPoints[i];
 702         }
 703         flushPolyBuf(buf, polybuf, pos, polycmd);
 704         if (close) {
 705             buf.putByte(NGCanvas.CLOSEPATH);
 706         }
 707         buf.putByte(NGCanvas.PATHEND);
 708         // Transform needs to be updated for rendering attributes even though
 709         // we have already trasnformed the points as we sent them.
 710         updateTransform();
 711         buf.putByte(command);
 712         // Now that we have changed the PG layer path, we need to mark our path dirty.
 713         markPathDirty();
 714     }
 715 
 716     private void writeImage(Image img,
 717                             double dx, double dy, double dw, double dh)
 718     {
 719         if (img == null || img.getProgress() < 1.0) return;
 720         Object platformImg = Toolkit.getImageAccessor().getPlatformImage(img);
 721         if (platformImg == null) return;
 722         updateTransform();
 723         GrowableDataBuffer buf = getBuffer();
 724         writeRectParams(buf, dx, dy, dw, dh, NGCanvas.DRAW_IMAGE);
 725         buf.putObject(platformImg);
 726     }
 727 
 728     private void writeImage(Image img,
 729                             double dx, double dy, double dw, double dh,


 776             buf.putByte(NGCanvas.TRANSFORM);
 777             buf.putDouble(curState.transform.getMxx());
 778             buf.putDouble(curState.transform.getMxy());
 779             buf.putDouble(curState.transform.getMxt());
 780             buf.putDouble(curState.transform.getMyx());
 781             buf.putDouble(curState.transform.getMyy());
 782             buf.putDouble(curState.transform.getMyt());
 783         }
 784     }
 785 
 786     void updateDimensions() {
 787         GrowableDataBuffer buf = getBuffer();
 788         buf.putByte(NGCanvas.SET_DIMS);
 789         buf.putFloat((float) theCanvas.getWidth());
 790         buf.putFloat((float) theCanvas.getHeight());
 791     }
 792 
 793     private void reset() {
 794         GrowableDataBuffer buf = getBuffer();
 795         // Only reset if we have a significant amount of data to omit,
 796         // this prevents a common occurence of "setFill(bg); fillRect();"
 797         // at the start of a session from invoking a reset.
 798         // But, do a reset anyway if the rendering layer has been falling
 799         // behind because that lets the synchronization step throw out the
 800         // older buffers that have been backing up.
 801         if (buf.writeValuePosition() > Canvas.DEFAULT_VAL_BUF_SIZE ||
 802             theCanvas.isRendererFallingBehind())
 803         {
 804             buf.reset();
 805             buf.putByte(NGCanvas.RESET);
 806             updateDimensions();
 807             txdirty = true;
 808             pathDirty = true;
 809             State s = this.curState;
 810             int numClipPaths = this.curState.numClipPaths;
 811             this.curState = new State();
 812             for (int i = 0; i < numClipPaths; i++) {
 813                 Path2D clip = clipStack.get(i);
 814                 buf.putByte(NGCanvas.PUSH_CLIP);
 815                 buf.putObject(clip);
 816             }


2592      * <p>
2593      * This method will be affected by any of the
2594      * <a href="#comm-attr">global common</a>
2595      * attributes as specified in the
2596      * <a href="#attr-ops-table">Rendering Attributes Table</a>.
2597      * </p>
2598      *
2599      * @param img the image to be drawn or null.
2600      * @param x the X coordinate on the destination for the upper left of the image.
2601      * @param y the Y coordinate on the destination for the upper left of the image.
2602      */
2603     public void drawImage(Image img, double x, double y) {
2604         if (img == null) return;
2605         double sw = img.getWidth();
2606         double sh = img.getHeight();
2607         writeImage(img, x, y, sw, sh);
2608     }
2609 
2610     /**
2611      * Draws an image into the given destination rectangle of the canvas. The
2612      * Image is scaled to fit into the destination rectagnle.
2613      * A {@code null} image value or an image still in progress will be ignored.
2614      * <p>
2615      * This method will be affected by any of the
2616      * <a href="#comm-attr">global common</a>
2617      * attributes as specified in the
2618      * <a href="#attr-ops-table">Rendering Attributes Table</a>.
2619      * </p>
2620      *
2621      * @param img the image to be drawn or null.
2622      * @param x the X coordinate on the destination for the upper left of the image.
2623      * @param y the Y coordinate on the destination for the upper left of the image.
2624      * @param w the width of the destination rectangle.
2625      * @param h the height of the destination rectangle.
2626      */
2627     public void drawImage(Image img, double x, double y, double w, double h) {
2628         writeImage(img, x, y, w, h);
2629     }
2630 
2631     /**
2632      * Draws the specified source rectangle of the given image to the given




 689         if (xPoints == null || yPoints == null) return;
 690         GrowableDataBuffer buf = getBuffer();
 691         buf.putByte(NGCanvas.PATHSTART);
 692         int pos = 0;
 693         byte polycmd = NGCanvas.MOVETO;
 694         for (int i = 0; i < nPoints; i++) {
 695             if (pos >= polybuf.length) {
 696                 flushPolyBuf(buf, polybuf, pos, polycmd);
 697                 pos = 0;
 698                 polycmd = NGCanvas.LINETO;
 699             }
 700             polybuf[pos++] = (float) xPoints[i];
 701             polybuf[pos++] = (float) yPoints[i];
 702         }
 703         flushPolyBuf(buf, polybuf, pos, polycmd);
 704         if (close) {
 705             buf.putByte(NGCanvas.CLOSEPATH);
 706         }
 707         buf.putByte(NGCanvas.PATHEND);
 708         // Transform needs to be updated for rendering attributes even though
 709         // we have already transformed the points as we sent them.
 710         updateTransform();
 711         buf.putByte(command);
 712         // Now that we have changed the PG layer path, we need to mark our path dirty.
 713         markPathDirty();
 714     }
 715 
 716     private void writeImage(Image img,
 717                             double dx, double dy, double dw, double dh)
 718     {
 719         if (img == null || img.getProgress() < 1.0) return;
 720         Object platformImg = Toolkit.getImageAccessor().getPlatformImage(img);
 721         if (platformImg == null) return;
 722         updateTransform();
 723         GrowableDataBuffer buf = getBuffer();
 724         writeRectParams(buf, dx, dy, dw, dh, NGCanvas.DRAW_IMAGE);
 725         buf.putObject(platformImg);
 726     }
 727 
 728     private void writeImage(Image img,
 729                             double dx, double dy, double dw, double dh,


 776             buf.putByte(NGCanvas.TRANSFORM);
 777             buf.putDouble(curState.transform.getMxx());
 778             buf.putDouble(curState.transform.getMxy());
 779             buf.putDouble(curState.transform.getMxt());
 780             buf.putDouble(curState.transform.getMyx());
 781             buf.putDouble(curState.transform.getMyy());
 782             buf.putDouble(curState.transform.getMyt());
 783         }
 784     }
 785 
 786     void updateDimensions() {
 787         GrowableDataBuffer buf = getBuffer();
 788         buf.putByte(NGCanvas.SET_DIMS);
 789         buf.putFloat((float) theCanvas.getWidth());
 790         buf.putFloat((float) theCanvas.getHeight());
 791     }
 792 
 793     private void reset() {
 794         GrowableDataBuffer buf = getBuffer();
 795         // Only reset if we have a significant amount of data to omit,
 796         // this prevents a common occurrence of "setFill(bg); fillRect();"
 797         // at the start of a session from invoking a reset.
 798         // But, do a reset anyway if the rendering layer has been falling
 799         // behind because that lets the synchronization step throw out the
 800         // older buffers that have been backing up.
 801         if (buf.writeValuePosition() > Canvas.DEFAULT_VAL_BUF_SIZE ||
 802             theCanvas.isRendererFallingBehind())
 803         {
 804             buf.reset();
 805             buf.putByte(NGCanvas.RESET);
 806             updateDimensions();
 807             txdirty = true;
 808             pathDirty = true;
 809             State s = this.curState;
 810             int numClipPaths = this.curState.numClipPaths;
 811             this.curState = new State();
 812             for (int i = 0; i < numClipPaths; i++) {
 813                 Path2D clip = clipStack.get(i);
 814                 buf.putByte(NGCanvas.PUSH_CLIP);
 815                 buf.putObject(clip);
 816             }


2592      * <p>
2593      * This method will be affected by any of the
2594      * <a href="#comm-attr">global common</a>
2595      * attributes as specified in the
2596      * <a href="#attr-ops-table">Rendering Attributes Table</a>.
2597      * </p>
2598      *
2599      * @param img the image to be drawn or null.
2600      * @param x the X coordinate on the destination for the upper left of the image.
2601      * @param y the Y coordinate on the destination for the upper left of the image.
2602      */
2603     public void drawImage(Image img, double x, double y) {
2604         if (img == null) return;
2605         double sw = img.getWidth();
2606         double sh = img.getHeight();
2607         writeImage(img, x, y, sw, sh);
2608     }
2609 
2610     /**
2611      * Draws an image into the given destination rectangle of the canvas. The
2612      * Image is scaled to fit into the destination rectangle.
2613      * A {@code null} image value or an image still in progress will be ignored.
2614      * <p>
2615      * This method will be affected by any of the
2616      * <a href="#comm-attr">global common</a>
2617      * attributes as specified in the
2618      * <a href="#attr-ops-table">Rendering Attributes Table</a>.
2619      * </p>
2620      *
2621      * @param img the image to be drawn or null.
2622      * @param x the X coordinate on the destination for the upper left of the image.
2623      * @param y the Y coordinate on the destination for the upper left of the image.
2624      * @param w the width of the destination rectangle.
2625      * @param h the height of the destination rectangle.
2626      */
2627     public void drawImage(Image img, double x, double y, double w, double h) {
2628         writeImage(img, x, y, w, h);
2629     }
2630 
2631     /**
2632      * Draws the specified source rectangle of the given image to the given


< prev index next >