/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../chunks/_rollupPluginBabelHelpers","../../../core/maybe","../../../chunks/mat3","../../../chunks/mat3f32","../../../chunks/vec2f32","./DisplayObject","./ImageryBitmapSource","../../webgl/enums","../../webgl/Texture"],(function(t,e,i,s,r,n,u,o,h,a){"use strict";function c(t){return t&&"render"in t}function l(t){return t&&!("render"in t)}function d(t){const e=document.createElement("canvas");return e.width=t.width,e.height=t.height,t.render(e.getContext("2d")),e}function _(t,e,i){const s={target:h.TextureType.TEXTURE_2D,pixelFormat:h.PixelFormat.RGBA,internalFormat:h.PixelFormat.RGBA,dataType:h.PixelType.UNSIGNED_BYTE,wrapMode:h.TextureWrapMode.CLAMP_TO_EDGE};return e&&i&&(s.width=e,s.height=i),new a.Texture(t,s)}let f=function(t){function u(i=null,s,r=!0){var n;return(n=t.call(this)||this).requestRenderOnSourceChangedEnabled=r,n._textureInvalidated=!0,n.stencilRef=0,n.coordScale=[1,1],n._height=void 0,n.pixelRatio=1,n.resolution=0,n.rotation=0,n._source=null,n._width=void 0,n.x=0,n.y=0,n.blendFunction=s,n.source=i,n.requestRender=n.requestRender.bind(e._assertThisInitialized(n)),n}e._inheritsLoose(u,t);var h=u.prototype;return h.destroy=function(){this._texture&&(this._texture.dispose(),this._texture=null)},h.beforeRender=function(e){t.prototype.beforeRender.call(this,e),this.updateTexture(e.context)},h.invalidateTexture=function(){this._textureInvalidated||(this._textureInvalidated=!0,this.requestRenderOnSourceChangedEnabled&&this.requestRender())},h._createTransforms=function(){return{dvs:r.create()}},h.setTransform=function(t){const e=s.identity(this.transforms.dvs),[i,r]=t.toScreenNoRotation([0,0],[this.x,this.y]),u=this.resolution/this.pixelRatio/t.resolution,o=u*this.width,h=u*this.height,a=Math.PI*this.rotation/180;s.translate(e,e,n.fromValues(i,r)),s.translate(e,e,n.fromValues(o/2,h/2)),s.rotate(e,e,-a),s.translate(e,e,n.fromValues(-o/2,-h/2)),s.scaleByVec2(e,e,n.fromValues(o,h)),s.multiply(this.transforms.dvs,t.displayViewMat3,e)},h.setSamplingProfile=function(t){this._texture&&(t.mips&&!this._texture.descriptor.hasMipmap&&this._texture.generateMipmap(),this._texture.setSamplingMode(t.samplingMode))},h.bind=function(t,e){this._texture&&t.bindTexture(this._texture,e)},h.updateTexture=function(t){var e;if(!this.stage)return null==(e=this._texture)||e.dispose(),void(this._texture=null);if(!this._textureInvalidated)return;this._textureInvalidated=!1,this._texture||(this.source?this._texture=_(t,this.sourceWidth,this.sourceHeight):this._texture=_(t));const s=this.source;if(s){if(this._texture.resize(this.sourceWidth,this.sourceHeight),c(s))if(s instanceof o){const t=s.getRenderedRasterPixels();this._texture.setData(i.isSome(t)?t.renderedRasterPixels:null)}else this._texture.setData(d(s));else l(s)&&this._texture.setData(s);this.ready()}else this._texture.setData(null)},h.onAttach=function(){this.invalidateTexture()},h.onDetach=function(){this.invalidateTexture()},e._createClass(u,[{key:"isSourceScaled",get:function(){return this.width!==this.sourceWidth||this.height!==this.sourceHeight}},{key:"height",get:function(){return void 0!==this._height?this._height:this.sourceHeight},set:function(t){this._height=t}},{key:"source",get:function(){return this._source},set:function(t){this._source=t,this.invalidateTexture()}},{key:"sourceHeight",get:function(){return this._source instanceof HTMLImageElement?this._source.naturalHeight:this._source.height}},{key:"sourceWidth",get:function(){return this._source instanceof HTMLImageElement?this._source.naturalWidth:this._source.width}},{key:"width",get:function(){return void 0!==this._width?this._width:this.sourceWidth},set:function(t){this._width=t}}]),u}(u.DisplayObject);t.Bitmap=f,t.isImageSource=c,t.rasterize=d,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
