@@ -28,11 +28,54 @@ import { convertEndian32, Endianness } from "#src/util/endian.js";
2828import { verifyOptionalString } from "#src/util/json.js" ;
2929import { Signal } from "#src/util/signal.js" ;
3030import { getCachedJson } from "#src/util/trackable.js" ;
31+ import { ScreenshotMode } from "#src/util/trackable_screenshot_mode.js" ;
32+ import type { ResolutionMetadata } from "#src/util/viewer_resolution_stats.js" ;
33+ import { getViewerResolutionMetadata } from "#src/util/viewer_resolution_stats.js" ;
3134import type { Viewer } from "#src/viewer.js" ;
3235
36+ export interface ScreenshotResult {
37+ id : string ;
38+ image : string ;
39+ imageType : string ;
40+ depthData : string | undefined ;
41+ width : number ;
42+ height : number ;
43+ resolutionMetadata : ResolutionMetadata ;
44+ }
45+
46+ export interface ScreenshotActionState {
47+ viewerState : any ;
48+ selectedValues : any ;
49+ screenshot : ScreenshotResult ;
50+ }
51+
52+ export interface ScreenshotChunkStatistics {
53+ downloadLatency : number ;
54+ visibleChunksDownloading : number ;
55+ visibleChunksFailed : number ;
56+ visibleChunksGpuMemory : number ;
57+ visibleChunksSystemMemory : number ;
58+ visibleChunksTotal : number ;
59+ visibleGpuMemory : number ;
60+ }
61+
62+ export interface StatisticsActionState {
63+ viewerState : any ;
64+ selectedValues : any ;
65+ screenshotStatistics : {
66+ id : string ;
67+ chunkSources : any [ ] ;
68+ total : ScreenshotChunkStatistics ;
69+ } ;
70+ }
71+
3372export class ScreenshotHandler extends RefCounted {
34- sendScreenshotRequested = new Signal < ( state : any ) => void > ( ) ;
35- sendStatisticsRequested = new Signal < ( state : any ) => void > ( ) ;
73+ sendScreenshotRequested = new Signal <
74+ ( state : ScreenshotActionState ) => void
75+ > ( ) ;
76+ sendStatisticsRequested = new Signal <
77+ ( state : StatisticsActionState ) => void
78+ > ( ) ;
3679 requestState = new TrackableValue < string | undefined > (
3780 undefined ,
3881 verifyOptionalString ,
@@ -124,12 +167,14 @@ export class ScreenshotHandler extends RefCounted {
124167 return ;
125168 }
126169 const { viewer } = this ;
127- if ( ! viewer . isReady ( ) ) {
170+ const shouldForceScreenshot =
171+ this . viewer . display . screenshotMode . value === ScreenshotMode . FORCE ;
172+ if ( ! viewer . isReady ( ) && ! shouldForceScreenshot ) {
128173 this . wasAlreadyVisible = false ;
129174 this . throttledSendStatistics ( requestState ) ;
130175 return ;
131176 }
132- if ( ! this . wasAlreadyVisible ) {
177+ if ( ! this . wasAlreadyVisible && ! shouldForceScreenshot ) {
133178 this . throttledSendStatistics ( requestState ) ;
134179 this . wasAlreadyVisible = true ;
135180 this . debouncedMaybeSendScreenshot ( ) ;
@@ -140,6 +185,7 @@ export class ScreenshotHandler extends RefCounted {
140185 this . throttledSendStatistics . cancel ( ) ;
141186 viewer . display . draw ( ) ;
142187 const screenshotData = viewer . display . canvas . toDataURL ( ) ;
188+ const resolutionMetadata = getViewerResolutionMetadata ( viewer ) ;
143189 const { width, height } = viewer . display . canvas ;
144190 const prefix = "data:image/png;base64," ;
145191 let imageType : string ;
@@ -169,6 +215,7 @@ export class ScreenshotHandler extends RefCounted {
169215 depthData,
170216 width,
171217 height,
218+ resolutionMetadata,
172219 } ,
173220 } ;
174221
0 commit comments