Skip to content

Commit 2d92f36

Browse files
Save power by freezing renders after inactivity (10s)
1 parent 6876b82 commit 2d92f36

File tree

14 files changed

+79
-21
lines changed

14 files changed

+79
-21
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "shaderlock"
33
description = "Wayland (wlroots) screenlocker with GPU shaders"
4-
version = "0.2.0"
4+
version = "0.3.0"
55
authors = ["Robin McCorkell <[email protected]>"]
66
license = "MIT"
77
edition = "2018"

dist/shaders/blur.frag

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ layout(set = 0, binding = 2) uniform Uniforms {
1010

1111
layout(push_constant) uniform FrameUniforms {
1212
float iTime;
13+
float iFadeAmount;
1314
};
1415

1516
const float AMOUNT = 4.0;
@@ -23,4 +24,5 @@ void main() {
2324
vec2 uv = ouv.xy / ouv.w;
2425

2526
f_color = texture(sampler2D(t_screenshot, s_screenshot), uv, lod_bias);
27+
f_color = mix(f_color, vec4(0.0, 0.0, 0.0, 1.0), iFadeAmount);
2628
}

dist/shaders/crt.frag

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ layout(set = 0, binding = 2) uniform Uniforms {
1010

1111
layout(push_constant) uniform FrameUniforms {
1212
float iTime;
13+
float iFadeAmount;
1314
};
1415

1516
const float BULGE_AMOUNT = 0.2;
@@ -91,4 +92,5 @@ void main() {
9192
c = scan_lines(c, uv_monitor);
9293

9394
f_color = c;
95+
f_color = mix(f_color, vec4(0.0, 0.0, 0.0, 1.0), iFadeAmount);
9496
}

dist/shaders/desaturate_fade.frag

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ layout(set = 0, binding = 2) uniform Uniforms {
1010

1111
layout(push_constant) uniform FrameUniforms {
1212
float iTime;
13+
float iFadeAmount;
1314
};
1415

1516
const vec3 LUMIN = vec3(0.299, 0.587, 0.114);
@@ -35,4 +36,5 @@ void main() {
3536

3637
vec4 desaturated = desaturate(texture(sampler2D(t_screenshot, s_screenshot), uv), desaturation);
3738
f_color = mix(desaturated, CLEAR_COLOR, fade);
39+
f_color = mix(f_color, vec4(0.0, 0.0, 0.0, 1.0), iFadeAmount);
3840
}

dist/shaders/dissolve.frag

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ layout(set = 0, binding = 2) uniform Uniforms {
1010

1111
layout(push_constant) uniform FrameUniforms {
1212
float iTime;
13+
float iFadeAmount;
1314
};
1415

1516
const float DISSOLVE_SPEED = 200;
16-
const float FALL_ACCEL = 400.0;
17+
const float FALL_ACCEL = 800.0;
1718
const float RANDOM_AMOUNT = 0.15;
1819
const float RANDOM_SIZE = 60.0;
1920

@@ -89,4 +90,5 @@ void main() {
8990
} else {
9091
f_color = texture(sampler2D(t_screenshot, s_screenshot), uv);
9192
}
93+
f_color = mix(f_color, vec4(0.0, 0.0, 0.0, 1.0), iFadeAmount);
9294
}

dist/shaders/overlay.frag

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ layout(set = 0, binding = 2) uniform Uniforms {
1010

1111
layout(push_constant) uniform FrameUniforms {
1212
float iTime;
13+
float iFadeAmount;
1314
};
1415

1516
const float PI = 3.141529;
@@ -33,4 +34,5 @@ void main() {
3334
vec2 uv = ouv.xy / ouv.w;
3435

3536
f_color = overlay(uv, amount);
37+
f_color = mix(f_color, vec4(0.0, 0.0, 0.0, 1.0), iFadeAmount);
3638
}

dist/shaders/paper_burn.frag

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ layout(set = 0, binding = 2) uniform Uniforms {
1010

1111
layout(push_constant) uniform FrameUniforms {
1212
float iTime;
13+
float iFadeAmount;
1314
};
1415

1516
const float NOISE_FREQ = 12.0;
@@ -76,4 +77,5 @@ void main() {
7677
f_color = mix(f_color, SCORCH_COLOR, scorch*SCORCH_MAX);
7778
f_color = mix(f_color, BURN_COLOR, burn*BURN_MAX);
7879
f_color = mix(f_color, vec4(0.0, 0.0, 0.0, 0.0), alpha);
80+
f_color = mix(f_color, vec4(0.0, 0.0, 0.0, 1.0), iFadeAmount);
7981
}

dist/shaders/vertical_band_slide.frag

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ layout(set = 0, binding = 2) uniform Uniforms {
1010

1111
layout(push_constant) uniform FrameUniforms {
1212
float iTime;
13+
float iFadeAmount;
1314
};
1415

1516
const vec4 CLEAR_COLOR = vec4(0.0, 0.0, 0.0, 1.0);
@@ -42,4 +43,5 @@ void main() {
4243
} else {
4344
f_color = texture(sampler2D(t_screenshot, s_screenshot), uv);
4445
}
46+
f_color = mix(f_color, vec4(0.0, 0.0, 0.0, 1.0), iFadeAmount);
4547
}

src/graphics.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
mod bg;
22
mod icon;
33

4+
use std::time::Duration;
5+
46
use anyhow::*;
57
#[allow(unused_imports)]
68
use log::{debug, error, info, warn};
@@ -49,7 +51,7 @@ impl Manager {
4951
let adapter = self
5052
.instance
5153
.request_adapter(&wgpu::RequestAdapterOptions {
52-
power_preference: wgpu::PowerPreference::Default,
54+
power_preference: wgpu::PowerPreference::LowPower,
5355
compatible_surface: Some(&surface),
5456
})
5557
.await
@@ -60,7 +62,7 @@ impl Manager {
6062
&wgpu::DeviceDescriptor {
6163
features: wgpu::Features::PUSH_CONSTANTS,
6264
limits: wgpu::Limits {
63-
max_push_constant_size: 4,
65+
max_push_constant_size: self::bg::PUSH_CONSTANTS_SIZE,
6466
..wgpu::Limits::default()
6567
},
6668
shader_validation: true,
@@ -132,7 +134,7 @@ impl State {
132134
self.icon.resize(&self.queue, resolution_transform);
133135
}
134136

135-
pub fn render(&mut self, time: f32) {
137+
pub fn render(&mut self, ctx: RenderContext) {
136138
let frame = self
137139
.swap_chain
138140
.get_current_frame()
@@ -145,10 +147,15 @@ impl State {
145147
label: Some("Render Encoder"),
146148
});
147149

148-
self.bg.render(&mut encoder, &frame, time);
150+
self.bg.render(&mut encoder, &frame, ctx);
149151
self.icon.render(&mut encoder, &frame);
150152

151153
// submit will accept anything that implements IntoIter
152154
self.queue.submit(std::iter::once(encoder.finish()));
153155
}
154156
}
157+
158+
pub struct RenderContext {
159+
pub elapsed: Duration,
160+
pub fade_amount: f32,
161+
}

0 commit comments

Comments
 (0)