Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 1 | /* |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 2 | * Copyright (C) 2008-2012 The Android Open Source Project |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 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 | 94d8e90a | 2009-06-10 16:09:05 -0700 | [diff] [blame] | 17 | package android.renderscript; |
Jack Palevich | 60aa3ea | 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; |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 28 | import android.view.Surface; |
| 29 | import android.view.SurfaceHolder; |
| 30 | import android.view.SurfaceView; |
| 31 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 32 | /** |
Tim Murray | a908422 | 2013-04-05 22:06:43 +0000 | [diff] [blame] | 33 | * @hide |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 34 | * @deprecated in API 16 |
Alex Sakhartchouk | 93c47f1 | 2011-11-11 11:49:45 -0800 | [diff] [blame] | 35 | * The Surface View for a graphics renderscript (RenderScriptGL) to draw on. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 36 | * |
| 37 | * <div class="special reference"> |
| 38 | * <h3>Developer Guides</h3> |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 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> |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 41 | * </div> |
Stephen Hines | b11e3d2 | 2011-01-11 19:30:58 -0800 | [diff] [blame] | 42 | */ |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 43 | public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback { |
| 44 | private SurfaceHolder mSurfaceHolder; |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 45 | private RenderScriptGL mRS; |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 46 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 47 | /** |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 48 | * @deprecated in API 16 |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 49 | * Standard View constructor. In order to render something, you |
Stephen Hines | b11e3d2 | 2011-01-11 19:30:58 -0800 | [diff] [blame] | 50 | * must call {@link android.opengl.GLSurfaceView#setRenderer} to |
| 51 | * register a renderer. |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 52 | */ |
| 53 | public RSSurfaceView(Context context) { |
| 54 | super(context); |
| 55 | init(); |
Jason Sams | 66b2771 | 2009-09-25 15:25:00 -0700 | [diff] [blame] | 56 | //Log.v(RenderScript.LOG_TAG, "RSSurfaceView"); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 59 | /** |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 60 | * @deprecated in API 16 |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 61 | * Standard View constructor. In order to render something, you |
Stephen Hines | b11e3d2 | 2011-01-11 19:30:58 -0800 | [diff] [blame] | 62 | * must call {@link android.opengl.GLSurfaceView#setRenderer} to |
| 63 | * register a renderer. |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 64 | */ |
| 65 | public RSSurfaceView(Context context, AttributeSet attrs) { |
| 66 | super(context, attrs); |
| 67 | init(); |
Jason Sams | 66b2771 | 2009-09-25 15:25:00 -0700 | [diff] [blame] | 68 | //Log.v(RenderScript.LOG_TAG, "RSSurfaceView"); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 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); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 78 | /** |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 79 | * @deprecated in API 16 |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 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) { |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 84 | mSurfaceHolder = holder; |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 87 | /** |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 88 | * @deprecated in API 16 |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 89 | * This method is part of the SurfaceHolder.Callback interface, and is |
| 90 | * not normally called or subclassed by clients of RSSurfaceView. |
| 91 | */ |
Alex Sakhartchouk | 38da508 | 2011-11-15 14:21:58 -0800 | [diff] [blame] | 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 | } |
Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 98 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 101 | /** |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 102 | * @deprecated in API 16 |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 103 | * This method is part of the SurfaceHolder.Callback interface, and is |
| 104 | * not normally called or subclassed by clients of RSSurfaceView. |
| 105 | */ |
Alex Sakhartchouk | 38da508 | 2011-11-15 14:21:58 -0800 | [diff] [blame] | 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 | } |
Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 111 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 112 | } |
| 113 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 114 | /** |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 115 | * @deprecated in API 16 |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 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 | */ |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 121 | public void pause() { |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 122 | if(mRS != null) { |
| 123 | mRS.pause(); |
| 124 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 127 | /** |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 128 | * @deprecated in API 16 |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 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 | */ |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 135 | public void resume() { |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 136 | if(mRS != null) { |
| 137 | mRS.resume(); |
| 138 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 141 | /** |
| 142 | * @deprecated in API 16 |
| 143 | **/ |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 144 | public RenderScriptGL createRenderScriptGL(RenderScriptGL.SurfaceConfig sc) { |
Shih-wei Liao | 6b32fab | 2010-12-10 01:03:59 -0800 | [diff] [blame] | 145 | RenderScriptGL rs = new RenderScriptGL(this.getContext(), sc); |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 146 | setRenderScriptGL(rs); |
| 147 | return rs; |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 150 | /** |
| 151 | * @deprecated in API 16 |
| 152 | **/ |
Alex Sakhartchouk | 38da508 | 2011-11-15 14:21:58 -0800 | [diff] [blame] | 153 | public void destroyRenderScriptGL() { |
| 154 | synchronized (this) { |
| 155 | mRS.destroy(); |
| 156 | mRS = null; |
| 157 | } |
Joe Onorato | 5fda65f | 2009-09-25 09:12:16 -0700 | [diff] [blame] | 158 | } |
Jason Sams | 2222aa9 | 2010-10-10 17:58:25 -0700 | [diff] [blame] | 159 | |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 160 | /** |
| 161 | * @deprecated in API 16 |
| 162 | **/ |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 163 | public void setRenderScriptGL(RenderScriptGL rs) { |
Romain Guy | a8551b1 | 2010-03-10 22:11:50 -0800 | [diff] [blame] | 164 | mRS = rs; |
| 165 | } |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 166 | |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 167 | /** |
| 168 | * @deprecated in API 16 |
| 169 | **/ |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 170 | public RenderScriptGL getRenderScriptGL() { |
| 171 | return mRS; |
| 172 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 173 | } |