blob: 05c0112f1bb7deb862885501a0b61b3d3bdf9441 [file] [log] [blame]
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001/*
Jason Samse619de62012-05-08 18:40:58 -07002 * Copyright (C) 2008-2012 The Android Open Source Project
Jack Palevich60aa3ea2009-05-26 13:45:08 -07003 *
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 Sams94d8e90a2009-06-10 16:09:05 -070017package android.renderscript;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070018
Artur Satayev2ebb31c2020-01-08 12:24:36 +000019import android.compat.annotation.UnsupportedAppUsage;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070020import android.content.Context;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070021import android.util.AttributeSet;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070022import android.view.SurfaceHolder;
23import android.view.SurfaceView;
24
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070025/**
Tim Murraya9084222013-04-05 22:06:43 +000026 * @hide
Jason Samse619de62012-05-08 18:40:58 -070027 * @deprecated in API 16
Alex Sakhartchouk93c47f12011-11-11 11:49:45 -080028 * The Surface View for a graphics renderscript (RenderScriptGL) to draw on.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080029 *
30 * <div class="special reference">
31 * <h3>Developer Guides</h3>
Tim Murrayc11e25c2013-04-09 11:01:01 -070032 * <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 Fernandez3aef8e1d2011-12-20 10:38:34 -080034 * </div>
Stephen Hinesb11e3d22011-01-11 19:30:58 -080035 */
Xusong Wang8b4548c2021-01-05 10:09:52 -080036@Deprecated
Jack Palevich60aa3ea2009-05-26 13:45:08 -070037public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
38 private SurfaceHolder mSurfaceHolder;
Jason Sams704ff642010-02-09 16:05:07 -080039 private RenderScriptGL mRS;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070040
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070041 /**
Jason Samse619de62012-05-08 18:40:58 -070042 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070043 * Standard View constructor. In order to render something, you
Stephen Hinesb11e3d22011-01-11 19:30:58 -080044 * must call {@link android.opengl.GLSurfaceView#setRenderer} to
45 * register a renderer.
Jack Palevich60aa3ea2009-05-26 13:45:08 -070046 */
Mathew Inwood15324472018-08-06 11:18:49 +010047 @UnsupportedAppUsage
Jack Palevich60aa3ea2009-05-26 13:45:08 -070048 public RSSurfaceView(Context context) {
49 super(context);
50 init();
Jason Sams66b27712009-09-25 15:25:00 -070051 //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
Jack Palevich60aa3ea2009-05-26 13:45:08 -070052 }
53
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070054 /**
Jason Samse619de62012-05-08 18:40:58 -070055 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070056 * Standard View constructor. In order to render something, you
Stephen Hinesb11e3d22011-01-11 19:30:58 -080057 * must call {@link android.opengl.GLSurfaceView#setRenderer} to
58 * register a renderer.
Jack Palevich60aa3ea2009-05-26 13:45:08 -070059 */
Mathew Inwood15324472018-08-06 11:18:49 +010060 @UnsupportedAppUsage
Jack Palevich60aa3ea2009-05-26 13:45:08 -070061 public RSSurfaceView(Context context, AttributeSet attrs) {
62 super(context, attrs);
63 init();
Jason Sams66b27712009-09-25 15:25:00 -070064 //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
Jack Palevich60aa3ea2009-05-26 13:45:08 -070065 }
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 Palevich60aa3ea2009-05-26 13:45:08 -070072 }
73
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070074 /**
Jason Samse619de62012-05-08 18:40:58 -070075 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070076 * 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 Palevich60aa3ea2009-05-26 13:45:08 -070080 mSurfaceHolder = holder;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070081 }
82
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070083 /**
Jason Samse619de62012-05-08 18:40:58 -070084 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070085 * This method is part of the SurfaceHolder.Callback interface, and is
86 * not normally called or subclassed by clients of RSSurfaceView.
87 */
Alex Sakhartchouk38da5082011-11-15 14:21:58 -080088 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 Samsefd9b6fb2009-11-03 13:58:36 -080094 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -070095 }
96
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070097 /**
Jason Samse619de62012-05-08 18:40:58 -070098 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070099 * This method is part of the SurfaceHolder.Callback interface, and is
100 * not normally called or subclassed by clients of RSSurfaceView.
101 */
Alex Sakhartchouk38da5082011-11-15 14:21:58 -0800102 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 Samsefd9b6fb2009-11-03 13:58:36 -0800107 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700108 }
109
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700110 /**
Jason Samse619de62012-05-08 18:40:58 -0700111 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700112 * 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 Samsbf6ef8d72010-12-06 15:59:59 -0800117 public void pause() {
Jason Sams65e7aa52009-09-24 17:38:20 -0700118 if(mRS != null) {
119 mRS.pause();
120 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700121 }
122
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700123 /**
Jason Samse619de62012-05-08 18:40:58 -0700124 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700125 * 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 Samsbf6ef8d72010-12-06 15:59:59 -0800131 public void resume() {
Jason Sams65e7aa52009-09-24 17:38:20 -0700132 if(mRS != null) {
133 mRS.resume();
134 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700135 }
136
Jason Samse619de62012-05-08 18:40:58 -0700137 /**
138 * @deprecated in API 16
139 **/
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800140 public RenderScriptGL createRenderScriptGL(RenderScriptGL.SurfaceConfig sc) {
Shih-wei Liao6b32fab2010-12-10 01:03:59 -0800141 RenderScriptGL rs = new RenderScriptGL(this.getContext(), sc);
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800142 setRenderScriptGL(rs);
143 return rs;
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700144 }
145
Jason Samse619de62012-05-08 18:40:58 -0700146 /**
147 * @deprecated in API 16
148 **/
Alex Sakhartchouk38da5082011-11-15 14:21:58 -0800149 public void destroyRenderScriptGL() {
150 synchronized (this) {
151 mRS.destroy();
152 mRS = null;
153 }
Joe Onorato5fda65f12009-09-25 09:12:16 -0700154 }
Jason Sams2222aa92010-10-10 17:58:25 -0700155
Jason Samse619de62012-05-08 18:40:58 -0700156 /**
157 * @deprecated in API 16
158 **/
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800159 public void setRenderScriptGL(RenderScriptGL rs) {
Romain Guya8551b12010-03-10 22:11:50 -0800160 mRS = rs;
161 }
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800162
Jason Samse619de62012-05-08 18:40:58 -0700163 /**
164 * @deprecated in API 16
165 **/
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800166 public RenderScriptGL getRenderScriptGL() {
167 return mRS;
168 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700169}