Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 26f894d2 authored by Yuli Huang's avatar Yuli Huang Committed by Android (Google) Code Review
Browse files

Merge "Fix b/5433856 and b/5433907."

parents 377b0652 e0e82f1d
Loading
Loading
Loading
Loading
+17 −10
Original line number Diff line number Diff line
@@ -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);
+1 −1
Original line number Diff line number Diff line
@@ -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) {
+29 −17
Original line number Diff line number Diff line
@@ -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) {
                changed = (photoBounds.width() != width) || (photoBounds.height() != height);
                if (changed) {
                    photoBounds.set(0, 0, width, height);
                }
            }
            this.photo = photo;
            fitPhotoToSurface();
            updateSurface(clearTransform, changed);
        }

        void fitPhotoToSurface() {
        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
+9 −2
Original line number Diff line number Diff line
@@ -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