piet_hardware/
image.rs

1// SPDX-License-Identifier: LGPL-3.0-or-later OR MPL-2.0
2// This file is a part of `piet-hardware`.
3//
4// `piet-hardware` is free software: you can redistribute it and/or modify it under the
5// terms of either:
6//
7// * GNU Lesser General Public License as published by the Free Software Foundation, either
8//   version 3 of the License, or (at your option) any later version.
9// * Mozilla Public License as published by the Mozilla Foundation, version 2.
10//
11// `piet-hardware` is distributed in the hope that it will be useful, but WITHOUT ANY
12// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
13// PURPOSE. See the GNU Lesser General Public License or the Mozilla Public License for more
14// details.
15//
16// You should have received a copy of the GNU Lesser General Public License and the Mozilla
17// Public License along with `piet-hardware`. If not, see <https://www.gnu.org/licenses/>.
18
19//! The image type for the GPU renderer.
20
21use super::gpu_backend::GpuContext;
22use super::resources::Texture;
23
24use piet::kurbo::Size;
25
26use std::rc::Rc;
27
28/// The image type used by the GPU renderer.
29#[derive(Debug)]
30pub struct Image<C: GpuContext + ?Sized> {
31    /// The texture.
32    texture: Rc<Texture<C>>,
33
34    /// The size of the image.
35    size: Size,
36}
37
38impl<C: GpuContext + ?Sized> Image<C> {
39    /// Create a new image from a texture.
40    pub(crate) fn new(texture: Texture<C>, size: Size) -> Self {
41        Self {
42            texture: Rc::new(texture),
43            size,
44        }
45    }
46
47    /// Get the texture.
48    pub(crate) fn texture(&self) -> &Texture<C> {
49        &self.texture
50    }
51}
52
53impl<C: GpuContext + ?Sized> Clone for Image<C> {
54    fn clone(&self) -> Self {
55        Self {
56            texture: self.texture.clone(),
57            size: self.size,
58        }
59    }
60}
61
62impl<C: GpuContext + ?Sized> piet::Image for Image<C> {
63    fn size(&self) -> Size {
64        self.size
65    }
66}