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