RSSurfaceView.java revision ebfb436a49673693b98469683451bd9ede797557
1/* 2 * Copyright (C) 2008 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 android.renderscript; 18 19import java.io.Writer; 20import java.util.ArrayList; 21import java.util.concurrent.Semaphore; 22 23import android.content.Context; 24import android.os.Handler; 25import android.os.Message; 26import android.util.AttributeSet; 27import android.util.Log; 28import android.util.Log; 29import android.view.Surface; 30import android.view.SurfaceHolder; 31import android.view.SurfaceView; 32 33/** 34 * @hide 35 * 36 **/ 37public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback { 38 private SurfaceHolder mSurfaceHolder; 39 40 /** 41 * Standard View constructor. In order to render something, you 42 * must call {@link #setRenderer} to register a renderer. 43 */ 44 public RSSurfaceView(Context context) { 45 super(context); 46 init(); 47 Log.v(RenderScript.LOG_TAG, "RSSurfaceView"); 48 } 49 50 /** 51 * Standard View constructor. In order to render something, you 52 * must call {@link #setRenderer} to register a renderer. 53 */ 54 public RSSurfaceView(Context context, AttributeSet attrs) { 55 super(context, attrs); 56 init(); 57 Log.v(RenderScript.LOG_TAG, "RSSurfaceView"); 58 } 59 60 private void init() { 61 // Install a SurfaceHolder.Callback so we get notified when the 62 // underlying surface is created and destroyed 63 SurfaceHolder holder = getHolder(); 64 holder.addCallback(this); 65 } 66 67 /** 68 * This method is part of the SurfaceHolder.Callback interface, and is 69 * not normally called or subclassed by clients of RSSurfaceView. 70 */ 71 public void surfaceCreated(SurfaceHolder holder) { 72 Log.v(RenderScript.LOG_TAG, "surfaceCreated"); 73 mSurfaceHolder = holder; 74 } 75 76 /** 77 * This method is part of the SurfaceHolder.Callback interface, and is 78 * not normally called or subclassed by clients of RSSurfaceView. 79 */ 80 public void surfaceDestroyed(SurfaceHolder holder) { 81 // Surface will be destroyed when we return 82 Log.v(RenderScript.LOG_TAG, "surfaceDestroyed"); 83 } 84 85 /** 86 * This method is part of the SurfaceHolder.Callback interface, and is 87 * not normally called or subclassed by clients of RSSurfaceView. 88 */ 89 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { 90 Log.v(RenderScript.LOG_TAG, "surfaceChanged"); 91 } 92 93 /** 94 * Inform the view that the activity is paused. The owner of this view must 95 * call this method when the activity is paused. Calling this method will 96 * pause the rendering thread. 97 * Must not be called before a renderer has been set. 98 */ 99 public void onPause() { 100 Log.v(RenderScript.LOG_TAG, "onPause"); 101 } 102 103 /** 104 * Inform the view that the activity is resumed. The owner of this view must 105 * call this method when the activity is resumed. Calling this method will 106 * recreate the OpenGL display and resume the rendering 107 * thread. 108 * Must not be called before a renderer has been set. 109 */ 110 public void onResume() { 111 Log.v(RenderScript.LOG_TAG, "onResume"); 112 } 113 114 /** 115 * Queue a runnable to be run on the GL rendering thread. This can be used 116 * to communicate with the Renderer on the rendering thread. 117 * Must not be called before a renderer has been set. 118 * @param r the runnable to be run on the GL rendering thread. 119 */ 120 public void queueEvent(Runnable r) { 121 Log.v(RenderScript.LOG_TAG, "queueEvent"); 122 } 123 124 /** 125 * This method is used as part of the View class and is not normally 126 * called or subclassed by clients of RSSurfaceView. 127 * Must not be called before a renderer has been set. 128 */ 129 @Override 130 protected void onDetachedFromWindow() { 131 super.onDetachedFromWindow(); 132 } 133 134 // ---------------------------------------------------------------------- 135 136 public RenderScript createRenderScript(boolean useDepth, boolean forceSW) { 137 Surface sur = null; 138 while ((sur == null) || (mSurfaceHolder == null)) { 139 sur = getHolder().getSurface(); 140 } 141 RenderScript rs = new RenderScript(sur, useDepth, forceSW); 142 return rs; 143 } 144 145 public RenderScript createRenderScript(boolean useDepth) { 146 return createRenderScript(useDepth, false); 147 } 148 149 150} 151 152