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 17 package com.android.camera.panorama; 18 19 import android.opengl.GLSurfaceView; 20 import android.util.Log; 21 22 import javax.microedition.khronos.egl.EGLConfig; 23 import javax.microedition.khronos.opengles.GL10; 24 25 public class MosaicRendererSurfaceViewRenderer implements GLSurfaceView.Renderer 26 { 27 private static final String TAG = "MosaicRendererSurfaceViewRenderer"; 28 private boolean mIsLandscapeOrientation; 29 30 private MosaicSurfaceCreateListener mSurfaceCreateListener; 31 MosaicRendererSurfaceViewRenderer(boolean isLandscapeOrientation)32 public MosaicRendererSurfaceViewRenderer(boolean isLandscapeOrientation) { 33 mIsLandscapeOrientation = isLandscapeOrientation; 34 } 35 36 /** A callback to be called when the surface is created */ 37 public interface MosaicSurfaceCreateListener { onMosaicSurfaceCreated(final int surface)38 public void onMosaicSurfaceCreated(final int surface); onMosaicSurfaceChanged()39 public void onMosaicSurfaceChanged(); 40 } 41 42 @Override onDrawFrame(GL10 gl)43 public void onDrawFrame(GL10 gl) { 44 MosaicRenderer.step(); 45 } 46 47 @Override onSurfaceChanged(GL10 gl, int width, int height)48 public void onSurfaceChanged(GL10 gl, int width, int height) { 49 MosaicRenderer.reset(width, height, mIsLandscapeOrientation); 50 Log.i(TAG, "Renderer: onSurfaceChanged"); 51 if (mSurfaceCreateListener != null) { 52 mSurfaceCreateListener.onMosaicSurfaceChanged(); 53 } 54 } 55 56 @Override onSurfaceCreated(GL10 gl, EGLConfig config)57 public void onSurfaceCreated(GL10 gl, EGLConfig config) { 58 Log.i(TAG, "onSurfaceCreated"); 59 if (mSurfaceCreateListener != null) { 60 mSurfaceCreateListener.onMosaicSurfaceCreated(MosaicRenderer.init()); 61 } 62 } 63 setMosaicSurfaceCreateListener(MosaicSurfaceCreateListener listener)64 public void setMosaicSurfaceCreateListener(MosaicSurfaceCreateListener listener) { 65 mSurfaceCreateListener = listener; 66 } 67 setReady()68 public void setReady() { 69 MosaicRenderer.ready(); 70 } 71 preprocess(float[] transformMatrix)72 public void preprocess(float[] transformMatrix) { 73 MosaicRenderer.preprocess(transformMatrix); 74 } 75 transferGPUtoCPU()76 public void transferGPUtoCPU() { 77 MosaicRenderer.transferGPUtoCPU(); 78 } 79 setWarping(boolean flag)80 public void setWarping(boolean flag) { 81 MosaicRenderer.setWarping(flag); 82 } 83 } 84