summaryrefslogtreecommitdiffstats
path: root/core/java/android/service
diff options
context:
space:
mode:
authorDianne Hackborn <hackbod@google.com>2009-09-11 21:13:37 -0700
committerDianne Hackborn <hackbod@google.com>2009-09-14 15:29:44 -0700
commit19382ac1a4e4e7c23a1346d299368763f149de9c (patch)
tree9165f1b94f1bd5e9966729b1047d03a733570867 /core/java/android/service
parent714ec1360cde8b1cbf6e6b8572256e4100f11560 (diff)
downloadframeworks_base-19382ac1a4e4e7c23a1346d299368763f149de9c.zip
frameworks_base-19382ac1a4e4e7c23a1346d299368763f149de9c.tar.gz
frameworks_base-19382ac1a4e4e7c23a1346d299368763f149de9c.tar.bz2
Some optizations to wallpaper drawing/scrolling.
First, fix some issues with the final wallpaper bitmap we use: ensure it is always 16bpp, and make sure dithering of its bitmap is turned off. We take of dithering when loading, to make sure we don't use it when drawing. Also add new APIs to return the wallpaper with the equivalent of Launcher's old FastBitmapDrawable. As doing this, also load the default wallpaper the same way as custom ones, taking care to resize it as needed at load time. Finally implement a mechanism for the window manager to wait for the wallpaper to redraw at its new position before returning from the application's call to change the offset. This ensures that the wallpaper better tracks the application. Note that there is a timeout in this wait that is relatively short, and if it expires we will run for a while without waiting. Change-Id: Ife449437746da85958bd447e0a6cf3d2223b398c
Diffstat (limited to 'core/java/android/service')
-rw-r--r--core/java/android/service/wallpaper/WallpaperService.java43
1 files changed, 41 insertions, 2 deletions
diff --git a/core/java/android/service/wallpaper/WallpaperService.java b/core/java/android/service/wallpaper/WallpaperService.java
index e5659d5..cd5cf10 100644
--- a/core/java/android/service/wallpaper/WallpaperService.java
+++ b/core/java/android/service/wallpaper/WallpaperService.java
@@ -28,9 +28,11 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Rect;
import android.os.IBinder;
+import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.util.Log;
+import android.util.LogPrinter;
import android.view.Gravity;
import android.view.IWindowSession;
import android.view.MotionEvent;
@@ -74,6 +76,8 @@ public abstract class WallpaperService extends Service {
private static final int MSG_WINDOW_RESIZED = 10030;
private static final int MSG_TOUCH_EVENT = 10040;
+ private Looper mCallbackLooper;
+
/**
* The actual implementation of a wallpaper. A wallpaper service may
* have multiple instances running (for example as a real wallpaper
@@ -120,6 +124,7 @@ public abstract class WallpaperService extends Service {
boolean mOffsetMessageEnqueued;
float mPendingXOffset;
float mPendingYOffset;
+ boolean mPendingSync;
MotionEvent mPendingMove;
final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@@ -212,10 +217,14 @@ public abstract class WallpaperService extends Service {
}
@Override
- public void dispatchWallpaperOffsets(float x, float y) {
+ public void dispatchWallpaperOffsets(float x, float y, boolean sync) {
synchronized (mLock) {
+ if (DEBUG) Log.v(TAG, "Dispatch wallpaper offsets: " + x + ", " + y);
mPendingXOffset = x;
mPendingYOffset = y;
+ if (sync) {
+ mPendingSync = true;
+ }
if (!mOffsetMessageEnqueued) {
mOffsetMessageEnqueued = true;
Message msg = mCaller.obtainMessage(MSG_WALLPAPER_OFFSETS);
@@ -551,9 +560,12 @@ public abstract class WallpaperService extends Service {
float xOffset;
float yOffset;
+ boolean sync;
synchronized (mLock) {
xOffset = mPendingXOffset;
yOffset = mPendingYOffset;
+ sync = mPendingSync;
+ mPendingSync = false;
mOffsetMessageEnqueued = false;
}
if (DEBUG) Log.v(TAG, "Offsets change in " + this
@@ -563,6 +575,14 @@ public abstract class WallpaperService extends Service {
final int availh = mIWallpaperEngine.mReqHeight-mCurHeight;
final int yPixels = availh > 0 ? -(int)(availh*yOffset+.5f) : 0;
onOffsetsChanged(xOffset, yOffset, xPixels, yPixels);
+
+ if (sync) {
+ try {
+ if (DEBUG) Log.v(TAG, "Reporting offsets change complete");
+ mSession.wallpaperOffsetsComplete(mWindow.asBinder());
+ } catch (RemoteException e) {
+ }
+ }
}
void detach() {
@@ -622,7 +642,13 @@ public abstract class WallpaperService extends Service {
IWallpaperEngineWrapper(WallpaperService context,
IWallpaperConnection conn, IBinder windowToken,
int windowType, boolean isPreview, int reqWidth, int reqHeight) {
- mCaller = new HandlerCaller(context, this);
+ if (DEBUG && mCallbackLooper != null) {
+ mCallbackLooper.setMessageLogging(new LogPrinter(Log.VERBOSE, TAG));
+ }
+ mCaller = new HandlerCaller(context,
+ mCallbackLooper != null
+ ? mCallbackLooper : context.getMainLooper(),
+ this);
mConnection = conn;
mWindowToken = windowToken;
mWindowType = windowType;
@@ -736,5 +762,18 @@ public abstract class WallpaperService extends Service {
return new IWallpaperServiceWrapper(this);
}
+ /**
+ * This allows subclasses to change the thread that most callbacks
+ * occur on. Currently hidden because it is mostly needed for the
+ * image wallpaper (which runs in the system process and doesn't want
+ * to get stuck running on that seriously in use main thread). Not
+ * exposed right now because the semantics of this are not totally
+ * well defined and some callbacks can still happen on the main thread).
+ * @hide
+ */
+ public void setCallbackLooper(Looper looper) {
+ mCallbackLooper = looper;
+ }
+
public abstract Engine onCreateEngine();
}