@@ -245,38 +245,6 @@ function FPSTracker(text) {
245245 }
246246}
247247
248- function Element ( ) {
249- throw 'TODO: Element'
250- }
251- function HTMLCanvasElement ( ) {
252- throw 'TODO: HTMLCanvasElement'
253- }
254- function HTMLVideoElement ( ) {
255- throw 'TODO: HTMLVideoElement'
256- }
257-
258- var KeyboardEvent = {
259- 'DOM_KEY_LOCATION_RIGHT' : 2 ,
260- } ;
261-
262- function PropertyBag ( ) {
263- this . addProperty = function ( ) {
264- } ;
265- this . removeProperty = function ( ) {
266- } ;
267- this . setProperty = function ( ) {
268- } ;
269- } ;
270-
271- var IndexedObjects = {
272- nextId : 1 ,
273- cache : { } ,
274- add : function ( object ) {
275- object . id = this . nextId ++ ;
276- this . cache [ object . id ] = object ;
277- }
278- } ;
279-
280248/**
281249 * Parse the content of an .ass file.
282250 * @param {!string } content the content of the file
@@ -338,69 +306,6 @@ function parseAss(content) {
338306 return sections ;
339307} ;
340308
341- function EventListener ( ) {
342- this . listeners = { } ;
343-
344- this . addEventListener = function addEventListener ( event , func ) {
345- if ( ! this . listeners [ event ] ) this . listeners [ event ] = [ ] ;
346- this . listeners [ event ] . push ( func ) ;
347- } ;
348-
349- this . removeEventListener = function ( event , func ) {
350- var list = this . listeners [ event ] ;
351- if ( ! list ) return ;
352- var me = list . indexOf ( func ) ;
353- if ( me < 0 ) return ;
354- list . splice ( me , 1 ) ;
355- } ;
356-
357- this . fireEvent = function fireEvent ( event ) {
358- event . preventDefault = function ( ) {
359- } ;
360-
361- if ( event . type in this . listeners ) {
362- this . listeners [ event . type ] . forEach ( function ( listener ) {
363- listener ( event ) ;
364- } ) ;
365- }
366- } ;
367- }
368-
369- function Image ( ) {
370- IndexedObjects . add ( this ) ;
371- EventListener . call ( this ) ;
372- var src = '' ;
373- Object . defineProperty ( this , 'src' , {
374- set : function ( value ) {
375- src = value ;
376- assert ( this . id ) ;
377- postMessage ( { target : 'Image' , method : 'src' , src : src , id : this . id } ) ;
378- } ,
379- get : function ( ) {
380- return src ;
381- }
382- } ) ;
383- }
384- Image . prototype . onload = function ( ) {
385- } ;
386- Image . prototype . onerror = function ( ) {
387- } ;
388-
389- var HTMLImageElement = Image ;
390- var windowExtra = new EventListener ( ) ;
391- for ( var x in windowExtra ) self [ x ] = windowExtra [ x ] ;
392-
393- self . close = function window_close ( ) {
394- postMessage ( { target : 'window' , method : 'close' } ) ;
395- } ;
396-
397- self . alert = function ( text ) {
398- Module . printErr ( 'alert forever: ' + text ) ;
399- while ( 1 ) {
400- }
401- ;
402- } ;
403-
404309self . scrollX = self . scrollY = 0 ; // TODO: proxy these
405310
406311self . requestAnimationFrame = ( function ( ) {
@@ -422,178 +327,16 @@ self.requestAnimationFrame = (function () {
422327 } ;
423328} ) ( ) ;
424329
425- var document = new EventListener ( ) ;
426-
427- document . createElement = function document_createElement ( what ) {
428- switch ( what ) {
429- case 'canvas' : {
430- var canvas = new EventListener ( ) ;
431- canvas . ensureData = function canvas_ensureData ( ) {
432- if ( ! canvas . data || canvas . data . width !== canvas . width || canvas . data . height !== canvas . height ) {
433- canvas . data = {
434- width : canvas . width ,
435- height : canvas . height ,
436- data : new Uint8ClampedArray ( canvas . width * canvas . height * 4 )
437- } ;
438- if ( canvas === Module [ 'canvas' ] ) {
439- postMessage ( { target : 'canvas' , op : 'resize' , width : canvas . width , height : canvas . height } ) ;
440- }
441- }
442- if ( canvas . data . data . length == 0 ) {
443- canvas . data . data = new Uint8ClampedArray ( canvas . width * canvas . height * 4 ) ;
444- }
445- } ;
446- canvas . getContext = function canvas_getContext ( type , attributes ) {
447- if ( canvas === Module [ 'canvas' ] ) {
448- postMessage ( { target : 'canvas' , op : 'getContext' , type : type , attributes : attributes } ) ;
449- }
450- if ( type === '2d' ) {
451- return {
452- getImageData : function ( x , y , w , h ) {
453- assert ( x == 0 && y == 0 && w == canvas . width && h == canvas . height ) ;
454- canvas . ensureData ( ) ;
455- return canvas . data ;
456- /*return {
457- width: canvas.data.width,
458- height: canvas.data.height,
459- data: new Uint8Array(canvas.data.data) // TODO: can we avoid this copy?
460- };*/
461- } ,
462- putImageData : function ( image , x , y ) {
463- canvas . ensureData ( ) ;
464- assert ( x == 0 && y == 0 && image . width == canvas . width && image . height == canvas . height ) ;
465- //canvas.data.data.set(image.data); // TODO: can we avoid this copy?
466- canvas . data . data = image . data ;
467- if ( canvas === Module [ 'canvas' ] ) {
468- //postMessage({target: 'canvas', op: 'render', image: canvas.data});
469-
470- postMessage ( {
471- target : 'canvas' ,
472- op : 'render' ,
473- buffer : canvas . data . data . buffer
474- } , [ canvas . data . data . buffer ] ) ;
475- canvas . data . data = new Uint8ClampedArray ( canvas . width * canvas . height * 4 ) ;
476- }
477- } ,
478- drawImage : function ( image , x , y , w , h , ox , oy , ow , oh ) {
479- assert ( ! x && ! y && ! ox && ! oy ) ;
480- assert ( w === ow && h === oh ) ;
481- assert ( canvas . width === w || w === undefined ) ;
482- assert ( canvas . height === h || h === undefined ) ;
483- assert ( image . width === canvas . width && image . height === canvas . height ) ;
484- canvas . ensureData ( ) ;
485- canvas . data . data . set ( image . data . data ) ; // TODO: can we avoid this copy?
486- if ( canvas === Module [ 'canvas' ] ) {
487- postMessage ( { target : 'canvas' , op : 'render' , image : canvas . data } ) ;
488- }
489- }
490- } ;
491- } else {
492- return null ;
493- }
494- } ;
495- canvas . boundingClientRect = { } ;
496- canvas . getBoundingClientRect = function canvas_getBoundingClientRect ( ) {
497- return {
498- width : canvas . boundingClientRect . width ,
499- height : canvas . boundingClientRect . height ,
500- top : canvas . boundingClientRect . top ,
501- left : canvas . boundingClientRect . left ,
502- bottom : canvas . boundingClientRect . bottom ,
503- right : canvas . boundingClientRect . right
504- } ;
505- } ;
506- canvas . style = new PropertyBag ( ) ;
507- canvas . exitPointerLock = function ( ) {
508- } ;
509-
510- canvas . width_ = canvas . width_ || 0 ;
511- canvas . height_ = canvas . height_ || 0 ;
512- Object . defineProperty ( canvas , 'width' , {
513- set : function ( value ) {
514- canvas . width_ = value ;
515- if ( canvas === Module [ 'canvas' ] ) {
516- postMessage ( { target : 'canvas' , op : 'resize' , width : canvas . width_ , height : canvas . height_ } ) ;
517- }
518- } ,
519- get : function ( ) {
520- return canvas . width_ ;
521- }
522- } ) ;
523- Object . defineProperty ( canvas , 'height' , {
524- set : function ( value ) {
525- canvas . height_ = value ;
526- if ( canvas === Module [ 'canvas' ] ) {
527- postMessage ( { target : 'canvas' , op : 'resize' , width : canvas . width_ , height : canvas . height_ } ) ;
528- }
529- } ,
530- get : function ( ) {
531- return canvas . height_ ;
532- }
533- } ) ;
534-
535- var style = {
536- parentCanvas : canvas ,
537- removeProperty : function ( ) {
538- } ,
539- setProperty : function ( ) {
540- } ,
541- } ;
542-
543- Object . defineProperty ( style , 'cursor' , {
544- set : function ( value ) {
545- if ( ! style . cursor_ || style . cursor_ !== value ) {
546- style . cursor_ = value ;
547- if ( style . parentCanvas === Module [ 'canvas' ] ) {
548- postMessage ( {
549- target : 'canvas' ,
550- op : 'setObjectProperty' ,
551- object : 'style' ,
552- property : 'cursor' ,
553- value : style . cursor_
554- } ) ;
555- }
556- }
557- } ,
558- get : function ( ) {
559- return style . cursor_ ;
560- }
561- } ) ;
562-
563- canvas . style = style ;
564-
565- return canvas ;
566- }
567- default :
568- throw 'document.createElement ' + what ;
569- }
570- } ;
571-
572- document . getElementById = function ( id ) {
573- if ( id === 'canvas' || id === 'application-canvas' ) {
574- return Module . canvas ;
575- }
576- throw 'document.getElementById failed on ' + id ;
577- } ;
578-
579- document . documentElement = { } ;
580-
581- document . styleSheets = [ {
582- cssRules : [ ] , // TODO: forward to client
583- insertRule : function ( rule , i ) {
584- this . cssRules . splice ( i , 0 , rule ) ;
585- }
586- } ] ;
587-
588- document . URL = 'http://worker.not.yet.ready.wait.for.window.onload?fake' ;
330+ /*var screen = {
331+ width: 0,
332+ height: 0
333+ };*/
589334
590- var screen = {
335+ screen = {
591336 width : 0 ,
592337 height : 0
593338} ;
594339
595- //Module.canvas = document.createElement('canvas');
596-
597340Module . setStatus = function ( ) {
598341} ;
599342
@@ -610,6 +353,7 @@ Module.printErr = function Module_printErr(x) {
610353
611354var frameId = 0 ;
612355var clientFrameId = 0 ;
356+ var commandBuffer = [ ] ;
613357
614358var postMainLoop = Module [ 'postMainLoop' ] ;
615359Module [ 'postMainLoop' ] = function ( ) {
@@ -656,10 +400,6 @@ function onMessageFromMainEmscriptenThread(message) {
656400 }
657401 //console.log('worker got ' + JSON.stringify(message.data).substr(0, 150) + '\n');
658402 switch ( message . data . target ) {
659- case 'document' : {
660- document . fireEvent ( message . data . event ) ;
661- break ;
662- }
663403 case 'window' : {
664404 self . fireEvent ( message . data . event ) ;
665405 break ;
@@ -692,30 +432,6 @@ function onMessageFromMainEmscriptenThread(message) {
692432 clientFrameId = message . data . id ;
693433 break ;
694434 }
695- case 'Image' : {
696- var img = IndexedObjects . cache [ message . data . id ] ;
697- switch ( message . data . method ) {
698- case 'onload' : {
699- img . width = message . data . width ;
700- img . height = message . data . height ;
701- img . data = { width : img . width , height : img . height , data : message . data . data } ;
702- img . complete = true ;
703- img . onload ( ) ;
704- break ;
705- }
706- case 'onerror' : {
707- img . onerror ( { srcElement : img } ) ;
708- break ;
709- }
710- }
711- break ;
712- }
713- case 'IDBStore' : {
714- assert ( message . data . method === 'response' ) ;
715- assert ( IDBStore . pending ) ;
716- IDBStore . pending ( message . data ) ;
717- break ;
718- }
719435 case 'worker-init' : {
720436 //Module.canvas = document.createElement('canvas');
721437 screen . width = self . width = message . data . width ;
@@ -731,8 +447,6 @@ function onMessageFromMainEmscriptenThread(message) {
731447 Module . canvas . boundingClientRect = message . data . boundingClientRect ;
732448 }
733449 }
734- document . URL = message . data . URL ;
735- self . fireEvent ( { type : 'load' } ) ;
736450 removeRunDependency ( 'worker-init' ) ;
737451 break ;
738452 }
0 commit comments