From 039eea17ae9fc2e38b2a9ab879db24c74110a484 Mon Sep 17 00:00:00 2001 From: chrox Date: Sun, 24 Mar 2013 18:28:54 +0800 Subject: [PATCH 1/2] bugfix: set toc/bookmark window dimension smaller than screen size Otherwise if text widgets in toc window expands out of screen, memory free on these widgets will mess up the heap. It sounds ridiculous but after we restrict toc window well inside the screen the bug in #815 is fixed. --- frontend/ui/reader/readerbookmark.lua | 4 ++-- frontend/ui/reader/readertoc.lua | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/ui/reader/readerbookmark.lua b/frontend/ui/reader/readerbookmark.lua index 8dc05530e..a0c90d12e 100644 --- a/frontend/ui/reader/readerbookmark.lua +++ b/frontend/ui/reader/readerbookmark.lua @@ -89,8 +89,8 @@ function ReaderBookmark:onShowBookmark() local bm_menu = Menu:new{ title = "Bookmarks", item_table = self.bookmarks, - width = Screen:getWidth()-20, - height = Screen:getHeight(), + width = Screen:getWidth()-50, + height = Screen:getHeight()-50, } -- buid up menu widget method as closure local doc = self.ui.document diff --git a/frontend/ui/reader/readertoc.lua b/frontend/ui/reader/readertoc.lua index d3c5c4603..355ca5483 100644 --- a/frontend/ui/reader/readertoc.lua +++ b/frontend/ui/reader/readertoc.lua @@ -85,8 +85,8 @@ function ReaderToc:onShowToc() title = "Table of Contents", item_table = self.toc, ui = self.ui, - width = Screen:getWidth()-20, - height = Screen:getHeight(), + width = Screen:getWidth()-50, + height = Screen:getHeight()-50, show_parent = menu_container, } From 01f045e7f99dff3752cd9342197297406f88cc38 Mon Sep 17 00:00:00 2001 From: chrox Date: Sun, 24 Mar 2013 18:37:33 +0800 Subject: [PATCH 2/2] add standalone glyph cache I found it will be especially helpful to cache glyph separately so that glyph caches won't be washed out by a single page cache. --- frontend/cache.lua | 9 ++++++++- frontend/ui/rendertext.lua | 14 +++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/frontend/cache.lua b/frontend/cache.lua index 9d51b2b42..b19dc144f 100644 --- a/frontend/cache.lua +++ b/frontend/cache.lua @@ -1,3 +1,4 @@ +require "dbg" --[[ Inheritable abstraction for cache items ]]-- @@ -29,8 +30,14 @@ Cache = { cache_order = {} } +function Cache:new(o) + o = o or {} + setmetatable(o, self) + self.__index = self + return o +end + function Cache:insert(key, object) - --@TODO add cache for different types of item 09.01 2013 (houqp) -- guarantee that we have enough memory in cache if(object.size > self.max_memsize) then -- we're not allowed to claim this much at all diff --git a/frontend/ui/rendertext.lua b/frontend/ui/rendertext.lua index aefc1983c..8f9ff9e4c 100644 --- a/frontend/ui/rendertext.lua +++ b/frontend/ui/rendertext.lua @@ -4,11 +4,19 @@ require "cache" TODO: all these functions should probably be methods on Face objects ]]-- +GlyphCache = Cache:new{ + max_memsize = 512*1024, + current_memsize = 0, + cache = {}, + -- this will hold the LRU order of the cache + cache_order = {} +} + function getGlyph(face, charcode, bgcolor, fgcolor) if bgcolor == nil then bgcolor = 0.0 end if fgcolor == nil then fgcolor = 1.0 end local hash = "glyph|"..face.hash.."|"..charcode.."|"..bgcolor.."|"..fgcolor - local glyph = Cache:check(hash) + local glyph = GlyphCache:check(hash) if glyph then -- cache hit return glyph[1] @@ -20,8 +28,8 @@ function getGlyph(face, charcode, bgcolor, fgcolor) end glyph = CacheItem:new{rendered_glyph} glyph.size = glyph[1].bb:getWidth() * glyph[1].bb:getHeight() / 2 + 32 - Cache:insert(hash, glyph) - return glyph[1] + GlyphCache:insert(hash, glyph) + return rendered_glyph end function getSubTextByWidth(text, face, width, kerning)