Skip to content

Commit

Permalink
DanmakuRenderer: request creating cache if danmaku has no cache and C…
Browse files Browse the repository at this point in the history
…acheManager exists
  • Loading branch information
ctiao committed Nov 15, 2015
1 parent 3dab9fc commit e13d64c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import master.flame.danmaku.danmaku.model.AbsDisplayer;
import master.flame.danmaku.danmaku.model.BaseDanmaku;
import master.flame.danmaku.danmaku.model.DanmakuTimer;
import master.flame.danmaku.danmaku.model.ICacheManager;
import master.flame.danmaku.danmaku.model.IDanmakuIterator;
import master.flame.danmaku.danmaku.model.IDanmakus;
import master.flame.danmaku.danmaku.model.IDrawingCache;
Expand Down Expand Up @@ -59,6 +60,7 @@ public CacheManagingDrawTask(DanmakuTimer timer, DanmakuContext config, TaskList
mMaxCacheSize = maxCacheSize * 2;
}
mCacheManager = new CacheManager(maxCacheSize, MAX_CACHE_SCREEN_SIZE);
mRenderer.setCacheManager(mCacheManager);
}

@Override
Expand Down Expand Up @@ -124,6 +126,7 @@ public void start() {
if (mCacheManager == null) {
mCacheManager = new CacheManager(mMaxCacheSize, MAX_CACHE_SCREEN_SIZE);
mCacheManager.begin();
mRenderer.setCacheManager(mCacheManager);
} else {
mCacheManager.resume();
}
Expand All @@ -133,6 +136,7 @@ public void start() {
public void quit() {
super.quit();
reset();
mRenderer.setCacheManager(null);
if (mCacheManager != null) {
mCacheManager.end();
mCacheManager = null;
Expand All @@ -147,7 +151,7 @@ public void prepare() {
mCacheManager.begin();
}

public class CacheManager {
public class CacheManager implements ICacheManager {

@SuppressWarnings("unused")
private static final String TAG = "CacheManager";
Expand Down Expand Up @@ -188,6 +192,7 @@ public void seek(long mills) {
mHandler.obtainMessage(CacheHandler.SEEK, mills).sendToTarget();
}

@Override
public void addDanmaku(BaseDanmaku danmaku) {
if (mHandler != null) {
if (danmaku.isLive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class DrawTask implements IDrawTask {

TaskListener mTaskListener;

IRenderer mRenderer;
final IRenderer mRenderer;

DanmakuTimer mTimer;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2013 Chen Hui <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package master.flame.danmaku.danmaku.model;

/**
* Created by ch on 15-11-15.
*/
public interface ICacheManager {
void addDanmaku(BaseDanmaku danmaku);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@
package master.flame.danmaku.danmaku.renderer;


import master.flame.danmaku.danmaku.model.ICacheManager;
import master.flame.danmaku.danmaku.model.BaseDanmaku;
import master.flame.danmaku.danmaku.model.IDanmakus;
import master.flame.danmaku.danmaku.model.IDisplayer;

public interface IRenderer {

public static final int NOTHING_RENDERING = 0;
public static final int CACHE_RENDERING = 1;
public static final int TEXT_RENDERING = 2;
int NOTHING_RENDERING = 0;
int CACHE_RENDERING = 1;
int TEXT_RENDERING = 2;

public class Area {
class Area {

public final float[] mRefreshRect = new float[4];
private int mMaxHeight;
Expand Down Expand Up @@ -125,14 +126,16 @@ public void set(RenderingState other) {
}
}

public RenderingState draw(IDisplayer disp, IDanmakus danmakus, long startRenderTime);
RenderingState draw(IDisplayer disp, IDanmakus danmakus, long startRenderTime);

public void clear();
void clear();

public void clearRetainer();
void clearRetainer();

public void release();
void release();

public void setVerifierEnabled(boolean enabled);
void setVerifierEnabled(boolean enabled);

void setCacheManager(ICacheManager cacheManager);

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package master.flame.danmaku.danmaku.renderer.android;

import master.flame.danmaku.danmaku.model.ICacheManager;
import master.flame.danmaku.danmaku.model.BaseDanmaku;
import master.flame.danmaku.danmaku.model.DanmakuTimer;
import master.flame.danmaku.danmaku.model.IDanmakuIterator;
Expand Down Expand Up @@ -43,6 +44,7 @@ public boolean skipLayout(BaseDanmaku danmaku, float fixedTop, int lines, boolea
}
};
private final DanmakusRetainer mDanmakusRetainer;
private ICacheManager mCacheManager;

public DanmakuRenderer(DanmakuContext config) {
mContext = config;
Expand Down Expand Up @@ -120,6 +122,7 @@ public RenderingState draw(IDisplayer disp, IDanmakus danmakus, long startRender
mRenderingState.cacheHitCount++;
} else if(renderingType == IRenderer.TEXT_RENDERING) {
mRenderingState.cacheMissCount++;
requestCreateCache(drawItem);
}
mRenderingState.addCount(drawItem.getType(), 1);
mRenderingState.addTotalCount(1);
Expand All @@ -136,5 +139,15 @@ public RenderingState draw(IDisplayer disp, IDanmakus danmakus, long startRender
mRenderingState.consumingTime = mStartTimer.update(System.currentTimeMillis());
return mRenderingState;
}


public void setCacheManager(ICacheManager cacheManager) {
mCacheManager = cacheManager;
}

private void requestCreateCache(BaseDanmaku drawItem) {
if (mCacheManager != null) {
mCacheManager.addDanmaku(drawItem);
}
}

}

0 comments on commit e13d64c

Please sign in to comment.