1eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal/*
2eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal * Copyright (C) 2011 The Android Open Source Project
3eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal *
4eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal * Licensed under the Apache License, Version 2.0 (the "License");
5eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal * you may not use this file except in compliance with the License.
6eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal * You may obtain a copy of the License at
7eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal *
8eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal *      http://www.apache.org/licenses/LICENSE-2.0
9eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal *
10eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal * Unless required by applicable law or agreed to in writing, software
11eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal * distributed under the License is distributed on an "AS IS" BASIS,
12eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal * See the License for the specific language governing permissions and
14eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal * limitations under the License.
15eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal */
16eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal
17eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansalpackage com.android.camera.panorama;
18eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal
19eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal/**
20eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal * The Java interface to JNI calls regarding mosaic preview rendering.
21eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal *
22eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal */
23eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansalpublic class MosaicRenderer
24eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal{
25eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal     static
26eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal     {
272d303cacaf6606f580f040a1b03feab9483e302cJun Tian         System.loadLibrary("jni_legacymosaic");
28eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal     }
29eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal
30eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal     /**
31eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal      * Function to be called in onSurfaceCreated() to initialize
32eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal      * the GL context, load and link the shaders and create the
3341a2e9735136f372de95652d0828600282c8e967mbansal      * program. Returns a texture ID to be used for SurfaceTexture.
3441a2e9735136f372de95652d0828600282c8e967mbansal      *
3541a2e9735136f372de95652d0828600282c8e967mbansal      * @return textureID the texture ID of the newly generated texture to
3641a2e9735136f372de95652d0828600282c8e967mbansal      *          be assigned to the SurfaceTexture object.
37eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal      */
3841a2e9735136f372de95652d0828600282c8e967mbansal     public static native int init();
39eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal
40eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal     /**
41eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal      * Pass the drawing surface's width and height to initialize the
42eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal      * renderer viewports and FBO dimensions.
43eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal      *
44eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal      * @param width width of the drawing surface in pixels.
45eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal      * @param height height of the drawing surface in pixels.
46d32aa042a7d7fdb52cd8cec571e7c648f837eaffWei-Ta Chen      * @param isLandscapeOrientation is the orientation of the activity layout in landscape.
47eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal      */
48d32aa042a7d7fdb52cd8cec571e7c648f837eaffWei-Ta Chen     public static native void reset(int width, int height, boolean isLandscapeOrientation);
49eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal
50eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal     /**
5141a2e9735136f372de95652d0828600282c8e967mbansal      * Calling this function will render the SurfaceTexture to a new 2D texture
521f227d20aa000d0798581f451b89b1d3b2bcd349Wei-Ta Chen      * using the provided STMatrix.
5341a2e9735136f372de95652d0828600282c8e967mbansal      *
5441a2e9735136f372de95652d0828600282c8e967mbansal      * @param stMatrix texture coordinate transform matrix obtained from the
5541a2e9735136f372de95652d0828600282c8e967mbansal      *        Surface texture
5641a2e9735136f372de95652d0828600282c8e967mbansal      */
5741a2e9735136f372de95652d0828600282c8e967mbansal     public static native void preprocess(float[] stMatrix);
5841a2e9735136f372de95652d0828600282c8e967mbansal
5941a2e9735136f372de95652d0828600282c8e967mbansal     /**
6041a2e9735136f372de95652d0828600282c8e967mbansal      * This function calls glReadPixels to transfer both the low-res and high-res
6141a2e9735136f372de95652d0828600282c8e967mbansal      * data from the GPU memory to the CPU memory for further processing by the
6241a2e9735136f372de95652d0828600282c8e967mbansal      * mosaicing library.
6341a2e9735136f372de95652d0828600282c8e967mbansal      */
6441a2e9735136f372de95652d0828600282c8e967mbansal     public static native void transferGPUtoCPU();
6541a2e9735136f372de95652d0828600282c8e967mbansal
6641a2e9735136f372de95652d0828600282c8e967mbansal     /**
67eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal      * Function to be called in onDrawFrame() to update the screen with
68eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal      * the new frame data.
69eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal      */
70eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal     public static native void step();
71eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal
72eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal     /**
73eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal      * Call this function when a new low-res frame has been processed by
74eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal      * the mosaicing library. This will tell the renderer library to
75eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal      * update its texture and warping transformation. Any calls to step()
76eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal      * after this call will use the new image frame and transformation data.
77eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal      */
78eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal     public static native void ready();
79eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal
80eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal     /**
81eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal      * This function allows toggling between showing the input image data
8241a2e9735136f372de95652d0828600282c8e967mbansal      * (without applying any warp) and the warped image data. For running
8341a2e9735136f372de95652d0828600282c8e967mbansal      * the renderer as a viewfinder, we set the flag to false. To see the
8441a2e9735136f372de95652d0828600282c8e967mbansal      * preview mosaic, we set the flag to true.
8541a2e9735136f372de95652d0828600282c8e967mbansal      *
8641a2e9735136f372de95652d0828600282c8e967mbansal      * @param flag boolean flag to set the warping to true or false.
87eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal      */
8841a2e9735136f372de95652d0828600282c8e967mbansal     public static native void setWarping(boolean flag);
89eeb94d4de94bfd4e01f3a716803f77a530f5b92cmbansal}
90