if (this._singleCanvas) { for (let i = 1; i < list.length; i++) { const el = list[i]; if (el.zlevel !== list[i - 1].zlevel || el.incremental) { this._needsManuallyCompositing = true; break; } } }
letprevLayer: Layer = null; let incrementalLayerCount = 0; let prevZlevel; let i; // list 即为要渲染的element(图形元素)列表。 for (i = 0; i < list.length; i++) { const el = list[i]; // el 内部其实并未维护zlevel信息(均为0) // 但维护了 incremental 信息 const zlevel = el.zlevel; let layer;
// TODO Not use magic number on zlevel. // Each layer with increment element can be separated to 3 layers. // (Other Element drawn after incremental element) // -----------------zlevel + EL_AFTER_INCREMENTAL_INC-------------------- // (Incremental element) // ----------------------zlevel + INCREMENTAL_INC------------------------ // (Element drawn before incremental element) // --------------------------------zlevel-------------------------------- // this.getLayer 会根据ID返回图层,如果无该图层则会创建图层并返回 // 如果el.incremental为true则创建新的图层 if (el.incremental) { layer = this.getLayer(zlevel + INCREMENTAL_INC/* 0.001 */, this._needsManuallyCompositing); layer.incremental = true; incrementalLayerCount = 1; } // incremental 元素之后的元素 将会在下一个图层创建。 else { layer = this.getLayer( zlevel + (incrementalLayerCount > 0 ? EL_AFTER_INCREMENTAL_INC/* 0.01 */ : 0), this._needsManuallyCompositing ); } // 以上将图层分为了三层,el.incremental的图层以及 el.incremental之前和之后的图层 // el.incremental图层即增量数据图层 if (!layer.__builtin__) { util.logError('ZLevel ' + zlevel + ' has been used by unkown layer ' + layer.id); }
if (layer !== prevLayer) { layer.__used = true; if (layer.__startIndex !== i) { layer.__dirty = true; } // 这里确定了当前图层一个元素的下标。 // 结合 updatePrevLayer(i) 更新上一个图层, // 确定了所有图层要渲染[待渲染的元素集合]中的哪一部分。 layer.__startIndex = i; if (!layer.incremental) { layer.__drawIndex = i; } else { // Mark layer draw index needs to update. layer.__drawIndex = -1; } updatePrevLayer(i); prevLayer = layer; } if ((el.__dirty & REDRAW_BIT) && !el.__inHover) { // Ignore dirty elements in hover layer. layer.__dirty = true; if (layer.incremental && layer.__drawIndex < 0) { // Start draw from the first dirty element. layer.__drawIndex = i; } } }
updatePrevLayer(i);
this.eachBuiltinLayer(function (layer, z) { // Used in last frame but not in this frame. Needs clear if (!layer.__used && layer.getElementCount() > 0) { layer.__dirty = true; layer.__startIndex = layer.__endIndex = layer.__drawIndex = 0; } // For incremental layer. In case start index changed and no elements are dirty. if (layer.__dirty && layer.__drawIndex < 0) { layer.__drawIndex = layer.__startIndex; } }); }