@@ -62,7 +62,7 @@ import * as binaryop_gpu from './binaryop_gpu';
62
62
import { BinaryOpProgram } from './binaryop_gpu' ;
63
63
import * as binaryop_packed_gpu from './binaryop_packed_gpu' ;
64
64
import { BinaryOpPackedProgram } from './binaryop_packed_gpu' ;
65
- import { getWebGLContext , createCanvas } from './canvas_util' ;
65
+ import { createCanvas , getWebGLContext } from './canvas_util' ;
66
66
import { ClipProgram } from './clip_gpu' ;
67
67
import { ClipPackedProgram } from './clip_packed_gpu' ;
68
68
import { ComplexAbsProgram } from './complex_abs_gpu' ;
@@ -222,8 +222,8 @@ export class MathBackendWebGL implements KernelBackend {
222
222
private numBytesInGPU = 0 ;
223
223
224
224
private canvas : HTMLCanvasElement ;
225
- private fromPixels2DContext : CanvasRenderingContext2D
226
- | OffscreenCanvasRenderingContext2D ;
225
+ private fromPixels2DContext : CanvasRenderingContext2D |
226
+ OffscreenCanvasRenderingContext2D ;
227
227
228
228
private programTimersStack : TimerNode [ ] ;
229
229
private activeTimers : TimerNode [ ] ;
@@ -272,36 +272,35 @@ export class MathBackendWebGL implements KernelBackend {
272
272
}
273
273
274
274
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 {
278
278
if ( pixels == null ) {
279
279
throw new Error (
280
280
'pixels passed to tf.browser.fromPixels() can not be null' ) ;
281
281
}
282
282
const texShape : [ number , number ] = [ pixels . height , pixels . width ] ;
283
283
const outShape = [ pixels . height , pixels . width , numChannels ] ;
284
284
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 ) ;
289
289
const isPixelData = ( pixels as PixelData ) . data instanceof Uint8Array ;
290
290
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 ;
297
296
298
297
if ( ! isCanvas && ! isPixelData && ! isImageData && ! isVideo && ! isImage ) {
299
298
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 } ` ) ;
305
304
}
306
305
307
306
if ( isImage || isVideo ) {
@@ -314,14 +313,14 @@ export class MathBackendWebGL implements KernelBackend {
314
313
'on the document object' ) ;
315
314
}
316
315
//@ts -ignore
317
- this . fromPixels2DContext = createCanvas ( ENV . getNumber ( 'WEBGL_VERSION' ) )
318
- . getContext ( '2d' ) ;
316
+ this . fromPixels2DContext =
317
+ createCanvas ( ENV . getNumber ( 'WEBGL_VERSION' ) ) . getContext ( '2d' ) ;
319
318
}
320
319
this . fromPixels2DContext . canvas . width = pixels . width ;
321
320
this . fromPixels2DContext . canvas . height = pixels . height ;
322
321
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
325
324
pixels = this . fromPixels2DContext . canvas ;
326
325
}
327
326
@@ -398,7 +397,7 @@ export class MathBackendWebGL implements KernelBackend {
398
397
const shouldTimeProgram = this . activeTimers != null ;
399
398
let start : number ;
400
399
if ( shouldTimeProgram ) {
401
- start = performance . now ( ) ;
400
+ start = util . now ( ) ;
402
401
}
403
402
404
403
let result : Float32Array ;
@@ -411,7 +410,7 @@ export class MathBackendWebGL implements KernelBackend {
411
410
}
412
411
413
412
if ( shouldTimeProgram ) {
414
- this . downloadWaitMs += performance . now ( ) - start ;
413
+ this . downloadWaitMs += util . now ( ) - start ;
415
414
}
416
415
return this . convertAndCacheOnCPU ( dataId , result ) ;
417
416
}
@@ -593,15 +592,15 @@ export class MathBackendWebGL implements KernelBackend {
593
592
if ( ENV . getNumber ( 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION' ) > 0 ) {
594
593
return this . gpgpu . beginQuery ( ) ;
595
594
}
596
- return { startMs : performance . now ( ) , endMs : null } ;
595
+ return { startMs : util . now ( ) , endMs : null } ;
597
596
}
598
597
599
598
private endTimer ( query : WebGLQuery | CPUTimerQuery ) : WebGLQuery | CPUTimerQuery {
600
599
if ( ENV . getNumber ( 'WEBGL_DISJOINT_QUERY_TIMER_EXTENSION_VERSION' ) > 0 ) {
601
600
this . gpgpu . endQuery ( ) ;
602
601
return query ;
603
602
}
604
- ( query as CPUTimerQuery ) . endMs = performance . now ( ) ;
603
+ ( query as CPUTimerQuery ) . endMs = util . now ( ) ;
605
604
return query ;
606
605
}
607
606
@@ -2553,7 +2552,7 @@ export class MathBackendWebGL implements KernelBackend {
2553
2552
const shouldTimeProgram = this . activeTimers != null ;
2554
2553
let start : number ;
2555
2554
if ( shouldTimeProgram ) {
2556
- start = performance . now ( ) ;
2555
+ start = util . now ( ) ;
2557
2556
}
2558
2557
2559
2558
let texShape = texData . texShape ;
@@ -2613,7 +2612,7 @@ export class MathBackendWebGL implements KernelBackend {
2613
2612
// Once uploaded, don't store the values on cpu.
2614
2613
texData . values = null ;
2615
2614
if ( shouldTimeProgram ) {
2616
- this . uploadWaitMs += performance . now ( ) - start ;
2615
+ this . uploadWaitMs += util . now ( ) - start ;
2617
2616
}
2618
2617
} else {
2619
2618
const newTexture = this . acquireTexture ( texShape , usage , dtype , isPacked ) ;
0 commit comments