Home | History | Annotate | Download | only in renderscript
      1 /*
      2  * Copyright (C) 2008-2012 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.os.Handler;
     25 import android.os.Message;
     26 import android.util.AttributeSet;
     27 import android.util.Log;
     28 import android.view.Surface;
     29 import android.view.SurfaceHolder;
     30 import android.view.SurfaceView;
     31 
     32 /**
     33  * @hide
     34  * @deprecated in API 16
     35  * The Surface View for a graphics renderscript (RenderScriptGL) to draw on.
     36  *
     37  * <div class="special reference">
     38  * <h3>Developer Guides</h3>
     39  * <p>For more information about creating an application that uses RenderScript, read the
     40  * <a href="{@docRoot}guide/topics/renderscript/index.html">RenderScript</a> developer guide.</p>
     41  * </div>
     42  */
     43 public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
     44     private SurfaceHolder mSurfaceHolder;
     45     private RenderScriptGL mRS;
     46 
     47     /**
     48      * @deprecated in API 16
     49      * Standard View constructor. In order to render something, you
     50      * must call {@link android.opengl.GLSurfaceView#setRenderer} to
     51      * register a renderer.
     52      */
     53     public RSSurfaceView(Context context) {
     54         super(context);
     55         init();
     56         //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
     57     }
     58 
     59     /**
     60      * @deprecated in API 16
     61      * Standard View constructor. In order to render something, you
     62      * must call {@link android.opengl.GLSurfaceView#setRenderer} to
     63      * register a renderer.
     64      */
     65     public RSSurfaceView(Context context, AttributeSet attrs) {
     66         super(context, attrs);
     67         init();
     68         //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
     69     }
     70 
     71     private void init() {
     72         // Install a SurfaceHolder.Callback so we get notified when the
     73         // underlying surface is created and destroyed
     74         SurfaceHolder holder = getHolder();
     75         holder.addCallback(this);
     76     }
     77 
     78     /**
     79      * @deprecated in API 16
     80      * This method is part of the SurfaceHolder.Callback interface, and is
     81      * not normally called or subclassed by clients of RSSurfaceView.
     82      */
     83     public void surfaceCreated(SurfaceHolder holder) {
     84         mSurfaceHolder = holder;
     85     }
     86 
     87     /**
     88      * @deprecated in API 16
     89      * This method is part of the SurfaceHolder.Callback interface, and is
     90      * not normally called or subclassed by clients of RSSurfaceView.
     91      */
     92     public void surfaceDestroyed(SurfaceHolder holder) {
     93         synchronized (this) {
     94             // Surface will be destroyed when we return
     95             if (mRS != null) {
     96                 mRS.setSurface(null, 0, 0);
     97             }
     98         }
     99     }
    100 
    101     /**
    102      * @deprecated in API 16
    103      * This method is part of the SurfaceHolder.Callback interface, and is
    104      * not normally called or subclassed by clients of RSSurfaceView.
    105      */
    106     public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
    107         synchronized (this) {
    108             if (mRS != null) {
    109                 mRS.setSurface(holder, w, h);
    110             }
    111         }
    112     }
    113 
    114    /**
    115      * @deprecated in API 16
    116      * Inform the view that the activity is paused. The owner of this view must
    117      * call this method when the activity is paused. Calling this method will
    118      * pause the rendering thread.
    119      * Must not be called before a renderer has been set.
    120      */
    121     public void pause() {
    122         if(mRS != null) {
    123             mRS.pause();
    124         }
    125     }
    126 
    127     /**
    128      * @deprecated in API 16
    129      * Inform the view that the activity is resumed. The owner of this view must
    130      * call this method when the activity is resumed. Calling this method will
    131      * recreate the OpenGL display and resume the rendering
    132      * thread.
    133      * Must not be called before a renderer has been set.
    134      */
    135     public void resume() {
    136         if(mRS != null) {
    137             mRS.resume();
    138         }
    139     }
    140 
    141     /**
    142      * @deprecated in API 16
    143      **/
    144     public RenderScriptGL createRenderScriptGL(RenderScriptGL.SurfaceConfig sc) {
    145       RenderScriptGL rs = new RenderScriptGL(this.getContext(), sc);
    146         setRenderScriptGL(rs);
    147         return rs;
    148     }
    149 
    150     /**
    151      * @deprecated in API 16
    152      **/
    153     public void destroyRenderScriptGL() {
    154         synchronized (this) {
    155             mRS.destroy();
    156             mRS = null;
    157         }
    158     }
    159 
    160     /**
    161      * @deprecated in API 16
    162      **/
    163     public void setRenderScriptGL(RenderScriptGL rs) {
    164         mRS = rs;
    165     }
    166 
    167     /**
    168      * @deprecated in API 16
    169      **/
    170     public RenderScriptGL getRenderScriptGL() {
    171         return mRS;
    172     }
    173 }
    174