Merge "Fix surface frame size reporting." into honeycomb

This commit is contained in:
Jeff Brown
2011-01-25 14:21:00 -08:00
committed by Android (Google) Code Review
6 changed files with 66 additions and 28 deletions

View File

@@ -547,6 +547,7 @@ public abstract class WallpaperService extends Service {
mCurHeight = h; mCurHeight = h;
} }
mSurfaceHolder.setSurfaceFrameSize(w, h);
mSurfaceHolder.mSurfaceLock.unlock(); mSurfaceHolder.mSurfaceLock.unlock();
if (!mSurfaceHolder.mSurface.isValid()) { if (!mSurfaceHolder.mSurface.isValid()) {

View File

@@ -158,6 +158,7 @@ public class SurfaceView extends View {
int mHeight = -1; int mHeight = -1;
int mFormat = -1; int mFormat = -1;
final Rect mSurfaceFrame = new Rect(); final Rect mSurfaceFrame = new Rect();
Rect mTmpDirty;
int mLastSurfaceWidth = -1, mLastSurfaceHeight = -1; int mLastSurfaceWidth = -1, mLastSurfaceHeight = -1;
boolean mUpdateWindowNeeded; boolean mUpdateWindowNeeded;
boolean mReportDrawNeeded; boolean mReportDrawNeeded;
@@ -739,9 +740,16 @@ public class SurfaceView extends View {
Canvas c = null; Canvas c = null;
if (!mDrawingStopped && mWindow != 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 { try {
c = mSurface.lockCanvas(frame); c = mSurface.lockCanvas(dirty);
} catch (Exception e) { } catch (Exception e) {
Log.e(LOG_TAG, "Exception locking surface", e); Log.e(LOG_TAG, "Exception locking surface", e);
} }

View File

@@ -1082,6 +1082,7 @@ public final class ViewRoot extends Handler implements ViewParent,
//mSurfaceHolder.mSurface.copyFrom(mSurface); //mSurfaceHolder.mSurface.copyFrom(mSurface);
mSurfaceHolder.mSurface = mSurface; mSurfaceHolder.mSurface = mSurface;
} }
mSurfaceHolder.setSurfaceFrameSize(mWidth, mHeight);
mSurfaceHolder.mSurfaceLock.unlock(); mSurfaceHolder.mSurfaceLock.unlock();
if (mSurface.isValid()) { if (mSurface.isValid()) {
if (!hadSurface) { if (!hadSurface) {

View File

@@ -88,9 +88,13 @@ public class ImageWallpaper extends WallpaperService {
class WallpaperObserver extends BroadcastReceiver { class WallpaperObserver extends BroadcastReceiver {
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (DEBUG) {
Log.d(TAG, "onReceive");
}
synchronized (mLock) { synchronized (mLock) {
updateWallpaperLocked(); updateWallpaperLocked();
drawFrameLocked(true, false); drawFrameLocked();
} }
// Assume we are the only one using the wallpaper in this // Assume we are the only one using the wallpaper in this
@@ -101,6 +105,10 @@ public class ImageWallpaper extends WallpaperService {
@Override @Override
public void onCreate(SurfaceHolder surfaceHolder) { public void onCreate(SurfaceHolder surfaceHolder) {
if (DEBUG) {
Log.d(TAG, "onCreate");
}
super.onCreate(surfaceHolder); super.onCreate(surfaceHolder);
IntentFilter filter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED); IntentFilter filter = new IntentFilter(Intent.ACTION_WALLPAPER_CHANGED);
mReceiver = new WallpaperObserver(); mReceiver = new WallpaperObserver();
@@ -120,9 +128,18 @@ public class ImageWallpaper extends WallpaperService {
@Override @Override
public void onVisibilityChanged(boolean visible) { public void onVisibilityChanged(boolean visible) {
if (DEBUG) {
Log.d(TAG, "onVisibilityChanged: visible=" + visible);
}
synchronized (mLock) { synchronized (mLock) {
if (mVisible != visible) {
if (DEBUG) {
Log.d(TAG, "Visibility changed to visible=" + visible);
}
mVisible = visible; mVisible = visible;
drawFrameLocked(false, false); drawFrameLocked();
}
} }
} }
@@ -135,6 +152,12 @@ public class ImageWallpaper extends WallpaperService {
public void onOffsetsChanged(float xOffset, float yOffset, public void onOffsetsChanged(float xOffset, float yOffset,
float xOffsetStep, float yOffsetStep, float xOffsetStep, float yOffsetStep,
int xPixels, int yPixels) { int xPixels, int yPixels) {
if (DEBUG) {
Log.d(TAG, "onOffsetsChanged: xOffset=" + xOffset + ", yOffset=" + yOffset
+ ", xOffsetStep=" + xOffsetStep + ", yOffsetStep=" + yOffsetStep
+ ", xPixels=" + xPixels + ", yPixels=" + yPixels);
}
synchronized (mLock) { synchronized (mLock) {
if (mXOffset != xOffset || mYOffset != yOffset) { if (mXOffset != xOffset || mYOffset != yOffset) {
if (DEBUG) { if (DEBUG) {
@@ -142,36 +165,27 @@ public class ImageWallpaper extends WallpaperService {
} }
mXOffset = xOffset; mXOffset = xOffset;
mYOffset = yOffset; mYOffset = yOffset;
drawFrameLocked(false, true); mOffsetsChanged = true;
} else {
drawFrameLocked(false, false);
} }
drawFrameLocked();
} }
} }
@Override @Override
public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) { public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
if (DEBUG) {
Log.d(TAG, "onSurfaceChanged: width=" + width + ", height=" + height);
}
super.onSurfaceChanged(holder, format, width, height); super.onSurfaceChanged(holder, format, width, height);
synchronized (mLock) { synchronized (mLock) {
drawFrameLocked(true, false); mRedrawNeeded = true;
drawFrameLocked();
} }
} }
@Override void drawFrameLocked() {
public void onSurfaceCreated(SurfaceHolder holder) {
super.onSurfaceCreated(holder);
}
@Override
public void onSurfaceDestroyed(SurfaceHolder holder) {
super.onSurfaceDestroyed(holder);
}
void drawFrameLocked(boolean redrawNeeded, boolean offsetsChanged) {
mRedrawNeeded |= redrawNeeded;
mOffsetsChanged |= offsetsChanged;
if (!mVisible) { if (!mVisible) {
if (DEBUG) { if (DEBUG) {
Log.d(TAG, "Suppressed drawFrame since wallpaper is not visible."); Log.d(TAG, "Suppressed drawFrame since wallpaper is not visible.");

View File

@@ -49,6 +49,7 @@ public abstract class BaseSurfaceHolder implements SurfaceHolder {
int mType = -1; int mType = -1;
final Rect mSurfaceFrame = new Rect(); final Rect mSurfaceFrame = new Rect();
Rect mTmpDirty;
public abstract void onUpdateSurface(); public abstract void onUpdateSurface();
public abstract void onRelayoutContainer(); public abstract void onRelayoutContainer();
@@ -171,9 +172,16 @@ public abstract class BaseSurfaceHolder implements SurfaceHolder {
Canvas c = null; Canvas c = null;
if (onAllowLockCanvas()) { if (onAllowLockCanvas()) {
Rect frame = dirty != null ? dirty : mSurfaceFrame; if (dirty == null) {
if (mTmpDirty == null) {
mTmpDirty = new Rect();
}
mTmpDirty.set(mSurfaceFrame);
dirty = mTmpDirty;
}
try { try {
c = mSurface.lockCanvas(frame); c = mSurface.lockCanvas(dirty);
} catch (Exception e) { } catch (Exception e) {
Log.e(TAG, "Exception locking surface", e); Log.e(TAG, "Exception locking surface", e);
} }
@@ -215,4 +223,11 @@ public abstract class BaseSurfaceHolder implements SurfaceHolder {
public Rect getSurfaceFrame() { public Rect getSurfaceFrame() {
return mSurfaceFrame; return mSurfaceFrame;
} }
public void setSurfaceFrameSize(int width, int height) {
mSurfaceFrame.top = 0;
mSurfaceFrame.left = 0;
mSurfaceFrame.right = width;
mSurfaceFrame.bottom = height;
}
}; };

View File

@@ -116,7 +116,6 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
private ViewGroup mContentParent; private ViewGroup mContentParent;
SurfaceHolder.Callback2 mTakeSurfaceCallback; SurfaceHolder.Callback2 mTakeSurfaceCallback;
BaseSurfaceHolder mSurfaceHolder;
InputQueue.Callback mTakeInputQueueCallback; InputQueue.Callback mTakeInputQueueCallback;