<commit_before>//! Element to render a texture
//!
//! # Why use this implementation
//!
//! This module provides the following elements
//!
//! ## Static texture
//!
//! [`TextureBuffer`] represents a static texture which is expected to not change.
//! It is possible to either use a [`pre-existing texture`](TextureBuffer::from_texture) or to create the texture
//! from [`RGBA memory`](TextureBuffer::from_memory).
//! The [`TextureBuffer`] can be used in the smithay pipeline by using [`TextureRenderElement::from_texture_buffer`].
//!  
//! ## Hardware accelerated rendering
//!
//! [`TextureRenderBuffer`] provides a solution for hardware accelerated rending with
//! proper damage tracking. It provides a [`RenderContext`] for rendering to the stored
//! texture. The collected damage from [`RenderContext::draw`] is used to report the
//! damaged regions in the [`TextureRenderElement`]. For rendering a [`TextureRenderBuffer`] you
//! can create a render element with [`TextureRenderElement::from_texture_render_buffer`].
//!
//! # Why **not** to use this implementation
//!
//! For software rendering you may take a look at [`MemoryRenderBuffer`](super::memory::MemoryRenderBuffer)
//! which provides proper damage tracking and is agnostic over the [`Renderer`](crate::backend::renderer::Renderer)
//!
//! # How to use it
//!
//! Both, [`TextureBuffer`] and [`TextureRenderBuffer`] represent a buffer of your texture data.
//! To render the buffer you have to create a [`TextureRenderElement`] in your render loop as
//! shown in the examples.
//!
//! To integrate custom texture based buffers the [`TextureRenderElement`] provides two functions
//! to create the render element. [`from_static_texture`](TextureRenderElement::from_static_texture) can be used to
//! create a render element from a static texture without damage tracking.
//! [`from_texture_with_damage`](TextureRenderElement::from_texture_with_damage) can be used to create
//! a render element from an existing texture with custom damage tracking.
//! In both cases you have to make sure to provide a stable [`Id`] or otherwise damage tracking will not work.
//!
//! ## [`TextureBuffer`]
//!
//! ```no_run
//! # use smithay::{
//! #     backend::renderer::{Frame, ImportMem, Renderer, Texture, TextureFilter},
//! #     utils::{Buffer, Physical, Rectangle, Size},
//! # };
//! # use slog::Drain;
//! #
//! # #[derive(Clone)]
//! # struct FakeTexture;
//! #
//! # impl Texture for FakeTexture {
//! #     fn width(&self) -> u32 {
//! #         unimplemented!()
//! #     }
//! #     fn height(&self) -> u32 {
//! #         unimplemented!()
//! #     }
//! # }
//! #
//! # struct FakeFrame;
//! #
//! # impl Frame for FakeFrame {
//! #     type Error = std::convert::Infallible;
//! #     type TextureId = FakeTexture;
//! #
//! #     fn clear(&mut self, _: [f32; 4], _: &[Rectangle<i32, Physical>]) -> Result<(), Self::Error> {
//! #         unimplemented!()
//! #     }
//! #     fn render_texture_from_to(
//! #         &mut self,
//! #         _: &Self::TextureId,
//! #         _: Rectangle<f64, Buffer>,
//! #         _: Rectangle<i32, Physical>,
//! #         _: &[Rectangle<i32, Physical>],
//! #         _: Transform,
//! #         _: f32,
//! #     ) -> Result<(), Self::Error> {
//! #         unimplemented!()
//! #     }
//! #     fn transformation(&self) -> Transform {
//! #         unimplemented!()
//! #     }
//! # }
//! #
//! # struct FakeRenderer;
//! #
//! # impl Renderer for FakeRenderer {
//! #     type Error = std::convert::Infallible;
//! #     type TextureId = FakeTexture;
//! #     type Frame = FakeFrame;
//! #
//! #     fn id(&self) -> usize {
//! #         unimplemented!()
//! #     }
//! #     fn downscale_filter(&mut self, _: TextureFilter) -> Result<(), Self::Error> {
//! #         unimplemented!()
//! #     }
//! #     fn upscale_filter(&mut self, _: TextureFilter) -> Result<(), Self::Error> {
//! #         unimplemented!()
//! #     }
//! #     fn render<F, R>(&mut self, _: Size<i32, Physical>, _: Transform, _: F) -> Result<R, Self::Error>
//! #     where
//! #         F: FnOnce(&mut Self, &mut Self::Frame) -> R,
//! #     {
//! #         unimplemented!()
//! #     }
//! # }
//! #
//! # impl ImportMem for FakeRenderer {
//! #     fn import_memory(
//! #         &mut self,
//! #         _: &[u8],
//! #         _: Size<i32, Buffer>,
//! #         _: bool,
//! #     ) -> Result<Self::TextureId, Self::Error> {
//! #         unimplemented!()
//! #     }
//! #     fn update_memory(
//! #         &mut self,
//! #         _: &Self::TextureId,
//! #         _: &[u8],
//! #         _: Rectangle<i32, Buffer>,
//! #     ) -> Result<(), Self::Error> {
//! #         unimplemented!()
//! #     }
//! # }
//! use smithay::{
//!     backend::renderer::{
//!         damage::DamageTrackedRenderer,
//!         element::texture::{TextureBuffer, TextureRenderElement},
//!     },
//!     utils::{Point, Transform},
//! };
//!
//! const WIDTH: i32 = 10;
//! const HEIGHT: i32 = 10;
//!
//! # let log = slog::Logger::root(slog::Discard.fuse(), slog::o!());
//!
//! let memory = vec![0; (WIDTH * 4 * HEIGHT) as usize];
//! # let mut renderer = FakeRenderer;
//!
//! // Create the texture buffer from a chunk of memory
//! let texture_buffer = TextureBuffer::from_memory(
//!     &mut renderer,
//!     &memory,
//!     (WIDTH, HEIGHT),
//!     false,
//!     1,
//!     Transform::Normal,
//!     None,
//! )
//! .expect("failed to import mem");
//!
//! let mut damage_tracked_renderer = DamageTrackedRenderer::new((800, 600), 1.0, Transform::Normal);
//!
//! loop {
//!     // Create a render element from the buffer
//!     let location = Point::from((100.0, 100.0));
//!     let render_element =
//!         TextureRenderElement::from_texture_buffer(location, &texture_buffer, None, None);
//!
//!     // Render the element(s)
//!     damage_tracked_renderer
//!         .render_output(&mut renderer, 0, &[&render_element], [0.8, 0.8, 0.9, 1.0], &log)
//!         .expect("failed to render output");
//! }
//! ```
//!
//! ## [`TextureRenderBuffer`]
//!
//! ```no_run
//! # use crate::{<commit_msg>renderer: correct test imports<commit_after>//! Element to render a texture
//!
//! # Why use this implementation
//!
//! This module provides the following elements
//!
//! ## Static texture
//!
//! [`TextureBuffer`] represents a static texture which is expected to not change.
//! It is possible to either use a [`pre-existing texture`](TextureBuffer::from_texture) or to create the texture
//! from [`RGBA memory`](TextureBuffer::from_memory).
//! The [`TextureBuffer`] can be used in the smithay pipeline by using [`TextureRenderElement::from_texture_buffer`].
//!  
//! ## Hardware accelerated rendering
//!
//! [`TextureRenderBuffer`] provides a solution for hardware accelerated rending with
//! proper damage tracking. It provides a [`RenderContext`] for rendering to the stored
//! texture. The collected damage from [`RenderContext::draw`] is used to report the
//! damaged regions in the [`TextureRenderElement`]. For rendering a [`TextureRenderBuffer`] you
//! can create a render element with [`TextureRenderElement::from_texture_render_buffer`].
//!
//! # Why **not** to use this implementation
//!
//! For software rendering you may take a look at [`MemoryRenderBuffer`](super::memory::MemoryRenderBuffer)
//! which provides proper damage tracking and is agnostic over the [`Renderer`](crate::backend::renderer::Renderer)
//!
//! # How to use it
//!
//! Both, [`TextureBuffer`] and [`TextureRenderBuffer`] represent a buffer of your texture data.
//! To render the buffer you have to create a [`TextureRenderElement`] in your render loop as
//! shown in the examples.
//!
//! To integrate custom texture based buffers the [`TextureRenderElement`] provides two functions
//! to create the render element. [`from_static_texture`](TextureRenderElement::from_static_texture) can be used to
//! create a render element from a static texture without damage tracking.
//! [`from_texture_with_damage`](TextureRenderElement::from_texture_with_damage) can be used to create
//! a render element from an existing texture with custom damage tracking.
//! In both cases you have to make sure to provide a stable [`Id`] or otherwise damage tracking will not work.
//!
//! ## [`TextureBuffer`]
//!
//! ```no_run
//! # use smithay::{
//! #     backend::renderer::{Frame, ImportMem, Renderer, Texture, TextureFilter},
//! #     utils::{Buffer, Physical, Rectangle, Size},
//! # };
//! # use slog::Drain;
//! #
//! # #[derive(Clone)]
//! # struct FakeTexture;
//! #
//! # impl Texture for FakeTexture {
//! #     fn width(&self) -> u32 {
//! #         unimplemented!()
//! #     }
//! #     fn height(&self) -> u32 {
//! #         unimplemented!()
//! #     }
//! # }
//! #
//! # struct FakeFrame;
//! #
//! # impl Frame for FakeFrame {
//! #     type Error = std::convert::Infallible;
//! #     type TextureId = FakeTexture;
//! #
//! #     fn clear(&mut self, _: [f32; 4], _: &[Rectangle<i32, Physical>]) -> Result<(), Self::Error> {
//! #         unimplemented!()
//! #     }
//! #     fn render_texture_from_to(
//! #         &mut self,
//! #         _: &Self::TextureId,
//! #         _: Rectangle<f64, Buffer>,
//! #         _: Rectangle<i32, Physical>,
//! #         _: &[Rectangle<i32, Physical>],
//! #         _: Transform,
//! #         _: f32,
//! #     ) -> Result<(), Self::Error> {
//! #         unimplemented!()
//! #     }
//! #     fn transformation(&self) -> Transform {
//! #         unimplemented!()
//! #     }
//! # }
//! #
//! # struct FakeRenderer;
//! #
//! # impl Renderer for FakeRenderer {
//! #     type Error = std::convert::Infallible;
//! #     type TextureId = FakeTexture;
//! #     type Frame = FakeFrame;
//! #
//! #     fn id(&self) -> usize {
//! #         unimplemented!()
//! #     }
//! #     fn downscale_filter(&mut self, _: TextureFilter) -> Result<(), Self::Error> {
//! #         unimplemented!()
//! #     }
//! #     fn upscale_filter(&mut self, _: TextureFilter) -> Result<(), Self::Error> {
//! #         unimplemented!()
//! #     }
//! #     fn render<F, R>(&mut self, _: Size<i32, Physical>, _: Transform, _: F) -> Result<R, Self::Error>
//! #     where
//! #         F: FnOnce(&mut Self, &mut Self::Frame) -> R,
//! #     {
//! #         unimplemented!()
//! #     }
//! # }
//! #
//! # impl ImportMem for FakeRenderer {
//! #     fn import_memory(
//! #         &mut self,
//! #         _: &[u8],
//! #         _: Size<i32, Buffer>,
//! #         _: bool,
//! #     ) -> Result<Self::TextureId, Self::Error> {
//! #         unimplemented!()
//! #     }
//! #     fn update_memory(
//! #         &mut self,
//! #         _: &Self::TextureId,
//! #         _: &[u8],
//! #         _: Rectangle<i32, Buffer>,
//! #     ) -> Result<(), Self::Error> {
//! #         unimplemented!()
//! #     }
//! # }
//! use smithay::{
//!     backend::renderer::{
//!         damage::DamageTrackedRenderer,
//!         element::texture::{TextureBuffer, TextureRenderElement},
//!     },
//!     utils::{Point, Transform},
//! };
//!
//! const WIDTH: i32 = 10;
//! const HEIGHT: i32 = 10;
//!
//! # let log = slog::Logger::root(slog::Discard.fuse(), slog::o!());
//!
//! let memory = vec![0; (WIDTH * 4 * HEIGHT) as usize];
//! # let mut renderer = FakeRenderer;
//!
//! // Create the texture buffer from a chunk of memory
//! let texture_buffer = TextureBuffer::from_memory(
//!     &mut renderer,
//!     &memory,
//!     (WIDTH, HEIGHT),
//!     false,
//!     1,
//!     Transform::Normal,
//!     None,
//! )
//! .expect("failed to import mem");
//!
//! let mut damage_tracked_renderer = DamageTrackedRenderer::new((800, 600), 1.0, Transform::Normal);
//!
//! loop {
//!     // Create a render element from the buffer
//!     let location = Point::from((100.0, 100.0));
//!     let render_element =
//!         TextureRenderElement::from_texture_buffer(location, &texture_buffer, None, None);
//!
//!     // Render the element(s)
//!     damage_tracked_renderer
//!         .render_output(&mut renderer, 0, &[&render_element], [0.8, 0.8, 0.9, 1.0], &log)
//!         .expect("failed to render output");
//! }
//! ```
//!
//! ## [`TextureRenderBuffer`]
//!
//! ```no_run
//! # use smithay::{
{'fraction_non_alphanumeric': 0.20565405670397907, 'fraction_numerical': 0.009968134651523818, 'mean_word_length': 2.608490566037736, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7473231', 'n_tokens_mistral': 4099, 'n_tokens_neox': 3679, 'n_words': 986}