Improve drawing cache speed by selecting the correct opacity and keeping a 32 bits

format when the window is 32 bits.

Change-Id: I46762def67fa7d6a331a75fa8660c6422394ccf2
This commit is contained in:
Romain Guy
2009-10-07 13:38:55 -07:00
parent 64dd5be583
commit 35b38cefcc
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 boolean opaque = drawingCacheBackgroundColor != 0 ||
(mBGDrawable != null && mBGDrawable.getOpacity() == PixelFormat.OPAQUE);
final boolean opaque = drawingCacheBackgroundColor != 0 || isOpaque();
final boolean translucentWindow = attachInfo.mTranslucentWindow;
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())) {
destroyDrawingCache();
return;
@@ -6203,7 +6204,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
(mUnscaledDrawingCache == null ? null : mUnscaledDrawingCache.get());
if (bitmap == null || bitmap.getWidth() != width || bitmap.getHeight() != height) {
Bitmap.Config quality;
if (!opaque) {
switch (mViewFlags & DRAWING_CACHE_QUALITY_MASK) {
@@ -6221,7 +6221,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
break;
}
} 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
@@ -6235,6 +6237,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, Accessibility
} else {
mUnscaledDrawingCache = new SoftReference<Bitmap>(bitmap);
}
if (opaque && translucentWindow) bitmap.setHasAlpha(false);
} catch (OutOfMemoryError e) {
// If there is not enough memory to create the bitmap cache, just
// 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;
/**
* Indicates whether the window is translucent/transparent
*/
boolean mTranslucentWindow;
/**
* For windows that are full-screen but using insets to layout inside
* 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) {
fadingEdgeLength = configuration.getScaledFadingEdgeLength();
scrollBarSize = configuration.getScaledScrollBarSize();
scrollBarDefaultDelayBeforeFade = configuration.getScrollDefaultDelay();
scrollBarFadeDuration = configuration.getScrollBarFadeDuration();
scrollBarDefaultDelayBeforeFade = ViewConfiguration.getScrollDefaultDelay();
scrollBarFadeDuration = ViewConfiguration.getScrollBarFadeDuration();
paint = new Paint();
matrix = new Matrix();

View File

@@ -408,7 +408,7 @@ public final class ViewRoot extends Handler implements ViewParent,
}
boolean restore = false;
if (attrs != null && mTranslator != null) {
if (mTranslator != null) {
restore = true;
attrs.backup();
mTranslator.translateWindowLayout(attrs);
@@ -422,7 +422,7 @@ public final class ViewRoot extends Handler implements ViewParent,
mSoftInputMode = attrs.softInputMode;
mWindowAttributesChanged = true;
mAttachInfo.mRootView = view;
mAttachInfo.mScalingRequired = mTranslator == null ? false : true;
mAttachInfo.mScalingRequired = mTranslator != null;
mAttachInfo.mApplicationScale =
mTranslator == null ? 1.0f : mTranslator.applicationScale;
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
// will be (assuming the window is visible).
attachInfo.mSurface = mSurface;
attachInfo.mTranslucentWindow = lp.format != PixelFormat.OPAQUE;
attachInfo.mHasWindowFocus = false;
attachInfo.mWindowVisibility = viewVisibility;
attachInfo.mRecomputeGlobalAttributes = false;