am 35b38cef: Improve drawing cache speed by selecting the correct opacity and keeping a 32 bits format when the window is 32 bits.

Merge commit '35b38cefcc92f1ed599a652ac5736ab9e9e75039' into eclair-mr2

* commit '35b38cefcc92f1ed599a652ac5736ab9e9e75039':
  Improve drawing cache speed by selecting the correct opacity and keeping a 32 bits
This commit is contained in:
Romain Guy
2009-10-07 14:30:41 -07:00
committed by Android Git Automerger
2 changed files with 18 additions and 9 deletions

View File

@@ -6188,11 +6188,12 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
} }
final int drawingCacheBackgroundColor = mDrawingCacheBackgroundColor; final int drawingCacheBackgroundColor = mDrawingCacheBackgroundColor;
final boolean opaque = drawingCacheBackgroundColor != 0 || final boolean opaque = drawingCacheBackgroundColor != 0 || isOpaque();
(mBGDrawable != null && mBGDrawable.getOpacity() == PixelFormat.OPAQUE); final boolean translucentWindow = attachInfo.mTranslucentWindow;
if (width <= 0 || height <= 0 || if (width <= 0 || height <= 0 ||
(width * height * (opaque ? 2 : 4) > // Projected bitmap size in bytes // Projected bitmap size in bytes
(width * height * (opaque && !translucentWindow ? 2 : 4) >
ViewConfiguration.get(mContext).getScaledMaximumDrawingCacheSize())) { ViewConfiguration.get(mContext).getScaledMaximumDrawingCacheSize())) {
destroyDrawingCache(); destroyDrawingCache();
return; return;
@@ -6203,7 +6204,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
(mUnscaledDrawingCache == null ? null : mUnscaledDrawingCache.get()); (mUnscaledDrawingCache == null ? null : mUnscaledDrawingCache.get());
if (bitmap == null || bitmap.getWidth() != width || bitmap.getHeight() != height) { if (bitmap == null || bitmap.getWidth() != width || bitmap.getHeight() != height) {
Bitmap.Config quality; Bitmap.Config quality;
if (!opaque) { if (!opaque) {
switch (mViewFlags & DRAWING_CACHE_QUALITY_MASK) { switch (mViewFlags & DRAWING_CACHE_QUALITY_MASK) {
@@ -6221,7 +6221,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
break; break;
} }
} else { } else {
quality = Bitmap.Config.RGB_565; // Optimization for translucent windows
// If the window is translucent, use a 32 bits bitmap to benefit from memcpy()
quality = translucentWindow ? Bitmap.Config.ARGB_8888 : Bitmap.Config.RGB_565;
} }
// Try to cleanup memory // Try to cleanup memory
@@ -6235,6 +6237,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
} else { } else {
mUnscaledDrawingCache = new SoftReference<Bitmap>(bitmap); mUnscaledDrawingCache = new SoftReference<Bitmap>(bitmap);
} }
if (opaque && translucentWindow) bitmap.setHasAlpha(false);
} catch (OutOfMemoryError e) { } catch (OutOfMemoryError e) {
// If there is not enough memory to create the bitmap cache, just // If there is not enough memory to create the bitmap cache, just
// ignore the issue as bitmap caches are not required to draw the // ignore the issue as bitmap caches are not required to draw the
@@ -8820,6 +8823,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
*/ */
int mWindowTop; int mWindowTop;
/**
* Indicates whether the window is translucent/transparent
*/
boolean mTranslucentWindow;
/** /**
* For windows that are full-screen but using insets to layout inside * For windows that are full-screen but using insets to layout inside
* of the screen decorations, these are the current insets for the * of the screen decorations, these are the current insets for the
@@ -9033,8 +9041,8 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
public ScrollabilityCache(ViewConfiguration configuration, View host) { public ScrollabilityCache(ViewConfiguration configuration, View host) {
fadingEdgeLength = configuration.getScaledFadingEdgeLength(); fadingEdgeLength = configuration.getScaledFadingEdgeLength();
scrollBarSize = configuration.getScaledScrollBarSize(); scrollBarSize = configuration.getScaledScrollBarSize();
scrollBarDefaultDelayBeforeFade = configuration.getScrollDefaultDelay(); scrollBarDefaultDelayBeforeFade = ViewConfiguration.getScrollDefaultDelay();
scrollBarFadeDuration = configuration.getScrollBarFadeDuration(); scrollBarFadeDuration = ViewConfiguration.getScrollBarFadeDuration();
paint = new Paint(); paint = new Paint();
matrix = new Matrix(); matrix = new Matrix();

View File

@@ -408,7 +408,7 @@ public final class ViewRoot extends Handler implements ViewParent,
} }
boolean restore = false; boolean restore = false;
if (attrs != null && mTranslator != null) { if (mTranslator != null) {
restore = true; restore = true;
attrs.backup(); attrs.backup();
mTranslator.translateWindowLayout(attrs); mTranslator.translateWindowLayout(attrs);
@@ -422,7 +422,7 @@ public final class ViewRoot extends Handler implements ViewParent,
mSoftInputMode = attrs.softInputMode; mSoftInputMode = attrs.softInputMode;
mWindowAttributesChanged = true; mWindowAttributesChanged = true;
mAttachInfo.mRootView = view; mAttachInfo.mRootView = view;
mAttachInfo.mScalingRequired = mTranslator == null ? false : true; mAttachInfo.mScalingRequired = mTranslator != null;
mAttachInfo.mApplicationScale = mAttachInfo.mApplicationScale =
mTranslator == null ? 1.0f : mTranslator.applicationScale; mTranslator == null ? 1.0f : mTranslator.applicationScale;
if (panelParentView != null) { if (panelParentView != null) {
@@ -680,6 +680,7 @@ public final class ViewRoot extends Handler implements ViewParent,
// object is not initialized to its backing store, but soon it // object is not initialized to its backing store, but soon it
// will be (assuming the window is visible). // will be (assuming the window is visible).
attachInfo.mSurface = mSurface; attachInfo.mSurface = mSurface;
attachInfo.mTranslucentWindow = lp.format != PixelFormat.OPAQUE;
attachInfo.mHasWindowFocus = false; attachInfo.mHasWindowFocus = false;
attachInfo.mWindowVisibility = viewVisibility; attachInfo.mWindowVisibility = viewVisibility;
attachInfo.mRecomputeGlobalAttributes = false; attachInfo.mRecomputeGlobalAttributes = false;