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

Canvas Rendering Degrades Proportionally With Size?

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 7u55
    • javafx
      • Windows 7 64bit
      • Java 7
      • Resolution: 1600 X 900
      • RAM: 8GB
      • CPU: Intel Core i7-2675QM 2.20GHz
      • GFX: Radeon HD 6775M

      As context, I am working on a Painting Application.
       
      The following is simply a StackPane with a Canvas of size 10000 X 10000.
      This extreme size is just for emphasis purposes, as I don't know how powerful Your machine is.
      For art, most artists wouldn't go above 3000 X 3000, where latency is already getting pretty ugly for my machine, with this issue.
       
      The Canvas has a MouseEventHandler attached, which allows You to freely draw on it.
       
      You will notice, that as You decrease the Canvas size in the code, drawing will become more and more smooth.
      After some testing, it seems like the whole Canvas is redrawn, for every small modification done in some area on it.
      Even when the bulk of it is off-screen.
       
      That would imply that:
      a.) Not just the area the stroke occurred in is redrawn, but the whole Canvas. And...
      b.) Not just the portion of the Canvas visible on the screen is redrawn, but the whole Canvas.
       
      Depth of my Knowledge:
      I am not a professional in Computer Graphics Programming, so those above are my humble guesses.
      I am also still a Beginning JavaFX & Java Learner, with about 4 Months Java, and 2 Months JavaFX experience.
      I am not trying to waste anyone's time or to troll anyone. A simple guide in the right direction would also be appreciated, if this is an issue that can be avoided.

      Here is a SSCCE:
       
      import javafx.application.Application;
      import javafx.event.EventHandler;
      import javafx.event.EventType;
      import javafx.scene.Scene;
      import javafx.scene.canvas.Canvas;
      import javafx.scene.canvas.GraphicsContext;
      import javafx.scene.input.MouseEvent;
      import javafx.scene.layout.StackPane;
      import javafx.stage.Stage;

      public class CanvasPerformanceDecline extends Application
      {
          @Override
          public void start(Stage primaryStage)
          {
              //Create Canvas and get GraphicsContext:
              final Canvas canvas = new Canvas( 10000, 10000 );
              final GraphicsContext graphicsContext = canvas.getGraphicsContext2D();

              //Allow DRAWING on Canvas with Mouse:
              canvas.addEventHandler( MouseEvent.ANY,
                                       
                                                   new EventHandler<MouseEvent>()
                                                   {
                                                       double pmouseX;
                                                       double pmouseY;
                                                                           
                                                       @Override
                                                       public void handle(MouseEvent mouseEvent)
                                                       {
                                                           EventType eventType = mouseEvent.getEventType();
                                                                                       
                                                           if (eventType == MouseEvent.MOUSE_PRESSED)
                                                           {
                                                               pmouseX = mouseEvent.getX();
                                                               pmouseY = mouseEvent.getY();
                                                           }
                                                           if (eventType == MouseEvent.MOUSE_DRAGGED)
                                                           {
                                                               double mouseX = mouseEvent.getX();
                                                               double mouseY = mouseEvent.getY();
                                                                                                                                                                  
                                                               //Stroke Line:
                                                               graphicsContext.strokeLine( pmouseX, pmouseY,mouseX,mouseY);
                                                                                               
                                                               pmouseX = mouseX;
                                                               pmouseY = mouseY;
                                                           }
                                                       } //END - public void handle(...)
                                       
                                                   }); //END - canvas.addEventHandler(...)
         
                            
              //PREPARE SCENE & STAGE:
              StackPane root = new StackPane();
                               root.getChildren().add(canvas);
                     
              Scene scene = new Scene(root, 300, 250);
                   
                            primaryStage.setTitle("CanvasPerformanceDecline");
                            primaryStage.setScene(scene);
                            primaryStage.show();
            
          } //END - public void start(...)

               
          public static void main(String[] args)
          {
              launch(args);
          }
           
      } //END - class CanvasPerformanceDecline
       
       
       
      Thanks for Your time and attention.

            Unassigned Unassigned
            duke J. Duke
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Imported: