mirror of
https://github.com/penpot/penpot.git
synced 2025-07-19 02:37:11 +02:00
Merge pull request #6187 from penpot/azazeln28-fix-surface-pool-missing-deallocation
🐛 Fix SurfacePool missing deallocation
This commit is contained in:
commit
a109f11926
1 changed files with 38 additions and 5 deletions
|
@ -7,6 +7,8 @@ use super::{gpu_state::GpuState, tiles::Tile};
|
||||||
use base64::{engine::general_purpose, Engine as _};
|
use base64::{engine::general_purpose, Engine as _};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
const POOL_CAPACITY_THRESHOLD: i32 = 4;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||||
pub enum SurfaceId {
|
pub enum SurfaceId {
|
||||||
Target,
|
Target,
|
||||||
|
@ -64,7 +66,6 @@ impl Surfaces {
|
||||||
let shape_strokes = target.new_surface_with_dimensions(extra_tile_dims).unwrap();
|
let shape_strokes = target.new_surface_with_dimensions(extra_tile_dims).unwrap();
|
||||||
let debug = target.new_surface_with_dimensions((width, height)).unwrap();
|
let debug = target.new_surface_with_dimensions((width, height)).unwrap();
|
||||||
|
|
||||||
const POOL_CAPACITY_THRESHOLD: i32 = 4;
|
|
||||||
let pool_capacity =
|
let pool_capacity =
|
||||||
(width / tile_dims.width) * (height / tile_dims.height) * POOL_CAPACITY_THRESHOLD;
|
(width / tile_dims.width) * (height / tile_dims.height) * POOL_CAPACITY_THRESHOLD;
|
||||||
let pool = SurfacePool::with_capacity(&mut target, tile_dims, pool_capacity as usize);
|
let pool = SurfacePool::with_capacity(&mut target, tile_dims, pool_capacity as usize);
|
||||||
|
@ -233,6 +234,14 @@ impl Surfaces {
|
||||||
self.tiles.visit(tile);
|
self.tiles.visit(tile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn cache_visited_amount(&self) -> usize {
|
||||||
|
self.tiles.visited_amount()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn cache_visited_capacity(&self) -> usize {
|
||||||
|
self.tiles.visited_capacity()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn cache_tile_surface(&mut self, tile: Tile, id: SurfaceId, color: skia::Color) {
|
pub fn cache_tile_surface(&mut self, tile: Tile, id: SurfaceId, color: skia::Color) {
|
||||||
let sampling_options = self.sampling_options;
|
let sampling_options = self.sampling_options;
|
||||||
let mut tile_surface = self.tiles.get_or_create(tile).unwrap();
|
let mut tile_surface = self.tiles.get_or_create(tile).unwrap();
|
||||||
|
@ -319,28 +328,43 @@ impl SurfacePool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn capacity(&self) -> usize {
|
||||||
|
self.surfaces.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn available(&self) -> usize {
|
||||||
|
let mut available: usize = 0;
|
||||||
|
for surface_ref in self.surfaces.iter() {
|
||||||
|
if surface_ref.in_use == false {
|
||||||
|
available += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
available
|
||||||
|
}
|
||||||
|
|
||||||
pub fn deallocate(&mut self, surface_ref_to_deallocate: &SurfaceRef) {
|
pub fn deallocate(&mut self, surface_ref_to_deallocate: &SurfaceRef) {
|
||||||
let surface_ref = self
|
let surface_ref = self
|
||||||
.surfaces
|
.surfaces
|
||||||
.get_mut(surface_ref_to_deallocate.index)
|
.get_mut(surface_ref_to_deallocate.index)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
surface_ref.in_use = false;
|
surface_ref.in_use = false;
|
||||||
|
self.index = surface_ref_to_deallocate.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn allocate(&mut self) -> Option<SurfaceRef> {
|
pub fn allocate(&mut self) -> Option<SurfaceRef> {
|
||||||
let start = self.index;
|
let start = self.index;
|
||||||
let len = self.surfaces.len();
|
let len = self.surfaces.len();
|
||||||
loop {
|
loop {
|
||||||
self.index = (self.index + 1) % len;
|
|
||||||
if self.index == start {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
if let Some(surface_ref) = self.surfaces.get_mut(self.index) {
|
if let Some(surface_ref) = self.surfaces.get_mut(self.index) {
|
||||||
if !surface_ref.in_use {
|
if !surface_ref.in_use {
|
||||||
surface_ref.in_use = true;
|
surface_ref.in_use = true;
|
||||||
return Some(surface_ref.clone());
|
return Some(surface_ref.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
self.index = (self.index + 1) % len;
|
||||||
|
if self.index == start {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -373,6 +397,7 @@ impl TileSurfaceCache {
|
||||||
// there should be a better solution.
|
// there should be a better solution.
|
||||||
for (tile, surface_ref) in self.grid.iter() {
|
for (tile, surface_ref) in self.grid.iter() {
|
||||||
if !self.visited.contains_key(tile) {
|
if !self.visited.contains_key(tile) {
|
||||||
|
self.pool.deallocate(surface_ref);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if !self.visited.get(tile).unwrap() {
|
if !self.visited.get(tile).unwrap() {
|
||||||
|
@ -404,6 +429,14 @@ impl TileSurfaceCache {
|
||||||
self.pool.clear();
|
self.pool.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn visited_amount(&self) -> usize {
|
||||||
|
self.visited.len()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn visited_capacity(&self) -> usize {
|
||||||
|
self.visited.capacity()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn clear_visited(&mut self) {
|
pub fn clear_visited(&mut self) {
|
||||||
self.visited.clear();
|
self.visited.clear();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue