Java Code Examples for master.flame.danmaku.danmaku.model.BaseDanmaku#isMeasured()

The following examples show how to use master.flame.danmaku.danmaku.model.BaseDanmaku#isMeasured() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CacheManagingDrawTask.java    From letv with Apache License 2.0 6 votes vote down vote up
public boolean createCache(BaseDanmaku item) {
    if (!item.isMeasured()) {
        item.measure(CacheManagingDrawTask.this.mDisp, true);
    }
    DrawingCache cache = null;
    try {
        cache = DanmakuUtils.buildDanmakuDrawingCache(item, CacheManagingDrawTask.this.mDisp, (DrawingCache) CacheManager.this.mCachePool.acquire());
        item.cache = cache;
        return true;
    } catch (OutOfMemoryError e) {
        if (cache != null) {
            CacheManager.this.mCachePool.release(cache);
        }
        item.cache = null;
        return false;
    } catch (Exception e2) {
        if (cache != null) {
            CacheManager.this.mCachePool.release(cache);
        }
        item.cache = null;
        return false;
    }
}
 
Example 2
Source File: CacheManagingDrawTask.java    From letv with Apache License 2.0 4 votes vote down vote up
private byte buildCache(BaseDanmaku item, boolean forceInsert) {
    if (!item.isMeasured()) {
        item.measure(CacheManagingDrawTask.this.mDisp, true);
    }
    DrawingCache cache = null;
    try {
        BaseDanmaku danmaku = CacheManager.this.findReuseableCache(item, true, 20);
        if (danmaku != null) {
            cache = (DrawingCache) danmaku.cache;
        }
        if (cache != null) {
            cache.increaseReference();
            item.cache = cache;
            CacheManagingDrawTask.this.mCacheManager.push(item, 0, forceInsert);
            return (byte) 0;
        }
        danmaku = CacheManager.this.findReuseableCache(item, false, 50);
        if (danmaku != null) {
            cache = (DrawingCache) danmaku.cache;
        }
        if (cache != null) {
            danmaku.cache = null;
            item.cache = DanmakuUtils.buildDanmakuDrawingCache(item, CacheManagingDrawTask.this.mDisp, cache);
            CacheManagingDrawTask.this.mCacheManager.push(item, 0, forceInsert);
            return (byte) 0;
        }
        if (!forceInsert) {
            if (CacheManager.this.mRealSize + DanmakuUtils.getCacheSize((int) item.paintWidth, (int) item.paintHeight) > CacheManager.this.mMaxSize) {
                return (byte) 1;
            }
        }
        cache = DanmakuUtils.buildDanmakuDrawingCache(item, CacheManagingDrawTask.this.mDisp, (DrawingCache) CacheManager.this.mCachePool.acquire());
        item.cache = cache;
        boolean pushed = CacheManagingDrawTask.this.mCacheManager.push(item, CacheManager.this.sizeOf(item), forceInsert);
        if (!pushed) {
            releaseDanmakuCache(item, cache);
        }
        return pushed ? (byte) 0 : (byte) 1;
    } catch (OutOfMemoryError e) {
        releaseDanmakuCache(item, null);
        return (byte) 1;
    } catch (Exception e2) {
        releaseDanmakuCache(item, null);
        return (byte) 1;
    }
}
 
Example 3
Source File: DanmakuRenderer.java    From letv with Apache License 2.0 4 votes vote down vote up
public RenderingState draw(IDisplayer disp, IDanmakus danmakus, long startRenderTime) {
    int lastTotalDanmakuCount = this.mRenderingState.totalDanmakuCount;
    this.mRenderingState.reset();
    IDanmakuIterator itr = danmakus.iterator();
    int orderInScreen = 0;
    this.mStartTimer.update(SystemClock.uptimeMillis());
    int sizeInScreen = danmakus.size();
    BaseDanmaku drawItem = null;
    while (itr.hasNext()) {
        drawItem = itr.next();
        if (!drawItem.hasPassedFilter()) {
            this.mContext.mDanmakuFilters.filter(drawItem, orderInScreen, sizeInScreen, this.mStartTimer, false, this.mContext);
        }
        if (drawItem.time >= startRenderTime && (!(drawItem.priority == (byte) 0 && drawItem.isFiltered()) && drawItem.time >= startRenderTime)) {
            if (!drawItem.isDanmakuTypeFiltered || !drawItem.isFiltered()) {
                if (drawItem.isLate()) {
                    if (this.mCacheManager == null || drawItem.hasDrawingCache()) {
                        break;
                    }
                    this.mCacheManager.addDanmaku(drawItem);
                } else {
                    orderInScreen++;
                    if (!drawItem.isMeasured()) {
                        drawItem.measure(disp, false);
                    }
                    this.mDanmakusRetainer.fix(drawItem, disp, this.mVerifier);
                    if (!drawItem.isOutside() && drawItem.isShown()) {
                        if (drawItem.lines != null || drawItem.getBottom() <= ((float) disp.getHeight())) {
                            int renderingType = drawItem.draw(disp);
                            RenderingState renderingState;
                            if (renderingType == 1) {
                                renderingState = this.mRenderingState;
                                renderingState.cacheHitCount++;
                            } else if (renderingType == 2) {
                                renderingState = this.mRenderingState;
                                renderingState.cacheMissCount++;
                                if (this.mCacheManager != null) {
                                    this.mCacheManager.addDanmaku(drawItem);
                                }
                            }
                            this.mRenderingState.addCount(drawItem.getType(), 1);
                            this.mRenderingState.addTotalCount(1);
                            if (!(this.mOnDanmakuShownListener == null || drawItem.firstShownFlag == this.mContext.mGlobalFlagValues.FIRST_SHOWN_RESET_FLAG)) {
                                drawItem.firstShownFlag = this.mContext.mGlobalFlagValues.FIRST_SHOWN_RESET_FLAG;
                                this.mOnDanmakuShownListener.onDanmakuShown(drawItem);
                            }
                        }
                    }
                }
            }
        }
    }
    this.mRenderingState.nothingRendered = this.mRenderingState.totalDanmakuCount == 0;
    this.mRenderingState.endTime = drawItem != null ? drawItem.time : -1;
    if (this.mRenderingState.nothingRendered) {
        this.mRenderingState.beginTime = -1;
    }
    this.mRenderingState.incrementCount = this.mRenderingState.totalDanmakuCount - lastTotalDanmakuCount;
    this.mRenderingState.consumingTime = this.mStartTimer.update(SystemClock.uptimeMillis());
    return this.mRenderingState;
}