/* * noVNC: HTML5 VNC client * Copyright (C) 2012 Joel Martin * Copyright (C) 2015 Samuel Mannehed for Cendio AB * Licensed under MPL 2.0 (see LICENSE.txt) * * See README.md for usage and integration instructions. */ var Display;!function(){"use strict";var t=!1;try{new ImageData(new Uint8ClampedArray(1),1,1),t=!0}catch(t){}Display=function(t){if(this._drawCtx=null,this._c_forceCanvas=!1,this._renderQ=[],this._fb_width=0,this._fb_height=0,this._maxWidth=0,this._maxHeight=0,this._viewportLoc={x:0,y:0,w:0,h:0},this._cleanRect={x1:0,y1:0,x2:-1,y2:-1},this._prevDrawStyle="",this._tile=null,this._tile16x16=null,this._tile_x=0,this._tile_y=0,Util.set_defaults(this,t,{true_color:!0,colourMap:[],scale:1,viewport:!1,render_mode:""}),Util.Debug(">> Display.constructor"),!this._target)throw new Error("Target must be set");if("string"==typeof this._target)throw new Error("target must be a DOM element");if(!this._target.getContext)throw new Error("no getContext method");if(this._drawCtx||(this._drawCtx=this._target.getContext("2d")),Util.Debug("User Agent: "+navigator.userAgent),Util.Engine.gecko&&Util.Debug("Browser: gecko "+Util.Engine.gecko),Util.Engine.webkit&&Util.Debug("Browser: webkit "+Util.Engine.webkit),Util.Engine.trident&&Util.Debug("Browser: trident "+Util.Engine.trident),Util.Engine.presto&&Util.Debug("Browser: presto "+Util.Engine.presto),this.clear(),!("createImageData"in this._drawCtx))throw new Error("Canvas does not support createImageData");this._render_mode="canvas rendering",null===this._prefer_js&&(Util.Info("Prefering javascript operations"),this._prefer_js=!0),(this._cursor_uri||null===this._cursor_uri||void 0===this._cursor_uri)&&(this._cursor_uri=Util.browserSupportsCursorURIs()),Util.Debug("<< Display.constructor")},Display.prototype={viewportChangePos:function(t,i){var e=this._viewportLoc;t=Math.floor(t),i=Math.floor(i),this._viewport||(t=-e.w,i=-e.h);var h=e.x+e.w-1,r=e.y+e.h-1;if(t<0&&e.x+t<0&&(t=-e.x),h+t>=this._fb_width&&(t-=h+t-this._fb_width+1),e.y+i<0&&(i=-e.y),r+i>=this._fb_height&&(i-=r+i-this._fb_height+1),0!==t||0!==i){Util.Debug("viewportChange deltaX: "+t+", deltaY: "+i),e.x+=t,h+=t,e.y+=i,r+=i;var s=this._cleanRect;e.x>s.x1&&(s.x1=e.x),hs.y1&&(s.y1=e.y),rthis._maxWidth&&(t=this._maxWidth),0!==this._maxHeight&&i>this._maxHeight&&(i=this._maxHeight));var h=this._cleanRect;te.x+t-1&&(h.x2=e.x+t-1),ie.y+i-1&&(h.y2=e.y+i-1),e.w=t,e.h=i;var r=this._target;if(r.width!==t||r.height!==i){var s=null;if(e.w>0&&e.h>0&&r.width>0&&r.height>0){var a=r.width=i.x2||i.y1>=i.y2)h.push({x:t.x,y:t.y,w:t.w,h:t.h});else{var r=t.x+t.w-1,s=t.y+t.h-1;t.xi.x2&&h.push({x:i.x2+1,y:t.y,w:r-i.x2,h:t.h}),t.yi.y2&&h.push({x:i.x1,y:i.y2+1,w:i.x2-i.x1+1,h:s-i.y2})}return this._cleanRect={x1:t.x,y1:t.y,x2:t.x+t.w-1,y2:t.y+t.h-1},{cleanBox:e,dirtyBoxes:h}},absX:function(t){return t+this._viewportLoc.x},absY:function(t){return t+this._viewportLoc.y},resize:function(t,i){this._prevDrawStyle="",this._fb_width=t,this._fb_height=i,this._rescale(this._scale),this.viewportChangeSize()},clear:function(){this._logo?(this.resize(this._logo.width,this._logo.height),this.blitStringImage(this._logo.data,0,0)):(6===Util.Engine.trident&&this._drawCtx.clearRect(0,0,this._viewportLoc.w,this._viewportLoc.h),this.resize(240,20),this._drawCtx.clearRect(0,0,this._viewportLoc.w,this._viewportLoc.h)),this._renderQ=[]},fillRect:function(t,i,e,h,r,s){0===this._renderQ.length||s?(this._setFillColor(r),this._drawCtx.fillRect(t-this._viewportLoc.x,i-this._viewportLoc.y,e,h)):this.renderQ_push({type:"fill",x:t,y:i,width:e,height:h,color:r})},copyImage:function(t,i,e,h,r,s,a){if(0===this._renderQ.length||a){var o=t-this._viewportLoc.x,_=i-this._viewportLoc.y,n=e-this._viewportLoc.x,l=h-this._viewportLoc.y;this._drawCtx.drawImage(this._target,o,_,r,s,n,l,r,s)}else this.renderQ_push({type:"copy",old_x:t,old_y:i,x:e,y:h,width:r,height:s})},startTile:function(t,i,e,h,r){if(this._tile_x=t,this._tile_y=i,this._tile=16===e&&16===h?this._tile16x16:this._drawCtx.createImageData(e,h),this._prefer_js){var s;s=this._true_color?r:this._colourMap[r[0]];for(var a=s[2],o=s[1],_=s[0],n=this._tile.data,l=0;lt.w||this._fb_height>t.h,e=0!==this._maxWidth&&0!==this._maxHeight,h=!1;return e&&(h=t.w>this._maxWidth||t.h>this._maxHeight),i||e&&h},get_context:function(){return this._drawCtx},set_scale:function(t){this._rescale(t)},set_width:function(t){this._fb_width=t},get_width:function(){return this._fb_width},set_height:function(t){this._fb_height=t},get_height:function(){return this._fb_height},autoscale:function(t,i,e){var h,r=t/i,s=this._fb_width/this._fb_height;h=s>=r?t/this._fb_width:i/this._fb_height;var a,o;return h>1&&e?(a=this._fb_width,o=this._fb_height,h=1):s>=r?(a=t,o=Math.round(t/s)):(a=Math.round(i*s),o=i),this._target.style.width=a+"px",this._target.style.height=o+"px",this._scale=h,h},_rescale:function(t){this._scale=t;var i,e;this._viewport&&0!==this._maxWidth&&0!==this._maxHeight?(i=Math.min(this._fb_width,this._maxWidth),e=Math.min(this._fb_height,this._maxHeight)):(i=this._fb_width,e=this._fb_height),this._target.style.width=Math.round(t*i)+"px",this._target.style.height=Math.round(t*e)+"px"},_setFillColor:function(t){var i;i=this._true_color?t:this._colourMap[t];var e="rgb("+i[2]+","+i[1]+","+i[0]+")";e!==this._prevDrawStyle&&(this._drawCtx.fillStyle=e,this._prevDrawStyle=e)},_rgbImageData:function(t,i,e,h,r,s,a,o){for(var _=this._drawCtx.createImageData(r,s),n=_.data,l=0,g=o;l0;){var i=this._renderQ[0];switch(i.type){case"copy":this.copyImage(i.old_x,i.old_y,i.x,i.y,i.width,i.height,!0);break;case"fill":this.fillRect(i.x,i.y,i.width,i.height,i.color,!0);break;case"blit":this.blitImage(i.x,i.y,i.width,i.height,i.data,0,!0);break;case"blitRgb":this.blitRgbImage(i.x,i.y,i.width,i.height,i.data,0,!0);break;case"blitRgbx":this.blitRgbxImage(i.x,i.y,i.width,i.height,i.data,0,!0);break;case"img":i.img.complete?this.drawImage(i.img,i.x,i.y):t=!1}t&&this._renderQ.shift()}this._renderQ.length>0&&requestAnimFrame(this._scan_renderQ.bind(this))}},Util.make_properties(Display,[["target","wo","dom"],["context","ro","raw"],["logo","rw","raw"],["true_color","rw","bool"],["colourMap","rw","arr"],["scale","rw","float"],["viewport","rw","bool"],["width","rw","int"],["height","rw","int"],["maxWidth","rw","int"],["maxHeight","rw","int"],["render_mode","ro","str"],["prefer_js","rw","str"],["cursor_uri","rw","raw"]]),Display.changeCursor=function(t,i,e,h,r,s,a,o){var _=s,n=a;n<_?n=_:_=n;var l=[];l.push16le=function(t){this.push(255&t,t>>8&255)},l.push32le=function(t){this.push(255&t,t>>8&255,t>>16&255,t>>24&255)};var g=_*n*4,w=Math.ceil(_*n/8),c=Math.ceil(_*n/8);l.push16le(0),l.push16le(2),l.push16le(1),l.push(_),l.push(n),l.push(0),l.push(0),l.push16le(h),l.push16le(r),l.push32le(40+g+w+c),l.push32le(22),l.push32le(40),l.push32le(_),l.push32le(2*n),l.push16le(1),l.push16le(32),l.push32le(0),l.push32le(w+c),l.push32le(0),l.push32le(0),l.push32le(0),l.push32le(0);var u,d;for(u=n-1;u>=0;u--)for(d=0;d<_;d++)if(d>=s||u>=a)l.push(0),l.push(0),l.push(0),l.push(0);else{var p=u*Math.ceil(s/8)+Math.floor(d/8),x=e[p]<