From: Owen Lin Date: Thu, 5 Apr 2012 04:45:54 +0000 (+0800) Subject: Draw less to improve performance. X-Git-Tag: android-x86-7.1-r1~2311 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=cd36bfc52cc4e7f4b667ba3c5e8eb950647ae9d1;p=android-x86%2Fpackages-apps-Gallery2.git Draw less to improve performance. Also adjust the upload order to upload nearby textures first. Change-Id: I2d6a8807a14b4602882dd2e5c03030c356f49e47 --- diff --git a/res/drawable/dark_strip.9.png b/res/drawable/dark_strip.9.png deleted file mode 100644 index dba0cae71..000000000 Binary files a/res/drawable/dark_strip.9.png and /dev/null differ diff --git a/src/com/android/gallery3d/ui/AlbumLabelMaker.java b/src/com/android/gallery3d/ui/AlbumLabelMaker.java index 4eac3cbeb..317fe52e3 100644 --- a/src/com/android/gallery3d/ui/AlbumLabelMaker.java +++ b/src/com/android/gallery3d/ui/AlbumLabelMaker.java @@ -24,6 +24,10 @@ public class AlbumLabelMaker { private static final int FONT_COLOR_TITLE = Color.WHITE; private static final int FONT_COLOR_COUNT = 0x80FFFFFF; // 50% white + // We keep a border around the album label to prevent aliasing + private static final int BORDER_SIZE = 1; + private static final int BACKGROUND_COLOR = 0x60000000; // 36% Dark + private final AlbumSetView.LabelSpec mSpec; private final TextPaint mTitlePaint; private final TextPaint mCountPaint; @@ -49,6 +53,10 @@ public class AlbumLabelMaker { mMtpIcon = new LazyLoadedBitmap(R.drawable.frame_overlay_gallery_ptp); } + public static int getBorderSize() { + return BORDER_SIZE; + } + private Bitmap getOverlayAlbumIcon(int sourceType) { switch (sourceType) { case DataSourceType.TYPE_CAMERA: @@ -97,7 +105,9 @@ public class AlbumLabelMaker { public synchronized void setLabelWidth(int width) { if (mLabelWidth == width) return; mLabelWidth = width; - mBitmapPool = new BitmapPool(mLabelWidth, mSpec.labelBackgroundHeight); + int borders = 2 * BORDER_SIZE; + mBitmapPool = new BitmapPool( + width + borders, mSpec.labelBackgroundHeight + borders); } public ThreadPool.Job requestLabel( @@ -146,23 +156,28 @@ public class AlbumLabelMaker { : String.valueOf(album.getTotalMediaItemCount()); Bitmap icon = getOverlayAlbumIcon(mSourceType); - Bitmap bitmap = null; - Canvas canvas; + Bitmap bitmap; int labelWidth; synchronized (this) { labelWidth = mLabelWidth; bitmap = mBitmapPool.getBitmap(); } + if (bitmap == null) { - bitmap = Bitmap.createBitmap(labelWidth, - s.labelBackgroundHeight, Config.ARGB_8888); - canvas = new Canvas(bitmap); - } else { - canvas = new Canvas(bitmap); - canvas.drawColor(0, PorterDuff.Mode.SRC); + int borders = 2 * BORDER_SIZE; + bitmap = Bitmap.createBitmap(labelWidth + borders, + s.labelBackgroundHeight + borders, Config.ARGB_8888); } + Canvas canvas = new Canvas(bitmap); + canvas.clipRect(BORDER_SIZE, BORDER_SIZE, + bitmap.getWidth() - BORDER_SIZE, + bitmap.getHeight() - BORDER_SIZE); + canvas.drawColor(BACKGROUND_COLOR, PorterDuff.Mode.SRC); + + canvas.translate(BORDER_SIZE, BORDER_SIZE); + // draw title if (jc.isCancelled()) return null; int x = s.leftMargin; diff --git a/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java b/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java index 606ab5925..784093c9f 100644 --- a/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java +++ b/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java @@ -276,23 +276,38 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener { return loader.isRequestInProgress(); } - private void queueTextureForUpload(boolean isActive, Texture texture) { - if ((texture == null) || !(texture instanceof BitmapTexture)) return; - if (isActive) { - mTextureUploader.addFgTexture((BitmapTexture) texture); - } else { - mTextureUploader.addBgTexture((BitmapTexture) texture); + private void uploadBackgroundTextureInSlot(int index) { + if (index < mContentStart || index >= mContentEnd) return; + AlbumSetEntry entry = mData[index % mData.length]; + if (entry.content instanceof BitmapTexture) { + mTextureUploader.addBgTexture((BitmapTexture) entry.content); + } + if (entry.label instanceof BitmapTexture) { + mTextureUploader.addBgTexture((BitmapTexture) entry.label); } } private void updateTextureUploadQueue() { if (!mIsActive) return; mTextureUploader.clear(); - for (int i = mContentStart, n = mContentEnd; i < n; ++i) { + + // Upload foreground texture + for (int i = mActiveStart, n = mActiveEnd; i < n; ++i) { AlbumSetEntry entry = mData[i % mData.length]; - boolean isActive = isActiveSlot(i); - queueTextureForUpload(isActive, entry.label); - queueTextureForUpload(isActive, entry.content); + if (entry.content instanceof BitmapTexture) { + mTextureUploader.addFgTexture((BitmapTexture) entry.content); + } + if (entry.label instanceof BitmapTexture) { + mTextureUploader.addFgTexture((BitmapTexture) entry.label); + } + } + + // add background textures + int range = Math.max( + (mContentEnd - mActiveEnd), (mActiveStart - mContentStart)); + for (int i = 0; i < range; ++i) { + uploadBackgroundTextureInSlot(mActiveEnd + i); + uploadBackgroundTextureInSlot(mActiveStart - i - 1); } } diff --git a/src/com/android/gallery3d/ui/AlbumSetView.java b/src/com/android/gallery3d/ui/AlbumSetView.java index 440487e98..03b92308b 100644 --- a/src/com/android/gallery3d/ui/AlbumSetView.java +++ b/src/com/android/gallery3d/ui/AlbumSetView.java @@ -18,7 +18,6 @@ package com.android.gallery3d.ui; import android.content.Context; -import com.android.gallery3d.R; import com.android.gallery3d.app.GalleryActivity; import com.android.gallery3d.data.MediaItem; import com.android.gallery3d.data.MediaObject; @@ -30,7 +29,7 @@ import com.android.gallery3d.ui.AlbumSetSlidingWindow.AlbumSetEntry; public class AlbumSetView extends AbstractSlotRenderer { @SuppressWarnings("unused") private static final String TAG = "AlbumSetView"; - private static final int CACHE_SIZE = 64; + private static final int CACHE_SIZE = 96; private static final int PLACEHOLDER_COLOR = 0xFF222222; private final ColorTexture mWaitLoadingTexture; @@ -40,7 +39,6 @@ public class AlbumSetView extends AbstractSlotRenderer { protected AlbumSetSlidingWindow mDataWindow; private SlotView mSlotView; - private NinePatchTexture mDarkStrip; private int mPressedIndex = -1; private Path mHighlightItemPath = null; @@ -81,7 +79,6 @@ public class AlbumSetView extends AbstractSlotRenderer { mWaitLoadingTexture.setSize(1, 1); Context context = activity.getAndroidContext(); - mDarkStrip = new NinePatchTexture(context, R.drawable.dark_strip); } public void setPressedIndex(int index) { @@ -180,9 +177,9 @@ public class AlbumSetView extends AbstractSlotRenderer { content = mDataWindow.getLoadingTexture(); } if (content != null) { - int h = mLabelSpec.labelBackgroundHeight; - drawFrame(canvas, mDarkStrip, 0, height - h, width, h); - content.draw(canvas, 0, height - h, width, h); + int b = AlbumLabelMaker.getBorderSize(); + int h = content.getHeight(); + content.draw(canvas, -b, height - h + b, width + b + b, h); } return 0; } diff --git a/src/com/android/gallery3d/ui/AlbumSlidingWindow.java b/src/com/android/gallery3d/ui/AlbumSlidingWindow.java index af6dc460d..4fbbe190d 100644 --- a/src/com/android/gallery3d/ui/AlbumSlidingWindow.java +++ b/src/com/android/gallery3d/ui/AlbumSlidingWindow.java @@ -20,7 +20,6 @@ import android.graphics.Bitmap; import android.os.Message; import com.android.gallery3d.app.GalleryActivity; -import com.android.gallery3d.common.BitmapUtils; import com.android.gallery3d.common.Utils; import com.android.gallery3d.data.MediaItem; import com.android.gallery3d.data.Path; @@ -157,26 +156,37 @@ public class AlbumSlidingWindow implements AlbumView.ModelListener { 0, Math.max(0, mSize - data.length)); int contentEnd = Math.min(contentStart + data.length, mSize); setContentWindow(contentStart, contentEnd); - updateUploadedTextures(); + updateTextureUploadQueue(); if (mIsActive) updateAllImageRequests(); } - private void uploadTexture(boolean isActive, Texture texture) { - if ((texture == null) || !(texture instanceof BitmapTexture)) return; - if (isActive) { - mTextureUploader.addFgTexture((BitmapTexture) texture); - } else { - mTextureUploader.addBgTexture((BitmapTexture) texture); + private void uploadBgTextureInSlot(int index) { + if (index < mContentEnd && index >= mContentStart) { + AlbumEntry entry = mData[index % mData.length]; + if (entry.content instanceof BitmapTexture) { + mTextureUploader.addBgTexture((BitmapTexture) entry.content); + } } } - private void updateUploadedTextures() { + private void updateTextureUploadQueue() { if (!mIsActive) return; mTextureUploader.clear(); - for (int i = mContentStart, n = mContentEnd; i < n; ++i) { + + // add foreground textures + for (int i = mActiveStart, n = mActiveEnd; i < n; ++i) { AlbumEntry entry = mData[i % mData.length]; - boolean isActive = isActiveSlot(i); - uploadTexture(isActive, entry.content); + if (entry.content instanceof BitmapTexture) { + mTextureUploader.addFgTexture((BitmapTexture) entry.content); + } + } + + // add background textures + int range = Math.max( + (mContentEnd - mActiveEnd), (mActiveStart - mContentStart)); + for (int i = 0; i < range; ++i) { + uploadBgTextureInSlot(mActiveEnd + i); + uploadBgTextureInSlot(mActiveStart - i - 1); } } diff --git a/src/com/android/gallery3d/ui/AlbumView.java b/src/com/android/gallery3d/ui/AlbumView.java index 7402280c6..04c29143e 100644 --- a/src/com/android/gallery3d/ui/AlbumView.java +++ b/src/com/android/gallery3d/ui/AlbumView.java @@ -28,7 +28,7 @@ public class AlbumView extends AbstractSlotRenderer { @SuppressWarnings("unused") private static final String TAG = "AlbumView"; - private static final int CACHE_SIZE = 64; + private static final int CACHE_SIZE = 96; private AlbumSlidingWindow mDataWindow; private final GalleryActivity mActivity;