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