summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d/ui/PreparePageFadeoutTexture.java
blob: b4310662fdd491984d3b0849b26193a0cfc7333a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.android.gallery3d.ui;

import android.os.ConditionVariable;

import com.android.gallery3d.app.AbstractGalleryActivity;
import com.android.gallery3d.ui.GLRoot.OnGLIdleListener;

public class PreparePageFadeoutTexture implements OnGLIdleListener {
    private static final long TIMEOUT = FadeTexture.DURATION;
    public static final String KEY_FADE_TEXTURE = "fade_texture";

    private RawTexture mTexture;
    private ConditionVariable mResultReady = new ConditionVariable(false);
    private boolean mCancelled = false;
    private GLView mRootPane;

    public PreparePageFadeoutTexture(int w, int h,  GLView rootPane) {
        mTexture = new RawTexture(w, h, true);
        mRootPane =  rootPane;
    }

    public synchronized RawTexture get() {
        if (mCancelled) {
            return null;
        } else if (mResultReady.block(TIMEOUT)) {
            return mTexture;
        } else {
            mCancelled = true;
            return null;
        }
    }

    @Override
    public boolean onGLIdle(GLCanvas canvas, boolean renderRequested) {
            if(!mCancelled) {
                canvas.beginRenderTarget(mTexture);
                mRootPane.render(canvas);
                canvas.endRenderTarget();
            } else {
                mTexture = null;
            }
            mResultReady.open();
            return false;
    }

    public static void prepareFadeOutTexture(AbstractGalleryActivity activity,
            SlotView slotView, GLView rootPane) {
        GLRoot root = activity.getGLRoot();
        PreparePageFadeoutTexture task = new PreparePageFadeoutTexture(
                slotView.getWidth(), slotView.getHeight() +
                activity.getGalleryActionBar().getHeight(), rootPane);
        RawTexture texture = null;
        root.unlockRenderThread();
        try {
            root.addOnGLIdleListener(task);
            texture = task.get();
        } finally {
            root.lockRenderThread();
        }

        if (texture != null) {
            activity.getTransitionStore().put(KEY_FADE_TEXTURE, texture);
        }
    }
}