Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tiled image support #897

Merged
merged 6 commits into from Feb 24, 2017

Make ImageDescriptor nicer to use.

  • Loading branch information
nical committed Feb 23, 2017
commit e920526478ac0fb44458240c2c2f0d2b5a574131
@@ -105,14 +105,7 @@ fn main() {
let vector_img = api.generate_image_key();
api.add_image(
vector_img,
ImageDescriptor {
format: ImageFormat::RGBA8,
width: 100,
height: 100,
stride: None,
is_opaque: true,
offset: 0,
},
ImageDescriptor::new(100, 100, ImageFormat::RGBA8).with_opaque_flag(true),
ImageData::new_blob_image(Vec::new()),
);

@@ -149,14 +142,7 @@ fn main() {
let mask_image = api.generate_image_key();
api.add_image(
mask_image,
ImageDescriptor {
width: 2,
height: 2,
stride: None,
format: ImageFormat::A8,
is_opaque: true,
offset: 0,
},
ImageDescriptor::new(2, 2, ImageFormat::A8).with_opaque_flag(true),
ImageData::new(vec![0, 80, 180, 255])
);
let mask = webrender_traits::ImageMask {
@@ -698,27 +698,13 @@ impl Renderer {
// TODO: Ensure that the white texture can never get evicted when the cache supports LRU eviction!
let white_image_id = texture_cache.new_item_id();
texture_cache.insert(white_image_id,
ImageDescriptor {
width: 2,
height: 2,
stride: None,
offset: 0,
format: ImageFormat::RGBA8,
is_opaque: false,
},
ImageDescriptor::new(2, 2, ImageFormat::RGBA8),
TextureFilter::Linear,
ImageData::Raw(Arc::new(white_pixels)));

let dummy_mask_image_id = texture_cache.new_item_id();
texture_cache.insert(dummy_mask_image_id,
ImageDescriptor {
width: 2,
height: 2,
stride: None,
offset: 0,
format: ImageFormat::A8,
is_opaque: false,
},
ImageDescriptor::new(2, 2, ImageFormat::A8),
TextureFilter::Linear,
ImageData::Raw(Arc::new(mask_pixels)));

@@ -368,6 +368,27 @@ pub struct ImageDescriptor {
}

impl ImageDescriptor {
pub fn new(width: u32, height: u32, format: ImageFormat) -> Self {
ImageDescriptor {
width: width,
height: height,
format: format,
stride: None,
offset: 0,
is_opaque: format == ImageFormat::RGB8,
}
}

pub fn with_opaque_flag(mut self, is_opaque: bool) -> Self {
self.is_opaque = is_opaque;
return self;
}

pub fn with_stride(mut self, stride: u32) -> Self {
self.stride = Some(stride);
return self;
}

pub fn compute_stride(&self) -> u32 {
self.stride.unwrap_or(self.width * self.format.bytes_per_pixel().unwrap())
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.