зеркало из https://github.com/mozilla/gecko-dev.git
Bug 931843 - Part 1: generate smaller thumbnails. r=kats
This commit is contained in:
Родитель
88d755b107
Коммит
4d2c4c281a
|
@ -96,18 +96,24 @@ public final class ThumbnailHelper {
|
|||
}
|
||||
|
||||
public void setThumbnailWidth(int width) {
|
||||
mPendingWidth.set(IntSize.nextPowerOfTwo(width));
|
||||
// Check inverted for safety: Bug 803299 Comment 34.
|
||||
if (GeckoAppShell.getScreenDepth() == 24) {
|
||||
mPendingWidth.set(width);
|
||||
} else {
|
||||
// Bug 776906: on 16-bit screens we need to ensure an even width.
|
||||
mPendingWidth.set((width & 1) == 0 ? width : width + 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateThumbnailSize() {
|
||||
// Apply any pending width updates
|
||||
// Apply any pending width updates.
|
||||
mWidth = mPendingWidth.get();
|
||||
|
||||
mWidth &= ~0x1; // Ensure the width is always an even number (bug 776906)
|
||||
mHeight = Math.round(mWidth * THUMBNAIL_ASPECT_RATIO);
|
||||
|
||||
int pixelSize = (GeckoAppShell.getScreenDepth() == 24) ? 4 : 2;
|
||||
int capacity = mWidth * mHeight * pixelSize;
|
||||
Log.d(LOGTAG, "Using new thumbnail size: " + capacity + " (width " + mWidth + ")");
|
||||
if (mBuffer == null || mBuffer.capacity() != capacity) {
|
||||
if (mBuffer != null) {
|
||||
mBuffer = DirectBufferAllocator.free(mBuffer);
|
||||
|
@ -139,6 +145,7 @@ public final class ThumbnailHelper {
|
|||
return;
|
||||
}
|
||||
|
||||
Log.d(LOGTAG, "Sending thumbnail event: " + mWidth + ", " + mHeight);
|
||||
GeckoEvent e = GeckoEvent.createThumbnailEvent(tab.getId(), mWidth, mHeight, mBuffer);
|
||||
GeckoAppShell.sendEventToGecko(e);
|
||||
}
|
||||
|
@ -172,6 +179,7 @@ public final class ThumbnailHelper {
|
|||
}
|
||||
|
||||
private void handleThumbnailData(Tab tab, ByteBuffer data) {
|
||||
Log.d(LOGTAG, "handleThumbnailData: " + data.capacity());
|
||||
if (data != mBuffer) {
|
||||
// This should never happen, but log it and recover gracefully
|
||||
Log.e(LOGTAG, "handleThumbnailData called with an unexpected ByteBuffer!");
|
||||
|
|
|
@ -18,6 +18,7 @@ import android.database.Cursor;
|
|||
import android.graphics.Rect;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.ContextMenu.ContextMenuInfo;
|
||||
import android.view.View;
|
||||
import android.widget.AbsListView;
|
||||
|
@ -179,13 +180,10 @@ public class TopSitesGridView extends GridView {
|
|||
return;
|
||||
}
|
||||
|
||||
final int childWidth = getColumnWidth();
|
||||
|
||||
// Set the column width as the thumbnail width.
|
||||
ThumbnailHelper.getInstance().setThumbnailWidth(childWidth);
|
||||
final int columnWidth = getColumnWidth();
|
||||
|
||||
// Get the first child from the adapter.
|
||||
final View child = new TopSitesGridItemView(getContext());
|
||||
final TopSitesGridItemView child = new TopSitesGridItemView(getContext());
|
||||
|
||||
// Set a default LayoutParams on the child, if it doesn't have one on its own.
|
||||
AbsListView.LayoutParams params = (AbsListView.LayoutParams) child.getLayoutParams();
|
||||
|
@ -197,11 +195,16 @@ public class TopSitesGridView extends GridView {
|
|||
|
||||
// Measure the exact width of the child, and the height based on the width.
|
||||
// Note: the child (and TopSitesThumbnailView) takes care of calculating its height.
|
||||
int childWidthSpec = MeasureSpec.makeMeasureSpec(childWidth, MeasureSpec.EXACTLY);
|
||||
int childWidthSpec = MeasureSpec.makeMeasureSpec(columnWidth, MeasureSpec.EXACTLY);
|
||||
int childHeightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
|
||||
child.measure(childWidthSpec, childHeightSpec);
|
||||
final int childHeight = child.getMeasuredHeight();
|
||||
|
||||
// This is the maximum width of the contents of each child in the grid.
|
||||
// Use this as the target width for thumbnails.
|
||||
final int thumbnailWidth = child.getMeasuredWidth() - child.getPaddingLeft() - child.getPaddingRight();
|
||||
ThumbnailHelper.getInstance().setThumbnailWidth(thumbnailWidth);
|
||||
|
||||
// Number of rows required to show these top sites.
|
||||
final int rows = (int) Math.ceil((double) mMaxSites / mNumColumns);
|
||||
final int childrenHeight = childHeight * rows;
|
||||
|
|
Загрузка…
Ссылка в новой задаче