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

The following examples show how to use master.flame.danmaku.danmaku.model.BaseDanmaku#hasDrawingCache() . 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 5 votes vote down vote up
private final void addDanmakuAndBuildCache(BaseDanmaku danmaku) {
    if (!danmaku.isTimeOut() && danmaku.time <= CacheManagingDrawTask.this.mCacheTimer.currMillisecond + CacheManagingDrawTask.this.mContext.mDanmakuFactory.MAX_DANMAKU_DURATION) {
        if (danmaku.priority != (byte) 0 || !danmaku.isFiltered()) {
            if (!danmaku.isDanmakuTypeFiltered || !danmaku.isFiltered()) {
                if (!danmaku.hasDrawingCache()) {
                    buildCache(danmaku, true);
                }
                if (danmaku.isLive) {
                    CacheManagingDrawTask.this.mCacheTimer.update(CacheManagingDrawTask.this.mTimer.currMillisecond + (CacheManagingDrawTask.this.mContext.mDanmakuFactory.MAX_DANMAKU_DURATION * ((long) CacheManager.this.mScreenSize)));
                }
            }
        }
    }
}
 
Example 2
Source File: CacheManagingDrawTask.java    From letv with Apache License 2.0 5 votes vote down vote up
private void evictAllNotInScreen(boolean removeAllReferences) {
    if (this.mCaches != null) {
        IDanmakuIterator it = this.mCaches.iterator();
        while (it.hasNext()) {
            BaseDanmaku danmaku = it.next();
            IDrawingCache<?> cache = danmaku.cache;
            boolean hasReferences;
            if (cache == null || !cache.hasReferences()) {
                hasReferences = false;
            } else {
                hasReferences = true;
            }
            if (removeAllReferences && hasReferences) {
                if (cache.get() != null) {
                    this.mRealSize -= cache.size();
                    cache.destroy();
                }
                entryRemoved(true, danmaku, null);
                it.remove();
            } else if (!danmaku.hasDrawingCache() || danmaku.isOutside()) {
                entryRemoved(true, danmaku, null);
                it.remove();
            }
        }
    }
    this.mRealSize = 0;
}
 
Example 3
Source File: CacheManagingDrawTask.java    From letv with Apache License 2.0 5 votes vote down vote up
protected void onDanmakuRemoved(BaseDanmaku danmaku) {
    super.onDanmakuRemoved(danmaku);
    if (danmaku.hasDrawingCache()) {
        if (danmaku.cache.hasReferences()) {
            danmaku.cache.decreaseReference();
        } else {
            danmaku.cache.destroy();
        }
        danmaku.cache = null;
    }
}
 
