Skip to content

Commit

Permalink
animations engine porting: SlideShowNavigator + Presenter integration
Browse files Browse the repository at this point in the history
new Transition2d version:
remove timing handling, make render with respect to a time parameter.
SlideShowNavigator handles mouse and keyboard events.
Initial integration with SlideShowPresenter.

Signed-off-by: Marco Cecchetti <[email protected]>
Change-Id: I4d58a5d9aafa5472ffef0f1b70854ca24cabe8d7
  • Loading branch information
mcecchetti authored and eszkadev committed Sep 5, 2024
1 parent f3da41a commit 439f18e
Show file tree
Hide file tree
Showing 34 changed files with 771 additions and 251 deletions.
26 changes: 14 additions & 12 deletions browser/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -421,19 +421,17 @@ COOL_JS_LST =\
src/slideshow/RenderContext.ts \
src/slideshow/SlideRenderer.ts \
src/slideshow/SlideShowPresenter.ts \
src/slideshow/Transition2d.ts \
src/slideshow/RendererBase.ts \
src/slideshow/StaticTextRenderer.ts \
src/slideshow/PauseTimer.ts \
src/slideshow/PerformTransition.ts \
src/slideshow/SlideAnimations.ts \
src/slideshow/CanvasLoader.ts \
src/slideshow/Transition3d.ts \
src/slideshow/Operation.ts \
src/slideshow/Primitive.ts \
src/slideshow/types.ts \
src/slideshow/engine/ActivityFactory.ts \
src/slideshow/engine/ActivityQueue.ts \
src/slideshow/engine/AnimatedElement.ts \
src/slideshow/engine/AnimationFactory.ts \
src/slideshow/engine/Duration.ts \
src/slideshow/engine/Effect.ts \
Expand All @@ -448,32 +446,34 @@ COOL_JS_LST =\
src/slideshow/engine/SlideAnimations.ts \
src/slideshow/engine/SlideChangeBase.ts \
src/slideshow/engine/SlideShowHandler.ts \
src/slideshow/engine/SlideShowNavigator.ts \
src/slideshow/engine/SlideTransition.ts \
src/slideshow/engine/SourceEventElement.ts \
src/slideshow/engine/TimerEventQueue.ts \
src/slideshow/engine/Timing.ts \
src/slideshow/engine/tools.ts \
src/slideshow/engine/activities/ActivityBase.ts \
src/slideshow/engine/activities/AnimationActivity.ts \
src/slideshow/engine/activities/ActivityBase.ts \
src/slideshow/engine/activities/SimpleContinuousActivityBase.ts \
src/slideshow/engine/activities/ContinuousActivityBase.ts \
src/slideshow/engine/activities/ContinuousKeyTimeActivityBase.ts \
src/slideshow/engine/activities/DiscreteActivityBase.ts \
src/slideshow/engine/activities/FromToByActivity.ts \
src/slideshow/engine/activities/SetActivity.ts \
src/slideshow/engine/activities/SimpleActivity.ts \
src/slideshow/engine/activities/SimpleContinuousActivityBase.ts \
src/slideshow/engine/activities/ValueListActivity.ts \
src/slideshow/engine/animationnodes/BaseNode.ts \
src/slideshow/engine/animationnodes/AnimationBaseNode.ts \
src/slideshow/engine/animationnodes/AnimationColorNode.ts \
src/slideshow/engine/animationnodes/AnimationNodeInfo.ts \
src/slideshow/engine/animationnodes/AnimationSetNode.ts \
src/slideshow/engine/animationnodes/AnimationTransformNode.ts \
src/slideshow/engine/animationnodes/AnimationTransitionFilterNode.ts \
src/slideshow/engine/animationnodes/BaseContainerNode.ts \
src/slideshow/engine/animationnodes/BaseNode.ts \
src/slideshow/engine/animationnodes/NodeContext.ts \
src/slideshow/engine/animationnodes/PropertyAnimationNode.ts \
>>>>>>> 4a1df2faca (SlideShow Rework: initial porting of js animation engine to typescript)
src/slideshow/engine/AnimatedElement.ts \
src/slideshow/Transition2d.ts \
src/slideshow/transition/FadeTransition.ts \
src/slideshow/transition/PlusTransition.ts \
src/slideshow/transition/CircleTransition.ts \
Expand Down Expand Up @@ -970,13 +970,12 @@ pot:
src/slideshow/RenderContext.ts \
src/slideshow/SlideRenderer.ts \
src/slideshow/SlideShowPresenter.ts \
src/slideshow/Transition2d.ts \
src/slideshow/RendererBase.ts \
src/slideshow/StaticTextRenderer.ts \
src/slideshow/PauseTimer.ts \
src/slideshow/PerformTransition.ts \
src/slideshow/engine/ActivityFactory.ts \
src/slideshow/engine/ActivityQueue.ts \
src/slideshow/engine/AnimatedElement.ts \
src/slideshow/engine/AnimationFactory.ts \
src/slideshow/engine/Duration.ts \
src/slideshow/engine/Effect.ts \
Expand All @@ -991,31 +990,34 @@ pot:
src/slideshow/engine/SlideAnimations.ts \
src/slideshow/engine/SlideChangeBase.ts \
src/slideshow/engine/SlideShowHandler.ts \
src/slideshow/engine/SlideShowNavigator.ts \
src/slideshow/engine/SlideTransition.ts \
src/slideshow/engine/SourceEventElement.ts \
src/slideshow/engine/TimerEventQueue.ts \
src/slideshow/engine/Timing.ts \
src/slideshow/engine/tools.ts \
src/slideshow/engine/activities/ActivityBase.ts \
src/slideshow/engine/activities/AnimationActivity.ts \
src/slideshow/engine/activities/ActivityBase.ts \
src/slideshow/engine/activities/SimpleContinuousActivityBase.ts \
src/slideshow/engine/activities/ContinuousActivityBase.ts \
src/slideshow/engine/activities/ContinuousKeyTimeActivityBase.ts \
src/slideshow/engine/activities/DiscreteActivityBase.ts \
src/slideshow/engine/activities/FromToByActivity.ts \
src/slideshow/engine/activities/SetActivity.ts \
src/slideshow/engine/activities/SimpleActivity.ts \
src/slideshow/engine/activities/SimpleContinuousActivityBase.ts \
src/slideshow/engine/activities/ValueListActivity.ts \
src/slideshow/engine/animationnodes/BaseNode.ts \
src/slideshow/engine/animationnodes/AnimationBaseNode.ts \
src/slideshow/engine/animationnodes/AnimationColorNode.ts \
src/slideshow/engine/animationnodes/AnimationNodeInfo.ts \
src/slideshow/engine/animationnodes/AnimationSetNode.ts \
src/slideshow/engine/animationnodes/AnimationTransformNode.ts \
src/slideshow/engine/animationnodes/AnimationTransitionFilterNode.ts \
src/slideshow/engine/animationnodes/BaseContainerNode.ts \
src/slideshow/engine/animationnodes/BaseNode.ts \
src/slideshow/engine/animationnodes/NodeContext.ts \
src/slideshow/engine/animationnodes/PropertyAnimationNode.ts \
src/slideshow/engine/AnimatedElement.ts \
src/slideshow/Transition2d.ts \
src/slideshow/transition/FadeTransition.ts \
src/slideshow/CanvasLoader.ts \
src/slideshow/Transition3d.ts \
Expand Down
3 changes: 1 addition & 2 deletions browser/src/slideshow/CanvasLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ class CanvasLoader2d implements CanvasLoader {
public stopLoader(): void {} // eslint-disable-line
}

class CanvasLoaderGl extends Transition2d implements CanvasLoader {
class CanvasLoaderGl extends RendererBase implements CanvasLoader {
private animationId: number | null = null;

constructor(transitionParameters: TransitionParameters) {
super(transitionParameters);
this.prepareTransition();
this.animationTime = 0; // Continuous animation
}

public renderUniformValue(): void {
Expand Down
2 changes: 1 addition & 1 deletion browser/src/slideshow/LayersCompositor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class LayersCompositor extends SlideShow.SlideCompositor {
this.layerDrawing.requestSlide(this._initialSlideNumber, () => {
const oldCallback = this._onGotSlideCallback;
this._onGotSlideCallback = null;
oldCallback.call(this._slideShowPresenter);
oldCallback();
});
}

Expand Down
9 changes: 8 additions & 1 deletion browser/src/slideshow/PerformTransition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

declare var SlideShow: any;

// TODO TransitionType, TransitionSubType to be moved to a separate file: engine/TransitionType.ts

enum TransitionType {
BARWIPE,
PINWHEELWIPE,
Expand Down Expand Up @@ -139,6 +141,11 @@ const stringToTransitionSubTypeMap: Record<string, TransitionSubType> = {
RotateIn: TransitionSubType.ROTATEIN,
};

// TODO SlideShow.PerformTransition (don't hack it, no more used)
// look at SlideTransition.createSlideTransition
// 3d transition still to be integrated in SlideTransition
// to be tested 2d context case with ported engine
// to be removed
SlideShow.PerformTransition = function (
transitionParameters: TransitionParameters,
) {
Expand Down Expand Up @@ -209,7 +216,7 @@ SlideShow.PerformTransition = function (
case TransitionType.WATERFALLWIPE:
new SlideShow.DiagonalTransition(transitionParameters).start();
break;

// TODO: move also MISCSHAPEWIPE to SlideTransition
case TransitionType.MISCSHAPEWIPE:
SlideShow.MicsShapeWipeTransition(transitionParameters).start();
break;
Expand Down
121 changes: 121 additions & 0 deletions browser/src/slideshow/RendererBase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/* -*- js-indent-level: 8 -*- */

/*
* Copyright the Collabora Online contributors.
*
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

declare var SlideShow: any;

// TODO TransitionParameters should be moved to new Transition2d
class TransitionParameters {
public context: RenderContext = null;
public current: WebGLTexture | ImageBitmap = null;
public next: WebGLTexture | ImageBitmap = null;
public slideInfo: SlideInfo = null;
public callback: VoidFunction = null;
}

// TODO old Transition2d refactored to a more minimal class: it's still used by
// CanvasLoader, StaticTextRenderer, PauseTimer, anyhow it should make a bit cleaner
abstract class RendererBase {
public canvas: HTMLCanvasElement;
public gl: WebGL2RenderingContext;
public program: WebGLProgram;
public vao!: WebGLVertexArrayObject | null;
public context: any;
private transitionParameters: TransitionParameters;
protected slideInfo: SlideInfo = null;
protected time: number = 0;
protected startTime: number | null = null;

constructor(transitionParameters: TransitionParameters) {
this.transitionParameters = transitionParameters;
this.context = transitionParameters.context;
this.gl = transitionParameters.context.getGl();
this.slideInfo = transitionParameters.slideInfo;

const vertexShaderSource = this.getVertexShader();
const fragmentShaderSource = this.getFragmentShader();

const vertexShader = this.context.createVertexShader(vertexShaderSource);
const fragmentShader =
this.context.createFragmentShader(fragmentShaderSource);

this.program = this.context.createProgram(vertexShader, fragmentShader);
}

public getVertexShader(): string {
return `#version 300 es
in vec4 a_position;
in vec2 a_texCoord;
out vec2 v_texCoord;
void main() {
gl_Position = a_position;
v_texCoord = a_texCoord;
}
`;
}

public abstract getFragmentShader(): string;

public prepareTransition(): void {
this.initBuffers();
this.gl.useProgram(this.program);
}

public initBuffers(): void {
const positions = new Float32Array([
...[-1.0, -1.0, 0, 0, 1],
...[1.0, -1.0, 0, 1, 1],
...[-1.0, 1.0, 0, 0, 0],
...[1.0, 1.0, 0, 1, 0],
]);

const buffer = this.gl.createBuffer();
this.gl.bindBuffer(this.gl.ARRAY_BUFFER, buffer);
this.gl.bufferData(this.gl.ARRAY_BUFFER, positions, this.gl.STATIC_DRAW);

this.vao = this.gl.createVertexArray();
this.gl.bindVertexArray(this.vao);

const positionLocation = this.gl.getAttribLocation(
this.program,
'a_position',
);
const texCoordLocation = this.gl.getAttribLocation(
this.program,
'a_texCoord',
);

this.gl.enableVertexAttribArray(positionLocation);
this.gl.vertexAttribPointer(
positionLocation,
3,
this.gl.FLOAT,
false,
5 * 4,
0,
);

this.gl.enableVertexAttribArray(texCoordLocation);
this.gl.vertexAttribPointer(
texCoordLocation,
2,
this.gl.FLOAT,
false,
5 * 4,
3 * 4,
);
}

public abstract render(): void;
}

SlideShow.RendererBase = RendererBase;
6 changes: 6 additions & 0 deletions browser/src/slideshow/SlideRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,16 @@ abstract class SlideRenderer {
protected _slideTexture: WebGLTexture | ImageBitmap;
protected _videos: VideoRenderInfo[] = [];
protected _canvas: HTMLCanvasElement;
protected _renderedSlideIndex: number = undefined;

constructor(canvas: HTMLCanvasElement) {
this._canvas = canvas;
}

public get lastRenderedSlideIndex() {
return this._renderedSlideIndex;
}

public getSlideTexture(): WebGLTexture {
return this._slideTexture;
}
Expand Down Expand Up @@ -100,6 +105,7 @@ abstract class SlideRenderer {
docHeight: number,
) {
this.deleteCurrentSlideTexture();
this._renderedSlideIndex = slideInfo.index;
this._slideTexture = currentSlideTexture;
this.prepareVideos(slideInfo, docWidth, docHeight);
requestAnimationFrame(this.render.bind(this));
Expand Down
Loading

0 comments on commit 439f18e

Please sign in to comment.