/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{generateUID as e}from"../../../../core/uid.js";class t{constructor(t,r,s){this._createTexture=t,this._parametersKey=r,this._repository=new Map,this._orphanCache=s.newCache(`procedural-texture-repository:${e()}`,e=>e.dispose())}destroy(){for(const{texture:e}of this._repository.values())e.dispose();this._repository.clear(),this._orphanCache.destroy()}swap(e,t=null){const r=this._acquire(e);return this.release(t),r}release(e){if(null==e)return;const t=this._parametersKey(e),r=this._repository.get(t);if(r&&(r.refCount--,0===r.refCount)){this._repository.delete(t);const{texture:e}=r;this._orphanCache.put(t,e)}}_acquire(e){if(null==e)return null;const t=this._parametersKey(e),s=this._repository.get(t);if(s)return s.refCount++,s.texture;const o=this._orphanCache.pop(t)??this._createTexture(e),i=new r(o);return this._repository.set(t,i),o}}class r{constructor(e){this.texture=e,this.refCount=1}}export{t as ProceduralTextureRepository};
