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

[WebView] HTML canvas clip() functionality broken

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8u5
    • Fix Version/s: 8u40
    • Component/s: javafx
    • Labels:
      None
    • Subcomponent:
      web

      Description

      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.

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated:
                Resolved:
                Imported: