summaryrefslogtreecommitdiffstats
path: root/src/com/android/galaxy4/GalaxyView.java
blob: ce0d33f158dd3af3558190669799be5652a88757 (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
package com.android.galaxy4;

import android.content.Context;
import android.graphics.PixelFormat;
import android.renderscript.RSSurfaceView;
import android.renderscript.RenderScriptGL;
import android.renderscript.RenderScriptGL.SurfaceConfig;
import android.view.SurfaceHolder;

public class GalaxyView extends RSSurfaceView {

    private RenderScriptGL mRS;
    private GalaxyRS mRender;

    public GalaxyView(Context context) {
        super(context);
        setFocusable(true);
        setFocusableInTouchMode(true);
        // getHolder().setFormat(PixelFormat.TRANSPARENT);
    }

    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
        super.surfaceChanged(holder, format, w, h);

        if (mRS == null) {
            RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
            mRS = createRenderScriptGL(sc);
            mRS.setSurface(holder, w, h);

            mRender = new GalaxyRS();
            mRender.init(mRS, getResources(), w, h);
        }

    }

    @Override
    protected void onDetachedFromWindow() {
        if (mRS != null) {
            mRS.setSurface(null, 0, 0);
            mRS = null;
            destroyRenderScriptGL();
        }
    }

}