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 | |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 19 | import android.content.Context; |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 20 | import android.util.AttributeSet; |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 21 | import android.view.SurfaceHolder; |
| 22 | import android.view.SurfaceView; |
| 23 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 24 | /** |
Tim Murray | a908422 | 2013-04-05 22:06:43 +0000 | [diff] [blame] | 25 | * @hide |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 26 | * @deprecated in API 16 |
Alex Sakhartchouk | 93c47f1 | 2011-11-11 11:49:45 -0800 | [diff] [blame] | 27 | * The Surface View for a graphics renderscript (RenderScriptGL) to draw on. |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 28 | * |
| 29 | * <div class="special reference"> |
| 30 | * <h3>Developer Guides</h3> |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 31 | * <p>For more information about creating an application that uses RenderScript, read the |
| 32 | * <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] | 33 | * </div> |
Stephen Hines | b11e3d2 | 2011-01-11 19:30:58 -0800 | [diff] [blame] | 34 | */ |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 35 | public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback { |
| 36 | private SurfaceHolder mSurfaceHolder; |
Jason Sams | 704ff64 | 2010-02-09 16:05:07 -0800 | [diff] [blame] | 37 | private RenderScriptGL mRS; |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 38 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 39 | /** |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 40 | * @deprecated in API 16 |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 41 | * Standard View constructor. In order to render something, you |
Stephen Hines | b11e3d2 | 2011-01-11 19:30:58 -0800 | [diff] [blame] | 42 | * must call {@link android.opengl.GLSurfaceView#setRenderer} to |
| 43 | * register a renderer. |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 44 | */ |
| 45 | public RSSurfaceView(Context context) { |
| 46 | super(context); |
| 47 | init(); |
Jason Sams | 66b2771 | 2009-09-25 15:25:00 -0700 | [diff] [blame] | 48 | //Log.v(RenderScript.LOG_TAG, "RSSurfaceView"); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 49 | } |
| 50 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 51 | /** |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 52 | * @deprecated in API 16 |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 53 | * Standard View constructor. In order to render something, you |
Stephen Hines | b11e3d2 | 2011-01-11 19:30:58 -0800 | [diff] [blame] | 54 | * must call {@link android.opengl.GLSurfaceView#setRenderer} to |
| 55 | * register a renderer. |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 56 | */ |
| 57 | public RSSurfaceView(Context context, AttributeSet attrs) { |
| 58 | super(context, attrs); |
| 59 | init(); |
Jason Sams | 66b2771 | 2009-09-25 15:25:00 -0700 | [diff] [blame] | 60 | //Log.v(RenderScript.LOG_TAG, "RSSurfaceView"); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | private void init() { |
| 64 | // Install a SurfaceHolder.Callback so we get notified when the |
| 65 | // underlying surface is created and destroyed |
| 66 | SurfaceHolder holder = getHolder(); |
| 67 | holder.addCallback(this); |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 70 | /** |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 71 | * @deprecated in API 16 |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 72 | * This method is part of the SurfaceHolder.Callback interface, and is |
| 73 | * not normally called or subclassed by clients of RSSurfaceView. |
| 74 | */ |
| 75 | public void surfaceCreated(SurfaceHolder holder) { |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 76 | mSurfaceHolder = holder; |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 79 | /** |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 80 | * @deprecated in API 16 |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 81 | * This method is part of the SurfaceHolder.Callback interface, and is |
| 82 | * not normally called or subclassed by clients of RSSurfaceView. |
| 83 | */ |
Alex Sakhartchouk | 38da508 | 2011-11-15 14:21:58 -0800 | [diff] [blame] | 84 | public void surfaceDestroyed(SurfaceHolder holder) { |
| 85 | synchronized (this) { |
| 86 | // Surface will be destroyed when we return |
| 87 | if (mRS != null) { |
| 88 | mRS.setSurface(null, 0, 0); |
| 89 | } |
Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 90 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 93 | /** |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 94 | * @deprecated in API 16 |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 95 | * This method is part of the SurfaceHolder.Callback interface, and is |
| 96 | * not normally called or subclassed by clients of RSSurfaceView. |
| 97 | */ |
Alex Sakhartchouk | 38da508 | 2011-11-15 14:21:58 -0800 | [diff] [blame] | 98 | public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) { |
| 99 | synchronized (this) { |
| 100 | if (mRS != null) { |
| 101 | mRS.setSurface(holder, w, h); |
| 102 | } |
Jason Sams | efd9b6fb | 2009-11-03 13:58:36 -0800 | [diff] [blame] | 103 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 106 | /** |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 107 | * @deprecated in API 16 |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 108 | * Inform the view that the activity is paused. The owner of this view must |
| 109 | * call this method when the activity is paused. Calling this method will |
| 110 | * pause the rendering thread. |
| 111 | * Must not be called before a renderer has been set. |
| 112 | */ |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 113 | public void pause() { |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 114 | if(mRS != null) { |
| 115 | mRS.pause(); |
| 116 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 117 | } |
| 118 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 119 | /** |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 120 | * @deprecated in API 16 |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 121 | * Inform the view that the activity is resumed. The owner of this view must |
| 122 | * call this method when the activity is resumed. Calling this method will |
| 123 | * recreate the OpenGL display and resume the rendering |
| 124 | * thread. |
| 125 | * Must not be called before a renderer has been set. |
| 126 | */ |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 127 | public void resume() { |
Jason Sams | 65e7aa5 | 2009-09-24 17:38:20 -0700 | [diff] [blame] | 128 | if(mRS != null) { |
| 129 | mRS.resume(); |
| 130 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 133 | /** |
| 134 | * @deprecated in API 16 |
| 135 | **/ |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 136 | public RenderScriptGL createRenderScriptGL(RenderScriptGL.SurfaceConfig sc) { |
Shih-wei Liao | 6b32fab | 2010-12-10 01:03:59 -0800 | [diff] [blame] | 137 | RenderScriptGL rs = new RenderScriptGL(this.getContext(), sc); |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 138 | setRenderScriptGL(rs); |
| 139 | return rs; |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 142 | /** |
| 143 | * @deprecated in API 16 |
| 144 | **/ |
Alex Sakhartchouk | 38da508 | 2011-11-15 14:21:58 -0800 | [diff] [blame] | 145 | public void destroyRenderScriptGL() { |
| 146 | synchronized (this) { |
| 147 | mRS.destroy(); |
| 148 | mRS = null; |
| 149 | } |
Joe Onorato | 5fda65f | 2009-09-25 09:12:16 -0700 | [diff] [blame] | 150 | } |
Jason Sams | 2222aa9 | 2010-10-10 17:58:25 -0700 | [diff] [blame] | 151 | |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 152 | /** |
| 153 | * @deprecated in API 16 |
| 154 | **/ |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 155 | public void setRenderScriptGL(RenderScriptGL rs) { |
Romain Guy | a8551b1 | 2010-03-10 22:11:50 -0800 | [diff] [blame] | 156 | mRS = rs; |
| 157 | } |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 158 | |
Jason Sams | e619de6 | 2012-05-08 18:40:58 -0700 | [diff] [blame] | 159 | /** |
| 160 | * @deprecated in API 16 |
| 161 | **/ |
Jason Sams | bf6ef8d | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 162 | public RenderScriptGL getRenderScriptGL() { |
| 163 | return mRS; |
| 164 | } |
Jack Palevich | 60aa3ea | 2009-05-26 13:45:08 -0700 | [diff] [blame] | 165 | } |