-
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathcompositor.test.ts
More file actions
141 lines (129 loc) · 3.88 KB
/
compositor.test.ts
File metadata and controls
141 lines (129 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import { describe, expect, it, vi } from 'vitest';
import { Compositor } from '../../src/engine/render/Compositor';
function makeRenderPass() {
return {
setPipeline: vi.fn(),
setBindGroup: vi.fn(),
draw: vi.fn(),
end: vi.fn(),
};
}
function makeLayerData() {
return [{
layer: {
id: 'layer-1',
maskClipId: undefined,
effects: [
{
id: 'fx-brightness',
name: 'Brightness',
type: 'brightness',
enabled: true,
params: { amount: 0.4 },
},
{
id: 'fx-blur',
name: 'Blur',
type: 'blur',
enabled: true,
params: { radius: 12 },
},
],
},
isVideo: false,
externalTexture: null,
textureView: { label: 'source-view' },
sourceWidth: 1920,
sourceHeight: 1080,
}] as any;
}
describe('Compositor scrub fast path', () => {
it('skips inline and complex effects while scrubbing', () => {
const updateLayerUniforms = vi.fn();
const applyEffects = vi.fn(() => ({
finalView: { label: 'effect-view' },
swapped: false,
}));
const compositor = new Compositor(
{
getOrCreateUniformBuffer: vi.fn(() => ({ label: 'ubo' })),
updateLayerUniforms,
getCompositePipeline: vi.fn(() => ({ label: 'pipeline' })),
createCompositeBindGroup: vi.fn(() => ({ label: 'bind-group' })),
getExternalCompositePipeline: vi.fn(),
createExternalCompositeBindGroup: vi.fn(),
invalidateBindGroupCache: vi.fn(),
} as any,
{ applyEffects } as any,
{
getMaskInfo: vi.fn(() => ({ hasMask: false, view: { label: 'mask' } })),
logMaskState: vi.fn(),
} as any
);
const commandEncoder = {
beginRenderPass: vi.fn(() => makeRenderPass()),
} as any;
compositor.composite(makeLayerData(), commandEncoder, {
device: {} as any,
sampler: {} as any,
pingView: { label: 'ping' } as any,
pongView: { label: 'pong' } as any,
outputWidth: 1920,
outputHeight: 1080,
skipEffects: true,
effectTempView: { label: 'tmp-a' } as any,
effectTempView2: { label: 'tmp-b' } as any,
});
expect(updateLayerUniforms.mock.calls[0][5]).toEqual({
brightness: 0,
contrast: 1,
saturation: 1,
invert: false,
});
expect(applyEffects).not.toHaveBeenCalled();
});
it('still applies layer effects when scrub fast path is disabled', () => {
const updateLayerUniforms = vi.fn();
const applyEffects = vi.fn(() => ({
finalView: { label: 'effect-view' },
swapped: false,
}));
const compositor = new Compositor(
{
getOrCreateUniformBuffer: vi.fn(() => ({ label: 'ubo' })),
updateLayerUniforms,
getCompositePipeline: vi.fn(() => ({ label: 'pipeline' })),
createCompositeBindGroup: vi.fn(() => ({ label: 'bind-group' })),
getExternalCompositePipeline: vi.fn(),
createExternalCompositeBindGroup: vi.fn(),
invalidateBindGroupCache: vi.fn(),
} as any,
{ applyEffects } as any,
{
getMaskInfo: vi.fn(() => ({ hasMask: false, view: { label: 'mask' } })),
logMaskState: vi.fn(),
} as any
);
const commandEncoder = {
beginRenderPass: vi.fn(() => makeRenderPass()),
} as any;
compositor.composite(makeLayerData(), commandEncoder, {
device: {} as any,
sampler: {} as any,
pingView: { label: 'ping' } as any,
pongView: { label: 'pong' } as any,
outputWidth: 1920,
outputHeight: 1080,
skipEffects: false,
effectTempView: { label: 'tmp-a' } as any,
effectTempView2: { label: 'tmp-b' } as any,
});
expect(updateLayerUniforms.mock.calls[0][5]).toEqual({
brightness: 0.4,
contrast: 1,
saturation: 1,
invert: false,
});
expect(applyEffects).toHaveBeenCalledTimes(1);
});
});