use super::{
TextureData, TextureDataError, TextureFormat, TextureId, TextureRect, TextureStatus,
TextureSubresource,
};
#[derive(Copy, Clone)]
pub struct ManagedTextureRef<'texture> {
texture: &'texture TextureData,
}
impl<'texture> ManagedTextureRef<'texture> {
pub(crate) fn new(texture: &'texture TextureData) -> Self {
Self { texture }
}
#[must_use]
pub fn status(self) -> TextureStatus {
self.texture.status()
}
#[must_use]
pub fn texture_id(self) -> TextureId {
self.texture.tex_id()
}
#[must_use]
pub fn format(self) -> TextureFormat {
self.texture.format()
}
#[must_use]
pub fn width(self) -> u32 {
self.texture.width()
}
#[must_use]
pub fn height(self) -> u32 {
self.texture.height()
}
#[must_use]
pub fn bytes_per_pixel(self) -> usize {
self.texture.bytes_per_pixel()
}
#[must_use]
pub fn unused_frames(self) -> usize {
self.texture.unused_frames()
}
#[must_use]
pub fn ref_count(self) -> u16 {
self.texture.ref_count()
}
#[must_use]
pub fn uses_colors(self) -> bool {
self.texture.use_colors()
}
#[must_use]
pub fn is_queued_for_destruction(self) -> bool {
self.texture.want_destroy_next_frame()
}
#[must_use]
pub fn pixels(self) -> Option<&'texture [u8]> {
self.texture.pixels()
}
#[must_use]
pub fn pixels_at(self, x: u32, y: u32) -> Option<&'texture [u8]> {
self.texture.pixels_at(x, y)
}
#[must_use]
pub fn pitch(self) -> usize {
self.texture.pitch()
}
#[must_use]
pub fn used_rect(self) -> TextureRect {
self.texture.used_rect()
}
#[must_use]
pub fn update_rect(self) -> TextureRect {
self.texture.update_rect()
}
pub fn updates(self) -> impl Iterator<Item = TextureRect> + 'texture {
self.texture.updates()
}
}
pub struct ManagedTextureMut<'texture> {
texture: &'texture mut TextureData,
mutated: &'texture mut bool,
}
impl<'texture> ManagedTextureMut<'texture> {
pub(crate) fn new(texture: &'texture mut TextureData, mutated: &'texture mut bool) -> Self {
Self { texture, mutated }
}
pub fn replace_pixels(&mut self, pixels: &[u8]) -> Result<(), TextureDataError> {
let result = self.texture.replace_pixels(pixels);
if result.is_ok() {
*self.mutated = true;
}
result
}
pub fn update_subresource(
&mut self,
update: TextureSubresource<'_>,
) -> Result<(), TextureDataError> {
let result = self.texture.update_subresource(update);
if result.is_ok() {
*self.mutated = true;
}
result
}
#[must_use]
pub fn view(&self) -> ManagedTextureRef<'_> {
ManagedTextureRef::new(self.texture)
}
}