@@ -215,6 +215,8 @@ class RenderWebGL extends EventEmitter {
215215 // tw: add high quality render option
216216 this . useHighQualityRender = false ;
217217
218+ this . dirty = true ;
219+
218220 this . _createGeometry ( ) ;
219221
220222 this . on ( RenderConstants . Events . NativeSizeChanged , this . onNativeSizeChanged ) ;
@@ -231,6 +233,7 @@ class RenderWebGL extends EventEmitter {
231233
232234 // tw: implement high quality pen option
233235 setUseHighQualityRender ( enabled ) {
236+ this . dirty = true ;
234237 this . useHighQualityRender = enabled ;
235238 this . emit ( RenderConstants . Events . UseHighQualityRenderChanged , enabled ) ;
236239 this . _updateRenderQuality ( ) ;
@@ -274,6 +277,7 @@ class RenderWebGL extends EventEmitter {
274277 * @param {int } pixelsTall The desired height in device-independent pixels.
275278 */
276279 resize ( pixelsWide , pixelsTall ) {
280+ this . dirty = true ;
277281 const { canvas} = this . _gl ;
278282 const pixelRatio = window . devicePixelRatio || 1 ;
279283 const newWidth = pixelsWide * pixelRatio ;
@@ -517,7 +521,7 @@ class RenderWebGL extends EventEmitter {
517521 return ;
518522 }
519523 const drawableID = this . _nextDrawableId ++ ;
520- const drawable = new Drawable ( drawableID ) ;
524+ const drawable = new Drawable ( drawableID , this ) ;
521525 this . _allDrawables [ drawableID ] = drawable ;
522526 this . _addToDrawList ( drawableID , group ) ;
523527 // tw: implement high quality render
@@ -588,6 +592,7 @@ class RenderWebGL extends EventEmitter {
588592 log . warn ( 'Cannot destroy drawable without known layer group.' ) ;
589593 return ;
590594 }
595+ this . dirty = true ;
591596 const drawable = this . _allDrawables [ drawableID ] ;
592597 drawable . dispose ( ) ;
593598 delete this . _allDrawables [ drawableID ] ;
@@ -643,6 +648,7 @@ class RenderWebGL extends EventEmitter {
643648 return ;
644649 }
645650
651+ this . dirty = true ;
646652 const currentLayerGroup = this . _layerGroups [ group ] ;
647653 const startIndex = currentLayerGroup . drawListOffset ;
648654 const endIndex = this . _endIndexForKnownLayerGroup ( currentLayerGroup ) ;
@@ -686,6 +692,11 @@ class RenderWebGL extends EventEmitter {
686692 * Draw all current drawables and present the frame on the canvas.
687693 */
688694 draw ( ) {
695+ if ( ! this . dirty ) {
696+ return ;
697+ }
698+ this . dirty = false ;
699+
689700 this . _doExitDrawRegion ( ) ;
690701
691702 const gl = this . _gl ;
@@ -1708,6 +1719,7 @@ class RenderWebGL extends EventEmitter {
17081719 * @param {int } penSkinID - the unique ID of a Pen Skin.
17091720 */
17101721 penClear ( penSkinID ) {
1722+ this . dirty = true ;
17111723 const skin = /** @type {PenSkin } */ this . _allSkins [ penSkinID ] ;
17121724 skin . clear ( ) ;
17131725 }
@@ -1720,6 +1732,7 @@ class RenderWebGL extends EventEmitter {
17201732 * @param {number } y - the Y coordinate of the point to draw.
17211733 */
17221734 penPoint ( penSkinID , penAttributes , x , y ) {
1735+ this . dirty = true ;
17231736 const skin = /** @type {PenSkin } */ this . _allSkins [ penSkinID ] ;
17241737 skin . drawPoint ( penAttributes , x , y ) ;
17251738 }
@@ -1734,6 +1747,7 @@ class RenderWebGL extends EventEmitter {
17341747 * @param {number } y1 - the Y coordinate of the end of the line.
17351748 */
17361749 penLine ( penSkinID , penAttributes , x0 , y0 , x1 , y1 ) {
1750+ this . dirty = true ;
17371751 const skin = /** @type {PenSkin } */ this . _allSkins [ penSkinID ] ;
17381752 skin . drawLine ( penAttributes , x0 , y0 , x1 , y1 ) ;
17391753 }
@@ -1744,6 +1758,7 @@ class RenderWebGL extends EventEmitter {
17441758 * @param {int } stampID - the unique ID of the Drawable to use as the stamp.
17451759 */
17461760 penStamp ( penSkinID , stampID ) {
1761+ this . dirty = true ;
17471762 const stampDrawable = this . _allDrawables [ stampID ] ;
17481763 if ( ! stampDrawable ) {
17491764 return ;
@@ -1829,6 +1844,7 @@ class RenderWebGL extends EventEmitter {
18291844 * @private
18301845 */
18311846 onNativeSizeChanged ( event ) {
1847+ this . dirty = true ;
18321848 const [ width , height ] = event . newSize ;
18331849
18341850 const gl = this . _gl ;
@@ -2157,6 +2173,7 @@ class RenderWebGL extends EventEmitter {
21572173 * @param {snapshotCallback } callback Function called in the next frame with the snapshot data
21582174 */
21592175 requestSnapshot ( callback ) {
2176+ this . dirty = true ;
21602177 this . _snapshotCallbacks . push ( callback ) ;
21612178 }
21622179}
0 commit comments