summaryrefslogtreecommitdiffstats
path: root/src/com/android/galaxy4/GalaxyView.java
blob: d9d372784460ac9f9f34d5182eeea54240494971 (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
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;
import android.view.WindowManager;
import android.app.Service;
import android.util.Log;
import android.util.DisplayMetrics;

public class GalaxyView extends RSSurfaceView {

    private RenderScriptGL mRS;
    private GalaxyRS mRender;

    public GalaxyView(Context context) {
        super(context);
        setFocusable(true);
        setFocusableInTouchMode(true);
    }

    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);

            DisplayMetrics metrics = new DisplayMetrics();
            ((WindowManager) getContext()
                    .getSystemService(Service.WINDOW_SERVICE))
                    .getDefaultDisplay().getMetrics(metrics);

            mRender = new GalaxyRS();
            mRender.init(metrics.densityDpi, mRS, getResources(), w, h);
        } else {
            mRender.createProgramVertex();
        }
    }

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

}