gears.surface: Change the way that caching works

Loading a file normally has the same behaviour as before. First the cache is
checked and if nothing is found, the file is loaded and cached.

This commit changes the behaviour of loading a file uncached. This no longer
removes the file from the cache if it is cached (why should it?) and also does
not put it in the cache.

This means that users of load_uncached and load_uncached_silently can now freely
modify the resulting surface without interfering with other API users.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2016-02-28 17:21:10 +01:00
parent f9d15691b8
commit 2ad147d740
1 changed files with 7 additions and 8 deletions

View File

@ -41,8 +41,6 @@ function surface.load_uncached_silently(_surface, default)
if not _surface then
return get_default(default)
end
-- Remove from cache if it was cached
surface_cache[_surface] = nil
-- lgi cairo surfaces don't get changed either
if cairo.Surface:is_type_of(_surface) then
return _surface
@ -57,12 +55,7 @@ function surface.load_uncached_silently(_surface, default)
end
end
-- Everything else gets forced into a surface
_surface = cairo.Surface(_surface, true)
-- If we loaded a file, cache it
if file then
surface_cache[file] = _surface
end
return _surface
return cairo.Surface(_surface, true)
end
--- Try to convert the argument into an lgi cairo surface.
@ -80,6 +73,12 @@ function surface.load_silently(_surface, default)
if cache then
return cache
end
local result, err = surface.load_uncached_silently(_surface, default)
if not err then
-- Cache the file
surface_cache[_surface] = result
end
return result, err
end
return surface.load_uncached_silently(_surface, default)
end