Example 4
Source File: CacheManagingDrawTask.java    From letv with Apache License 2.0 4 votes vote down vote up
public void handleMessage(Message msg) {
    switch (msg.what) {
        case 1:
            CacheManager.this.evictAllNotInScreen();
            for (int i = 0; i < 300; i++) {
                CacheManager.this.mCachePool.release(new DrawingCache());
            }
            break;
        case 2:
            addDanmakuAndBuildCache(msg.obj);
            return;
        case 3:
            removeMessages(3);
            boolean repositioned = !(CacheManagingDrawTask.this.mTaskListener == null || CacheManagingDrawTask.this.mReadyState) || this.mSeekedFlag;
            prepareCaches(repositioned);
            if (repositioned) {
                this.mSeekedFlag = false;
            }
            if (CacheManagingDrawTask.this.mTaskListener != null && !CacheManagingDrawTask.this.mReadyState) {
                CacheManagingDrawTask.this.mTaskListener.ready();
                CacheManagingDrawTask.this.mReadyState = true;
                return;
            }
            return;
        case 4:
            CacheManager.this.clearTimeOutCaches();
            return;
        case 5:
            Long seekMills = msg.obj;
            if (seekMills != null) {
                CacheManagingDrawTask.this.mCacheTimer.update(seekMills.longValue());
                this.mSeekedFlag = true;
                CacheManager.this.evictAllNotInScreen();
                resume();
                return;
            }
            return;
        case 6:
            removeCallbacksAndMessages(null);
            this.mPause = true;
            CacheManager.this.evictAll();
            CacheManager.this.clearCachePool();
            getLooper().quit();
            return;
        case 7:
            CacheManager.this.evictAll();
            CacheManagingDrawTask.this.mCacheTimer.update(CacheManagingDrawTask.this.mTimer.currMillisecond - CacheManagingDrawTask.this.mContext.mDanmakuFactory.MAX_DANMAKU_DURATION);
            this.mSeekedFlag = true;
            return;
        case 8:
            CacheManager.this.evictAllNotInScreen(true);
            CacheManagingDrawTask.this.mCacheTimer.update(CacheManagingDrawTask.this.mTimer.currMillisecond);
            return;
        case 9:
            CacheManager.this.evictAllNotInScreen(true);
            CacheManagingDrawTask.this.mCacheTimer.update(CacheManagingDrawTask.this.mTimer.currMillisecond);
            CacheManagingDrawTask.this.requestClear();
            return;
        case 16:
            break;
        case 17:
            Pair<BaseDanmaku, Boolean> pair = msg.obj;
            if (pair != null) {
                BaseDanmaku cacheitem = pair.first;
                if (((Boolean) pair.second).booleanValue()) {
                    cacheitem.requestFlags |= 1;
                }
                cacheitem.requestFlags |= 2;
                if (!((Boolean) pair.second).booleanValue() && cacheitem.hasDrawingCache() && !cacheitem.cache.hasReferences()) {
                    cacheitem.cache = DanmakuUtils.buildDanmakuDrawingCache(cacheitem, CacheManagingDrawTask.this.mDisp, (DrawingCache) cacheitem.cache);
                    CacheManager.this.push(cacheitem, 0, true);
                    return;
                } else if (cacheitem.isLive) {
                    CacheManager.this.clearCache(cacheitem);
                    createCache(cacheitem);
                    return;
                } else {
                    CacheManager.this.entryRemoved(true, cacheitem, null);
                    addDanmakuAndBuildCache(cacheitem);
                    return;
                }
            }
            return;
        default:
            return;
    }
    long delayed = dispatchAction();
    if (delayed <= 0) {
        delayed = CacheManagingDrawTask.this.mContext.mDanmakuFactory.MAX_DANMAKU_DURATION / 2;
    }
    sendEmptyMessageDelayed(16, delayed);
}
 
