@@ -62,7 +62,7 @@ import * as binaryop_gpu from './binaryop_gpu';
6262import { BinaryOpProgram } from './binaryop_gpu' ;
6363import * as binaryop_packed_gpu from './binaryop_packed_gpu' ;
6464import { BinaryOpPackedProgram } from './binaryop_packed_gpu' ;
65- import { getWebGLContext , createCanvas } from './canvas_util' ;
65+ import { createCanvas , getWebGLContext } from './canvas_util' ;
6666import { ClipProgram } from './clip_gpu' ;
6767import { ClipPackedProgram } from './clip_packed_gpu' ;
6868import { ComplexAbsProgram } from './complex_abs_gpu' ;
@@ -222,8 +222,8 @@ export class MathBackendWebGL implements KernelBackend {
222222 private numBytesInGPU = 0 ;
223223
224224 private canvas : HTMLCanvasElement ;
225- private fromPixels2DContext : CanvasRenderingContext2D
226- | OffscreenCanvasRenderingContext2D ;
225+ private fromPixels2DContext : CanvasRenderingContext2D |
226+ OffscreenCanvasRenderingContext2D ;
227227
228228 private programTimersStack : TimerNode [ ] ;
229229 private activeTimers : TimerNode [ ] ;
@@ -272,36 +272,35 @@ export class MathBackendWebGL implements KernelBackend {
272272 }
273273
274274 fromPixels (
275- pixels : PixelData | ImageData | HTMLImageElement | HTMLCanvasElement |
276- HTMLVideoElement ,
277- numChannels : number ) : Tensor3D {
275+ pixels : PixelData | ImageData | HTMLImageElement | HTMLCanvasElement |
276+ HTMLVideoElement ,
277+ numChannels : number ) : Tensor3D {
278278 if ( pixels == null ) {
279279 throw new Error (
280280 'pixels passed to tf.browser.fromPixels() can not be null' ) ;
281281 }
282282 const texShape : [ number , number ] = [ pixels . height , pixels . width ] ;
283283 const outShape = [ pixels . height , pixels . width , numChannels ] ;
284284
285- const isCanvas = ( typeof ( OffscreenCanvas ) !== 'undefined'
286- && pixels instanceof OffscreenCanvas )
287- || ( typeof ( HTMLCanvasElement ) !== 'undefined'
288- && pixels instanceof HTMLCanvasElement ) ;
285+ const isCanvas = ( typeof ( OffscreenCanvas ) !== 'undefined' &&
286+ pixels instanceof OffscreenCanvas ) ||
287+ ( typeof ( HTMLCanvasElement ) !== 'undefined' &&
288+ pixels instanceof HTMLCanvasElement ) ;
289289 const isPixelData = ( pixels as PixelData ) . data instanceof Uint8Array ;
290290 const isImageData =
291- typeof ( ImageData ) !== 'undefined' && pixels instanceof ImageData ;
292- const isVideo =
293- typeof ( HTMLVideoElement ) !== 'undefined'
294- && pixels instanceof HTMLVideoElement ;
295- const isImage = typeof ( HTMLImageElement ) !== 'undefined'
296- && pixels instanceof HTMLImageElement ;
291+ typeof ( ImageData ) !== 'undefined' && pixels instanceof ImageData ;
292+ const isVideo = typeof ( HTMLVideoElement ) !== 'undefined' &&
293+ pixels instanceof HTMLVideoElement ;
294+ const isImage = typeof ( HTMLImageElement ) !== 'undefined' &&
295+ pixels instanceof HTMLImageElement ;
297296
298297 if ( ! isCanvas && ! isPixelData && ! isImageData && ! isVideo && ! isImage ) {
299298 throw new Error (
300- 'pixels passed to tf.browser.fromPixels() must be either an ' +
301- `HTMLVideoElement, HTMLImageElement, HTMLCanvasElement, ImageData ` +
302- `in browser, or OffscreenCanvas, ImageData in webworker` +
303- ` or {data: Uint32Array, width: number, height: number}, ` +
304- `but was ${ ( pixels as { } ) . constructor . name } ` ) ;
299+ 'pixels passed to tf.browser.fromPixels() must be either an ' +
300+ `HTMLVideoElement, HTMLImageElement, HTMLCanvasElement, ImageData ` +
301+ `in browser, or OffscreenCanvas, ImageData in webworker` +
302+ ` or {data: Uint32Array, width: number, height: number}, ` +
303+ `but was ${ ( pixels as { } ) . constructor . name } ` ) ;
305304 }
306305
307306 if ( isImage || isVideo ) {
@@ -314,14 +313,14 @@ export class MathBackendWebGL implements KernelBackend {
314313 'on the document object' ) ;
315314 }
316315 //@ts -ignore
317- this . fromPixels2DContext = createCanvas ( ENV . getNumber ( 'WEBGL_VERSION' ) )
318- . getContext ( '2d' ) ;
316+ this . fromPixels2DContext =
317+ createCanvas ( ENV . getNumber ( 'WEBGL_VERSION' ) ) . getContext ( '2d' ) ;
319318 }
320319 this . fromPixels2DContext . canvas . width = pixels . width ;
321320 this . fromPixels2DContext . canvas . height = pixels . height ;
322321 this . fromPixels2DContext . drawImage (
323- pixels as HTMLVideoElement , 0 , 0 , pixels . width , pixels . height ) ;
324- //@ts -ignore
322+ pixels as HTMLVideoElement , 0 , 0 , pixels . width , pixels . height ) ;
323+ //@ts -ignore
325324 pixels = this . fromPixels2DContext . canvas ;
326325 }
327326
@@ -398,7 +397,7 @@ export class MathBackendWebGL implements KernelBackend {
398397 const shouldTimeProgram = this . activeTimers != null ;
399398 let start : number ;
400399 if ( shouldTimeProgram ) {
401- start = performance . now ( ) ;
400+ start = util . now ( ) ;
402401 }
403402
404403 let result : Float32Array ;
@@ -411,7 +410,7 @@ export class MathBackendWebGL implements KernelBackend {
411410 }
412411
413412 if ( shouldTimeProgram ) {
414- this . downloadWaitMs += performance . now ( ) - start ;
413+ this . downloadWaitMs += util . now ( ) - start ;
415414 }
416415 return this . convertAndCacheOnCPU ( dataId , result ) ;
417416 }
@@ -593,15 +592,15 @@ export class MathBackendWebGL implements KernelBackend {
593592 if ( ENV . getNumber ( 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION' ) > 0 ) {
594593 return this . gpgpu . beginQuery ( ) ;
595594 }
596- return { startMs : performance . now ( ) , endMs : null } ;
595+ return { startMs : util . now ( ) , endMs : null } ;
597596 }
598597
599598 private endTimer ( query : WebGLQuery | CPUTimerQuery ) : WebGLQuery | CPUTimerQuery {
600599 if ( ENV . getNumber ( 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION' ) > 0 ) {
601600 this . gpgpu . endQuery ( ) ;
602601 return query ;
603602 }
604- ( query as CPUTimerQuery ) . endMs = performance . now ( ) ;
603+ ( query as CPUTimerQuery ) . endMs = util . now ( ) ;
605604 return query ;
606605 }
607606
@@ -2553,7 +2552,7 @@ export class MathBackendWebGL implements KernelBackend {
25532552 const shouldTimeProgram = this . activeTimers != null ;
25542553 let start : number ;
25552554 if ( shouldTimeProgram ) {
2556- start = performance . now ( ) ;
2555+ start = util . now ( ) ;
25572556 }
25582557
25592558 let texShape = texData . texShape ;
@@ -2613,7 +2612,7 @@ export class MathBackendWebGL implements KernelBackend {
26132612 // Once uploaded, don't store the values on cpu.
26142613 texData . values = null ;
26152614 if ( shouldTimeProgram ) {
2616- this . uploadWaitMs += performance . now ( ) - start ;
2615+ this . uploadWaitMs += util . now ( ) - start ;
26172616 }
26182617 } else {
26192618 const newTexture = this . acquireTexture ( texShape , usage , dtype , isPacked ) ;
0 commit comments