MCPcopy Index your code
hub / github.com/ChartGPU/ChartGPU / createGPUContext

Function createGPUContext

src/core/GPUContext.ts:86–109  ·  view source on GitHub ↗
(
  canvas?: SupportedCanvas,
  options?: GPUContextOptions
)

Source from the content-addressed store, hash-verified

84 * @returns A new GPUContextState instance
85 */
86export function createGPUContext(
87 canvas?: SupportedCanvas,
88 options?: GPUContextOptions
89): GPUContextState {
90 // Auto-detect DPR on main thread, default to 1.0 in workers
91 const dprRaw =
92 options?.devicePixelRatio ?? (typeof window !== 'undefined' ? window.devicePixelRatio : 1.0);
93 // Be resilient: callers may pass 0/NaN/Infinity. Fall back to 1 instead of throwing.
94 const dpr = Number.isFinite(dprRaw) && dprRaw > 0 ? dprRaw : 1.0;
95 const alphaMode = options?.alphaMode ?? 'opaque';
96 const powerPreference = options?.powerPreference ?? 'high-performance';
97
98 return {
99 adapter: null,
100 device: null,
101 initialized: false,
102 canvas: canvas || null,
103 canvasContext: null,
104 preferredFormat: null,
105 devicePixelRatio: dpr,
106 alphaMode,
107 powerPreference,
108 };
109}
110
111/**
112 * Initializes the WebGPU context by requesting an adapter and device.

Callers 4

initChartMethod · 0.90
createGPUContextAsyncFunction · 0.85
constructorMethod · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected