/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{disposeMaybe as t,abortMaybe as s}from"../../../core/maybe.js";import e from"../../../core/ObjectPool.js";import i from"../../../core/PooledArray.js";import{releaseTerrainData as a}from"./terrainUtils.js";import{computeUpsampleInfo as n}from"./tileUtils.js";class o{constructor(){this.waitingAgents=new i,this.pendingUpdates=0}static acquire(t){const s=l.acquire();return s._init(t),s}release(){this.dispose(),p.delete(this),l.release(this)}dispose(){this.loadingAgent=t(this.loadingAgent),this.abortRequest(),this._unsetUpsampleInfo(),this.pendingUpdates=0,this._data=a(this._data)}static prune(){l.prune(0)}_init(t){this.waitingAgents.clear(),this._data=a(this._data),this.dataMissing=!1,this.dataInvalidated=!1,this._unsetUpsampleInfo(),this.abortRequest(),this.loadingAgent=null,this.pendingUpdates=0,this._pool=t,this.elevationBounds=null}invalidateSourceData(){this.dataInvalidated=!0,this.dataMissing=!1,this._unsetUpsampleInfo()}abortRequest(){this.requestAbort=s(this.requestAbort),this.requestPromise=null}_unsetUpsampleInfo(){this.upsampleInfo&&(this.upsampleInfo.tile?.unrefMapData(),this._pool.release(this.upsampleInfo),this.upsampleInfo=null)}setUpsampleInfo(t,s){if(t!==s&&null!=s){if(null==this.upsampleInfo)this.upsampleInfo=this._pool.acquire();else{if(this.upsampleInfo.tile===s)return;this.upsampleInfo.tile?.unrefMapData()}s.refMapData(),n(t,s,this.upsampleInfo)}else this._unsetUpsampleInfo()}get data(){return this._data}set data(t){a(this._data),this._data=t}}const l=new e(()=>new o,null,()=>{}),p=new Map;function r(){p.size>0&&(console.log(`${p.size} live TilePerLayerInfo allocations:`),p.forEach(t=>console.log(t,"\n")))}function h(){l.prune(),p.clear()}export{o as TilePerLayerInfo,h as clearTilePerLayerInfo,r as printAllocations};
