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

[WebView] HTML canvas clip() functionality broken

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8u40
    • 8u5
    • javafx
    • None
    • web

      The canvas clipping doesn't work as expected:

      <html>
      <head>
      </head>
      <body onload="draw();">
      <script type="text/javascript">
        function draw() {
        
            var canvas = document.getElementById("canvas");
            var ctx = canvas.getContext("2d");

            ctx.fillStyle = "blue";
            ctx.fillRect(0,0,200,200);

      // ctx.save();

            ctx.beginPath();
            ctx.moveTo(30, 30);
            ctx.lineTo(30, 70);
            ctx.lineTo(70, 70);
            ctx.lineTo(70, 30);
            ctx.lineTo(30, 30);
            ctx.clip();

            ctx.fillStyle = "green";
            ctx.fillRect(0,0,200,200);

      // ctx.restore();
        }

      </script>
      Canvas:<br>
      <canvas id="canvas" width="200" height="200"></canvas>
      </body>
      </html>


      if 'ctx.save()/restore()' is uncommented the script works fine.

      The reason is WCGraphicsPrismContext creates a new ClipLayer when clipping is needed and pushes the current state to the stack. The same machinery is used for context save/restore functionality. When the drawing is finished, the clip layer is not rendered on the 'primary' layer until the restore() is called.

            anashaty Anton Nashatyrev (Inactive)
            anashaty Anton Nashatyrev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: