🔧 Use an array of effect instances

This commit is contained in:
Simon Schneegans
2022-05-05 21:17:03 +02:00
parent 3b0be6236c
commit e20bcd46d7
3 changed files with 61 additions and 40 deletions
+23 -10
View File
@@ -30,10 +30,12 @@ const utils = Me.imports.src.utils;
//////////////////////////////////////////////////////////////////////////////////////////
// The shader class for this effect is registered further down in this file. When this
// effect is used for the first time, shaderInstance will store one instance of
// ShaderClass which will be used whenever this effect is used.
let ShaderClass = null;
let shaderInstance = null;
// effect is used for the first time, an instance of this shader class is created. Once
// the effect is finished, the shader will be stored in the shaderInstances array and will
// then be reused if a new shader is requested. ShaderClass which will be used whenever
// this effect is used.
let ShaderClass = null;
let availableShaders = [];
// The effect class is completely static. It can be used to get some metadata (like the
// effect's name or supported GNOME Shell versions), to initialize the respective page of
@@ -101,15 +103,26 @@ var Fire = class Fire {
// ---------------------------------------------------------------- API for extension.js
// This is called from extension.js whenever a window is opened or closed with this
// effect.
// effect. It returns an instance of the shader class, trying to reuse previously
// created shaders.
static getShader(actor, settings, forOpening) {
if (shaderInstance == null) {
shaderInstance = new ShaderClass();
let shader;
if (availableShaders.length == 0) {
shader = new ShaderClass();
} else {
shader = availableShaders.pop();
}
shaderInstance.setUniforms(settings, forOpening);
shader.setUniforms(settings, forOpening);
return shaderInstance;
return shader;
}
// This will be called from extension.js once a shader which was previously acquired via
// getShader() is not used anymore.
static returnShader(shader) {
availableShaders.push(shader);
}
// The tweakTransition() is called from extension.js to tweak a window's open / close
@@ -133,7 +146,7 @@ var Fire = class Fire {
// This is called from extension.js if the extension is disabled. This should free all
// static resources.
static cleanUp() {
shaderInstance = null;
availableShaders = [];
}
// ----------------------------------------------------------------------- private stuff
+22 -9
View File
@@ -27,10 +27,12 @@ const utils = Me.imports.src.utils;
//////////////////////////////////////////////////////////////////////////////////////////
// The shader class for this effect is registered further down in this file. When this
// effect is used for the first time, shaderInstance will store one instance of
// ShaderClass which will be used whenever this effect is used.
let ShaderClass = null;
let shaderInstance = null;
// effect is used for the first time, an instance of this shader class is created. Once
// the effect is finished, the shader will be stored in the shaderInstances array and will
// then be reused if a new shader is requested. ShaderClass which will be used whenever
// this effect is used.
let ShaderClass = null;
let availableShaders = [];
// The effect class is completely static. It can be used to get some metadata (like the
// effect's name or supported GNOME Shell versions), to initialize the respective page of
@@ -83,15 +85,26 @@ var Hexagon = class Hexagon {
// ---------------------------------------------------------------- API for extension.js
// This is called from extension.js whenever a window is opened or closed with this
// effect.
// effect. It returns an instance of the shader class, trying to reuse previously
// created shaders.
static getShader(actor, settings, forOpening) {
if (shaderInstance == null) {
shaderInstance = new ShaderClass();
let shader;
if (availableShaders.length == 0) {
shader = new ShaderClass();
} else {
shader = availableShaders.pop();
}
shaderInstance.setUniforms(settings, forOpening);
shader.setUniforms(settings, forOpening);
return shaderInstance;
return shader;
}
// This will be called from extension.js once a shader which was previously acquired via
// getShader() is not used anymore.
static returnShader(shader) {
availableShaders.push(shader);
}
// The tweakTransition() is called from extension.js to tweak a window's open / close