@@ -105,6 +105,10 @@ export default class Layer extends Eventful {
105105 __startIndex = 0
106106 __endIndex = 0
107107
108+ // indices in the previous frame
109+ __prevStartIndex : number = null
110+ __prevEndIndex : number = null
111+
108112 __builtin__ : boolean
109113
110114 constructor ( id : string | HTMLCanvasElement , painter : CanvasPainter , dpr ?: number ) {
@@ -149,6 +153,11 @@ export default class Layer extends Eventful {
149153 return this . __endIndex - this . __startIndex ;
150154 }
151155
156+ afterBrush ( ) {
157+ this . __prevStartIndex = this . __startIndex ;
158+ this . __prevEndIndex = this . __endIndex ;
159+ }
160+
152161 initContext ( ) {
153162 this . ctx = this . dom . getContext ( '2d' ) ;
154163 ( this . ctx as ZRCanvasRenderingContext ) . dpr = this . dpr ;
@@ -165,23 +174,30 @@ export default class Layer extends Eventful {
165174 }
166175 }
167176
168- createRepaintRects ( displayList : Displayable [ ] , prevList : Displayable [ ] ) {
177+ /**
178+ * Create repaint list when using dirty rect rendering.
179+ *
180+ * @param layer onlu elements in this layer will be used to compute
181+ * @param displayList current rendering list
182+ * @param prevList last frame rendering list
183+ * @return repaint rects. null for the first frame, [] for no element dirty
184+ */
185+ createRepaintRects (
186+ layer : Layer ,
187+ displayList : Displayable [ ] ,
188+ prevList : Displayable [ ]
189+ ) {
169190 if ( this . __firstTimePaint ) {
170- util . each ( displayList , el => {
171- if ( el . __dirty ) {
172- el . setPrevPaintRect ( el . getPaintRect ( ) ) ;
173- }
174- } ) ;
175-
176191 this . __firstTimePaint = false ;
177- return [ ] ;
192+ return null ;
178193 }
179194
180195 const mergedRepaintRects : BoundingRect [ ] = [ ] ;
181196 const rects : BoundingRect [ ] = [ ] ;
182197
183198 // Add current and previous bounding rect
184- util . each ( displayList , el => {
199+ for ( let i = layer . __startIndex ; i < layer . __endIndex ; ++ i ) {
200+ const el = displayList [ i ] ;
185201 if ( el . __dirty ) {
186202 el . __needsRepaintDirtyRect = false ;
187203
@@ -193,21 +209,21 @@ export default class Layer extends Eventful {
193209 const curRect = el . getPaintRect ( ) ;
194210 if ( isValidPaintRect ( curRect ) ) {
195211 rects . push ( curRect ) ;
196- el . setPrevPaintRect ( curRect ) ;
197212 }
198213 }
199- } ) ;
214+ }
200215
201216 // Add removed displayables because they need to be cleared
202- util . each ( prevList , el => {
217+ for ( let i = layer . __prevStartIndex ; i < layer . __prevEndIndex ; ++ i ) {
218+ const el = prevList [ i ] ;
203219 if ( el . __needsRepaintDirtyRect ) {
204220 // el is removed
205221 const prevRect = el . getPrevPaintRect ( ) ;
206222 if ( isValidPaintRect ( prevRect ) ) {
207223 rects . push ( prevRect ) ;
208224 }
209225 }
210- } ) ;
226+ }
211227
212228 // Merge
213229 util . each ( rects , rect => {
@@ -395,11 +411,11 @@ export default class Layer extends Eventful {
395411 }
396412 } ;
397413
398- if ( ! repaintRects || ! repaintRects . length ) {
414+ if ( ! repaintRects ) {
399415 // Clear the full canvas
400416 doClear ( new BoundingRect ( 0 , 0 , width , height ) ) ;
401417 }
402- else {
418+ else if ( repaintRects . length ) {
403419 // Clear the repaint areas
404420 util . each ( repaintRects , rect => {
405421 doClear ( new BoundingRect (
0 commit comments