MosaicRenderer.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
19/**
20 * The Java interface to JNI calls regarding mosaic preview rendering.
21 *
22 */
23public class MosaicRenderer
24{
25     static
26     {
27         System.loadLibrary("jni_mosaic");
28     }
29
30     /**
31      * Function to be called in onSurfaceCreated() to initialize
32      * the GL context, load and link the shaders and create the
33      * program. Returns a texture ID to be used for SurfaceTexture.
34      *
35      * @return textureID the texture ID of the newly generated texture to
36      *          be assigned to the SurfaceTexture object.
37      */
38     public static native int init();
39
40     /**
41      * Pass the drawing surface's width and height to initialize the
42      * renderer viewports and FBO dimensions.
43      *
44      * @param width width of the drawing surface in pixels.
45      * @param height height of the drawing surface in pixels.
46      */
47     public static native void reset(int width, int height);
48
49     /**
50      * Calling this function will render the SurfaceTexture to a new 2D texture
51      * using the provided STMatrix and then call glReadPixels to fill the data
52      * array that will be processed by the mosaicing thread.
53      *
54      * @param stMatrix texture coordinate transform matrix obtained from the
55      *        Surface texture
56      */
57     public static native void preprocess(float[] stMatrix);
58
59     /**
60      * This function calls glReadPixels to transfer both the low-res and high-res
61      * data from the GPU memory to the CPU memory for further processing by the
62      * mosaicing library.
63      */
64     public static native void transferGPUtoCPU();
65
66     /**
67      * Function to be called in onDrawFrame() to update the screen with
68      * the new frame data.
69      */
70     public static native void step();
71
72     /**
73      * Call this function when a new low-res frame has been processed by
74      * the mosaicing library. This will tell the renderer library to
75      * update its texture and warping transformation. Any calls to step()
76      * after this call will use the new image frame and transformation data.
77      */
78     public static native void ready();
79
80     /**
81      * This function allows toggling between showing the input image data
82      * (without applying any warp) and the warped image data. For running
83      * the renderer as a viewfinder, we set the flag to false. To see the
84      * preview mosaic, we set the flag to true.
85      *
86      * @param flag boolean flag to set the warping to true or false.
87      */
88     public static native void setWarping(boolean flag);
89}
90