blob: 6bdde387b3343db0663e98203c82f42b851cfa6e [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 */
Jack Palevich60aa3ea2009-05-26 13:45:08 -070036public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
37 private SurfaceHolder mSurfaceHolder;
Jason Sams704ff642010-02-09 16:05:07 -080038 private RenderScriptGL mRS;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070039
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070040 /**
Jason Samse619de62012-05-08 18:40:58 -070041 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070042 * Standard View constructor. In order to render something, you
Stephen Hinesb11e3d22011-01-11 19:30:58 -080043 * must call {@link android.opengl.GLSurfaceView#setRenderer} to
44 * register a renderer.
Jack Palevich60aa3ea2009-05-26 13:45:08 -070045 */
Mathew Inwood15324472018-08-06 11:18:49 +010046 @UnsupportedAppUsage
Jack Palevich60aa3ea2009-05-26 13:45:08 -070047 public RSSurfaceView(Context context) {
48 super(context);
49 init();
Jason Sams66b27712009-09-25 15:25:00 -070050 //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
Jack Palevich60aa3ea2009-05-26 13:45:08 -070051 }
52
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070053 /**
Jason Samse619de62012-05-08 18:40:58 -070054 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070055 * Standard View constructor. In order to render something, you
Stephen Hinesb11e3d22011-01-11 19:30:58 -080056 * must call {@link android.opengl.GLSurfaceView#setRenderer} to
57 * register a renderer.
Jack Palevich60aa3ea2009-05-26 13:45:08 -070058 */
Mathew Inwood15324472018-08-06 11:18:49 +010059 @UnsupportedAppUsage
Jack Palevich60aa3ea2009-05-26 13:45:08 -070060 public RSSurfaceView(Context context, AttributeSet attrs) {
61 super(context, attrs);
62 init();
Jason Sams66b27712009-09-25 15:25:00 -070063 //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
Jack Palevich60aa3ea2009-05-26 13:45:08 -070064 }
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 Palevich60aa3ea2009-05-26 13:45:08 -070071 }
72
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070073 /**
Jason Samse619de62012-05-08 18:40:58 -070074 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070075 * 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 Palevich60aa3ea2009-05-26 13:45:08 -070079 mSurfaceHolder = holder;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070080 }
81
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070082 /**
Jason Samse619de62012-05-08 18:40:58 -070083 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070084 * This method is part of the SurfaceHolder.Callback interface, and is
85 * not normally called or subclassed by clients of RSSurfaceView.
86 */
Alex Sakhartchouk38da5082011-11-15 14:21:58 -080087 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 Samsefd9b6fb2009-11-03 13:58:36 -080093 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -070094 }
95
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070096 /**
Jason Samse619de62012-05-08 18:40:58 -070097 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070098 * This method is part of the SurfaceHolder.Callback interface, and is
99 * not normally called or subclassed by clients of RSSurfaceView.
100 */
Alex Sakhartchouk38da5082011-11-15 14:21:58 -0800101 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 Samsefd9b6fb2009-11-03 13:58:36 -0800106 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700107 }
108
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700109 /**
Jason Samse619de62012-05-08 18:40:58 -0700110 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700111 * 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 Samsbf6ef8d2010-12-06 15:59:59 -0800116 public void pause() {
Jason Sams65e7aa52009-09-24 17:38:20 -0700117 if(mRS != null) {
118 mRS.pause();
119 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700120 }
121
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700122 /**
Jason Samse619de62012-05-08 18:40:58 -0700123 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700124 * 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 Samsbf6ef8d2010-12-06 15:59:59 -0800130 public void resume() {
Jason Sams65e7aa52009-09-24 17:38:20 -0700131 if(mRS != null) {
132 mRS.resume();
133 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700134 }
135
Jason Samse619de62012-05-08 18:40:58 -0700136 /**
137 * @deprecated in API 16
138 **/
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800139 public RenderScriptGL createRenderScriptGL(RenderScriptGL.SurfaceConfig sc) {
Shih-wei Liao6b32fab2010-12-10 01:03:59 -0800140 RenderScriptGL rs = new RenderScriptGL(this.getContext(), sc);
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800141 setRenderScriptGL(rs);
142 return rs;
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700143 }
144
Jason Samse619de62012-05-08 18:40:58 -0700145 /**
146 * @deprecated in API 16
147 **/
Alex Sakhartchouk38da5082011-11-15 14:21:58 -0800148 public void destroyRenderScriptGL() {
149 synchronized (this) {
150 mRS.destroy();
151 mRS = null;
152 }
Joe Onorato5fda65f2009-09-25 09:12:16 -0700153 }
Jason Sams2222aa92010-10-10 17:58:25 -0700154
Jason Samse619de62012-05-08 18:40:58 -0700155 /**
156 * @deprecated in API 16
157 **/
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800158 public void setRenderScriptGL(RenderScriptGL rs) {
Romain Guya8551b12010-03-10 22:11:50 -0800159 mRS = rs;
160 }
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800161
Jason Samse619de62012-05-08 18:40:58 -0700162 /**
163 * @deprecated in API 16
164 **/
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800165 public RenderScriptGL getRenderScriptGL() {
166 return mRS;
167 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700168}