Skip to content

Commit 12a319d

Browse files
committed
refactor(slideshow): extract color uniform logic into computeColor
Signed-off-by: codewithvk <vivek.javiya@collabora.com> Change-Id: I5fe84e0fed6f8fec09901b1a7b6351c2768ed4b0
1 parent c28c691 commit 12a319d

File tree

2 files changed

+51
-33
lines changed

2 files changed

+51
-33
lines changed

browser/src/slideshow/LayerRenderer.ts

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ interface LayerRenderer {
3131
getRenderContext(): RenderContext;
3232
}
3333

34+
interface RenderUniforms {
35+
bounds: BoundsType | null;
36+
alpha: number;
37+
fromFillColor: Float32Array;
38+
toFillColor: Float32Array;
39+
fromLineColor: Float32Array;
40+
toLineColor: Float32Array;
41+
}
42+
3443
class LayerRendererGl implements LayerRenderer {
3544
private static readonly DefaultVertices = [-1, -1, 1, -1, -1, 1, 1, 1];
3645
private static readonly DefaultFromColor = new Float32Array([0, 0, 0, 0]);
@@ -178,19 +187,9 @@ class LayerRendererGl implements LayerRenderer {
178187
}
179188
}
180189

181-
drawBitmap(
182-
imageInfo: ImageInfo | ImageBitmap,
190+
public static computeColor(
183191
properties?: AnimatedElementRenderProperties,
184-
): void {
185-
if (this.disposed) {
186-
console.log('LayerRenderer is disposed');
187-
return;
188-
}
189-
if (!imageInfo) {
190-
console.log('LayerRenderer.drawBitmap: no image');
191-
return;
192-
}
193-
192+
): RenderUniforms {
194193
let bounds: BoundsType = null;
195194
let alpha = 1.0;
196195
let fromFillColor = LayerRendererGl.DefaultFromColor;
@@ -212,6 +211,37 @@ class LayerRendererGl implements LayerRenderer {
212211
}
213212
}
214213
}
214+
return {
215+
bounds,
216+
alpha,
217+
fromFillColor,
218+
toFillColor,
219+
fromLineColor,
220+
toLineColor,
221+
};
222+
}
223+
224+
drawBitmap(
225+
imageInfo: ImageInfo | ImageBitmap,
226+
properties?: AnimatedElementRenderProperties,
227+
): void {
228+
if (this.disposed) {
229+
console.log('LayerRenderer is disposed');
230+
return;
231+
}
232+
if (!imageInfo) {
233+
console.log('LayerRenderer.drawBitmap: no image');
234+
return;
235+
}
236+
237+
const {
238+
bounds,
239+
alpha,
240+
fromFillColor,
241+
toFillColor,
242+
fromLineColor,
243+
toLineColor,
244+
} = LayerRendererGl.computeColor(properties);
215245

216246
let texture: WebGLTexture;
217247
let textureKey: string;

browser/src/slideshow/Transition2d.ts

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -183,27 +183,15 @@ class Transition2d extends TransitionBase {
183183
0,
184184
);
185185
} else {
186-
let bounds: BoundsType = null;
187-
let alpha = 1.0;
188-
let fromFillColor = Transition2d.DefaultFromColor;
189-
let toFillColor = Transition2d.DefaultToColor;
190-
let fromLineColor = Transition2d.DefaultFromColor;
191-
let toLineColor = Transition2d.DefaultToColor;
192-
if (properties) {
193-
bounds = properties.bounds;
194-
alpha = properties.alpha;
195-
const colorMap = properties.colorMap;
196-
if (colorMap) {
197-
if (colorMap.fromFillColor && colorMap.toFillColor) {
198-
fromFillColor = colorMap.fromFillColor.toFloat32Array();
199-
toFillColor = colorMap.toFillColor.toFloat32Array();
200-
}
201-
if (colorMap.fromLineColor && colorMap.toLineColor) {
202-
fromLineColor = colorMap.fromLineColor.toFloat32Array();
203-
toLineColor = colorMap.toLineColor.toFloat32Array();
204-
}
205-
}
206-
}
186+
const {
187+
bounds,
188+
alpha,
189+
fromFillColor,
190+
toFillColor,
191+
fromLineColor,
192+
toLineColor,
193+
} = LayerRendererGl.computeColor(properties);
194+
207195
console.debug(`Transition2d.render: alpha: ${alpha}`);
208196

209197
this.setPositionBuffer(bounds);

0 commit comments

Comments
 (0)