public boolean createCache(BaseDanmaku item) { // measure if (!item.isMeasured()) { item.measure(mDisp); } DrawingCache cache = null; try { cache = mCachePool.acquire(); cache = DanmakuUtils.buildDanmakuDrawingCache(item, mDisp, cache); item.cache = cache; } catch (OutOfMemoryError e) { // Log.e("cache", "break at error: oom"); if (cache != null) { mCachePool.release(cache); } item.cache = null; return false; } catch (Exception e) { // Log.e("cache", "break at exception:" + e.getMessage()); if (cache != null) { mCachePool.release(cache); } item.cache = null; return false; } return true; }
private byte buildCache(BaseDanmaku item, boolean forceInsert) { // measure if (!item.isMeasured()) { item.measure(mDisp); } DrawingCache cache = null; try { // try to find reuseable cache BaseDanmaku danmaku = findReuseableCache(item, true, 20); if (danmaku != null) { cache = (DrawingCache) danmaku.cache; } if (cache != null) { cache.increaseReference(); item.cache = cache; // Log.w("cache", danmaku.text + "DrawingCache hit!!:" + item.paintWidth + "," + // danmaku.paintWidth); mCacheManager.push(item, 0, forceInsert); return RESULT_SUCCESS; } // try to find reuseable cache from timeout || no-refrerence caches danmaku = findReuseableCache(item, false, 50); if (danmaku != null) { cache = (DrawingCache) danmaku.cache; } if (cache != null) { danmaku.cache = null; // Log.e("cache", danmaku.text + "DrawingCache hit!!:" + item.paintWidth + "," + // danmaku.paintWidth); cache = DanmakuUtils.buildDanmakuDrawingCache(item, mDisp, cache); // redraw item.cache = cache; mCacheManager.push(item, 0, forceInsert); return RESULT_SUCCESS; } // guess cache size if (!forceInsert) { int cacheSize = DanmakuUtils.getCacheSize((int) item.paintWidth, (int) item.paintHeight); if (mRealSize + cacheSize > mMaxSize) { // Log.d("cache", "break at MaxSize:"+mMaxSize); return RESULT_FAILED; } } cache = mCachePool.acquire(); cache = DanmakuUtils.buildDanmakuDrawingCache(item, mDisp, cache); item.cache = cache; boolean pushed = mCacheManager.push(item, sizeOf(item), forceInsert); if (!pushed) { releaseDanmakuCache(item, cache); // Log.e("cache", "break at push failed:" + mMaxSize); } return pushed ? RESULT_SUCCESS : RESULT_FAILED; } catch (OutOfMemoryError e) { // Log.e("cache", "break at error: oom"); releaseDanmakuCache(item, cache); return RESULT_FAILED; } catch (Exception e) { // Log.e("cache", "break at exception:" + e.getMessage()); releaseDanmakuCache(item, cache); return RESULT_FAILED; } }