aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/gfx/buffer_map.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/gfx/buffer_map.rs')
-rw-r--r--src/components/gfx/buffer_map.rs27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/components/gfx/buffer_map.rs b/src/components/gfx/buffer_map.rs
index 06dd1e2255e..abb995b39ba 100644
--- a/src/components/gfx/buffer_map.rs
+++ b/src/components/gfx/buffer_map.rs
@@ -2,10 +2,12 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-use std::hashmap::HashMap;
-use std::to_bytes::Cb;
use geom::size::Size2D;
+use layers::platform::surface::NativePaintingGraphicsContext;
use servo_msg::compositor_msg::Tile;
+use std::hashmap::HashMap;
+use std::to_bytes::Cb;
+use std::util;
/// This is a struct used to store buffers when they are not in use.
/// The render task can quickly query for a particular size of buffer when it
@@ -15,7 +17,7 @@ pub struct BufferMap<T> {
map: HashMap<BufferKey, BufferValue<T>>,
/// The current amount of memory stored by the BufferMap's buffers.
mem: uint,
- /// The maximum allowed memory. Unused buffers willl be deleted
+ /// The maximum allowed memory. Unused buffers will be deleted
/// when this threshold is exceeded.
max_mem: uint,
/// A monotonically increasing counter to track how recently tile sizes were used.
@@ -64,8 +66,8 @@ impl<T: Tile> BufferMap<T> {
}
}
- // Insert a new buffer into the map.
- pub fn insert(&mut self, new_buffer: T) {
+ /// Insert a new buffer into the map.
+ pub fn insert(&mut self, graphics_context: &NativePaintingGraphicsContext, new_buffer: T) {
let new_key = BufferKey::get(new_buffer.get_size_2d());
// If all our buffers are the same size and we're already at our
@@ -95,7 +97,9 @@ impl<T: Tile> BufferMap<T> {
};
if {
let list = &mut self.map.get_mut(&old_key).buffers;
- self.mem -= list.pop().get_mem();
+ let condemned_buffer = list.pop();
+ self.mem -= condemned_buffer.get_mem();
+ condemned_buffer.destroy(graphics_context);
list.is_empty()
}
{ // then
@@ -132,4 +136,15 @@ impl<T: Tile> BufferMap<T> {
ret
}
+
+ /// Destroys all buffers.
+ pub fn clear(&mut self, graphics_context: &NativePaintingGraphicsContext) {
+ let map = util::replace(&mut self.map, HashMap::new());
+ for (_, value) in map.move_iter() {
+ for tile in value.buffers.move_iter() {
+ tile.destroy(graphics_context)
+ }
+ }
+ self.mem = 0
+ }
}