Example 5
Source File: CacheManagingDrawTask.java    From letv with Apache License 2.0 4 votes vote down vote up
private long prepareCaches(boolean repositioned) {
    long curr = CacheManagingDrawTask.this.mCacheTimer.currMillisecond;
    long end = curr + (CacheManagingDrawTask.this.mContext.mDanmakuFactory.MAX_DANMAKU_DURATION * ((long) CacheManager.this.mScreenSize));
    if (end < CacheManagingDrawTask.this.mTimer.currMillisecond) {
        return 0;
    }
    long startTime = SystemClock.uptimeMillis();
    IDanmakus danmakus = null;
    int tryCount = 0;
    boolean hasException = false;
    do {
        BaseDanmaku first;
        try {
            danmakus = CacheManagingDrawTask.this.danmakuList.subnew(curr, end);
        } catch (Exception e) {
            hasException = true;
            SystemClock.sleep(10);
        }
        tryCount++;
        if (tryCount >= 3 || danmakus != null) {
            if (danmakus != null) {
                CacheManagingDrawTask.this.mCacheTimer.update(end);
                return 0;
            }
            first = danmakus.first();
            BaseDanmaku last = danmakus.last();
            if (first != null || last == null) {
                CacheManagingDrawTask.this.mCacheTimer.update(end);
                return 0;
            }
            long sleepTime = Math.min(100, 30 + ((10 * (first.time - CacheManagingDrawTask.this.mTimer.currMillisecond)) / CacheManagingDrawTask.this.mContext.mDanmakuFactory.MAX_DANMAKU_DURATION));
            if (repositioned) {
                sleepTime = 0;
            }
            IDanmakuIterator itr = danmakus.iterator();
            BaseDanmaku item = null;
            int orderInScreen = 0;
            int currScreenIndex = 0;
            int sizeInScreen = danmakus.size();
            while (!this.mPause && !this.mCancelFlag && itr.hasNext()) {
                item = itr.next();
                if (last.time >= CacheManagingDrawTask.this.mTimer.currMillisecond) {
                    if (!item.hasDrawingCache() && (repositioned || (!item.isTimeOut() && item.isOutside()))) {
                        if (!item.hasPassedFilter()) {
                            CacheManagingDrawTask.this.mContext.mDanmakuFilters.filter(item, orderInScreen, sizeInScreen, null, true, CacheManagingDrawTask.this.mContext);
                        }
                        if (!((item.priority == (byte) 0 && item.isFiltered()) || (item.isDanmakuTypeFiltered && item.isFiltered()))) {
                            int screenIndex = (int) ((item.time - curr) / CacheManagingDrawTask.this.mContext.mDanmakuFactory.MAX_DANMAKU_DURATION);
                            if (currScreenIndex == screenIndex) {
                                orderInScreen++;
                            } else {
                                orderInScreen = 0;
                                currScreenIndex = screenIndex;
                            }
                            if (!repositioned) {
                                try {
                                    synchronized (CacheManagingDrawTask.this.mDrawingNotify) {
                                        CacheManagingDrawTask.this.mDrawingNotify.wait(sleepTime);
                                    }
                                } catch (InterruptedException e2) {
                                    e2.printStackTrace();
                                }
                            }
                            if (buildCache(item, false) != (byte) 1) {
                                if (!repositioned && SystemClock.uptimeMillis() - startTime >= DanmakuFactory.COMMON_DANMAKU_DURATION * ((long) CacheManager.this.mScreenSize)) {
                                    break;
                                }
                            }
                            break;
                        }
                    }
                }
                break;
            }
            long consumingTime = SystemClock.uptimeMillis() - startTime;
            if (item != null) {
                CacheManagingDrawTask.this.mCacheTimer.update(item.time);
                return consumingTime;
            }
            CacheManagingDrawTask.this.mCacheTimer.update(end);
            return consumingTime;
        }
    } while (hasException);
    if (danmakus != null) {
        first = danmakus.first();
        BaseDanmaku last2 = danmakus.last();
        if (first != null) {
        }
        CacheManagingDrawTask.this.mCacheTimer.update(end);
        return 0;
    }
    CacheManagingDrawTask.this.mCacheTimer.update(end);
    return 0;
}
 
Example 6
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;
}
 
Example 7
Source File: AndroidDisplayer.java    From letv with Apache License 2.0 4 votes vote down vote up
public int draw(BaseDanmaku danmaku) {
    float top = danmaku.getTop();
    float left = danmaku.getLeft();
    if (this.canvas == null) {
        return 0;
    }
    Paint alphaPaint = null;
    boolean needRestore = false;
    if (danmaku.getType() == 7) {
        if (danmaku.getAlpha() == AlphaValue.TRANSPARENT) {
            return 0;
        }
        if (!(danmaku.rotationZ == 0.0f && danmaku.rotationY == 0.0f)) {
            saveCanvas(danmaku, this.canvas, left, top);
            needRestore = true;
        }
        if (danmaku.getAlpha() != AlphaValue.MAX) {
            alphaPaint = this.ALPHA_PAINT;
            alphaPaint.setAlpha(danmaku.getAlpha());
        }
    }
    if (alphaPaint != null && alphaPaint.getAlpha() == AlphaValue.TRANSPARENT) {
        return 0;
    }
    boolean cacheDrawn = false;
    int result = 1;
    if (danmaku.hasDrawingCache() && danmaku.cache != null) {
        DrawingCacheHolder holder = ((DrawingCache) danmaku.cache).get();
        if (holder != null) {
            cacheDrawn = holder.draw(this.canvas, left, top, alphaPaint);
        }
    }
    if (!cacheDrawn) {
        if (alphaPaint != null) {
            this.PAINT.setAlpha(alphaPaint.getAlpha());
        } else {
            resetPaintAlpha(this.PAINT);
        }
        drawDanmaku(danmaku, this.canvas, left, top, false);
        result = 2;
    }
    if (danmaku.isClickZan) {
        this.sStuffer.drawClickBg(danmaku, this.canvas, left, top);
    }
    if (needRestore) {
        restoreCanvas(this.canvas);
    }
    return result;
}