summaryrefslogtreecommitdiffstats
path: root/core/java/android
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2011-06-09 19:05:15 -0700
committerJeff Brown <jeffbrown@google.com>2011-06-10 18:13:30 -0700
commit24572375323dee79e3b456af07640ca194fd40bf (patch)
tree0a8923e3213aeb18d385e2c7eb2816d7698be49e /core/java/android
parent0a2f6640defa14b1bf1753ee2faf7e3d32c259f0 (diff)
downloadframeworks_base-24572375323dee79e3b456af07640ca194fd40bf.zip
frameworks_base-24572375323dee79e3b456af07640ca194fd40bf.tar.gz
frameworks_base-24572375323dee79e3b456af07640ca194fd40bf.tar.bz2
Optimize orientation changes.
Modified setRotation to allow it to restart a rotation in progress as long as the rotation animation has not yet started. This enables the system to recover more quickly from mispredicted orientation changes. Removed the call to System.gc() when freezing the display, which added 60-80ms before we even started the orientation change. We used to need this to make it less likely that an upcoming GC would cause a pause during the window animation, but this is not longer a concern with the concurrent GC in place. Changed the wallpaper surface to be 32bit. This accelerates drawing and improves the overall appearance slightly. Reduced code duplication in the WallpaperManager. Change-Id: Ic6e5e8bdce4b970b11badddd0355baaed40df88a
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/app/WallpaperManager.java166
-rw-r--r--core/java/android/service/wallpaper/WallpaperService.java2
2 files changed, 67 insertions, 101 deletions
diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java
index 113c610..3626bf5 100644
--- a/core/java/android/app/WallpaperManager.java
+++ b/core/java/android/app/WallpaperManager.java
@@ -25,6 +25,8 @@ import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
@@ -115,7 +117,9 @@ public class WallpaperManager {
@Override
public void draw(Canvas canvas) {
- canvas.drawBitmap(mBitmap, mDrawLeft, mDrawTop, null);
+ Paint paint = new Paint();
+ paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
+ canvas.drawBitmap(mBitmap, mDrawLeft, mDrawTop, paint);
}
@Override
@@ -245,40 +249,20 @@ public class WallpaperManager {
if (fd != null) {
int width = params.getInt("width", 0);
int height = params.getInt("height", 0);
-
- if (width <= 0 || height <= 0) {
- // Degenerate case: no size requested, just load
- // bitmap as-is.
- Bitmap bm = null;
- try {
- bm = BitmapFactory.decodeFileDescriptor(
- fd.getFileDescriptor(), null, null);
- } catch (OutOfMemoryError e) {
- Log.w(TAG, "Can't decode file", e);
- }
+
+ try {
+ BitmapFactory.Options options = new BitmapFactory.Options();
+ Bitmap bm = BitmapFactory.decodeFileDescriptor(
+ fd.getFileDescriptor(), null, options);
+ return generateBitmap(context, bm, width, height);
+ } catch (OutOfMemoryError e) {
+ Log.w(TAG, "Can't decode file", e);
+ } finally {
try {
fd.close();
} catch (IOException e) {
}
- if (bm != null) {
- bm.setDensity(DisplayMetrics.DENSITY_DEVICE);
- }
- return bm;
}
-
- // Load the bitmap with full color depth, to preserve
- // quality for later processing.
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inDither = false;
- options.inPreferredConfig = Bitmap.Config.ARGB_8888;
- Bitmap bm = BitmapFactory.decodeFileDescriptor(
- fd.getFileDescriptor(), null, options);
- try {
- fd.close();
- } catch (IOException e) {
- }
-
- return generateBitmap(context, bm, width, height);
}
} catch (RemoteException e) {
}
@@ -292,42 +276,18 @@ public class WallpaperManager {
if (is != null) {
int width = mService.getWidthHint();
int height = mService.getHeightHint();
-
- if (width <= 0 || height <= 0) {
- // Degenerate case: no size requested, just load
- // bitmap as-is.
- Bitmap bm = null;
- try {
- bm = BitmapFactory.decodeStream(is, null, null);
- } catch (OutOfMemoryError e) {
- Log.w(TAG, "Can't decode stream", e);
- }
+
+ try {
+ BitmapFactory.Options options = new BitmapFactory.Options();
+ Bitmap bm = BitmapFactory.decodeStream(is, null, options);
+ return generateBitmap(context, bm, width, height);
+ } catch (OutOfMemoryError e) {
+ Log.w(TAG, "Can't decode stream", e);
+ } finally {
try {
is.close();
} catch (IOException e) {
}
- if (bm != null) {
- bm.setDensity(DisplayMetrics.DENSITY_DEVICE);
- }
- return bm;
- }
-
- // Load the bitmap with full color depth, to preserve
- // quality for later processing.
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inDither = false;
- options.inPreferredConfig = Bitmap.Config.ARGB_8888;
- Bitmap bm = BitmapFactory.decodeStream(is, null, options);
- try {
- is.close();
- } catch (IOException e) {
- }
-
- try {
- return generateBitmap(context, bm, width, height);
- } catch (OutOfMemoryError e) {
- Log.w(TAG, "Can't generate default bitmap", e);
- return bm;
}
}
} catch (RemoteException e) {
@@ -711,48 +671,54 @@ public class WallpaperManager {
static Bitmap generateBitmap(Context context, Bitmap bm, int width, int height) {
if (bm == null) {
- return bm;
+ return null;
}
+
bm.setDensity(DisplayMetrics.DENSITY_DEVICE);
-
+
+ if (bm.getWidth() == width && bm.getHeight() == height) {
+ return bm;
+ }
+
// This is the final bitmap we want to return.
- // XXX We should get the pixel depth from the system (to match the
- // physical display depth), when there is a way.
- Bitmap newbm = Bitmap.createBitmap(width, height,
- Bitmap.Config.RGB_565);
- newbm.setDensity(DisplayMetrics.DENSITY_DEVICE);
- Canvas c = new Canvas(newbm);
- c.setDensity(DisplayMetrics.DENSITY_DEVICE);
- Rect targetRect = new Rect();
- targetRect.left = targetRect.top = 0;
- targetRect.right = bm.getWidth();
- targetRect.bottom = bm.getHeight();
-
- int deltaw = width - targetRect.right;
- int deltah = height - targetRect.bottom;
-
- if (deltaw > 0 || deltah > 0) {
- // We need to scale up so it covers the entire
- // area.
- float scale = 1.0f;
- if (deltaw > deltah) {
- scale = width / (float)targetRect.right;
- } else {
- scale = height / (float)targetRect.bottom;
+ try {
+ Bitmap newbm = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+ newbm.setDensity(DisplayMetrics.DENSITY_DEVICE);
+
+ Canvas c = new Canvas(newbm);
+ Rect targetRect = new Rect();
+ targetRect.right = bm.getWidth();
+ targetRect.bottom = bm.getHeight();
+
+ int deltaw = width - targetRect.right;
+ int deltah = height - targetRect.bottom;
+
+ if (deltaw > 0 || deltah > 0) {
+ // We need to scale up so it covers the entire area.
+ float scale = 1.0f;
+ if (deltaw > deltah) {
+ scale = width / (float)targetRect.right;
+ } else {
+ scale = height / (float)targetRect.bottom;
+ }
+ targetRect.right = (int)(targetRect.right*scale);
+ targetRect.bottom = (int)(targetRect.bottom*scale);
+ deltaw = width - targetRect.right;
+ deltah = height - targetRect.bottom;
}
- targetRect.right = (int)(targetRect.right*scale);
- targetRect.bottom = (int)(targetRect.bottom*scale);
- deltaw = width - targetRect.right;
- deltah = height - targetRect.bottom;
+
+ targetRect.offset(deltaw/2, deltah/2);
+
+ Paint paint = new Paint();
+ paint.setFilterBitmap(true);
+ paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
+ c.drawBitmap(bm, null, targetRect, paint);
+
+ bm.recycle();
+ return newbm;
+ } catch (OutOfMemoryError e) {
+ Log.w(TAG, "Can't generate default bitmap", e);
+ return bm;
}
-
- targetRect.offset(deltaw/2, deltah/2);
- Paint paint = new Paint();
- paint.setFilterBitmap(true);
- paint.setDither(true);
- c.drawBitmap(bm, null, targetRect, paint);
-
- bm.recycle();
- return newbm;
}
}
diff --git a/core/java/android/service/wallpaper/WallpaperService.java b/core/java/android/service/wallpaper/WallpaperService.java
index eae7574..8fc8b9d 100644
--- a/core/java/android/service/wallpaper/WallpaperService.java
+++ b/core/java/android/service/wallpaper/WallpaperService.java
@@ -181,7 +181,7 @@ public abstract class WallpaperService extends Service {
final BaseSurfaceHolder mSurfaceHolder = new BaseSurfaceHolder() {
{
- mRequestedFormat = PixelFormat.RGB_565;
+ mRequestedFormat = PixelFormat.RGBX_8888;
}
@Override