/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../../chunks/_rollupPluginBabelHelpers","../../../../core/Error","../../../../core/Logger","../../../../core/maybe","../../../../core/reactiveUtils","../../../../chunks/mat3f32","../DisplayObject","./Mesh2D","../../../webgl/VertexArrayObject"],(function(e,t,r,i,s,c,o,n,h){"use strict";const a=r.getLogger("esri.views.2d.engine.webgl.ClippingInfo"),l=e=>parseFloat(e)/100;return function(r){function o(e,t){var i;return(i=r.call(this)||this)._clip=t,i._cache={},i.stage=e,i._handle=s.watch((()=>t.version),(()=>i._invalidate())),i.ready(),i}e._inheritsLoose(o,r),o.fromClipArea=function(e,t){return new o(e,t)};var f=o.prototype;return f._destroyGL=function(){i.isSome(this._cache.mesh)&&(this._cache.mesh.destroy(),this._cache.mesh=null),i.isSome(this._cache.vao)&&(this._cache.vao.dispose(),this._cache.vao=null)},f.destroy=function(){this._destroyGL(),this._handle.remove()},f.getVAO=function(e,t,r,s){const[c,o]=t.size;if("geometry"!==this._clip.type&&this._lastWidth===c&&this._lastHeight===o||(this._lastWidth=c,this._lastHeight=o,this._destroyGL()),i.isNone(this._cache.vao)){const i=this._createMesh(t,this._clip),c=i.getIndexBuffer(e),o=i.getVertexBuffers(e);this._cache.mesh=i,this._cache.vao=new h.VertexArrayObject(e,r,s,o,c)}return this._cache.vao},f._createTransforms=function(){return{dvs:c.create()}},f._invalidate=function(){this._destroyGL(),this.requestRender()},f._createScreenRect=function(e,t){const[r,i]=e.size,s="string"==typeof t.left?l(t.left)*r:t.left,c="string"==typeof t.right?l(t.right)*r:t.right,o="string"==typeof t.top?l(t.top)*i:t.top,n="string"==typeof t.bottom?l(t.bottom)*i:t.bottom,h=s,a=o;return{x:h,y:a,width:Math.max(r-c-h,0),height:Math.max(i-n-a,0)}},f._createMesh=function(e,r){switch(r.type){case"rect":return n.fromRect(this._createScreenRect(e,r));case"path":return n.fromPath(r);case"geometry":return n.fromGeometry(e,r);default:return a.error(new t("mapview-bad-type","Unable to create ClippingInfo mesh from clip of type: ${clip.type}")),n.fromRect({x:0,y:0,width:1,height:1})}},o}(o.DisplayObject)}));
