Update how the effect triggers repaint (again...)

This commit is contained in:
wheaney 2024-06-28 14:16:37 -07:00
parent 2d34eb2d17
commit 8ffbe4cb87
1 changed files with 13 additions and 17 deletions

View File

@ -280,10 +280,6 @@ export const XREffect = GObject.registerClass({
constructor(params = {}) { constructor(params = {}) {
super(params); super(params);
// target a slightly lower framerate than the monitor's refresh rate to prevent repainting too frequently
const frameTimeFramerate = this.target_framerate * 1.25;
this._frametime = Math.floor(1000 / frameTimeFramerate);
this._is_display_distance_at_end = false; this._is_display_distance_at_end = false;
this._distance_ease_timeline = null; this._distance_ease_timeline = null;
@ -296,6 +292,8 @@ export const XREffect = GObject.registerClass({
this.customBannerImage = new Clutter.Image(); this.customBannerImage = new Clutter.Image();
this.customBannerImage.set_data(customBanner.get_pixels(), Cogl.PixelFormat.RGB_888, this.customBannerImage.set_data(customBanner.get_pixels(), Cogl.PixelFormat.RGB_888,
customBanner.width, customBanner.height, customBanner.rowstride); customBanner.width, customBanner.height, customBanner.rowstride);
this._redraw_timeline = null;
} }
_change_distance() { _change_distance() {
@ -323,9 +321,6 @@ export const XREffect = GObject.registerClass({
} }
vfunc_paint_target(node, paintContext) { vfunc_paint_target(node, paintContext) {
var now = Date.now();
var lastPaint = this._last_paint || 0;
var frametime = this._frametime;
var calibratingImage = this.calibratingImage; var calibratingImage = this.calibratingImage;
var customBannerImage = this.customBannerImage; var customBannerImage = this.customBannerImage;
let data = Globals.ipc_file.load_contents(null); let data = Globals.ipc_file.load_contents(null);
@ -346,10 +341,12 @@ export const XREffect = GObject.registerClass({
this.setIntermittentUniformVariables = setIntermittentUniformVariables.bind(this); this.setIntermittentUniformVariables = setIntermittentUniformVariables.bind(this);
this.setIntermittentUniformVariables(); this.setIntermittentUniformVariables();
this._redraw_timeout_id = GLib.timeout_add(GLib.PRIORITY_DEFAULT, this._frametime, () => { this._redraw_timeline = Clutter.Timeline.new_for_actor(this.get_actor(), 1000);
if ((now - lastPaint) > frametime) global.stage.queue_redraw(); this._redraw_timeline.connect('new-frame', (() => {
return GLib.SOURCE_CONTINUE; this.queue_repaint();
}); }).bind(this));
this._redraw_timeline.set_repeat_count(-1);
this._redraw_timeline.start();
this._uniforms_timeout_id = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 250, (() => { this._uniforms_timeout_id = GLib.timeout_add(GLib.PRIORITY_DEFAULT, 250, (() => {
this.setIntermittentUniformVariables(); this.setIntermittentUniformVariables();
@ -392,16 +389,15 @@ export const XREffect = GObject.registerClass({
Cogl.PipelineFilter.LINEAR Cogl.PipelineFilter.LINEAR
); );
} }
super.vfunc_paint_target(node, paintContext);
} else {
super.vfunc_paint_target(node, paintContext);
} }
this._last_paint = now; super.vfunc_paint_target(node, paintContext);
} }
cleanup() { cleanup() {
if (this._redraw_timeout_id) GLib.source_remove(this._redraw_timeout_id); if (this._redraw_timeline) {
this._redraw_timeline.stop();
this._redraw_timeline = null;
}
if (this._uniforms_timeout_id) GLib.source_remove(this._uniforms_timeout_id); if (this._uniforms_timeout_id) GLib.source_remove(this._uniforms_timeout_id);
} }
}); });