diff options
author | Yuli Huang <yuli@google.com> | 2011-10-10 00:55:26 +0800 |
---|---|---|
committer | Yuli Huang <yuli@google.com> | 2011-10-10 02:57:08 +0800 |
commit | 566f653e477d8d594e6c69e394a52f616100bd31 (patch) | |
tree | d033d299a75fc355d33b7b66829d96b50ca1b0f8 /src/com/android/gallery3d/photoeditor | |
parent | 9d62da7986aef9d89356f6b169fafecd8936d9f6 (diff) | |
download | android_packages_apps_Snap-566f653e477d8d594e6c69e394a52f616100bd31.tar.gz android_packages_apps_Snap-566f653e477d8d594e6c69e394a52f616100bd31.tar.bz2 android_packages_apps_Snap-566f653e477d8d594e6c69e394a52f616100bd31.zip |
Fix b/5433856 and b/5433907.
1. Make PhotoView restore rotation after the device awakes or
the orientation changes.
2. Avoid outputting top filter until the active effect requests its
output to fix incorrect Crop/Rotate/Doodle effects after device awakes.
3. Speed up rotation speed by removing queued outdated rotation.
Change-Id: I5b82ccfe4e27ad5f1d2505bdd7a7540e0a77b55d
Diffstat (limited to 'src/com/android/gallery3d/photoeditor')
4 files changed, 56 insertions, 30 deletions
diff --git a/src/com/android/gallery3d/photoeditor/FilterStack.java b/src/com/android/gallery3d/photoeditor/FilterStack.java index 67b904d55..e84c92e12 100644 --- a/src/com/android/gallery3d/photoeditor/FilterStack.java +++ b/src/com/android/gallery3d/photoeditor/FilterStack.java @@ -45,6 +45,7 @@ public class FilterStack { private Photo source; private Runnable queuedTopFilterChange; + private boolean topFilterOutputted; private volatile boolean paused; public FilterStack(PhotoView photoView, StackListener stackListener) { @@ -69,18 +70,20 @@ public class FilterStack { buffers[0] = Photo.create(source.width(), source.height()); reallocateBuffer(1); + // Source photo will be displayed if there is no filter stacked. Photo photo = source; - for (int i = 0; i < appliedStack.size() && !paused; i++) { + int size = topFilterOutputted ? appliedStack.size() : appliedStack.size() - 1; + for (int i = 0; i < size && !paused; i++) { photo = runFilter(i); } - // Source photo will be displayed if there is no filter stacked. - photoView.setPhoto(photo); + photoView.setPhoto(photo, topFilterOutputted); } } private void invalidateTopFilter() { if (!appliedStack.empty()) { - photoView.setPhoto(runFilter(appliedStack.size() - 1)); + photoView.setPhoto(runFilter(appliedStack.size() - 1), true); + topFilterOutputted = true; } } @@ -135,8 +138,8 @@ public class FilterStack { @Override public void run() { - Photo photo = appliedStack.empty() ? - null : buffers[getOutBufferIndex(appliedStack.size() - 1)]; + int filterIndex = appliedStack.size() - (topFilterOutputted ? 1 : 2); + Photo photo = (filterIndex < 0) ? source : buffers[getOutBufferIndex(filterIndex)]; final Bitmap bitmap = (photo != null) ? photo.save() : null; photoView.post(new Runnable() { @@ -161,6 +164,12 @@ public class FilterStack { }); } + private void pushFilterInternal(Filter filter) { + appliedStack.push(filter); + topFilterOutputted = false; + stackChanged(); + } + public void pushFilter(final Filter filter) { photoView.queue(new Runnable() { @@ -169,8 +178,7 @@ public class FilterStack { while (!redoStack.empty()) { redoStack.pop().release(); } - appliedStack.push(filter); - stackChanged(); + pushFilterInternal(filter); } }); } @@ -196,8 +204,7 @@ public class FilterStack { @Override public void run() { if (!redoStack.empty()) { - appliedStack.push(redoStack.pop()); - stackChanged(); + pushFilterInternal(redoStack.pop()); invalidateTopFilter(); } callbackDone(callback); diff --git a/src/com/android/gallery3d/photoeditor/Photo.java b/src/com/android/gallery3d/photoeditor/Photo.java index 4aaa90681..52d9692b1 100644 --- a/src/com/android/gallery3d/photoeditor/Photo.java +++ b/src/com/android/gallery3d/photoeditor/Photo.java @@ -50,7 +50,7 @@ public class Photo { } public boolean matchDimension(Photo photo) { - return ((photo.width() == width()) && (photo.height() == height())); + return ((photo.width == width) && (photo.height == height)); } public void changeDimension(int width, int height) { diff --git a/src/com/android/gallery3d/photoeditor/PhotoView.java b/src/com/android/gallery3d/photoeditor/PhotoView.java index 8c758ddb1..b2e510329 100644 --- a/src/com/android/gallery3d/photoeditor/PhotoView.java +++ b/src/com/android/gallery3d/photoeditor/PhotoView.java @@ -76,8 +76,8 @@ public class PhotoView extends GLSurfaceView { /** * Sets photo for display; this method must be queued for GL thread. */ - public void setPhoto(Photo photo) { - renderer.setPhoto(photo); + public void setPhoto(Photo photo, boolean clearTransform) { + renderer.setPhoto(photo, clearTransform); } /** @@ -98,21 +98,36 @@ public class PhotoView extends GLSurfaceView { Photo photo; int viewWidth; int viewHeight; + float rotatedDegrees; - void setPhoto(Photo photo) { + void setPhoto(Photo photo, boolean clearTransform) { int width = (photo != null) ? photo.width() : 0; int height = (photo != null) ? photo.height() : 0; + boolean changed; synchronized (photoBounds) { - photoBounds.set(0, 0, width, height); + changed = (photoBounds.width() != width) || (photoBounds.height() != height); + if (changed) { + photoBounds.set(0, 0, width, height); + } } this.photo = photo; - fitPhotoToSurface(); + updateSurface(clearTransform, changed); } - void fitPhotoToSurface() { - if (photo != null) { - RendererUtils.setRenderToFit(renderContext, photo.width(), photo.height(), - viewWidth, viewHeight); + void updateSurface(boolean clearTransform, boolean sizeChanged) { + boolean transformed = (rotatedDegrees != 0); + if ((clearTransform && transformed) || (sizeChanged && !transformed)) { + // Fit photo when clearing existing transforms or changing surface/photo sizes. + if (photo != null) { + RendererUtils.setRenderToFit(renderContext, photo.width(), photo.height(), + viewWidth, viewHeight); + rotatedDegrees = 0; + } + } else { + // Restore existing transformations for orientation changes or awaking from sleep. + if (rotatedDegrees != 0) { + rotatePhoto(rotatedDegrees); + } } } @@ -120,12 +135,7 @@ public class PhotoView extends GLSurfaceView { if (photo != null) { RendererUtils.setRenderToRotate(renderContext, photo.width(), photo.height(), viewWidth, viewHeight, degrees); - } - } - - void renderPhoto() { - if (photo != null) { - RendererUtils.renderTexture(renderContext, photo.texture(), viewWidth, viewHeight); + rotatedDegrees = degrees; } } @@ -143,14 +153,16 @@ public class PhotoView extends GLSurfaceView { if (!queue.isEmpty()) { requestRender(); } - renderPhoto(); + if (photo != null) { + RendererUtils.renderTexture(renderContext, photo.texture(), viewWidth, viewHeight); + } } @Override public void onSurfaceChanged(GL10 gl, int width, int height) { viewWidth = width; viewHeight = height; - fitPhotoToSurface(); + updateSurface(false, true); } @Override diff --git a/src/com/android/gallery3d/photoeditor/actions/RotateAction.java b/src/com/android/gallery3d/photoeditor/actions/RotateAction.java index dee78f17a..cc1903886 100644 --- a/src/com/android/gallery3d/photoeditor/actions/RotateAction.java +++ b/src/com/android/gallery3d/photoeditor/actions/RotateAction.java @@ -33,6 +33,7 @@ public class RotateAction extends EffectAction { private RotateFilter filter; private float rotateDegrees; + private Runnable queuedRotationChange; private RotateView rotateView; public RotateAction(Context context, AttributeSet attrs) { @@ -75,18 +76,24 @@ public class RotateAction extends EffectAction { } private void transformPhotoView(final float degrees) { - photoView.queue(new Runnable() { + // Remove the outdated rotation change before queuing a new one. + if (queuedRotationChange != null) { + photoView.remove(queuedRotationChange); + } + queuedRotationChange = new Runnable() { @Override public void run() { photoView.rotatePhoto(degrees); } - }); + }; + photoView.queue(queuedRotationChange); } }); rotateView.setRotatedAngle(DEFAULT_ANGLE); rotateView.setRotateSpan(DEFAULT_ROTATE_SPAN); rotateDegrees = 0; + queuedRotationChange = null; } @Override |