summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/compositing/draws-content/canvas-background-layer.html
blob: 35dc8e3a9c52eb89f3ec5ddd720f29e42e8bbf54 (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!DOCTYPE html>
<html>
  <head>
    <style type="text/css">
      .container {
        width: 60px;
        height: 60px;
        margin: 5px;
      }
      canvas {
        background-color: green;
      }
      #canvas-simple {}
      #canvas-padding { padding: 5px; }
      #canvas-border { border: 5px solid; }
      #canvas-image { background-image: url("../resources/simple_image.png"); }
      #canvas-transparent-background { background-color: rgba(0, 255, 0, 0.5); }
      #canvas-opaque { border: 5px solid; }
    </style>
    <script>
        if (window.testRunner)
            testRunner.dumpAsText();

        function drawCanvas(canvasID, hasAlpha) {
            var canvas = document.getElementById(canvasID);
            var context = canvas.getContext("2d", {alpha: hasAlpha});
            context.clearRect(0, 0, canvas.width, canvas.height);
        };

        function doTest() {
            // Simple background can be direct-composited with content-layer.
            // The container GraphicsLayer does not paint anything.
            // The content layer should be treated as opaque because the
            // background color is opaque.
            drawCanvas('canvas-simple', true);

            // Padding makes the background-box bigger than content-box.
            // The container GraphicsLayer needs to paint background.
            drawCanvas('canvas-padding', true);

            // Content layer cannot direct-composite any kind of box decoration.
            // The container GraphicsLayer needs to paint box decorations.
            drawCanvas('canvas-border', true);

            // Content layer cannot direct-composite background image.
            // The container GraphicsLayer needs to paint background image.
            drawCanvas('canvas-image', true);

            // Simple background can be direct-composited with content-layer.
            // The container GraphicsLayer does not paint anything.
            // The content layer should not be treated as opaque because the 
            // background color is not opaque.
            drawCanvas('canvas-transparent-background', true);

            // Background cannot be direct-composited because of box decoration.
            // However contents of the canvas are opaque so the background does
            // not need to be painted.
            drawCanvas('canvas-opaque', false);

            if (window.testRunner && window.internals)
                document.getElementById('layer-tree').innerText = window.internals.layerTreeAsText(document);
        };
        window.addEventListener('load', doTest, false);
    </script>
  </head>

  <body>
    <div class="container">
      <canvas id="canvas-simple" width="50" height="50"></canvas>
    </div>
    <div class="container">
      <canvas id="canvas-transparent-background" width="50" height="50"></canvas>
    </div>
    <div class="container">
      <canvas id="canvas-padding" width="50" height="50"></canvas>
    </div>
    <div class="container">
      <canvas id="canvas-border" width="50" height="50"></canvas>
    </div>
    <div class="container">
      <canvas id="canvas-image" width="50" height="50"></canvas>
    </div>
    <div class="container">
      <canvas id="canvas-opaque" width="50" height="50"></canvas>
    </div> 
    <pre id="layer-tree"></pre>
  </body>
</html>