ライブ壁紙に半透明のカラー オーバーレイを追加しようとしています。何を試しても、ロード時間が非常に遅くなります。drawARGB を試し、ペイントでアルファを設定し、ピクセルごとにアルファ ビットマップを作成しました。これらの方法はすべて、読み込み時間が遅くなります。私のコードは次のとおりです。
public void draw()
{
long borderLoadTime = 0;
long drawStart = 0;
long drawEnd = 0;
long whileLoopEnd = 0;
long overlayStart = 0;
long overlayEnd = 0;
long holderTime = 0;
long lockTime = 0;
long start = System.currentTimeMillis();
long drawCounter = 0;
Canvas c = new Canvas();
c = holder.lockCanvas();
long canvasLoadTime = System.currentTimeMillis();
if (c != null)
{
if (borderToggle)
c.drawRGB(InfinityService.BORDER_RED,
InfinityService.BORDER_GREEN,
InfinityService.BORDER_BLUE);
else
c.drawColor(Color.BLACK);
borderLoadTime = System.currentTimeMillis();
synchronized (grid)
{
lockTime = System.currentTimeMillis();
for (GridRow row : grid.getImageGrid().values())
{
for (Box box : row.getRow().values())
{
drawStart = System.currentTimeMillis();
if (box.getImgLeft() < getWidth()
&& box.getImgTop() < getHeight()
&& box.getImgRight() > 0
&& box.getImgBottom() > 0)
{
c.drawBitmap(serviceContext.getImages().get(box.getPhoto()),
Math.round(box.getImgLeft()),
Math.round(box.getImgTop()), p);
}
drawEnd = System.currentTimeMillis();
drawCounter += drawEnd - drawStart;
}
}
whileLoopEnd = System.currentTimeMillis();
}
overlayStart = System.currentTimeMillis();
if (overlayToggle)
c.drawARGB(InfinityService.OVERLAY_ALPHA,
InfinityService.OVERLAY_RED,
InfinityService.OVERLAY_GREEN,
InfinityService.OVERLAY_BLUE);
overlayEnd = System.currentTimeMillis();
holder.unlockCanvasAndPost(c);
holderTime = System.currentTimeMillis();
}
Log.d(InfinityService.TAG, "CANVAS LOAD: "
+ (canvasLoadTime - start) + " ms");
Log.d(InfinityService.TAG, "BORDER LOAD: "
+ (borderLoadTime - canvasLoadTime) + " ms");
Log.d(InfinityService.TAG, "BITMAP DRAW TIME: " + drawCounter
+ " ms");
Log.d(InfinityService.TAG, "LOOP TIME: "
+ ((whileLoopEnd - lockTime) - drawCounter) + " ms");
Log.d(InfinityService.TAG, "OVERLAY LOAD: "
+ (overlayEnd - overlayStart) + " ms");
Log.d(InfinityService.TAG, "HOLDER UNLOCK: "
+ (holderTime - overlayEnd) + " ms");
Log.d(InfinityService.TAG,
"LOCK TIME: "
+ ((overlayStart - borderLoadTime) - (whileLoopEnd - lockTime))
+ " ms");
Log.d(InfinityService.TAG,
"------------------------------------");
}
描画されたフレームのログ エントリの一部を次に示します。drawARGB がこのように遅い時間になっていることに注目してください。さらに、キャンバスのロックとロック解除の呼び出しも、完了するまでに長い時間がかかります。
11-10 16:09:34.803: D/InfinityService(10233): CANVAS LOAD: 0 ms
11-10 16:09:34.803: D/InfinityService(10233): BORDER LOAD: 1 ms
11-10 16:09:34.803: D/InfinityService(10233): BITMAP DRAW TIME: 4 ms
11-10 16:09:34.803: D/InfinityService(10233): LOOP TIME: 0 ms
11-10 16:09:34.803: D/InfinityService(10233): OVERLAY LOAD: 8 ms
11-10 16:09:34.803: D/InfinityService(10233): HOLDER UNLOCK: 1 ms
11-10 16:09:34.803: D/InfinityService(10233): LOCK TIME: 0 ms
11-10 16:09:34.803: D/InfinityService(10233): ------------------------------------
11-10 16:09:34.873: D/InfinityService(10233): CANVAS LOAD: 1 ms
11-10 16:09:34.873: D/InfinityService(10233): BORDER LOAD: 0 ms
11-10 16:09:34.873: D/InfinityService(10233): BITMAP DRAW TIME: 4 ms
11-10 16:09:34.873: D/InfinityService(10233): LOOP TIME: 0 ms
11-10 16:09:34.873: D/InfinityService(10233): OVERLAY LOAD: 17 ms
11-10 16:09:34.873: D/InfinityService(10233): HOLDER UNLOCK: 3 ms
11-10 16:09:34.873: D/InfinityService(10233): LOCK TIME: 0 ms
11-10 16:09:34.873: D/InfinityService(10233): ------------------------------------
11-10 16:09:34.953: D/InfinityService(10233): CANVAS LOAD: 1 ms
11-10 16:09:34.953: D/InfinityService(10233): BORDER LOAD: 2 ms
11-10 16:09:34.953: D/InfinityService(10233): BITMAP DRAW TIME: 3 ms
11-10 16:09:34.963: D/InfinityService(10233): LOOP TIME: 3 ms
11-10 16:09:34.963: D/InfinityService(10233): OVERLAY LOAD: 24 ms
11-10 16:09:34.963: D/InfinityService(10233): HOLDER UNLOCK: 3 ms
11-10 16:09:34.963: D/InfinityService(10233): LOCK TIME: 0 ms
11-10 16:09:34.963: D/InfinityService(10233): ------------------------------------
11-10 16:09:35.044: D/InfinityService(10233): CANVAS LOAD: 0 ms
11-10 16:09:35.044: D/InfinityService(10233): BORDER LOAD: 1 ms
11-10 16:09:35.044: D/InfinityService(10233): BITMAP DRAW TIME: 4 ms
11-10 16:09:35.044: D/InfinityService(10233): LOOP TIME: 2 ms
11-10 16:09:35.044: D/InfinityService(10233): OVERLAY LOAD: 24 ms
11-10 16:09:35.044: D/InfinityService(10233): HOLDER UNLOCK: 4 ms
11-10 16:09:35.054: D/InfinityService(10233): LOCK TIME: 0 ms
11-10 16:09:35.054: D/InfinityService(10233): ------------------------------------
11-10 16:09:35.164: D/InfinityService(10233): CANVAS LOAD: 1 ms
11-10 16:09:35.164: D/InfinityService(10233): BORDER LOAD: 1 ms
11-10 16:09:35.164: D/InfinityService(10233): BITMAP DRAW TIME: 5 ms
11-10 16:09:35.164: D/InfinityService(10233): LOOP TIME: 2 ms
11-10 16:09:35.164: D/InfinityService(10233): OVERLAY LOAD: 43 ms
11-10 16:09:35.164: D/InfinityService(10233): HOLDER UNLOCK: 15 ms
11-10 16:09:35.164: D/InfinityService(10233): LOCK TIME: 0 ms
11-10 16:09:35.164: D/InfinityService(10233): ------------------------------------
11-10 16:09:35.234: D/InfinityService(10233): CANVAS LOAD: 0 ms
11-10 16:09:35.234: D/InfinityService(10233): BORDER LOAD: 1 ms
11-10 16:09:35.234: D/InfinityService(10233): BITMAP DRAW TIME: 2 ms
11-10 16:09:35.234: D/InfinityService(10233): LOOP TIME: 1 ms
11-10 16:09:35.234: D/InfinityService(10233): OVERLAY LOAD: 18 ms
11-10 16:09:35.234: D/InfinityService(10233): HOLDER UNLOCK: 2 ms
11-10 16:09:35.234: D/InfinityService(10233): LOCK TIME: 0 ms
11-10 16:09:35.234: D/InfinityService(10233): ------------------------------------
11-10 16:09:35.304: D/InfinityService(10233): CANVAS LOAD: 0 ms
11-10 16:09:35.304: D/InfinityService(10233): BORDER LOAD: 1 ms
11-10 16:09:35.304: D/InfinityService(10233): BITMAP DRAW TIME: 2 ms
11-10 16:09:35.304: D/InfinityService(10233): LOOP TIME: 1 ms
11-10 16:09:35.304: D/InfinityService(10233): OVERLAY LOAD: 19 ms
11-10 16:09:35.304: D/InfinityService(10233): HOLDER UNLOCK: 1 ms
11-10 16:09:35.304: D/InfinityService(10233): LOCK TIME: 0 ms
11-10 16:09:35.304: D/InfinityService(10233): ------------------------------------
11-10 16:09:35.374: D/InfinityService(10233): CANVAS LOAD: 0 ms
11-10 16:09:35.374: D/InfinityService(10233): BORDER LOAD: 1 ms
11-10 16:09:35.374: D/InfinityService(10233): BITMAP DRAW TIME: 3 ms
11-10 16:09:35.374: D/InfinityService(10233): LOOP TIME: 0 ms
11-10 16:09:35.374: D/InfinityService(10233): OVERLAY LOAD: 7 ms
11-10 16:09:35.374: D/InfinityService(10233): HOLDER UNLOCK: 13 ms
11-10 16:09:35.374: D/InfinityService(10233): LOCK TIME: 0 ms
11-10 16:09:35.374: D/InfinityService(10233): ------------------------------------
11-10 16:09:35.444: D/InfinityService(10233): CANVAS LOAD: 1 ms
11-10 16:09:35.444: D/InfinityService(10233): BORDER LOAD: 0 ms
11-10 16:09:35.444: D/InfinityService(10233): BITMAP DRAW TIME: 3 ms
11-10 16:09:35.444: D/InfinityService(10233): LOOP TIME: 0 ms
11-10 16:09:35.444: D/InfinityService(10233): OVERLAY LOAD: 8 ms
11-10 16:09:35.444: D/InfinityService(10233): HOLDER UNLOCK: 11 ms
11-10 16:09:35.444: D/InfinityService(10233): LOCK TIME: 1 ms
11-10 16:09:35.444: D/InfinityService(10233): ------------------------------------
11-10 16:09:35.614: D/InfinityService(10233): CANVAS LOAD: 1 ms
11-10 16:09:35.614: D/InfinityService(10233): BORDER LOAD: 0 ms
11-10 16:09:35.614: D/InfinityService(10233): BITMAP DRAW TIME: 4 ms
11-10 16:09:35.614: D/InfinityService(10233): LOOP TIME: 0 ms
11-10 16:09:35.614: D/InfinityService(10233): OVERLAY LOAD: 117 ms
11-10 16:09:35.614: D/InfinityService(10233): HOLDER UNLOCK: 9 ms
11-10 16:09:35.614: D/InfinityService(10233): LOCK TIME: 0 ms
11-10 16:09:35.614: D/InfinityService(10233): ------------------------------------
11-10 16:09:35.844: D/InfinityService(10233): CANVAS LOAD: 0 ms
11-10 16:09:35.844: D/InfinityService(10233): BORDER LOAD: 1 ms
11-10 16:09:35.844: D/InfinityService(10233): BITMAP DRAW TIME: 3 ms
11-10 16:09:35.844: D/InfinityService(10233): LOOP TIME: 0 ms
11-10 16:09:35.844: D/InfinityService(10233): OVERLAY LOAD: 67 ms
11-10 16:09:35.844: D/InfinityService(10233): HOLDER UNLOCK: 108 ms
11-10 16:09:35.844: D/InfinityService(10233): LOCK TIME: 0 ms
11-10 16:09:35.844: D/InfinityService(10233): ------------------------------------
アルファ カラー オーバーレイを使用すると、両方のデバイスでパフォーマンスが大幅に低下することに気付きました。
これは、2D android キャンバス描画の欠点として避けられないのでしょうか? この問題に関してopenGLは役立ちますか?