001package Torello.Browser;
002
003import java.util.*;
004import javax.json.*;
005import javax.json.stream.*;
006import java.io.*;
007
008import java.lang.reflect.Method;
009import java.lang.reflect.Parameter;
010import java.util.function.Function;
011
012import Torello.Java.Additional.*;
013
014import static Torello.Java.Additional.JFlag.*;
015
016import Torello.Java.StrCmpr;
017import Torello.JavaDoc.StaticFunctional;
018import Torello.JavaDoc.JDHeaderBackgroundImg;
019import Torello.JavaDoc.Excuse;
020
021/**
022 * <SPAN CLASS=CopiedJDK><B><CODE>[No Description Provided by Google]</CODE></B></SPAN>
023 * 
024 * <EMBED CLASS='external-html' DATA-FILE-ID=CODE_GEN_NOTE>
025 */
026@StaticFunctional(Excused={"counter"}, Excuses={Excuse.CONFIGURATION})
027@JDHeaderBackgroundImg(EmbedTagFileID="WOOD_PLANK_NOTE")
028public class LayerTree
029{
030    // ********************************************************************************************
031    // ********************************************************************************************
032    // Class Header Stuff
033    // ********************************************************************************************
034    // ********************************************************************************************
035
036
037    // No Pubic Constructors
038    private LayerTree () { }
039
040    // These two Vector's are used by all the "Methods" exported by this class.  java.lang.reflect
041    // is used to generate the JSON String's.  It saves thousands of lines of Auto-Generated Code.
042    private static final Map<String, Vector<String>>    parameterNames = new HashMap<>();
043    private static final Map<String, Vector<Class<?>>>  parameterTypes = new HashMap<>();
044
045    // Some Methods do not take any parameters - for instance all the "enable()" and "disable()"
046    // I simply could not get ride of RAW-TYPES and UNCHECKED warnings... so there are now,
047    // offically, two empty-vectors.  One for String's, and the other for Classes.
048
049    private static final Vector<String>     EMPTY_VEC_STR = new Vector<>();
050    private static final Vector<Class<?>>   EMPTY_VEC_CLASS = new Vector<>();
051
052    static
053    {
054        for (Method m : LayerTree.class.getMethods())
055        {
056            // This doesn't work!  The parameter names are all "arg0" ... "argN"
057            // It works for java.lang.reflect.Field, BUT NOT java.lang.reflect.Parameter!
058            //
059            // Vector<String> parameterNamesList = new Vector<>(); -- NOPE!
060
061            Vector<Class<?>> parameterTypesList = new Vector<>();
062        
063            for (Parameter p : m.getParameters()) parameterTypesList.add(p.getType());
064
065            parameterTypes.put(
066                m.getName(),
067                (parameterTypesList.size() > 0) ? parameterTypesList : EMPTY_VEC_CLASS
068            );
069        }
070    }
071
072    static
073    {
074        Vector<String> v = null;
075
076        v = new Vector<String>(1);
077        parameterNames.put("compositingReasons", v);
078        Collections.addAll(v, new String[]
079        { "layerId", });
080
081        parameterNames.put("disable", EMPTY_VEC_STR);
082
083        parameterNames.put("enable", EMPTY_VEC_STR);
084
085        v = new Vector<String>(1);
086        parameterNames.put("loadSnapshot", v);
087        Collections.addAll(v, new String[]
088        { "tiles", });
089
090        v = new Vector<String>(1);
091        parameterNames.put("makeSnapshot", v);
092        Collections.addAll(v, new String[]
093        { "layerId", });
094
095        v = new Vector<String>(4);
096        parameterNames.put("profileSnapshot", v);
097        Collections.addAll(v, new String[]
098        { "snapshotId", "minRepeatCount", "minDuration", "clipRect", });
099
100        v = new Vector<String>(1);
101        parameterNames.put("releaseSnapshot", v);
102        Collections.addAll(v, new String[]
103        { "snapshotId", });
104
105        v = new Vector<String>(4);
106        parameterNames.put("replaySnapshot", v);
107        Collections.addAll(v, new String[]
108        { "snapshotId", "fromStep", "toStep", "scale", });
109
110        v = new Vector<String>(1);
111        parameterNames.put("snapshotCommandLog", v);
112        Collections.addAll(v, new String[]
113        { "snapshotId", });
114    }
115
116
117    // ********************************************************************************************
118    // ********************************************************************************************
119    // Types - Static Inner Classes
120    // ********************************************************************************************
121    // ********************************************************************************************
122
123    // public static class LayerId => String
124    
125    // public static class SnapshotId => String
126    
127    // public static class PaintProfile => Number[]
128    
129    /** Rectangle where scrolling happens on the main thread. */
130    public static class ScrollRect extends BaseType
131    {
132        /** For Object Serialization.  java.io.Serializable */
133        protected static final long serialVersionUID = 1;
134        
135        public boolean[] optionals()
136        { return new boolean[] { false, false, }; }
137        
138        /** Rectangle itself. */
139        public final DOM.Rect rect;
140        
141        /** Reason for rectangle to force scrolling on the main thread */
142        public final String type;
143        
144        /**
145         * Constructor
146         *
147         * @param rect Rectangle itself.
148         * 
149         * @param type Reason for rectangle to force scrolling on the main thread
150         * <BR />Acceptable Values: ["RepaintsOnScroll", "TouchEventHandler", "WheelEventHandler"]
151         */
152        public ScrollRect(DOM.Rect rect, String type)
153        {
154            // Exception-Check(s) to ensure that if any parameters which are not declared as
155            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
156            
157            if (rect == null) BRDPC.throwNPE("rect");
158            if (type == null) BRDPC.throwNPE("type");
159            
160            // Exception-Check(s) to ensure that if any parameters which must adhere to a
161            // provided List of Enumerated Values, fails, then IllegalArgumentException shall throw.
162            
163            BRDPC.checkIAE(
164                "type", type,
165                "RepaintsOnScroll", "TouchEventHandler", "WheelEventHandler"
166            );
167            
168            this.rect  = rect;
169            this.type  = type;
170        }
171        
172        /**
173         * JSON Object Constructor
174         * @param jo A Json-Object having data about an instance of {@code 'ScrollRect'}.
175         */
176        public ScrollRect (JsonObject jo)
177        {
178            this.rect  = ReadJSON.XL.getObject(jo, "rect", DOM.Rect.class, false, true);
179            this.type  = ReadJSON.getString(jo, "type", false, true);
180        }
181        
182    }
183    
184    /** Sticky position constraints. */
185    public static class StickyPositionConstraint extends BaseType
186    {
187        /** For Object Serialization.  java.io.Serializable */
188        protected static final long serialVersionUID = 1;
189        
190        public boolean[] optionals()
191        { return new boolean[] { false, false, true, true, }; }
192        
193        /** Layout rectangle of the sticky element before being shifted */
194        public final DOM.Rect stickyBoxRect;
195        
196        /** Layout rectangle of the containing block of the sticky element */
197        public final DOM.Rect containingBlockRect;
198        
199        /**
200         * The nearest sticky layer that shifts the sticky box
201         * <BR />
202         * <BR /><B>OPTIONAL</B>
203         */
204        public final String nearestLayerShiftingStickyBox;
205        
206        /**
207         * The nearest sticky layer that shifts the containing block
208         * <BR />
209         * <BR /><B>OPTIONAL</B>
210         */
211        public final String nearestLayerShiftingContainingBlock;
212        
213        /**
214         * Constructor
215         *
216         * @param stickyBoxRect Layout rectangle of the sticky element before being shifted
217         * 
218         * @param containingBlockRect Layout rectangle of the containing block of the sticky element
219         * 
220         * @param nearestLayerShiftingStickyBox The nearest sticky layer that shifts the sticky box
221         * <BR /><B>OPTIONAL</B>
222         * 
223         * @param nearestLayerShiftingContainingBlock The nearest sticky layer that shifts the containing block
224         * <BR /><B>OPTIONAL</B>
225         */
226        public StickyPositionConstraint(
227                DOM.Rect stickyBoxRect, DOM.Rect containingBlockRect, 
228                String nearestLayerShiftingStickyBox, String nearestLayerShiftingContainingBlock
229            )
230        {
231            // Exception-Check(s) to ensure that if any parameters which are not declared as
232            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
233            
234            if (stickyBoxRect == null)       BRDPC.throwNPE("stickyBoxRect");
235            if (containingBlockRect == null) BRDPC.throwNPE("containingBlockRect");
236            
237            this.stickyBoxRect                        = stickyBoxRect;
238            this.containingBlockRect                  = containingBlockRect;
239            this.nearestLayerShiftingStickyBox        = nearestLayerShiftingStickyBox;
240            this.nearestLayerShiftingContainingBlock  = nearestLayerShiftingContainingBlock;
241        }
242        
243        /**
244         * JSON Object Constructor
245         * @param jo A Json-Object having data about an instance of {@code 'StickyPositionConstraint'}.
246         */
247        public StickyPositionConstraint (JsonObject jo)
248        {
249            this.stickyBoxRect                        = ReadJSON.XL.getObject(jo, "stickyBoxRect", DOM.Rect.class, false, true);
250            this.containingBlockRect                  = ReadJSON.XL.getObject(jo, "containingBlockRect", DOM.Rect.class, false, true);
251            this.nearestLayerShiftingStickyBox        = ReadJSON.getString(jo, "nearestLayerShiftingStickyBox", true, false);
252            this.nearestLayerShiftingContainingBlock  = ReadJSON.getString(jo, "nearestLayerShiftingContainingBlock", true, false);
253        }
254        
255    }
256    
257    /** Serialized fragment of layer picture along with its offset within the layer. */
258    public static class PictureTile extends BaseType
259    {
260        /** For Object Serialization.  java.io.Serializable */
261        protected static final long serialVersionUID = 1;
262        
263        public boolean[] optionals()
264        { return new boolean[] { false, false, false, }; }
265        
266        /** Offset from owning layer left boundary */
267        public final Number x;
268        
269        /** Offset from owning layer top boundary */
270        public final Number y;
271        
272        /** Base64-encoded snapshot data. (Encoded as a base64 string when passed over JSON) */
273        public final String picture;
274        
275        /**
276         * Constructor
277         *
278         * @param x Offset from owning layer left boundary
279         * 
280         * @param y Offset from owning layer top boundary
281         * 
282         * @param picture Base64-encoded snapshot data. (Encoded as a base64 string when passed over JSON)
283         */
284        public PictureTile(Number x, Number y, String picture)
285        {
286            // Exception-Check(s) to ensure that if any parameters which are not declared as
287            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
288            
289            if (x == null)       BRDPC.throwNPE("x");
290            if (y == null)       BRDPC.throwNPE("y");
291            if (picture == null) BRDPC.throwNPE("picture");
292            
293            this.x        = x;
294            this.y        = y;
295            this.picture  = picture;
296        }
297        
298        /**
299         * JSON Object Constructor
300         * @param jo A Json-Object having data about an instance of {@code 'PictureTile'}.
301         */
302        public PictureTile (JsonObject jo)
303        {
304            this.x        = ReadJSON.getNUMBER(jo, "x", false, true);
305            this.y        = ReadJSON.getNUMBER(jo, "y", false, true);
306            this.picture  = ReadJSON.getString(jo, "picture", false, true);
307        }
308        
309    }
310    
311    /** Information about a compositing layer. */
312    public static class Layer extends BaseType
313    {
314        /** For Object Serialization.  java.io.Serializable */
315        protected static final long serialVersionUID = 1;
316        
317        public boolean[] optionals()
318        { return new boolean[] { false, true, true, false, false, false, false, true, true, true, true, false, false, true, true, true, }; }
319        
320        /** The unique id for this layer. */
321        public final String layerId;
322        
323        /**
324         * The id of parent (not present for root).
325         * <BR />
326         * <BR /><B>OPTIONAL</B>
327         */
328        public final String parentLayerId;
329        
330        /**
331         * The backend id for the node associated with this layer.
332         * <BR />
333         * <BR /><B>OPTIONAL</B>
334         */
335        public final Integer backendNodeId;
336        
337        /** Offset from parent layer, X coordinate. */
338        public final Number offsetX;
339        
340        /** Offset from parent layer, Y coordinate. */
341        public final Number offsetY;
342        
343        /** Layer width. */
344        public final Number width;
345        
346        /** Layer height. */
347        public final Number height;
348        
349        /**
350         * Transformation matrix for layer, default is identity matrix
351         * <BR />
352         * <BR /><B>OPTIONAL</B>
353         */
354        public final Number[] transform;
355        
356        /**
357         * Transform anchor point X, absent if no transform specified
358         * <BR />
359         * <BR /><B>OPTIONAL</B>
360         */
361        public final Number anchorX;
362        
363        /**
364         * Transform anchor point Y, absent if no transform specified
365         * <BR />
366         * <BR /><B>OPTIONAL</B>
367         */
368        public final Number anchorY;
369        
370        /**
371         * Transform anchor point Z, absent if no transform specified
372         * <BR />
373         * <BR /><B>OPTIONAL</B>
374         */
375        public final Number anchorZ;
376        
377        /** Indicates how many time this layer has painted. */
378        public final int paintCount;
379        
380        /**
381         * Indicates whether this layer hosts any content, rather than being used for
382         * transform/scrolling purposes only.
383         */
384        public final boolean drawsContent;
385        
386        /**
387         * Set if layer is not visible.
388         * <BR />
389         * <BR /><B>OPTIONAL</B>
390         */
391        public final Boolean invisible;
392        
393        /**
394         * Rectangles scrolling on main thread only.
395         * <BR />
396         * <BR /><B>OPTIONAL</B>
397         */
398        public final LayerTree.ScrollRect[] scrollRects;
399        
400        /**
401         * Sticky position constraint information
402         * <BR />
403         * <BR /><B>OPTIONAL</B>
404         */
405        public final LayerTree.StickyPositionConstraint stickyPositionConstraint;
406        
407        /**
408         * Constructor
409         *
410         * @param layerId The unique id for this layer.
411         * 
412         * @param parentLayerId The id of parent (not present for root).
413         * <BR /><B>OPTIONAL</B>
414         * 
415         * @param backendNodeId The backend id for the node associated with this layer.
416         * <BR /><B>OPTIONAL</B>
417         * 
418         * @param offsetX Offset from parent layer, X coordinate.
419         * 
420         * @param offsetY Offset from parent layer, Y coordinate.
421         * 
422         * @param width Layer width.
423         * 
424         * @param height Layer height.
425         * 
426         * @param transform Transformation matrix for layer, default is identity matrix
427         * <BR /><B>OPTIONAL</B>
428         * 
429         * @param anchorX Transform anchor point X, absent if no transform specified
430         * <BR /><B>OPTIONAL</B>
431         * 
432         * @param anchorY Transform anchor point Y, absent if no transform specified
433         * <BR /><B>OPTIONAL</B>
434         * 
435         * @param anchorZ Transform anchor point Z, absent if no transform specified
436         * <BR /><B>OPTIONAL</B>
437         * 
438         * @param paintCount Indicates how many time this layer has painted.
439         * 
440         * @param drawsContent 
441         * Indicates whether this layer hosts any content, rather than being used for
442         * transform/scrolling purposes only.
443         * 
444         * @param invisible Set if layer is not visible.
445         * <BR /><B>OPTIONAL</B>
446         * 
447         * @param scrollRects Rectangles scrolling on main thread only.
448         * <BR /><B>OPTIONAL</B>
449         * 
450         * @param stickyPositionConstraint Sticky position constraint information
451         * <BR /><B>OPTIONAL</B>
452         */
453        public Layer(
454                String layerId, String parentLayerId, Integer backendNodeId, Number offsetX, 
455                Number offsetY, Number width, Number height, Number[] transform, Number anchorX, 
456                Number anchorY, Number anchorZ, int paintCount, boolean drawsContent, 
457                Boolean invisible, LayerTree.ScrollRect[] scrollRects, 
458                LayerTree.StickyPositionConstraint stickyPositionConstraint
459            )
460        {
461            // Exception-Check(s) to ensure that if any parameters which are not declared as
462            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
463            
464            if (layerId == null) BRDPC.throwNPE("layerId");
465            if (offsetX == null) BRDPC.throwNPE("offsetX");
466            if (offsetY == null) BRDPC.throwNPE("offsetY");
467            if (width == null)   BRDPC.throwNPE("width");
468            if (height == null)  BRDPC.throwNPE("height");
469            
470            this.layerId                   = layerId;
471            this.parentLayerId             = parentLayerId;
472            this.backendNodeId             = backendNodeId;
473            this.offsetX                   = offsetX;
474            this.offsetY                   = offsetY;
475            this.width                     = width;
476            this.height                    = height;
477            this.transform                 = transform;
478            this.anchorX                   = anchorX;
479            this.anchorY                   = anchorY;
480            this.anchorZ                   = anchorZ;
481            this.paintCount                = paintCount;
482            this.drawsContent              = drawsContent;
483            this.invisible                 = invisible;
484            this.scrollRects               = scrollRects;
485            this.stickyPositionConstraint  = stickyPositionConstraint;
486        }
487        
488        /**
489         * JSON Object Constructor
490         * @param jo A Json-Object having data about an instance of {@code 'Layer'}.
491         */
492        public Layer (JsonObject jo)
493        {
494            this.layerId                   = ReadJSON.getString(jo, "layerId", false, true);
495            this.parentLayerId             = ReadJSON.getString(jo, "parentLayerId", true, false);
496            this.backendNodeId             = ReadJSON.getINTEGER(jo, "backendNodeId", true);
497            this.offsetX                   = ReadJSON.getNUMBER(jo, "offsetX", false, true);
498            this.offsetY                   = ReadJSON.getNUMBER(jo, "offsetY", false, true);
499            this.width                     = ReadJSON.getNUMBER(jo, "width", false, true);
500            this.height                    = ReadJSON.getNUMBER(jo, "height", false, true);
501            this.transform                 = (jo.getJsonArray("transform") == null)
502            ? null
503            : ReadArrJSON.DimN.arrNumber(jo.getJsonArray("transform"), -1, 0, null, Number[].class);;
504            this.anchorX                   = ReadJSON.getNUMBER(jo, "anchorX", true, false);
505            this.anchorY                   = ReadJSON.getNUMBER(jo, "anchorY", true, false);
506            this.anchorZ                   = ReadJSON.getNUMBER(jo, "anchorZ", true, false);
507            this.paintCount                = ReadJSON.getInt(jo, "paintCount");
508            this.drawsContent              = ReadJSON.getBoolean(jo, "drawsContent");
509            this.invisible                 = ReadJSON.getBOOLEAN(jo, "invisible", true);
510            this.scrollRects               = (jo.getJsonArray("scrollRects") == null)
511            ? null
512            : ReadArrJSON.DimN.objArr(jo.getJsonArray("scrollRects"), null, 0, LayerTree.ScrollRect[].class);
513            this.stickyPositionConstraint  = ReadJSON.XL.getObject(jo, "stickyPositionConstraint", LayerTree.StickyPositionConstraint.class, true, false);
514        }
515        
516    }
517    
518    /** <CODE>[No Description Provided by Google]</CODE> */
519    public static class layerPainted extends BrowserEvent
520    {
521        /** For Object Serialization.  java.io.Serializable */
522        protected static final long serialVersionUID = 1;
523        
524        public boolean[] optionals()
525        { return new boolean[] { false, false, }; }
526        
527        /** The id of the painted layer. */
528        public final String layerId;
529        
530        /** Clip rectangle. */
531        public final DOM.Rect clip;
532        
533        /**
534         * Constructor
535         *
536         * @param layerId The id of the painted layer.
537         * 
538         * @param clip Clip rectangle.
539         */
540        public layerPainted(String layerId, DOM.Rect clip)
541        {
542            super("LayerTree", "layerPainted", 2);
543            
544            // Exception-Check(s) to ensure that if any parameters which are not declared as
545            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
546            
547            if (layerId == null) BRDPC.throwNPE("layerId");
548            if (clip == null)    BRDPC.throwNPE("clip");
549            
550            this.layerId  = layerId;
551            this.clip     = clip;
552        }
553        
554        /**
555         * JSON Object Constructor
556         * @param jo A Json-Object having data about an instance of {@code 'layerPainted'}.
557         */
558        public layerPainted (JsonObject jo)
559        {
560            super("LayerTree", "layerPainted", 2);
561        
562            this.layerId  = ReadJSON.getString(jo, "layerId", false, true);
563            this.clip     = ReadJSON.XL.getObject(jo, "clip", DOM.Rect.class, false, true);
564        }
565        
566    }
567    
568    /** <CODE>[No Description Provided by Google]</CODE> */
569    public static class layerTreeDidChange extends BrowserEvent
570    {
571        /** For Object Serialization.  java.io.Serializable */
572        protected static final long serialVersionUID = 1;
573        
574        public boolean[] optionals()
575        { return new boolean[] { true, }; }
576        
577        /**
578         * Layer tree, absent if not in the comspositing mode.
579         * <BR />
580         * <BR /><B>OPTIONAL</B>
581         */
582        public final LayerTree.Layer[] layers;
583        
584        /**
585         * Constructor
586         *
587         * @param layers Layer tree, absent if not in the comspositing mode.
588         * <BR /><B>OPTIONAL</B>
589         */
590        public layerTreeDidChange(LayerTree.Layer[] layers)
591        {
592            super("LayerTree", "layerTreeDidChange", 1);
593            
594            this.layers  = layers;
595        }
596        
597        /**
598         * JSON Object Constructor
599         * @param jo A Json-Object having data about an instance of {@code 'layerTreeDidChange'}.
600         */
601        public layerTreeDidChange (JsonObject jo)
602        {
603            super("LayerTree", "layerTreeDidChange", 1);
604        
605            this.layers  = (jo.getJsonArray("layers") == null)
606            ? null
607            : ReadArrJSON.DimN.objArr(jo.getJsonArray("layers"), null, 0, LayerTree.Layer[].class);
608        }
609        
610    }
611    
612    
613    // Counter for keeping the WebSocket Request ID's distinct.
614    private static int counter = 1;
615    
616    /**
617     * Provides the reasons why the given layer was composited.
618     * 
619     * @param layerId The id of the layer for which we want to get the reasons it was composited.
620     * 
621     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
622     * {@link Ret2}&gt;</CODE>
623     *
624     * <BR /><BR />This {@link Script} may be <B STYLE='color:red'>executed</B> (using 
625     * {@link Script#exec()}), and a {@link Promise} returned.
626     *
627     * <BR /><BR />When the {@code Promise} is <B STYLE='color: red'>awaited</B>
628     * (using {@link Promise#await()}), the {@code Ret2} will subsequently
629     * be returned from that call.
630     * 
631     * <BR /><BR />The <B STYLE='color: red'>returned</B> values are encapsulated
632     * in an instance of <B>{@link Ret2}</B>
633     *
634     * <BR /><BR /><UL CLASS=JDUL>
635     * <LI><CODE><B>Ret2.a:</B> String[] (<B>compositingReasons</B>)</CODE>
636     *     <BR />A list of strings specifying reasons for the given layer to become composited.
637     *     <BR /><BR /></LI>
638     * <LI><CODE><B>Ret2.b:</B> String[] (<B>compositingReasonIds</B>)</CODE>
639     *     <BR />A list of strings specifying reason IDs for the given layer to become composited.
640     *     </LI>
641     * </UL>
642     */
643    public static Script<String, JsonObject, Ret2<String[], String[]>> compositingReasons
644        (String layerId)
645    {
646        // Exception-Check(s) to ensure that if any parameters which are not declared as
647        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
648        
649        if (layerId == null) BRDPC.throwNPE("layerId");
650        
651        final int       webSocketID = 27000000 + counter++;
652        final boolean[] optionals   = { false, };
653        
654        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
655        String requestJSON = WriteJSON.get(
656            parameterTypes.get("compositingReasons"),
657            parameterNames.get("compositingReasons"),
658            optionals, webSocketID,
659            "LayerTree.compositingReasons",
660            layerId
661        );
662        
663        // 'JSON Binding' ... Converts Browser Response-JSON into Java-Type 'Ret2'
664        Function<JsonObject, Ret2<String[], String[]>> 
665            responseProcessor = (JsonObject jo) -> new Ret2<>(
666                (jo.getJsonArray("compositingReasons") == null)
667                    ? null
668                    : ReadArrJSON.DimN.strArr(jo.getJsonArray("compositingReasons"), null, 0, String[].class),
669                (jo.getJsonArray("compositingReasonIds") == null)
670                    ? null
671                    : ReadArrJSON.DimN.strArr(jo.getJsonArray("compositingReasonIds"), null, 0, String[].class)
672            );
673        
674        // Pass the 'defaultSender' to Script-Constructor
675        // The sender that is used can be changed before executing script.
676        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
677    }
678    
679    /**
680     * Disables compositing tree inspection.
681     * 
682     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
683     * {@link Ret0}&gt;</CODE>
684     *
685     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
686     * browser receives the invocation-request.
687     *
688     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
689     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
690     * {@code >} to ensure the Browser Function has run to completion.
691     */
692    public static Script<String, JsonObject, Ret0> disable()
693    {
694        final int          webSocketID = 27001000 + counter++;
695        final boolean[]    optionals   = new boolean[0];
696        
697        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
698        String requestJSON = WriteJSON.get(
699            parameterTypes.get("disable"),
700            parameterNames.get("disable"),
701            optionals, webSocketID,
702            "LayerTree.disable"
703        );
704        
705        // This Remote Command does not have a Return-Value.
706        return new Script<>
707            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
708    }
709    
710    /**
711     * Enables compositing tree inspection.
712     * 
713     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
714     * {@link Ret0}&gt;</CODE>
715     *
716     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
717     * browser receives the invocation-request.
718     *
719     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
720     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
721     * {@code >} to ensure the Browser Function has run to completion.
722     */
723    public static Script<String, JsonObject, Ret0> enable()
724    {
725        final int          webSocketID = 27002000 + counter++;
726        final boolean[]    optionals   = new boolean[0];
727        
728        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
729        String requestJSON = WriteJSON.get(
730            parameterTypes.get("enable"),
731            parameterNames.get("enable"),
732            optionals, webSocketID,
733            "LayerTree.enable"
734        );
735        
736        // This Remote Command does not have a Return-Value.
737        return new Script<>
738            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
739    }
740    
741    /**
742     * Returns the snapshot identifier.
743     * 
744     * @param tiles An array of tiles composing the snapshot.
745     * 
746     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
747     * String&gt;</CODE>
748     * 
749     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
750     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
751     * String&gt;</CODE> will be returned.
752     *
753     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
754     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
755      * may be retrieved.</I>
756     *
757     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
758     * <BR /><BR /><UL CLASS=JDUL>
759     * <LI><CODE>String (<B>snapshotId</B></CODE>)
760     *     <BR />The id of the snapshot.
761     * </LI>
762     * </UL> */
763    public static Script<String, JsonObject, String> loadSnapshot(LayerTree.PictureTile[] tiles)
764    {
765        // Exception-Check(s) to ensure that if any parameters which are not declared as
766        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
767        
768        if (tiles == null) BRDPC.throwNPE("tiles");
769        
770        final int       webSocketID = 27003000 + counter++;
771        final boolean[] optionals   = { false, };
772        
773        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
774        String requestJSON = WriteJSON.get(
775            parameterTypes.get("loadSnapshot"),
776            parameterNames.get("loadSnapshot"),
777            optionals, webSocketID,
778            "LayerTree.loadSnapshot",
779            (Object) tiles
780        );
781        
782        // 'JSON Binding' ... Converts Browser Response-JSON to 'String'
783        Function<JsonObject, String> responseProcessor = (JsonObject jo) ->
784            ReadJSON.getString(jo, "snapshotId", false, true);
785        
786        // Pass the 'defaultSender' to Script-Constructor
787        // The sender that is used can be changed before executing script.
788        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
789    }
790    
791    /**
792     * Returns the layer snapshot identifier.
793     * 
794     * @param layerId The id of the layer.
795     * 
796     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
797     * String&gt;</CODE>
798     * 
799     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
800     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
801     * String&gt;</CODE> will be returned.
802     *
803     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
804     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
805      * may be retrieved.</I>
806     *
807     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
808     * <BR /><BR /><UL CLASS=JDUL>
809     * <LI><CODE>String (<B>snapshotId</B></CODE>)
810     *     <BR />The id of the layer snapshot.
811     * </LI>
812     * </UL> */
813    public static Script<String, JsonObject, String> makeSnapshot(String layerId)
814    {
815        // Exception-Check(s) to ensure that if any parameters which are not declared as
816        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
817        
818        if (layerId == null) BRDPC.throwNPE("layerId");
819        
820        final int       webSocketID = 27004000 + counter++;
821        final boolean[] optionals   = { false, };
822        
823        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
824        String requestJSON = WriteJSON.get(
825            parameterTypes.get("makeSnapshot"),
826            parameterNames.get("makeSnapshot"),
827            optionals, webSocketID,
828            "LayerTree.makeSnapshot",
829            layerId
830        );
831        
832        // 'JSON Binding' ... Converts Browser Response-JSON to 'String'
833        Function<JsonObject, String> responseProcessor = (JsonObject jo) ->
834            ReadJSON.getString(jo, "snapshotId", false, true);
835        
836        // Pass the 'defaultSender' to Script-Constructor
837        // The sender that is used can be changed before executing script.
838        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
839    }
840    
841    /**
842     * <CODE>[No Description Provided by Google]</CODE>
843     * 
844     * @param snapshotId The id of the layer snapshot.
845     * 
846     * @param minRepeatCount The maximum number of times to replay the snapshot (1, if not specified).
847     * <BR /><B>OPTIONAL</B>
848     * 
849     * @param minDuration The minimum duration (in seconds) to replay the snapshot.
850     * <BR /><B>OPTIONAL</B>
851     * 
852     * @param clipRect The clip rectangle to apply when replaying the snapshot.
853     * <BR /><B>OPTIONAL</B>
854     * 
855     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
856     * Number[][]&gt;</CODE>
857     * 
858     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
859     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
860     * Number[][]&gt;</CODE> will be returned.
861     *
862     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
863     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
864      * may be retrieved.</I>
865     *
866     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
867     * <BR /><BR /><UL CLASS=JDUL>
868     * <LI><CODE>Number[][] (<B>timings</B></CODE>)
869     *     <BR />The array of paint profiles, one per run.
870     * </LI>
871     * </UL> */
872    public static Script<String, JsonObject, Number[][]> profileSnapshot
873        (String snapshotId, Integer minRepeatCount, Number minDuration, DOM.Rect clipRect)
874    {
875        // Exception-Check(s) to ensure that if any parameters which are not declared as
876        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
877        
878        if (snapshotId == null) BRDPC.throwNPE("snapshotId");
879        
880        final int       webSocketID = 27005000 + counter++;
881        final boolean[] optionals   = { false, true, true, true, };
882        
883        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
884        String requestJSON = WriteJSON.get(
885            parameterTypes.get("profileSnapshot"),
886            parameterNames.get("profileSnapshot"),
887            optionals, webSocketID,
888            "LayerTree.profileSnapshot",
889            snapshotId, minRepeatCount, minDuration, clipRect
890        );
891        
892        // 'JSON Binding' ... Converts Browser Response-JSON to 'Number[][]'
893        Function<JsonObject, Number[][]> responseProcessor = (JsonObject jo) ->
894            (jo.getJsonArray("timings") == null)
895                ? null
896                : ReadArrJSON.DimN.arrNumber(jo.getJsonArray("timings"), -1, 0, null, Number[][].class);;
897        
898        // Pass the 'defaultSender' to Script-Constructor
899        // The sender that is used can be changed before executing script.
900        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
901    }
902    
903    /**
904     * Releases layer snapshot captured by the back-end.
905     * 
906     * @param snapshotId The id of the layer snapshot.
907     * 
908     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
909     * {@link Ret0}&gt;</CODE>
910     *
911     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
912     * browser receives the invocation-request.
913     *
914     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
915     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
916     * {@code >} to ensure the Browser Function has run to completion.
917     */
918    public static Script<String, JsonObject, Ret0> releaseSnapshot(String snapshotId)
919    {
920        // Exception-Check(s) to ensure that if any parameters which are not declared as
921        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
922        
923        if (snapshotId == null) BRDPC.throwNPE("snapshotId");
924        
925        final int       webSocketID = 27006000 + counter++;
926        final boolean[] optionals   = { false, };
927        
928        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
929        String requestJSON = WriteJSON.get(
930            parameterTypes.get("releaseSnapshot"),
931            parameterNames.get("releaseSnapshot"),
932            optionals, webSocketID,
933            "LayerTree.releaseSnapshot",
934            snapshotId
935        );
936        
937        // This Remote Command does not have a Return-Value.
938        return new Script<>
939            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
940    }
941    
942    /**
943     * Replays the layer snapshot and returns the resulting bitmap.
944     * 
945     * @param snapshotId The id of the layer snapshot.
946     * 
947     * @param fromStep The first step to replay from (replay from the very start if not specified).
948     * <BR /><B>OPTIONAL</B>
949     * 
950     * @param toStep The last step to replay to (replay till the end if not specified).
951     * <BR /><B>OPTIONAL</B>
952     * 
953     * @param scale The scale to apply while replaying (defaults to 1).
954     * <BR /><B>OPTIONAL</B>
955     * 
956     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
957     * String&gt;</CODE>
958     * 
959     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
960     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
961     * String&gt;</CODE> will be returned.
962     *
963     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
964     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
965      * may be retrieved.</I>
966     *
967     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
968     * <BR /><BR /><UL CLASS=JDUL>
969     * <LI><CODE>String (<B>dataURL</B></CODE>)
970     *     <BR />A data: URL for resulting image.
971     * </LI>
972     * </UL> */
973    public static Script<String, JsonObject, String> replaySnapshot
974        (String snapshotId, Integer fromStep, Integer toStep, Number scale)
975    {
976        // Exception-Check(s) to ensure that if any parameters which are not declared as
977        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
978        
979        if (snapshotId == null) BRDPC.throwNPE("snapshotId");
980        
981        final int       webSocketID = 27007000 + counter++;
982        final boolean[] optionals   = { false, true, true, true, };
983        
984        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
985        String requestJSON = WriteJSON.get(
986            parameterTypes.get("replaySnapshot"),
987            parameterNames.get("replaySnapshot"),
988            optionals, webSocketID,
989            "LayerTree.replaySnapshot",
990            snapshotId, fromStep, toStep, scale
991        );
992        
993        // 'JSON Binding' ... Converts Browser Response-JSON to 'String'
994        Function<JsonObject, String> responseProcessor = (JsonObject jo) ->
995            ReadJSON.getString(jo, "dataURL", false, true);
996        
997        // Pass the 'defaultSender' to Script-Constructor
998        // The sender that is used can be changed before executing script.
999        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1000    }
1001    
1002    /**
1003     * Replays the layer snapshot and returns canvas log.
1004     * 
1005     * @param snapshotId The id of the layer snapshot.
1006     * 
1007     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1008     * JsonArray&gt;</CODE>
1009     * 
1010     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1011     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1012     * JsonArray&gt;</CODE> will be returned.
1013     *
1014     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1015     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1016      * may be retrieved.</I>
1017     *
1018     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1019     * <BR /><BR /><UL CLASS=JDUL>
1020     * <LI><CODE>JsonArray (<B>commandLog</B></CODE>)
1021     *     <BR />The array of canvas function calls.
1022     * </LI>
1023     * </UL> */
1024    public static Script<String, JsonObject, JsonArray> snapshotCommandLog(String snapshotId)
1025    {
1026        // Exception-Check(s) to ensure that if any parameters which are not declared as
1027        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
1028        
1029        if (snapshotId == null) BRDPC.throwNPE("snapshotId");
1030        
1031        final int       webSocketID = 27008000 + counter++;
1032        final boolean[] optionals   = { false, };
1033        
1034        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1035        String requestJSON = WriteJSON.get(
1036            parameterTypes.get("snapshotCommandLog"),
1037            parameterNames.get("snapshotCommandLog"),
1038            optionals, webSocketID,
1039            "LayerTree.snapshotCommandLog",
1040            snapshotId
1041        );
1042        
1043        // 'JSON Binding' ... Converts Browser Response-JSON to 'JsonArray'
1044        Function<JsonObject, JsonArray> responseProcessor = (JsonObject jo) ->
1045            jo.getJsonArray("commandLog");
1046        
1047        // Pass the 'defaultSender' to Script-Constructor
1048        // The sender that is used can be changed before executing script.
1049        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1050    }
1051    
1052}