UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 1.1 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.32/esri/copyright.txt for details. */ 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};