Browse Source

Keep track of the number of layout and render calls

Popov72 5 years ago
parent
commit
2dd20ab995

+ 2 - 0
gui/src/2D/advancedDynamicTexture.ts

@@ -550,6 +550,7 @@ export class AdvancedDynamicTexture extends DynamicTexture {
         // Layout
         this.onBeginLayoutObservable.notifyObservers(this);
         var measure = new Measure(0, 0, renderWidth, renderHeight);
+        Control.numLayoutCalls = 0;
         this._rootContainer._layout(measure, context);
         this.onEndLayoutObservable.notifyObservers(this);
         this._isDirty = false; // Restoring the dirty state that could have been set by controls during layout processing
@@ -570,6 +571,7 @@ export class AdvancedDynamicTexture extends DynamicTexture {
 
         // Render
         this.onBeginRenderObservable.notifyObservers(this);
+        Control.numRenderCalls = 0;
         this._rootContainer._render(context, this._invalidatedRectangle);
         this.onEndRenderObservable.notifyObservers(this);
         this._invalidatedRectangle = null;

+ 2 - 0
gui/src/2D/controls/container.ts

@@ -304,6 +304,8 @@ export class Container extends Control {
             return false;
         }
 
+        Control.numLayoutCalls++;
+
         if (this._isDirty) {
             this._currentMeasure.transformToRef(this._transformMatrix, this._prevCurrentMeasureTransformedIntoGlobalSpace);
         }

+ 10 - 0
gui/src/2D/controls/control.ts

@@ -25,6 +25,11 @@ export class Control {
      */
     public static AllowAlphaInheritance = false;
 
+    /** Gets the number of layout calls made the last time the ADT has been rendered */
+    public static numLayoutCalls = 0;
+    /** Gets the number of render calls made the last time the ADT has been rendered */
+    public static numRenderCalls = 0;
+
     private _alpha = 1;
     private _alphaSet = false;
     private _zIndex = 0;
@@ -1356,6 +1361,8 @@ export class Control {
         }
 
         if (this._isDirty || !this._cachedParentMeasure.isEqualsTo(parentMeasure)) {
+            Control.numLayoutCalls++;
+
             this._currentMeasure.transformToRef(this._transformMatrix, this._prevCurrentMeasureTransformedIntoGlobalSpace);
 
             context.save();
@@ -1596,6 +1603,9 @@ export class Control {
             this._isDirty = false;
             return false;
         }
+
+        Control.numRenderCalls++;
+
         context.save();
 
         this._applyStates(context);