Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8335184

GraphicsContex.clip() works slowly when doubles are used

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • jfx11, 8, jfx21, jfx22, jfx23
    • javafx
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      openjdk version "21.0.2" 2024-01-16
      OpenJDK Runtime Environment (build 21.0.2+13-58)
      OpenJDK 64-Bit Server VM (build 21.0.2+13-58, mixed mode, sharing)

      OS: Ubuntu 20.04.3 LTS

      A DESCRIPTION OF THE PROBLEM :
      GraphicsContex.clip() works slowly when doubles are used for setting clip form.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run this code. Ather that try variant #2. See the difference.


      ---------- BEGIN SOURCE ----------
      public class JavaFxTest7 extends Application {

        public static void main(String[] args) {
            launch(args);
        }

        @Override
        public void start(Stage primaryStage) {
            Canvas canvas = new Canvas(600, 600);
            GraphicsContext gc = canvas.getGraphicsContext2D();
            gc.setFill(Color.GREEN);

            var timeLine = new Timeline(new KeyFrame(Duration.millis(1000 / 50), (e) -> {
              gc.clearRect(0, 0, 600, 600);
              for (var i = 0; i < 2000; i++) {
                //variant #1
                var x = ThreadLocalRandom.current().nextInt(0, 600);
                var y = ThreadLocalRandom.current().nextInt(0, 600);
                //variant #2
      // var x = ThreadLocalRandom.current().nextDouble(0, 600);
      // var y = ThreadLocalRandom.current().nextDouble(0, 600);
                gc.save();
                gc.beginPath();
                gc.rect(x, y, canvas.getWidth() - x, canvas.getHeight() - y);
                gc.closePath();
                gc.clip();
                gc.fillText(String.valueOf(i), (int) x, (int) y + 20);
                gc.restore();
              }

            }));
            timeLine.setCycleCount(Timeline.INDEFINITE);
            timeLine.play();

            Pane root = new Pane();
            root.getChildren().add(canvas);
            primaryStage.setScene(new Scene(root));
            primaryStage.show();
        }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Using int seems to solve the problem

      FREQUENCY : always


        1. bug.mp4
          15.25 MB
        2. Test.java
          2 kB

            kcr Kevin Rushforth
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: