int mHeight = -1;
int mFormat = -1;
final Rect mSurfaceFrame = new Rect();
+ Rect mTmpDirty;
int mLastSurfaceWidth = -1, mLastSurfaceHeight = -1;
boolean mUpdateWindowNeeded;
boolean mReportDrawNeeded;
Canvas c = null;
if (!mDrawingStopped && mWindow != null) {
- Rect frame = dirty != null ? dirty : mSurfaceFrame;
+ if (dirty == null) {
+ if (mTmpDirty == null) {
+ mTmpDirty = new Rect();
+ }
+ mTmpDirty.set(mSurfaceFrame);
+ dirty = mTmpDirty;
+ }
+
try {
- c = mSurface.lockCanvas(frame);
+ c = mSurface.lockCanvas(dirty);
} catch (Exception e) {
Log.e(LOG_TAG, "Exception locking surface", e);
}
class WallpaperObserver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) {
+ if (DEBUG) {
+ Log.d(TAG, "onReceive");
+ }
+
synchronized (mLock) {
updateWallpaperLocked();
- drawFrameLocked(true, false);
+ drawFrameLocked();
}
// Assume we are the only one using the wallpaper in this
@Override
public void onCreate(SurfaceHolder surfaceHolder) {
+ if (DEBUG) {
+ Log.d(TAG, "onCreate");
+ }
+
super.onCreate(surfaceHolder);
IntentFilter filter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED);
mReceiver = new WallpaperObserver();
@Override
public void onVisibilityChanged(boolean visible) {
+ if (DEBUG) {
+ Log.d(TAG, "onVisibilityChanged: visible=" + visible);
+ }
+
synchronized (mLock) {
- mVisible = visible;
- drawFrameLocked(false, false);
+ if (mVisible != visible) {
+ if (DEBUG) {
+ Log.d(TAG, "Visibility changed to visible=" + visible);
+ }
+ mVisible = visible;
+ drawFrameLocked();
+ }
}
}
public void onOffsetsChanged(float xOffset, float yOffset,
float xOffsetStep, float yOffsetStep,
int xPixels, int yPixels) {
+ if (DEBUG) {
+ Log.d(TAG, "onOffsetsChanged: xOffset=" + xOffset + ", yOffset=" + yOffset
+ + ", xOffsetStep=" + xOffsetStep + ", yOffsetStep=" + yOffsetStep
+ + ", xPixels=" + xPixels + ", yPixels=" + yPixels);
+ }
+
synchronized (mLock) {
if (mXOffset != xOffset || mYOffset != yOffset) {
if (DEBUG) {
}
mXOffset = xOffset;
mYOffset = yOffset;
- drawFrameLocked(false, true);
- } else {
- drawFrameLocked(false, false);
+ mOffsetsChanged = true;
}
+ drawFrameLocked();
}
}
@Override
public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
- super.onSurfaceChanged(holder, format, width, height);
-
- synchronized (mLock) {
- drawFrameLocked(true, false);
+ if (DEBUG) {
+ Log.d(TAG, "onSurfaceChanged: width=" + width + ", height=" + height);
}
- }
- @Override
- public void onSurfaceCreated(SurfaceHolder holder) {
- super.onSurfaceCreated(holder);
- }
+ super.onSurfaceChanged(holder, format, width, height);
- @Override
- public void onSurfaceDestroyed(SurfaceHolder holder) {
- super.onSurfaceDestroyed(holder);
+ synchronized (mLock) {
+ mRedrawNeeded = true;
+ drawFrameLocked();
+ }
}
- void drawFrameLocked(boolean redrawNeeded, boolean offsetsChanged) {
- mRedrawNeeded |= redrawNeeded;
- mOffsetsChanged |= offsetsChanged;
-
+ void drawFrameLocked() {
if (!mVisible) {
if (DEBUG) {
Log.d(TAG, "Suppressed drawFrame since wallpaper is not visible.");
int mType = -1;
final Rect mSurfaceFrame = new Rect();
+ Rect mTmpDirty;
public abstract void onUpdateSurface();
public abstract void onRelayoutContainer();
Canvas c = null;
if (onAllowLockCanvas()) {
- Rect frame = dirty != null ? dirty : mSurfaceFrame;
+ if (dirty == null) {
+ if (mTmpDirty == null) {
+ mTmpDirty = new Rect();
+ }
+ mTmpDirty.set(mSurfaceFrame);
+ dirty = mTmpDirty;
+ }
+
try {
- c = mSurface.lockCanvas(frame);
+ c = mSurface.lockCanvas(dirty);
} catch (Exception e) {
Log.e(TAG, "Exception locking surface", e);
}
public Rect getSurfaceFrame() {
return mSurfaceFrame;
}
+
+ public void setSurfaceFrameSize(int width, int height) {
+ mSurfaceFrame.top = 0;
+ mSurfaceFrame.left = 0;
+ mSurfaceFrame.right = width;
+ mSurfaceFrame.bottom = height;
+ }
};