Skip to content

Commit

Permalink
Auto merge of #995 - nical:tiled-img-update, r=glennw
Browse files Browse the repository at this point in the history
Make image update work with tiled images.

Fixes issue #994. The only change ended up being to move the computation of the image descriptor for tiles up a bit so that it could also be used in case of an image update.

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/995)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo authored Mar 21, 2017
2 parents 656a712 + 8fb41c9 commit d4c349d
Showing 1 changed file with 41 additions and 45 deletions.
86 changes: 41 additions & 45 deletions webrender/src/resource_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,13 +658,48 @@ impl ResourceCache {
// external handle doesn't need to update the texture_cache.
}
ImageData::Raw(..) | ImageData::ExternalBuffer(..) | ImageData::Blob(..) => {
let descriptor = if let Some(tile) = request.tile {
let tile_size = image_template.tiling.unwrap() as u32;
let image_descriptor = &image_template.descriptor;
let stride = image_descriptor.compute_stride();
let bpp = image_descriptor.format.bytes_per_pixel().unwrap();

// Storage for the tiles on the right and bottom edges is shrunk to
// fit the image data (See decompose_tiled_image in frame.rs).
let actual_width = if (tile.x as u32) < image_descriptor.width / tile_size {
tile_size
} else {
image_descriptor.width % tile_size
};

let actual_height = if (tile.y as u32) < image_descriptor.height / tile_size {
tile_size
} else {
image_descriptor.height % tile_size
};

let offset = image_descriptor.offset + tile.y as u32 * tile_size * stride
+ tile.x as u32 * tile_size * bpp;

ImageDescriptor {
width: actual_width,
height: actual_height,
stride: Some(stride),
offset: offset,
format: image_descriptor.format,
is_opaque: image_descriptor.is_opaque,
}
} else {
image_template.descriptor.clone()
};

match self.cached_images.entry(request.clone(), self.current_frame_id) {
Occupied(entry) => {
let image_id = entry.get().texture_cache_id;

if entry.get().epoch != image_template.epoch {
self.texture_cache.update(image_id,
image_template.descriptor,
descriptor,
image_data);

// Update the cached epoch
Expand All @@ -682,50 +717,11 @@ impl ResourceCache {
ImageRendering::Auto | ImageRendering::CrispEdges => TextureFilter::Linear,
};

if let Some(tile) = request.tile {
let tile_size = image_template.tiling.unwrap() as u32;
let image_descriptor = image_template.descriptor.clone();
let stride = image_descriptor.compute_stride();
let bpp = image_descriptor.format.bytes_per_pixel().unwrap();

// Storage for the tiles on the right and bottom edges is shrunk to
// fit the image data (See decompose_tiled_image in frame.rs).
let actual_width = if (tile.x as u32) < image_descriptor.width / tile_size {
tile_size
} else {
image_descriptor.width % tile_size
};

let actual_height = if (tile.y as u32) < image_descriptor.height / tile_size {
tile_size
} else {
image_descriptor.height % tile_size
};

let offset = image_descriptor.offset + tile.y as u32 * tile_size * stride
+ tile.x as u32 * tile_size * bpp;

let tile_descriptor = ImageDescriptor {
width: actual_width,
height: actual_height,
stride: Some(stride),
offset: offset,
format: image_descriptor.format,
is_opaque: image_descriptor.is_opaque,
};

self.texture_cache.insert(image_id,
tile_descriptor,
filter,
image_data,
texture_cache_profile);
} else {
self.texture_cache.insert(image_id,
image_template.descriptor,
filter,
image_data,
texture_cache_profile);
}
self.texture_cache.insert(image_id,
descriptor,
filter,
image_data,
texture_cache_profile);

entry.insert(CachedImageInfo {
texture_cache_id: image_id,
Expand Down

0 comments on commit d4c349d

Please sign in to comment.