@@ -215,6 +215,8 @@ class RenderWebGL extends EventEmitter {
215
215
// tw: add high quality render option
216
216
this . useHighQualityRender = false ;
217
217
218
+ this . dirty = true ;
219
+
218
220
this . _createGeometry ( ) ;
219
221
220
222
this . on ( RenderConstants . Events . NativeSizeChanged , this . onNativeSizeChanged ) ;
@@ -231,6 +233,7 @@ class RenderWebGL extends EventEmitter {
231
233
232
234
// tw: implement high quality pen option
233
235
setUseHighQualityRender ( enabled ) {
236
+ this . dirty = true ;
234
237
this . useHighQualityRender = enabled ;
235
238
this . emit ( RenderConstants . Events . UseHighQualityRenderChanged , enabled ) ;
236
239
this . _updateRenderQuality ( ) ;
@@ -274,6 +277,7 @@ class RenderWebGL extends EventEmitter {
274
277
* @param {int } pixelsTall The desired height in device-independent pixels.
275
278
*/
276
279
resize ( pixelsWide , pixelsTall ) {
280
+ this . dirty = true ;
277
281
const { canvas} = this . _gl ;
278
282
const pixelRatio = window . devicePixelRatio || 1 ;
279
283
const newWidth = pixelsWide * pixelRatio ;
@@ -517,7 +521,7 @@ class RenderWebGL extends EventEmitter {
517
521
return ;
518
522
}
519
523
const drawableID = this . _nextDrawableId ++ ;
520
- const drawable = new Drawable ( drawableID ) ;
524
+ const drawable = new Drawable ( drawableID , this ) ;
521
525
this . _allDrawables [ drawableID ] = drawable ;
522
526
this . _addToDrawList ( drawableID , group ) ;
523
527
// tw: implement high quality render
@@ -588,6 +592,7 @@ class RenderWebGL extends EventEmitter {
588
592
log . warn ( 'Cannot destroy drawable without known layer group.' ) ;
589
593
return ;
590
594
}
595
+ this . dirty = true ;
591
596
const drawable = this . _allDrawables [ drawableID ] ;
592
597
drawable . dispose ( ) ;
593
598
delete this . _allDrawables [ drawableID ] ;
@@ -643,6 +648,7 @@ class RenderWebGL extends EventEmitter {
643
648
return ;
644
649
}
645
650
651
+ this . dirty = true ;
646
652
const currentLayerGroup = this . _layerGroups [ group ] ;
647
653
const startIndex = currentLayerGroup . drawListOffset ;
648
654
const endIndex = this . _endIndexForKnownLayerGroup ( currentLayerGroup ) ;
@@ -686,6 +692,11 @@ class RenderWebGL extends EventEmitter {
686
692
* Draw all current drawables and present the frame on the canvas.
687
693
*/
688
694
draw ( ) {
695
+ if ( ! this . dirty ) {
696
+ return ;
697
+ }
698
+ this . dirty = false ;
699
+
689
700
this . _doExitDrawRegion ( ) ;
690
701
691
702
const gl = this . _gl ;
@@ -1708,6 +1719,7 @@ class RenderWebGL extends EventEmitter {
1708
1719
* @param {int } penSkinID - the unique ID of a Pen Skin.
1709
1720
*/
1710
1721
penClear ( penSkinID ) {
1722
+ this . dirty = true ;
1711
1723
const skin = /** @type {PenSkin } */ this . _allSkins [ penSkinID ] ;
1712
1724
skin . clear ( ) ;
1713
1725
}
@@ -1720,6 +1732,7 @@ class RenderWebGL extends EventEmitter {
1720
1732
* @param {number } y - the Y coordinate of the point to draw.
1721
1733
*/
1722
1734
penPoint ( penSkinID , penAttributes , x , y ) {
1735
+ this . dirty = true ;
1723
1736
const skin = /** @type {PenSkin } */ this . _allSkins [ penSkinID ] ;
1724
1737
skin . drawPoint ( penAttributes , x , y ) ;
1725
1738
}
@@ -1734,6 +1747,7 @@ class RenderWebGL extends EventEmitter {
1734
1747
* @param {number } y1 - the Y coordinate of the end of the line.
1735
1748
*/
1736
1749
penLine ( penSkinID , penAttributes , x0 , y0 , x1 , y1 ) {
1750
+ this . dirty = true ;
1737
1751
const skin = /** @type {PenSkin } */ this . _allSkins [ penSkinID ] ;
1738
1752
skin . drawLine ( penAttributes , x0 , y0 , x1 , y1 ) ;
1739
1753
}
@@ -1744,6 +1758,7 @@ class RenderWebGL extends EventEmitter {
1744
1758
* @param {int } stampID - the unique ID of the Drawable to use as the stamp.
1745
1759
*/
1746
1760
penStamp ( penSkinID , stampID ) {
1761
+ this . dirty = true ;
1747
1762
const stampDrawable = this . _allDrawables [ stampID ] ;
1748
1763
if ( ! stampDrawable ) {
1749
1764
return ;
@@ -1829,6 +1844,7 @@ class RenderWebGL extends EventEmitter {
1829
1844
* @private
1830
1845
*/
1831
1846
onNativeSizeChanged ( event ) {
1847
+ this . dirty = true ;
1832
1848
const [ width , height ] = event . newSize ;
1833
1849
1834
1850
const gl = this . _gl ;
@@ -2157,6 +2173,7 @@ class RenderWebGL extends EventEmitter {
2157
2173
* @param {snapshotCallback } callback Function called in the next frame with the snapshot data
2158
2174
*/
2159
2175
requestSnapshot ( callback ) {
2176
+ this . dirty = true ;
2160
2177
this . _snapshotCallbacks . push ( callback ) ;
2161
2178
}
2162
2179
}
0 commit comments