summaryrefslogtreecommitdiff
path: root/gfx/doc/B2GInputFlow.svg
blob: ee6f4332c28dd1c9a8390b12fa388f12703f1907 (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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
<?xml version="1.0"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="1000" height="800">
 <title>Touch input event flow on B2G</title>
 <g id="arrows"></g>
 <style type="text/css"><![CDATA[
    text {
        fill: black;
        text-anchor: middle;
        white-space: pre-line;
        font-size: 14px;
    }
    rect {
        fill: none;
    }
    line {
        stroke: black;
    }
    .parentinput rect {
        stroke: black;
    }
    text.parentinput {
        fill: black;
        text-anchor: start;
    }
    .parentmain rect {
        stroke: orange;
    }
    text.parentmain {
        fill: orange;
        text-anchor: start;
    }
    .parentcompositor rect {
        stroke: green;
    }
    text.parentcompositor {
        fill: green;
        text-anchor: start;
    }
    .childmain rect {
        stroke: red;
    }
    text.childmain {
        fill: red;
        text-anchor: start;
    }
    .bothmain rect {
        stroke: blue;
    }
    text.bothmain {
        fill: blue;
        text-anchor: start;
    }
 ]]></style>
 <script type="text/javascript"><![CDATA[
    var svg = "http://www.w3.org/2000/svg";
    var maxY = 0;

    function breaks(text) {
        var count = 0;
        for (var i = text.length - 1; i >= 0; i--) {
            if (text.charAt(i) == '\n') {
                count++;
            }
        }
        return count;
    }

    function makeAction(text, x, y, thread) {
        maxY = Math.max(maxY, y);
        var g = document.createElementNS(svg, "g");
        g.setAttribute("class", "action " + thread);
        g.setAttribute("transform", "translate(" + x + ", " + (y + 30) + ")");
        var r = document.createElementNS(svg, "rect");
        r.setAttribute("width", "100");
        r.setAttribute("height", "40");
        var t = document.createElementNS(svg, "text");
        t.setAttribute("x", "50");
        t.setAttribute("y", 25 - (7 * breaks(text)));
        t.appendChild(document.createTextNode(text));
        g.appendChild(r);
        g.appendChild(t);
        return g;
    }

    function makeChoice(text, x, y, thread) {
        maxY = Math.max(maxY, y);
        var g = document.createElementNS(svg, "g");
        g.setAttribute("class", "choice " + thread);
        g.setAttribute("transform", "translate(" + (x + 15) + ", " + (y + 15) + ")");
        var g2 = document.createElementNS(svg, "g");
        g2.setAttribute("transform", "rotate(-45, 35, 35)");
        var r = document.createElementNS(svg, "rect");
        r.setAttribute("width", "70");
        r.setAttribute("height", "70");
        g2.appendChild(r);
        var t = document.createElementNS(svg, "text");
        t.setAttribute("x", "35");
        t.setAttribute("y", 40 - (7 * breaks(text)));
        t.appendChild(document.createTextNode(text));
        g.appendChild(g2);
        g.appendChild(t);
        return g;
    }

    function makeLabelChoice(label, point) {
        var t = document.createElementNS(svg, "text");
        t.setAttribute("x", point.x);
        t.setAttribute("y", point.y);
        t.appendChild(document.createTextNode(label));
        return t;
    }

    function makeLine(sx, sy, ex, ey) {
        maxY = Math.max(maxY, sy, ey);
        var l = document.createElementNS(svg, "line");
        l.setAttribute("x1", sx);
        l.setAttribute("y1", sy);
        l.setAttribute("x2", ex);
        l.setAttribute("y2", ey);
        return l;
    }

    function makeArrow(start, end) {
        var g = document.createElementNS(svg, "g");
        g.appendChild(makeLine(start.x, start.y, end.x, end.y));
        if (start.x != end.x) {
            start.x = end.x + (4 * Math.sign(start.x - end.x));
            g.appendChild(makeLine(start.x, start.y - 4, end.x, end.y));
            g.appendChild(makeLine(start.x, start.y + 4, end.x, end.y));
        } else if (start.y != end.y) {
            start.y = end.y + (4 * Math.sign(start.y - end.y));
            g.appendChild(makeLine(start.x - 4, start.y, end.x, end.y));
            g.appendChild(makeLine(start.x + 4, start.y, end.x, end.y));
        }
        return g;
    }

    function makeVHArrow(start, end) {
        var g = document.createElementNS(svg, "g");
        g.appendChild(makeLine(start.x, start.y, start.x, end.y));
        start.y = end.y;
        g.appendChild(makeArrow(start, end));
        return g;
    }

    function makeHVArrow(start, end) {
        var g = document.createElementNS(svg, "g");
        g.appendChild(makeLine(start.x, start.y, end.x, start.y));
        start.x = end.x;
        g.appendChild(makeArrow(start, end));
        return g;
    }

    function makeVHVArrow(start, end, length) {
        var g = document.createElementNS(svg, "g");
        g.appendChild(makeLine(start.x, start.y, start.x, start.y + length));
        start.y += length;
        g.appendChild(makeLine(start.x, start.y, end.x, start.y));
        start.x = end.x;
        g.appendChild(makeArrow(start, end));
        return g;
    }

    function makeHVHArrow(start, end, length) {
        var g = document.createElementNS(svg, "g");
        g.appendChild(makeLine(start.x, start.y, start.x + length, start.y));
        start.x += length;
        g.appendChild(makeLine(start.x, start.y, start.x, end.y));
        start.y = end.y;
        g.appendChild(makeArrow(start, end));
        return g;
    }

    function translation(group) {
        var r = new RegExp("translate\\((\\d+), (\\d+)\\)");
        var result = r.exec(group.getAttribute("transform"));
        return { x: parseInt(result[1]), y: parseInt(result[2]) };
    }

    function isAction(group) {
        return group.classList.contains("action");
    }

    function isChoice(group) {
        return group.classList.contains("choice");
    }

    function offset(point, x, y) {
        point.x += x;
        point.y += y;
        return point;
    }

    function rightOf(group) {
        var t = translation(group);
        if (isAction(group)) {
            return offset(t, 100, 20);
        }
        if (isChoice(group)) {
            return offset(t, 85, 35);
        }
        return t;
    }

    function leftOf(group) {
        var t = translation(group);
        if (isAction(group)) {
            return offset(t, 0, 20);
        }
        if (isChoice(group)) {
            return offset(t, -15, 35);
        }
        return t;
    }

    function topOf(group) {
        var t = translation(group);
        if (isAction(group)) {
            return offset(t, 50, 0);
        }
        if (isChoice(group)) {
            return offset(t, 35, -15);
        }
        return t;
    }

    function bottomOf(group) {
        var t = translation(group);
        if (isAction(group)) {
            return offset(t, 50, 40);
        }
        if (isChoice(group)) {
            return offset(t, 35, 85);
        }
        return t;
    }

    function midpoint(start, end) {
        return { x: (start.x + end.x) / 2,
                 y: (start.y + end.y) / 2 };
    }

    function makeLegend(label, thread) {
        var t = document.createElementNS(svg, "text");
        t.setAttribute("x", "10");
        t.setAttribute("y", maxY);
        t.setAttribute("class", thread);
        maxY += 15;
        t.appendChild(document.createTextNode(label));
        return t;
    }

    var android = makeAction("Android/Gonk", 20, 0, "parentinput");
    var sendNative = makeAction("DOMWindowUtils\nsendNativeTouchPoint", 20, 100, "parentmain");
    var apzHitTest = makeAction("APZ hit test", 150, 0, "parentcompositor");
    var apzUntransform = makeAction("APZ\nuntransform", 300, 0, "parentcompositor");
    var apzGesture = makeAction("APZ gesture\ndetection", 450, 0, "parentcompositor");
    var apzTransform = makeAction("APZ transform\nupdate", 600, 0, "parentcompositor");
    var compositor = makeAction("Compositor", 750, 0, "parentcompositor");
    var nsAppShell = makeAction("nsAppShell", 150, 100, "parentmain");
    var rootHitTest = makeAction("Gecko hit test\n(root process)", 300, 100, "parentmain");
    var rootEsm = makeAction("Gecko ESM\n(root process)", 450, 100, "parentmain");
    var isEdgeGesture = makeChoice("Edge gesture?", 300, 200, "parentmain");
    var edgeConsume = makeAction("Consume\nevent block", 150, 200, "parentmain");
    var bepjsm = makeAction("BEParent.jsm\nsendTouchEvent", 450, 200, "parentmain");
    var iframeSend = makeAction("HTMLIFrameElement\nsendTouchEvent", 20, 275, "parentmain");
    var isApzTarget = makeChoice("Target\nhas APZ?", 600, 200, "parentmain");
    var sendTouchEvent = makeAction("Target\nsendTouchEventToWindow", 750, 100, "parentmain");
    var injectTouch = makeAction("injectTouchEvent", 750, 200, "parentmain");
    var targetESM = makeAction("Target window\nESM", 750, 450, "bothmain");
    var tabParent = makeAction("TabParent", 750, 350, "parentmain");
    var geckoUntransform = makeAction("Gecko\nuntransform", 600, 350, "parentmain");
    var tabChild = makeAction("TabChild", 450, 350, "childmain");
    var isApzcEnabled = makeChoice("APZ\nenabled?", 300, 350, "childmain");
    var tabGesture = makeAction("TabChild gesture\ndetection", 150, 350, "childmain");
    var childHitTest = makeAction("Gecko hit test\n(child process)", 300, 450, "childmain");
    var childEsm = makeAction("Gecko ESM\n(child process)", 450, 450, "childmain");
    var childContent = makeAction("Content\n(child process)", 600, 450, "childmain");

    document.documentElement.appendChild(android);
    document.documentElement.appendChild(sendNative);
    document.documentElement.appendChild(apzHitTest);
    document.documentElement.appendChild(apzUntransform);
    document.documentElement.appendChild(apzGesture);
    document.documentElement.appendChild(apzTransform);
    document.documentElement.appendChild(compositor);
    document.documentElement.appendChild(nsAppShell);
    document.documentElement.appendChild(rootHitTest);
    document.documentElement.appendChild(rootEsm);
    document.documentElement.appendChild(isEdgeGesture);
    document.documentElement.appendChild(edgeConsume);
    document.documentElement.appendChild(bepjsm);
    document.documentElement.appendChild(iframeSend);
    document.documentElement.appendChild(isApzTarget);
    document.documentElement.appendChild(sendTouchEvent);
    document.documentElement.appendChild(injectTouch);
    document.documentElement.appendChild(targetESM);
    document.documentElement.appendChild(tabParent);
    document.documentElement.appendChild(geckoUntransform);
    document.documentElement.appendChild(tabChild);
    document.documentElement.appendChild(isApzcEnabled);
    document.documentElement.appendChild(tabGesture);
    document.documentElement.appendChild(childHitTest);
    document.documentElement.appendChild(childEsm);
    document.documentElement.appendChild(childContent);

    document.documentElement.appendChild(makeLabelChoice("Y", offset(leftOf(isEdgeGesture), -5, -5)));
    document.documentElement.appendChild(makeLabelChoice("N", offset(rightOf(isEdgeGesture), 5, -5)));
    document.documentElement.appendChild(makeLabelChoice("N", offset(topOf(isApzTarget), 8, -10)));
    document.documentElement.appendChild(makeLabelChoice("Y", offset(rightOf(isApzTarget), 10, 14)));
    document.documentElement.appendChild(makeLabelChoice("N", offset(leftOf(isApzcEnabled), -5, -5)));
    document.documentElement.appendChild(makeLabelChoice("Y", offset(bottomOf(isApzcEnabled), 10, 14)));

    var arrows = document.getElementById('arrows');
    arrows.appendChild(makeArrow(rightOf(android), leftOf(apzHitTest)));
    arrows.appendChild(makeVHVArrow(topOf(sendNative), midpoint(rightOf(android), leftOf(apzHitTest)), -20));
    arrows.appendChild(makeArrow(rightOf(apzHitTest), leftOf(apzUntransform)));
    arrows.appendChild(makeArrow(rightOf(apzUntransform), leftOf(apzGesture)));
    arrows.appendChild(makeArrow(rightOf(apzGesture), leftOf(apzTransform)));
    arrows.appendChild(makeArrow(rightOf(apzTransform), leftOf(compositor)));
    arrows.appendChild(makeVHVArrow(midpoint(leftOf(apzUntransform), rightOf(apzGesture)), topOf(nsAppShell), 40));
    arrows.appendChild(makeArrow(rightOf(nsAppShell), leftOf(rootHitTest)));
    arrows.appendChild(makeArrow(rightOf(rootHitTest), leftOf(rootEsm)));
    arrows.appendChild(makeVHVArrow(bottomOf(rootEsm), topOf(isEdgeGesture), 15));
    arrows.appendChild(makeArrow(leftOf(isEdgeGesture), rightOf(edgeConsume)));
    arrows.appendChild(makeArrow(rightOf(isEdgeGesture), leftOf(bepjsm), 20));
    arrows.appendChild(makeHVArrow(rightOf(iframeSend), bottomOf(bepjsm)));
    arrows.appendChild(makeArrow(rightOf(bepjsm), leftOf(isApzTarget)));
    arrows.appendChild(makeArrow(rightOf(isApzTarget), leftOf(injectTouch)));
    arrows.appendChild(makeArrow(bottomOf(injectTouch), topOf(tabParent)));
    arrows.appendChild(makeVHArrow(topOf(isApzTarget), leftOf(sendTouchEvent)));
    arrows.appendChild(makeHVHArrow(rightOf(sendTouchEvent), rightOf(targetESM), 30));
    arrows.appendChild(makeArrow(leftOf(tabParent), rightOf(geckoUntransform)));
    arrows.appendChild(makeArrow(leftOf(geckoUntransform), rightOf(tabChild)));
    arrows.appendChild(makeArrow(leftOf(tabChild), rightOf(isApzcEnabled)));
    arrows.appendChild(makeArrow(leftOf(isApzcEnabled), rightOf(tabGesture)));
    arrows.appendChild(makeArrow(bottomOf(isApzcEnabled), topOf(childHitTest)));
    arrows.appendChild(makeVHArrow(bottomOf(tabGesture), leftOf(childHitTest)));
    arrows.appendChild(makeArrow(rightOf(childHitTest), leftOf(childEsm)));
    arrows.appendChild(makeArrow(rightOf(childEsm), leftOf(childContent)));
    arrows.appendChild(makeVHVArrow(midpoint(leftOf(apzGesture), rightOf(apzTransform)), topOf(tabChild), 300));

    document.documentElement.appendChild(makeLegend("Main process input thread", "parentinput"));
    document.documentElement.appendChild(makeLegend("Main process main thread", "parentmain"));
    document.documentElement.appendChild(makeLegend("Main process compositor thread", "parentcompositor"));
    document.documentElement.appendChild(makeLegend("Child process main thread", "childmain"));
    document.documentElement.appendChild(makeLegend("Undetermined process main thread", "bothmain"));
 ]]></script>
</svg>