summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/compositing/squashing/add-remove-squashed-layers.html
blob: 0cb63bbc5e4b7a9ff3b11960b1138cf15c330078 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<!DOCTYPE html>
<html>
<head>
<style>
div {
  position: absolute;
  z-index: 1;
  width: 100px;
  height: 100px;
}

.composited {
  -webkit-transform: translatez(0);
  top: 60px;
  left: 60px;
  width: 400px;
  height: 400px;
  background-color: gray;
}

.overlap1 {
  top: 140px;
  left: 140px;
  background-color: blue;
}

.overlap2 {
  top: 220px;
  left: 220px;
  background-color: lime;
}

.overlap3 {
  top: 300px;
  left: 300px;
  background-color: magenta;
}

div:hover {
  background-color: green;
}

.green {
  background-color: green;
}

#C {
  display: none;
}

#testResults {
  display: none;
}

</style>
<script>
    if (window.testRunner)
        testRunner.dumpAsText();

    var isInteractive = true;

    if (window.internals) {
        internals.settings.setLayerSquashingEnabled(true);
        isInteractive = false;
    }

    function resetLayers()
    {
        document.getElementById("A").style.display = "block";
        document.getElementById("B").style.display = "block";
        document.getElementById("C").style.display = "none";
        if (isInteractive) {
            document.removeEventListener("click", resetLayers);
            document.addEventListener("click", addOverlap3);
        }
    }

    function addOverlap2()
    {
        document.getElementById("B").style.display = "block";
        if (isInteractive) {
            document.removeEventListener("click", addOverlap2);
            document.addEventListener("click", resetLayers);
        }
    }

    function removeOverlap1()
    {
        document.getElementById("A").style.display = "none";
        if (isInteractive) {
            document.removeEventListener("click", removeOverlap1);
            document.addEventListener("click", addOverlap2);
        }
    }


    function removeOverlap2()
    {
        document.getElementById("B").style.display = "none";
        if (isInteractive) {
            document.removeEventListener("click", removeOverlap2);
            document.addEventListener("click", removeOverlap1);
        }
    }

    function addOverlap3()
    {
        document.getElementById("C").style.display = "block";
        if (isInteractive) {
            document.removeEventListener("click", addOverlap3);
            document.addEventListener("click", removeOverlap2);
        }
    }

    document.addEventListener("click", addOverlap3);

    function runTest()
    {
        if (!window.internals)
            return;

        // Case 1
        document.getElementById('Case1').textContent = window.internals.layerTreeAsText(document);

        // Case 2
        window.internals.startTrackingRepaints(document);
        addOverlap3();
        document.getElementById('Case2').textContent = window.internals.layerTreeAsText(document, internals.LAYER_TREE_INCLUDES_REPAINT_RECTS);
        window.internals.stopTrackingRepaints(document);

        // Case 3
        window.internals.startTrackingRepaints(document);
        removeOverlap2();
        document.getElementById('Case3').textContent = window.internals.layerTreeAsText(document, internals.LAYER_TREE_INCLUDES_REPAINT_RECTS);
        window.internals.stopTrackingRepaints(document);

        // Case 4
        window.internals.startTrackingRepaints(document);
        removeOverlap1();
        document.getElementById('Case4').textContent = window.internals.layerTreeAsText(document, internals.LAYER_TREE_INCLUDES_REPAINT_RECTS);
        window.internals.stopTrackingRepaints(document);

        // Case 5
        window.internals.startTrackingRepaints(document);
        addOverlap2();
        document.getElementById('Case5').textContent = window.internals.layerTreeAsText(document, internals.LAYER_TREE_INCLUDES_REPAINT_RECTS);
        window.internals.stopTrackingRepaints(document);

        // Case 6
        window.internals.startTrackingRepaints(document);
        resetLayers();
        document.getElementById('Case6').textContent = window.internals.layerTreeAsText(document, internals.LAYER_TREE_INCLUDES_REPAINT_RECTS);
        window.internals.stopTrackingRepaints(document);

        // Display the test results only after test is done so that it does not affect repaint rect results.
        document.getElementById('testResults').style.display = "block";
    }
</script>
</head>

<body onload="runTest()">

  <p>Test that layers can be nicely added or removed from a squashed layer, without unnecessary repaints on any layer.
     Click anywhere to test interactively; keep clicking to proceed through the test.</p>

  <div class="composited"></div>
  <div id="A" class="overlap1"></div>
  <div id="B" class="overlap2"></div>
  <div id="C" class="overlap3"></div>

  <div id="testResults">
    CASE 1, original layer tree with overlap1 and overlap2:
    <pre id="Case1"></pre>

    CASE 2, overlap3 gets added:
    <pre id="Case2"></pre>

    CASE 3, overlap2 gets removed.  Since this does not resize the layer, there should only be a repaint of overlap2:
    <pre id="Case3"></pre>

    CASE 4, overlap1 gets removed:
    <pre id="Case4"></pre>

    CASE 5, overlap2 gets added back:
    <pre id="Case5"></pre>

    CASE 6, overlap1 gets added back, and overlap3 gets removed:
    <pre id="Case6"></pre>
  </div>

</body>

</html>