Skip to content

Commit

Permalink
annoate functions with proper visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
LGFae committed Feb 23, 2024
1 parent ff3731b commit d2b9140
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 33 deletions.
33 changes: 20 additions & 13 deletions daemon/src/bump_pool.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
//! A pool implementation that only gives buffers of a fixed size, creating new ones if none of
//! them are freed

use std::sync::{
atomic::{AtomicBool, Ordering},
Arc,
Expand Down Expand Up @@ -33,13 +30,15 @@ impl Drop for Buffer {
}

#[derive(Debug)]
pub struct BumpPool {
/// A pool implementation that only gives buffers of a fixed size, creating new ones if none of
/// them are freed. It also takes care of copying the previous buffer's content over to the new one
/// for us
pub(crate) struct BumpPool {
pool: RawPool,
buffers: Vec<Buffer>,
width: i32,
height: i32,
stride: i32,
qh: QueueHandle<Daemon>,
last_used_buffer: Option<usize>,
}

Expand Down Expand Up @@ -73,7 +72,6 @@ impl BumpPool {
width,
height,
stride,
qh: qh.clone(),
last_used_buffer: None,
}
}
Expand All @@ -88,7 +86,7 @@ impl BumpPool {
self.buffer_len() * buffer_index
}

fn grow(&mut self) {
fn grow(&mut self, qh: &QueueHandle<Daemon>) {
let len = self.buffer_len();
self.pool
.resize(self.pool.len() + len)
Expand All @@ -102,15 +100,17 @@ impl BumpPool {
self.stride,
wl_shm::Format::Xrgb8888,
released.clone(),
&self.qh,
qh,
),
released,
));
log::info!("BumpPool with: {} buffers", self.buffers.len());
}

