• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

packages/apps/Gallery2


Commit MetaInfo

修订版0461b1058ff1b3bb9933a6e912851eda0bddf46c (tree)
时间2011-09-23 13:48:14
作者Chih-Chung Chang <chihchung@goog...>
CommiterAndroid (Google) Code Review

Log Message

Merge "Fix 5223982: Adding one pixel transparent border around the texture."

更改概述

差异

Binary files /dev/null and b/res/drawable/dark_strip.9.png differ
--- a/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java
+++ b/src/com/android/gallery3d/ui/AlbumSetSlidingWindow.java
@@ -357,7 +357,7 @@ public class AlbumSetSlidingWindow implements AlbumSetView.ModelListener {
357357 if (mActiveRequestCount == 0) requestNonactiveImages();
358358 }
359359 if (bitmap != null) {
360- BitmapTexture texture = new BitmapTexture(bitmap);
360+ BitmapTexture texture = new BitmapTexture(bitmap, true);
361361 texture.setThrottled(true);
362362 updateContent(texture);
363363 if (mListener != null) mListener.onContentInvalidated();
--- a/src/com/android/gallery3d/ui/AlbumSlidingWindow.java
+++ b/src/com/android/gallery3d/ui/AlbumSlidingWindow.java
@@ -304,7 +304,7 @@ public class AlbumSlidingWindow implements AlbumView.ModelListener {
304304 if (mActiveRequestCount == 0) requestNonactiveImages();
305305 }
306306 if (bitmap != null) {
307- BitmapTexture texture = new BitmapTexture(bitmap);
307+ BitmapTexture texture = new BitmapTexture(bitmap, true);
308308 texture.setThrottled(true);
309309 updateContent(texture);
310310 if (mListener != null && isActiveSlot) {
--- a/src/com/android/gallery3d/ui/BasicTexture.java
+++ b/src/com/android/gallery3d/ui/BasicTexture.java
@@ -43,6 +43,8 @@ abstract class BasicTexture implements Texture {
4343 private int mTextureWidth;
4444 private int mTextureHeight;
4545
46+ private boolean mHasBorder;
47+
4648 protected WeakReference<GLCanvas> mCanvasRef = null;
4749 private static WeakHashMap<BasicTexture, Object> sAllTextures
4850 = new WeakHashMap<BasicTexture, Object>();
@@ -100,6 +102,25 @@ abstract class BasicTexture implements Texture {
100102 return mTextureHeight;
101103 }
102104
105+ // Returns true if the texture has one pixel transparent border around the
106+ // actual content. This is used to avoid jigged edges.
107+ //
108+ // The jigged edges appear because we use GL_CLAMP_TO_EDGE for texture wrap
109+ // mode (GL_CLAMP is not available in OpenGL ES), so a pixel partially
110+ // covered by the texture will use the color of the edge texel. If we add
111+ // the transparent border, the color of the edge texel will be mixed with
112+ // appropriate amount of transparent.
113+ //
114+ // Currently our background is black, so we can draw the thumbnails without
115+ // enabling blending.
116+ public boolean hasBorder() {
117+ return mHasBorder;
118+ }
119+
120+ protected void setBorder(boolean hasBorder) {
121+ mHasBorder = hasBorder;
122+ }
123+
103124 public void draw(GLCanvas canvas, int x, int y) {
104125 canvas.drawTexture(this, x, y, getWidth(), getHeight());
105126 }
--- a/src/com/android/gallery3d/ui/BitmapTexture.java
+++ b/src/com/android/gallery3d/ui/BitmapTexture.java
@@ -29,6 +29,11 @@ public class BitmapTexture extends UploadedTexture {
2929 protected Bitmap mContentBitmap;
3030
3131 public BitmapTexture(Bitmap bitmap) {
32+ this(bitmap, false);
33+ }
34+
35+ public BitmapTexture(Bitmap bitmap, boolean hasBorder) {
36+ super(hasBorder);
3237 Utils.assertTrue(bitmap != null && !bitmap.isRecycled());
3338 mContentBitmap = bitmap;
3439 }
--- a/src/com/android/gallery3d/ui/GLCanvasImpl.java
+++ b/src/com/android/gallery3d/ui/GLCanvasImpl.java
@@ -341,9 +341,17 @@ public class GLCanvasImpl implements GLCanvas {
341341 // Test whether it has been rotated or flipped, if so, glDrawTexiOES
342342 // won't work
343343 if (isMatrixRotatedOrFlipped(mMatrixValues)) {
344- setTextureCoords(0, 0,
345- (float) texture.getWidth() / texture.getTextureWidth(),
346- (float) texture.getHeight() / texture.getTextureHeight());
344+ if (texture.hasBorder()) {
345+ setTextureCoords(
346+ 1.0f / texture.getTextureWidth(),
347+ 1.0f / texture.getTextureHeight(),
348+ (texture.getWidth() - 1.0f) / texture.getTextureWidth(),
349+ (texture.getHeight() - 1.0f) / texture.getTextureHeight());
350+ } else {
351+ setTextureCoords(0, 0,
352+ (float) texture.getWidth() / texture.getTextureWidth(),
353+ (float) texture.getHeight() / texture.getTextureHeight());
354+ }
347355 textureRect(x, y, width, height);
348356 } else {
349357 // draw the rect from bottom-left to top-right
--- a/src/com/android/gallery3d/ui/GridDrawer.java
+++ b/src/com/android/gallery3d/ui/GridDrawer.java
@@ -24,7 +24,6 @@ import android.graphics.Color;
2424 import android.text.Layout;
2525
2626 public class GridDrawer extends IconDrawer {
27- private final NinePatchTexture mFrameSelected;
2827 private Texture mImportLabel;
2928 private int mGridWidth;
3029 private final SelectionManager mSelectionManager;
@@ -37,7 +36,6 @@ public class GridDrawer extends IconDrawer {
3736 public GridDrawer(Context context, SelectionManager selectionManager) {
3837 super(context);
3938 mContext = context;
40- mFrameSelected = new NinePatchTexture(context, R.drawable.grid_selected);
4139 mSelectionManager = selectionManager;
4240 }
4341
@@ -80,7 +78,7 @@ public class GridDrawer extends IconDrawer {
8078 if (mSelectionManager.isPressedPath(path)) {
8179 drawPressedFrame(canvas, x, y, width, height);
8280 } else if (mSelectionMode && mSelectionManager.isItemSelected(path)) {
83- drawFrame(canvas, mFrameSelected, x, y, width, height);
81+ drawSelectedFrame(canvas, x, y, width, height);
8482 }
8583 }
8684
--- a/src/com/android/gallery3d/ui/HighlightDrawer.java
+++ b/src/com/android/gallery3d/ui/HighlightDrawer.java
@@ -21,13 +21,11 @@ import com.android.gallery3d.data.Path;
2121 import android.content.Context;
2222
2323 public class HighlightDrawer extends IconDrawer {
24- private final NinePatchTexture mFrameSelected;
2524 private SelectionManager mSelectionManager;
2625 private Path mHighlightItem;
2726
2827 public HighlightDrawer(Context context, SelectionManager selectionManager) {
2928 super(context);
30- mFrameSelected = new NinePatchTexture(context, R.drawable.grid_selected);
3129 mSelectionManager = selectionManager;
3230 }
3331
@@ -64,8 +62,8 @@ public class HighlightDrawer extends IconDrawer {
6462
6563 if (mSelectionManager.isPressedPath(path)) {
6664 drawPressedFrame(canvas, x, y, width, height);
67- } else if (path == mHighlightItem) {
68- drawFrame(canvas, mFrameSelected, x, y, width, height);
65+ } else if (path == mHighlightItem) {
66+ drawSelectedFrame(canvas, x, y, width, height);
6967 }
7068 }
7169 }
--- a/src/com/android/gallery3d/ui/IconDrawer.java
+++ b/src/com/android/gallery3d/ui/IconDrawer.java
@@ -29,6 +29,8 @@ public abstract class IconDrawer extends SelectionDrawer {
2929 private final ResourceTexture mPicasaIcon;
3030 private final ResourceTexture mMtpIcon;
3131 private final NinePatchTexture mFramePressed;
32+ private final NinePatchTexture mFrameSelected;
33+ private final NinePatchTexture mDarkStrip;
3234 private final ResourceTexture mPanoramaBorder;
3335 private final Texture mVideoOverlay;
3436 private final Texture mVideoPlayIcon;
@@ -50,6 +52,8 @@ public abstract class IconDrawer extends SelectionDrawer {
5052 mVideoPlayIcon = new ResourceTexture(context, R.drawable.ic_gallery_play);
5153 mPanoramaBorder = new ResourceTexture(context, R.drawable.ic_pan_thumb);
5254 mFramePressed = new NinePatchTexture(context, R.drawable.grid_pressed);
55+ mFrameSelected = new NinePatchTexture(context, R.drawable.grid_selected);
56+ mDarkStrip = new NinePatchTexture(context, R.drawable.dark_strip);
5357 mIconSize = context.getResources().getDimensionPixelSize(
5458 R.dimen.albumset_icon_size);
5559 }
@@ -144,7 +148,7 @@ public abstract class IconDrawer extends SelectionDrawer {
144148 int drawLabelBackground) {
145149 int x = -width / 2;
146150 int y = (height + 1) / 2 - drawLabelBackground;
147- canvas.fillRect(x, y, width, drawLabelBackground, LABEL_BACKGROUND_COLOR);
151+ drawFrame(canvas, mDarkStrip, x, y, width, drawLabelBackground);
148152 }
149153
150154 protected void drawPressedFrame(GLCanvas canvas, int x, int y, int width,
@@ -152,6 +156,11 @@ public abstract class IconDrawer extends SelectionDrawer {
152156 drawFrame(canvas, mFramePressed, x, y, width, height);
153157 }
154158
159+ protected void drawSelectedFrame(GLCanvas canvas, int x, int y, int width,
160+ int height) {
161+ drawFrame(canvas, mFrameSelected, x, y, width, height);
162+ }
163+
155164 @Override
156165 public void drawFocus(GLCanvas canvas, int width, int height) {
157166 }
--- a/src/com/android/gallery3d/ui/SlotView.java
+++ b/src/com/android/gallery3d/ui/SlotView.java
@@ -238,8 +238,6 @@ public class SlotView extends GLView {
238238
239239 @Override
240240 protected void render(GLCanvas canvas) {
241- canvas.save(GLCanvas.SAVE_FLAG_CLIP);
242- canvas.clipRect(0, 0, getWidth(), getHeight());
243241 super.render(canvas);
244242
245243 long currentTimeMillis = canvas.currentAnimationTimeMillis();
@@ -296,7 +294,6 @@ public class SlotView extends GLView {
296294 mUIListener.onUserInteractionEnd();
297295 }
298296 mMoreAnimation = more;
299- canvas.restore();
300297 }
301298
302299 private boolean renderItem(GLCanvas canvas, ItemEntry entry,
--- a/src/com/android/gallery3d/ui/UploadedTexture.java
+++ b/src/com/android/gallery3d/ui/UploadedTexture.java
@@ -57,9 +57,18 @@ abstract class UploadedTexture extends BasicTexture {
5757 private static final int UPLOAD_LIMIT = 100;
5858
5959 protected Bitmap mBitmap;
60+ private int mBorder;
6061
6162 protected UploadedTexture() {
63+ this(false);
64+ }
65+
66+ protected UploadedTexture(boolean hasBorder) {
6267 super(null, 0, STATE_UNLOADED);
68+ if (hasBorder) {
69+ setBorder(true);
70+ mBorder = 1;
71+ }
6372 }
6473
6574 private static class BorderKey implements Cloneable {
@@ -114,14 +123,14 @@ abstract class UploadedTexture extends BasicTexture {
114123 private Bitmap getBitmap() {
115124 if (mBitmap == null) {
116125 mBitmap = onGetBitmap();
126+ int w = mBitmap.getWidth() + mBorder * 2;
127+ int h = mBitmap.getHeight() + mBorder * 2;
117128 if (mWidth == UNSPECIFIED) {
118- setSize(mBitmap.getWidth(), mBitmap.getHeight());
119- } else if (mWidth != mBitmap.getWidth()
120- || mHeight != mBitmap.getHeight()) {
129+ setSize(w, h);
130+ } else if (mWidth != w || mHeight != h) {
121131 throw new IllegalStateException(String.format(
122132 "cannot change size: this = %s, orig = %sx%s, new = %sx%s",
123- toString(), mWidth, mHeight, mBitmap.getWidth(),
124- mBitmap.getHeight()));
133+ toString(), mWidth, mHeight, w, h));
125134 }
126135 }
127136 return mBitmap;
@@ -176,8 +185,8 @@ abstract class UploadedTexture extends BasicTexture {
176185 int format = GLUtils.getInternalFormat(bitmap);
177186 int type = GLUtils.getType(bitmap);
178187 canvas.getGLInstance().glBindTexture(GL11.GL_TEXTURE_2D, mId);
179- GLUtils.texSubImage2D(
180- GL11.GL_TEXTURE_2D, 0, 0, 0, bitmap, format, type);
188+ GLUtils.texSubImage2D(GL11.GL_TEXTURE_2D, 0, mBorder, mBorder,
189+ bitmap, format, type);
181190 freeBitmap();
182191 mContentValid = true;
183192 }
@@ -200,14 +209,20 @@ abstract class UploadedTexture extends BasicTexture {
200209 Bitmap bitmap = getBitmap();
201210 if (bitmap != null) {
202211 try {
212+ int bWidth = bitmap.getWidth();
213+ int bHeight = bitmap.getHeight();
214+ int width = bWidth + mBorder * 2;
215+ int height = bHeight + mBorder * 2;
216+ int texWidth = getTextureWidth();
217+ int texHeight = getTextureHeight();
203218 // Define a vertically flipped crop rectangle for
204219 // OES_draw_texture.
205- int width = bitmap.getWidth();
206- int height = bitmap.getHeight();
207- sCropRect[0] = 0;
208- sCropRect[1] = height;
209- sCropRect[2] = width;
210- sCropRect[3] = -height;
220+ // The four values in sCropRect are: left, bottom, width, and
221+ // height. Negative value of width or height means flip.
222+ sCropRect[0] = mBorder;
223+ sCropRect[1] = mBorder + bHeight;
224+ sCropRect[2] = bWidth;
225+ sCropRect[3] = -bHeight;
211226
212227 // Upload the bitmap to a new texture.
213228 gl.glGenTextures(1, sTextureId, 0);
@@ -223,7 +238,7 @@ abstract class UploadedTexture extends BasicTexture {
223238 gl.glTexParameterf(GL11.GL_TEXTURE_2D,
224239 GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
225240
226- if (width == getTextureWidth() && height == getTextureHeight()) {
241+ if (bWidth == texWidth && bHeight == texHeight) {
227242 GLUtils.texImage2D(GL11.GL_TEXTURE_2D, 0, bitmap, 0);
228243 } else {
229244 int format = GLUtils.getInternalFormat(bitmap);
@@ -231,23 +246,35 @@ abstract class UploadedTexture extends BasicTexture {
231246 Config config = bitmap.getConfig();
232247
233248 gl.glTexImage2D(GL11.GL_TEXTURE_2D, 0, format,
234- getTextureWidth(), getTextureHeight(),
235- 0, format, type, null);
236- GLUtils.texSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, bitmap,
237- format, type);
238-
239- if (width != getTextureWidth()) {
240- Bitmap line = getBorderLine(true, config, getTextureHeight());
241- GLUtils.texSubImage2D(
242- GL11.GL_TEXTURE_2D, 0, width, 0, line, format, type);
249+ texWidth, texHeight, 0, format, type, null);
250+ GLUtils.texSubImage2D(GL11.GL_TEXTURE_2D, 0,
251+ mBorder, mBorder, bitmap, format, type);
252+
253+ if (mBorder > 0) {
254+ // Left border
255+ Bitmap line = getBorderLine(true, config, texHeight);
256+ GLUtils.texSubImage2D(GL11.GL_TEXTURE_2D, 0,
257+ 0, 0, line, format, type);
258+
259+ // Top border
260+ line = getBorderLine(false, config, texWidth);
261+ GLUtils.texSubImage2D(GL11.GL_TEXTURE_2D, 0,
262+ 0, 0, line, format, type);
243263 }
244264
245- if (height != getTextureHeight()) {
246- Bitmap line = getBorderLine(false, config, getTextureWidth());
247- GLUtils.texSubImage2D(
248- GL11.GL_TEXTURE_2D, 0, 0, height, line, format, type);
265+ // Right border
266+ if (mBorder + bWidth < texWidth) {
267+ Bitmap line = getBorderLine(true, config, texHeight);
268+ GLUtils.texSubImage2D(GL11.GL_TEXTURE_2D, 0,
269+ mBorder + bWidth, 0, line, format, type);
249270 }
250271
272+ // Bottom border
273+ if (mBorder + bHeight < texHeight) {
274+ Bitmap line = getBorderLine(false, config, texWidth);
275+ GLUtils.texSubImage2D(GL11.GL_TEXTURE_2D, 0,
276+ 0, mBorder + bHeight, line, format, type);
277+ }
251278 }
252279 } finally {
253280 freeBitmap();