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