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

Allow updating images that are not raw buffers #1004

Merged
merged 4 commits into from Mar 29, 2017
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Prev

Treat updating non-existant images as an error.

  • Loading branch information
nical committed Mar 28, 2017
commit 80b500af92a108d8fa5a2944431135dd39f65856
@@ -310,38 +310,31 @@ impl ResourceCache {
data: ImageData,
dirty_rect: Option<DeviceUintRect>) {

let (next_epoch, prev_dirty_rect) = match self.image_templates.get(&image_key) {
Some(image) => {
assert!(image.descriptor.width == descriptor.width);
assert!(image.descriptor.height == descriptor.height);
assert!(image.descriptor.format == descriptor.format);

let Epoch(current_epoch) = image.epoch;
(Epoch(current_epoch + 1), image.dirty_rect)
}
None => {
// TODO: We should consider this an error (updating an image that does
// not exist).
(Epoch(0), None)
let resource = if let Some(image) = self.image_templates.get(&image_key) {
assert!(image.descriptor.width == descriptor.width);
assert!(image.descriptor.height == descriptor.height);
assert!(image.descriptor.format == descriptor.format);

let next_epoch = Epoch(image.epoch.0 + 1);

let mut tiling = image.tiling;
if tiling.is_none() && self.should_tile(&descriptor, &data) {
tiling = Some(DEFAULT_TILE_SIZE);
}
};

let tiling = if self.should_tile(&descriptor, &data) {
Some(DEFAULT_TILE_SIZE)
ImageResource {
descriptor: descriptor,
data: data,
epoch: next_epoch,
tiling: tiling,
dirty_rect: match (dirty_rect, image.dirty_rect) {
(Some(rect), Some(prev_rect)) => Some(rect.union(&prev_rect)),
(Some(rect), None) => Some(rect),
_ => None,
},
}
} else {
None
};

let resource = ImageResource {
descriptor: descriptor,
data: data,
epoch: next_epoch,
tiling: tiling,
dirty_rect: match (dirty_rect, prev_dirty_rect) {
(Some(rect), Some(prev_rect)) => Some(rect.union(&prev_rect)),
(Some(rect), None) => Some(rect),
_ => None,
},
panic!("Attempt to update non-existant image (key {:?}).", image_key);
};

self.image_templates.insert(image_key, resource);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.