/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../core/floatRGBA","../../../../core/maybe","../../../webgl/enums","../../../webgl/Texture"],(function(e,t,r,i,n){"use strict";let o=function(){function e(e){this._rctx=e,this.cache=new Map}var t=e.prototype;return t.dispose=function(){this.cache.forEach((e=>e.texture=r.disposeMaybe(e.texture))),this.cache.clear()},t._acquire=function(e){if(r.isNone(e))return null;const t=this._patternId(e),o=this.cache.get(t);if(o)return o.refCount++,o.bind;const s=e.pixelRatio,{encodedData:c,sdfNormalizer:u,pixels:l,paddedPixels:p}=a(e.pattern,s),d=l/s,h={refCount:1,texture:null,bind:e=>(r.isNone(h.texture)&&(h.texture=new n.Texture(this._rctx,{width:p,height:1,internalFormat:i.PixelFormat.RGBA,pixelFormat:i.PixelFormat.RGBA,dataType:i.PixelType.UNSIGNED_BYTE,wrapMode:i.TextureWrapMode.CLAMP_TO_EDGE},c)),e.bindTexture("stipplePatternTexture",h.texture),{pixelSize:d,sdfNormalizer:u,pixels:l})};return this.cache.set(t,h),h.bind},t.release=function(e){if(r.isNone(e))return;const t=this._patternId(e),i=this.cache.get(t);i&&(i.refCount--,0===i.refCount&&(r.isSome(i.texture)&&i.texture.dispose(),this.cache.delete(t)))},t.swap=function(e,t){const r=this._acquire(t);return this.release(e),r},t._patternId=function(e){return`${e.pattern.join(",")}-r${e.pixelRatio}`},e}();function a(e,r){const i=e.map((e=>Math.round(e*r))),n=1/r,o=Math.floor(i.reduce(((e,t)=>e+t))),a=i.reduce(((e,t)=>Math.max(e,t))),s=(Math.floor(.5*(a-1))+.5)*n,c=[];let u=1;for(const t of i){for(let e=0;e<t;e++){const r=u*(Math.min(e,t-1-e)+.5)*n/s*.5+.5;c.push(r)}u=-u}const l=Math.round(i[0]/2),p=[...c.slice(l),...c.slice(0,l)],d=o+2,h=new Uint8Array(4*d);let f=4;for(const x of p)t.packFloatRGBA(x,h,f),f+=4;return h.copyWithin(0,f-4,f),h.copyWithin(f,4,8),{encodedData:h,sdfNormalizer:s,paddedPixels:d,pixels:o}}e.StippleTextureRepository=o,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
