1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71

content / test / data / gpu / webcodecs / draw-image.html [blame]

<!DOCTYPE html>
<!--
Take frames coming from various sources and render them to a canvas with
CanvasRenderingContext2D.drawImage().
-->
<html>

<head>
  <title>drawImage() test</title>
  <script src="webcodecs_common.js"></script>
  <script type="text/javascript">
    'use strict';

    async function main(arg) {
      const frames_to_draw = 5;
      let source_type = arg.source_type;
      let cnv = document.getElementById('display');
      let ctx = cnv.getContext('2d');
      let source = await createFrameSource(source_type, cnv.width, cnv.height);
      if (!source) {
        TEST.skip('Unsupported source: ' + source_type);
        return;
      }

      for (let i = 0; i < frames_to_draw; i++) {
        let frame = await source.getNextFrame();
        ctx.drawImage(frame, 0, 0, cnv.width, cnv.height);
        switch (source_type) {
          case 'camera': {
            if (arg.validate_camera_frames)
              checkFourColorsFrame(ctx, cnv.width, cnv.height, 5);
            else
              TEST.log("Skip render result validation");
            break;
          }
          case 'arraybuffer':
          case 'offscreen':
          case 'capture': {
            checkFourColorsFrame(ctx, cnv.width, cnv.height, 5);
            break;
          }
          case 'sw_decoder':
          case 'hw_decoder': {
            checkFourColorsFrame(ctx, cnv.width, cnv.height, 15);
            break;
          }
          case 'hbd_arraybuffer': {
            checkFourColorsFrame(ctx, cnv.width, cnv.height, 15);
            break;
          }
          default:
            TEST.reportFailure("Unexpected frame source.");
        }
        frame.close();
        await waitForNextFrame();
      }
      source.close();
      TEST.log('Test completed');
    }
    addManualTestButton([{'source_type': 'offscreen'}]);
    addManualTestButton([{'source_type': 'hbd_arraybuffer'}]);
  </script>
</head>

<body>
  <div>
    <canvas id='display' width="640" height="480"></canvas>
  </div>
</body>

</html>