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

Commit 9d36d82f authored by nicolasroard's avatar nicolasroard Committed by Android (Google) Code Review
Browse files

Merge "Fix flickering while editing" into gb-ub-photos-carlsbad

parents f818028e 20826208
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.gallery3d.filtershow.pipeline;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.support.v8.renderscript.Allocation;
import android.support.v8.renderscript.RenderScript;
import android.util.Log;
@@ -33,7 +34,8 @@ public class Buffer {
    public Buffer(Bitmap bitmap) {
        RenderScript rs = CachingPipeline.getRenderScriptContext();
        if (bitmap != null) {
            mBitmap = bitmap;
            BitmapCache cache = MasterImage.getImage().getBitmapCache();
            mBitmap = cache.getBitmapCopy(bitmap, BitmapCache.PREVIEW_CACHE);
        }
        if (mUseAllocation) {
            // TODO: recreate the allocation when the RS context changes
@@ -43,7 +45,23 @@ public class Buffer {
        }
    }

    public Bitmap getBitmap() {
    public boolean isSameSize(Bitmap bitmap) {
        if (mBitmap == null || bitmap == null) {
            return false;
        }
        if (mBitmap.getWidth() == bitmap.getWidth()
                && mBitmap.getHeight() == bitmap.getHeight()) {
            return true;
        }
        return false;
    }

    public synchronized void useBitmap(Bitmap bitmap) {
        Canvas canvas = new Canvas(mBitmap);
        canvas.drawBitmap(bitmap, 0, 0, null);
    }

    public synchronized Bitmap getBitmap() {
        return mBitmap;
    }

+1 −1
Original line number Diff line number Diff line
@@ -419,9 +419,9 @@ public class CachingPipeline implements PipelineInterface {
        }
        setupEnvironment(preset, false);
        Vector<FilterRepresentation> filters = preset.getFilters();
        buffer.removeProducer();
        Bitmap result = mCachedProcessing.process(mOriginalBitmap, filters, mEnvironment);
        buffer.setProducer(result);
        mEnvironment.cache(result);
    }

    public synchronized void computeOld(SharedBuffer buffer, ImagePreset preset, int type) {
+9 −13
Original line number Diff line number Diff line
@@ -29,20 +29,16 @@ public class SharedBuffer {
    private volatile boolean mNeedsSwap = false;
    private volatile boolean mNeedsRepaint = true;

    public void setProducer(Bitmap producer) {
        removeProducer();
        Buffer buffer = new Buffer(producer);
        synchronized (this) {
            mProducer = buffer;
        }
    }

    public void removeProducer() {
        synchronized (this) {
            if (mProducer != null) {
    public synchronized void setProducer(Bitmap producer) {
        if (mProducer != null
                && !mProducer.isSameSize(producer)) {
            mProducer.remove();
            mProducer = null;
        }
        if (mProducer == null) {
            mProducer = new Buffer(producer);
        } else {
            mProducer.useBitmap(producer);
        }
    }