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