2014-04-30 15:24:44 +00:00
|
|
|
local Blitbuffer = require("ffi/blitbuffer")
|
2013-10-18 20:38:07 +00:00
|
|
|
local CacheItem = require("cacheitem")
|
2014-04-30 15:24:44 +00:00
|
|
|
local serial = require("serialize")
|
2016-12-29 08:10:38 +00:00
|
|
|
local logger = require("logger")
|
2013-10-18 20:38:07 +00:00
|
|
|
|
|
|
|
local TileCacheItem = CacheItem:new{}
|
|
|
|
|
|
|
|
function TileCacheItem:onFree()
|
2014-03-13 13:52:43 +00:00
|
|
|
if self.bb.free then
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("free blitbuffer", self.bb)
|
2014-03-13 13:52:43 +00:00
|
|
|
self.bb:free()
|
|
|
|
end
|
2013-10-18 20:38:07 +00:00
|
|
|
end
|
|
|
|
|
2014-04-30 15:24:44 +00:00
|
|
|
function TileCacheItem:dump(filename)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("dumping tile cache to", filename, self.excerpt)
|
2014-04-30 15:24:44 +00:00
|
|
|
return serial.dump(self.size, self.excerpt, self.pageno,
|
|
|
|
self.bb.w, self.bb.h, self.bb.pitch, self.bb:getType(),
|
|
|
|
Blitbuffer.tostring(self.bb), filename)
|
|
|
|
end
|
|
|
|
|
|
|
|
function TileCacheItem:load(filename)
|
|
|
|
local w, h, pitch, bb_type, bb_data
|
|
|
|
self.size, self.excerpt, self.pageno,
|
|
|
|
w, h, pitch, bb_type, bb_data = serial.load(filename)
|
|
|
|
self.bb = Blitbuffer.fromstring(w, h, bb_type, bb_data, pitch)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("loading tile cache from", filename, self)
|
2014-04-30 15:24:44 +00:00
|
|
|
end
|
|
|
|
|
2013-10-18 20:38:07 +00:00
|
|
|
return TileCacheItem
|