MosaicRendererSurfaceViewRenderer.java revision 41a2e9735136f372de95652d0828600282c8e967
1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.camera.panorama;
18
19import javax.microedition.khronos.egl.EGLConfig;
20import javax.microedition.khronos.opengles.GL10;
21
22import android.app.Activity;
23import android.graphics.SurfaceTexture;
24import android.opengl.GLSurfaceView;
25import android.util.Log;
26
27public class MosaicRendererSurfaceViewRenderer implements GLSurfaceView.Renderer
28{
29    @Override
30    public void onDrawFrame(GL10 gl) {
31        MosaicRenderer.step();
32    }
33
34    @Override
35    public void onSurfaceChanged(GL10 gl, int width, int height) {
36        Log.i(TAG, "Renderer: onSurfaceChanged");
37        MosaicRenderer.reset(width, height);
38        Log.i(TAG, "Renderer: onSurfaceChanged");
39    }
40
41    @Override
42    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
43        mTextureID = MosaicRenderer.init();
44
45        mActivity.runOnUiThread(new Runnable() {
46
47            @Override
48            public void run() {
49                mActivity.createSurfaceTextureAndStartPreview(mTextureID);
50                setSurfaceTexture(mActivity.getSurfaceTexture());
51            }
52        });
53    }
54
55    public void setReady() {
56        MosaicRenderer.ready();
57    }
58
59    public void preprocess() {
60        MosaicRenderer.preprocess(mSTMatrix);
61    }
62
63    public void transferGPUtoCPU() {
64        MosaicRenderer.transferGPUtoCPU();
65    }
66
67    public void setWarping(boolean flag) {
68        MosaicRenderer.setWarping(flag);
69    }
70
71    public void updateSurfaceTexture() {
72        mSurface.updateTexImage();
73        mSurface.getTransformMatrix(mSTMatrix);
74    }
75
76    public void setUIObject(Activity activity) {
77        mActivity = (PanoramaActivity)activity;
78    }
79
80    public int getTextureID() {
81        return mTextureID;
82    }
83
84    public void setSurfaceTexture(SurfaceTexture surface) {
85        mSurface = surface;
86    }
87
88    private float[] mSTMatrix = new float[16];
89    private int mTextureID;
90
91    private PanoramaActivity mActivity;
92
93    private static String TAG = "MosaicRendererSurfaceViewRenderer";
94
95    private SurfaceTexture mSurface;
96}
97