use crate::sys::{A_long, PF_LayerDef, PF_LayerDefault_MYSELF};
use crate::gpu::GPU_BYTES_PER_PIXEL;
use crate::host::host_layer::HostLayer;
pub(crate) struct LinkedLayer {
layer: HostLayer,
cpu_world: Box<PF_LayerDef>,
gpu_world: Box<PF_LayerDef>,
pub(crate) gpu_uploaded: bool,
pub(crate) unlinked: PF_LayerDef,
}
impl LinkedLayer {
pub(crate) fn new(layer: crate::pixel::AnyLayer, unlinked: PF_LayerDef) -> Self {
let mut layer = HostLayer::new(layer);
let mut cpu_world = layer.as_sys();
cpu_world.dephault = PF_LayerDefault_MYSELF as A_long;
let mut gpu_world = cpu_world;
gpu_world.rowbytes = layer.width() as i32 * GPU_BYTES_PER_PIXEL as i32;
Self {
layer,
cpu_world: Box::new(cpu_world),
gpu_world: Box::new(gpu_world),
gpu_uploaded: false,
unlinked,
}
}
pub(crate) fn layer(&self) -> &crate::pixel::AnyLayer {
self.layer.layer()
}
pub(crate) fn param_def(&self) -> PF_LayerDef {
*self.cpu_world
}
pub(crate) fn size(&self) -> (i32, i32) {
(self.layer.width() as i32, self.layer.height() as i32)
}
pub(crate) fn world_ptr(&mut self, gpu: bool) -> *mut PF_LayerDef {
if gpu {
&mut *self.gpu_world
} else {
&mut *self.cpu_world
}
}
pub(crate) fn gpu_len(&self) -> usize {
self.layer.width() as usize * self.layer.height() as usize * GPU_BYTES_PER_PIXEL
}
}