Home | History | Annotate | Download | only in renderscript
      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 android.renderscript;
     18 
     19 import java.io.Writer;
     20 import java.util.ArrayList;
     21 import java.util.concurrent.Semaphore;
     22 
     23 import android.content.Context;
     24 import android.graphics.SurfaceTexture;
     25 import android.os.Handler;
     26 import android.os.Message;
     27 import android.util.AttributeSet;
     28 import android.util.Log;
     29 import android.view.TextureView;
     30 
     31 /**
     32  * @deprecated in API 16
     33  * The Texture View for a graphics renderscript (RenderScriptGL)
     34  * to draw on.
     35  *
     36  */
     37 public class RSTextureView extends TextureView implements TextureView.SurfaceTextureListener {
     38     private RenderScriptGL mRS;
     39     private SurfaceTexture mSurfaceTexture;
     40 
     41     /**
     42      * @deprecated in API 16
     43      * Standard View constructor. In order to render something, you
     44      * must call {@link android.opengl.GLSurfaceView#setRenderer} to
     45      * register a renderer.
     46      */
     47     public RSTextureView(Context context) {
     48         super(context);
     49         init();
     50         //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
     51     }
     52 
     53     /**
     54      * @deprecated in API 16
     55      * Standard View constructor. In order to render something, you
     56      * must call {@link android.opengl.GLSurfaceView#setRenderer} to
     57      * register a renderer.
     58      */
     59     public RSTextureView(Context context, AttributeSet attrs) {
     60         super(context, attrs);
     61         init();
     62         //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
     63     }
     64 
     65     private void init() {
     66         setSurfaceTextureListener(this);
     67         //android.util.Log.e("rs", "getSurfaceTextureListerner " + getSurfaceTextureListener());
     68     }
     69 
     70     /**
     71      * @deprecated in API 16
     72      */
     73     @Override
     74     public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
     75         //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureAvailable");
     76         mSurfaceTexture = surface;
     77 
     78         if (mRS != null) {
     79             mRS.setSurfaceTexture(mSurfaceTexture, width, height);
     80         }
     81     }
     82 
     83     /**
     84      * @deprecated in API 16
     85      */
     86     @Override
     87     public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
     88         //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureSizeChanged");
     89         mSurfaceTexture = surface;
     90 
     91         if (mRS != null) {
     92             mRS.setSurfaceTexture(mSurfaceTexture, width, height);
     93         }
     94     }
     95 
     96     /**
     97      * @deprecated in API 16
     98      */
     99     @Override
    100     public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
    101         //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureDestroyed");
    102         mSurfaceTexture = surface;
    103 
    104         if (mRS != null) {
    105             mRS.setSurfaceTexture(null, 0, 0);
    106         }
    107 
    108         return true;
    109     }
    110 
    111     /**
    112      * @deprecated in API 16
    113      */
    114     @Override
    115     public void onSurfaceTextureUpdated(SurfaceTexture surface) {
    116         //Log.e(RenderScript.LOG_TAG, "onSurfaceTextureUpdated");
    117         mSurfaceTexture = surface;
    118     }
    119 
    120    /**
    121      * @deprecated in API 16
    122      * Inform the view that the activity is paused. The owner of this view must
    123      * call this method when the activity is paused. Calling this method will
    124      * pause the rendering thread.
    125      * Must not be called before a renderer has been set.
    126      */
    127     public void pause() {
    128         if(mRS != null) {
    129             mRS.pause();
    130         }
    131     }
    132 
    133     /**
    134      * @deprecated in API 16
    135      * Inform the view that the activity is resumed. The owner of this view must
    136      * call this method when the activity is resumed. Calling this method will
    137      * recreate the OpenGL display and resume the rendering
    138      * thread.
    139      * Must not be called before a renderer has been set.
    140      */
    141     public void resume() {
    142         if(mRS != null) {
    143             mRS.resume();
    144         }
    145     }
    146 
    147     /**
    148      * @deprecated in API 16
    149      * Create a new RenderScriptGL object and attach it to the
    150      * TextureView if present.
    151      *
    152      *
    153      * @param sc The RS surface config to create.
    154      *
    155      * @return RenderScriptGL The new object created.
    156      */
    157     public RenderScriptGL createRenderScriptGL(RenderScriptGL.SurfaceConfig sc) {
    158         RenderScriptGL rs = new RenderScriptGL(this.getContext(), sc);
    159         setRenderScriptGL(rs);
    160         if (mSurfaceTexture != null) {
    161             mRS.setSurfaceTexture(mSurfaceTexture, getWidth(), getHeight());
    162         }
    163         return rs;
    164     }
    165 
    166     /**
    167      * @deprecated in API 16
    168      * Destroy the RenderScriptGL object associated with this
    169      * TextureView.
    170      */
    171     public void destroyRenderScriptGL() {
    172         mRS.destroy();
    173         mRS = null;
    174     }
    175 
    176     /**
    177      * @deprecated in API 16
    178      * Set a new RenderScriptGL object.  This also will attach the
    179      * new object to the TextureView if present.
    180      *
    181      * @param rs The new RS object.
    182      */
    183     public void setRenderScriptGL(RenderScriptGL rs) {
    184         mRS = rs;
    185         if (mSurfaceTexture != null) {
    186             mRS.setSurfaceTexture(mSurfaceTexture, getWidth(), getHeight());
    187         }
    188     }
    189 
    190     /**
    191      * @deprecated in API 16
    192      * Returns the previously set RenderScriptGL object.
    193      *
    194      * @return RenderScriptGL
    195      */
    196     public RenderScriptGL getRenderScriptGL() {
    197         return mRS;
    198     }
    199 }
    200 
    201