/// Returns a drawable surface. If we can't find a free buffer, we request more memory
pub fn get_drawable(&mut self) -> &mut [u8] {
///
/// This functions automatically handles copying the previous buffer over onto the new one
pub(crate) fn get_drawable(&mut self, qh: &QueueHandle<Daemon>) -> &mut [u8] {
let (i, buf) = match self
.buffers
.iter()
Expand All @@ -119,7 +119,7 @@ impl BumpPool {
{
Some((i, buf)) => (i, buf),
None => {
self.grow();
self.grow(qh);
(self.buffers.len() - 1, self.buffers.last().unwrap())
}
};
Expand All @@ -139,12 +139,19 @@ impl BumpPool {
&mut self.pool.mmap()[offset..offset + len]
}

pub fn get_commitable_buffer(&self) -> &WlBuffer {
#[inline]
pub(crate) fn get_commitable_buffer(&self) -> &WlBuffer {
let i = self.last_used_buffer.unwrap();
&self.buffers[i].inner
}

pub fn resize(&mut self, width: i32, height: i32, stride: i32) {
pub(crate) fn resize(
&mut self,
width: i32,
height: i32,
stride: i32,
qh: &QueueHandle<Daemon>,
) {
self.width = width;
self.height = height;
self.stride = stride;
Expand All @@ -159,7 +166,7 @@ impl BumpPool {
stride,
wl_shm::Format::Xrgb8888,
released.clone(),
&self.qh,
qh,
),
released,
));
Expand Down
40 changes: 20 additions & 20 deletions daemon/src/wallpaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ struct AnimationState {
}

#[derive(Debug)]
pub struct AnimationToken {
pub(super) struct AnimationToken {
id: usize,
transition_done: Arc<AtomicBool>,
}

impl AnimationToken {
pub fn is_transition_done(&self) -> bool {
pub(super) fn is_transition_done(&self) -> bool {
self.transition_done.load(Ordering::Acquire)
}

pub fn set_transition_done(&self, wallpaper: &Wallpaper) {
pub(super) fn set_transition_done(&self, wallpaper: &Wallpaper) {
if wallpaper.has_animation_id(self) {
self.transition_done.store(true, Ordering::Release);
}
Expand All @@ -61,7 +61,7 @@ struct WallpaperInner {
img: BgImg,
}

pub struct Wallpaper {
pub(super) struct Wallpaper {
output_id: u32,
inner: RwLock<WallpaperInner>,
layer_surface: LayerSurface,
Expand All @@ -73,7 +73,7 @@ pub struct Wallpaper {
}

impl Wallpaper {
pub fn new(
pub(crate) fn new(
output_info: OutputInfo,
layer_surface: LayerSurface,
shm: &Shm,
Expand Down Expand Up @@ -138,46 +138,46 @@ impl Wallpaper {
}

#[inline]
pub fn has_id(&self, id: u32) -> bool {
pub(super) fn has_id(&self, id: u32) -> bool {
self.output_id == id
}

#[inline]
pub fn has_animation_id(&self, token: &AnimationToken) -> bool {
pub(super) fn has_animation_id(&self, token: &AnimationToken) -> bool {
self.animation_state
.id
.load(std::sync::atomic::Ordering::Acquire)
== token.id
}

#[inline]
pub fn has_surface(&self, surface: &WlSurface) -> bool {
pub(super) fn has_surface(&self, surface: &WlSurface) -> bool {
self.layer_surface.wl_surface() == surface
}

pub fn get_dimensions(&self) -> (u32, u32) {
pub(super) fn get_dimensions(&self) -> (u32, u32) {
let inner = self.inner.read().unwrap();
let width = inner.width.get() as u32;
let height = inner.height.get() as u32;
let scale_factor = inner.scale_factor.get() as u32;
(width * scale_factor, height * scale_factor)
}

pub fn canvas_change<F, T>(&self, f: F) -> T
pub(super) fn canvas_change<F, T>(&self, f: F) -> T
where
F: FnOnce(&mut [u8]) -> T,
{
let mut inner = self.inner.write().unwrap();
f(inner.pool.get_drawable())
f(inner.pool.get_drawable(&self.qh))
}

#[inline]
pub fn get_img_info(&self) -> BgImg {
pub(super) fn get_img_info(&self) -> BgImg {
self.inner.read().unwrap().img.clone()
}

#[inline]
pub fn create_animation_token(&self) -> AnimationToken {
pub(super) fn create_animation_token(&self) -> AnimationToken {
let id = self.animation_state.id.load(Ordering::Acquire);
AnimationToken {
id,
Expand All @@ -186,21 +186,21 @@ impl Wallpaper {
}

#[inline]
pub fn frame_callback_completed(&self, time: u32) {
pub(super) fn frame_callback_completed(&self, time: u32) {
*self.frame_callback_handler.time.lock().unwrap() = Some(time);
self.frame_callback_handler.cvar.notify_all();
}

/// Stops all animations with the current id, by increasing that id
#[inline]
pub fn stop_animations(&self) {
pub(super) fn stop_animations(&self) {
self.animation_state.id.fetch_add(1, Ordering::AcqRel);
self.animation_state
.transition_finished
.store(false, Ordering::Release);
}

pub fn clear(&self, color: [u8; 3]) {
pub(super) fn clear(&self, color: [u8; 3]) {
self.canvas_change(|canvas| {
for pixel in canvas.chunks_exact_mut(4) {
pixel[2] = color[0];
Expand All @@ -210,12 +210,12 @@ impl Wallpaper {
})
}

pub fn set_img_info(&self, img_info: BgImg) {
pub(super) fn set_img_info(&self, img_info: BgImg) {
log::debug!("output {} - drawing: {}", self.output_id, img_info);
self.inner.write().unwrap().img = img_info;
}

pub fn draw(&self) {
pub(super) fn draw(&self) {
{
let mut time = self.frame_callback_handler.time.lock().unwrap();
while time.is_none() {
Expand All @@ -237,7 +237,7 @@ impl Wallpaper {
surface.frame(&self.qh, surface.clone());
}

pub fn resize(
pub(super) fn resize(
&self,
width: Option<NonZeroI32>,
height: Option<NonZeroI32>,
Expand All @@ -263,7 +263,7 @@ impl Wallpaper {
let w = width.get() * scale_factor.get();
let h = height.get() * scale_factor.get();
let stride = w * 4;
inner.pool.resize(w, h, stride);
inner.pool.resize(w, h, stride, &self.qh);
drop(inner);

*self.frame_callback_handler.time.lock().unwrap() = Some(0);
Expand Down

0 comments on commit d2b9140

Please sign in to comment.