blob: 308d97a3c5ce4bb0c3002dbf37d7b57c7b1d5d9c [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
19import java.io.Writer;
20import java.util.ArrayList;
21import java.util.concurrent.Semaphore;
22
23import android.content.Context;
24import android.os.Handler;
25import android.os.Message;
26import android.util.AttributeSet;
27import android.util.Log;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070028import android.view.Surface;
29import android.view.SurfaceHolder;
30import android.view.SurfaceView;
31
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070032/**
Tim Murraya9084222013-04-05 22:06:43 +000033 * @hide
Jason Samse619de62012-05-08 18:40:58 -070034 * @deprecated in API 16
Alex Sakhartchouk93c47f12011-11-11 11:49:45 -080035 * The Surface View for a graphics renderscript (RenderScriptGL) to draw on.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080036 *
37 * <div class="special reference">
38 * <h3>Developer Guides</h3>
Tim Murrayc11e25c2013-04-09 11:01:01 -070039 * <p>For more information about creating an application that uses RenderScript, read the
40 * <a href="{@docRoot}guide/topics/renderscript/index.html">RenderScript</a> developer guide.</p>
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080041 * </div>
Stephen Hinesb11e3d22011-01-11 19:30:58 -080042 */
Jack Palevich60aa3ea2009-05-26 13:45:08 -070043public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
44 private SurfaceHolder mSurfaceHolder;
Jason Sams704ff642010-02-09 16:05:07 -080045 private RenderScriptGL mRS;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070046
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070047 /**
Jason Samse619de62012-05-08 18:40:58 -070048 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070049 * Standard View constructor. In order to render something, you
Stephen Hinesb11e3d22011-01-11 19:30:58 -080050 * must call {@link android.opengl.GLSurfaceView#setRenderer} to
51 * register a renderer.
Jack Palevich60aa3ea2009-05-26 13:45:08 -070052 */
53 public RSSurfaceView(Context context) {
54 super(context);
55 init();
Jason Sams66b27712009-09-25 15:25:00 -070056 //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
Jack Palevich60aa3ea2009-05-26 13:45:08 -070057 }
58
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070059 /**
Jason Samse619de62012-05-08 18:40:58 -070060 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070061 * Standard View constructor. In order to render something, you
Stephen Hinesb11e3d22011-01-11 19:30:58 -080062 * must call {@link android.opengl.GLSurfaceView#setRenderer} to
63 * register a renderer.
Jack Palevich60aa3ea2009-05-26 13:45:08 -070064 */
65 public RSSurfaceView(Context context, AttributeSet attrs) {
66 super(context, attrs);
67 init();
Jason Sams66b27712009-09-25 15:25:00 -070068 //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
Jack Palevich60aa3ea2009-05-26 13:45:08 -070069 }
70
71 private void init() {
72 // Install a SurfaceHolder.Callback so we get notified when the
73 // underlying surface is created and destroyed
74 SurfaceHolder holder = getHolder();
75 holder.addCallback(this);
Jack Palevich60aa3ea2009-05-26 13:45:08 -070076 }
77
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070078 /**
Jason Samse619de62012-05-08 18:40:58 -070079 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070080 * This method is part of the SurfaceHolder.Callback interface, and is
81 * not normally called or subclassed by clients of RSSurfaceView.
82 */
83 public void surfaceCreated(SurfaceHolder holder) {
Jack Palevich60aa3ea2009-05-26 13:45:08 -070084 mSurfaceHolder = holder;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070085 }
86
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070087 /**
Jason Samse619de62012-05-08 18:40:58 -070088 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070089 * This method is part of the SurfaceHolder.Callback interface, and is
90 * not normally called or subclassed by clients of RSSurfaceView.
91 */
Alex Sakhartchouk38da5082011-11-15 14:21:58 -080092 public void surfaceDestroyed(SurfaceHolder holder) {
93 synchronized (this) {
94 // Surface will be destroyed when we return
95 if (mRS != null) {
96 mRS.setSurface(null, 0, 0);
97 }
Jason Samsefd9b6fb2009-11-03 13:58:36 -080098 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -070099 }
100
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700101 /**
Jason Samse619de62012-05-08 18:40:58 -0700102 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700103 * This method is part of the SurfaceHolder.Callback interface, and is
104 * not normally called or subclassed by clients of RSSurfaceView.
105 */
Alex Sakhartchouk38da5082011-11-15 14:21:58 -0800106 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
107 synchronized (this) {
108 if (mRS != null) {
109 mRS.setSurface(holder, w, h);
110 }
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800111 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700112 }
113
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700114 /**
Jason Samse619de62012-05-08 18:40:58 -0700115 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700116 * Inform the view that the activity is paused. The owner of this view must
117 * call this method when the activity is paused. Calling this method will
118 * pause the rendering thread.
119 * Must not be called before a renderer has been set.
120 */
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800121 public void pause() {
Jason Sams65e7aa52009-09-24 17:38:20 -0700122 if(mRS != null) {
123 mRS.pause();
124 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700125 }
126
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700127 /**
Jason Samse619de62012-05-08 18:40:58 -0700128 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700129 * Inform the view that the activity is resumed. The owner of this view must
130 * call this method when the activity is resumed. Calling this method will
131 * recreate the OpenGL display and resume the rendering
132 * thread.
133 * Must not be called before a renderer has been set.
134 */
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800135 public void resume() {
Jason Sams65e7aa52009-09-24 17:38:20 -0700136 if(mRS != null) {
137 mRS.resume();
138 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700139 }
140
Jason Samse619de62012-05-08 18:40:58 -0700141 /**
142 * @deprecated in API 16
143 **/
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800144 public RenderScriptGL createRenderScriptGL(RenderScriptGL.SurfaceConfig sc) {
Shih-wei Liao6b32fab2010-12-10 01:03:59 -0800145 RenderScriptGL rs = new RenderScriptGL(this.getContext(), sc);
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800146 setRenderScriptGL(rs);
147 return rs;
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700148 }
149
Jason Samse619de62012-05-08 18:40:58 -0700150 /**
151 * @deprecated in API 16
152 **/
Alex Sakhartchouk38da5082011-11-15 14:21:58 -0800153 public void destroyRenderScriptGL() {
154 synchronized (this) {
155 mRS.destroy();
156 mRS = null;
157 }
Joe Onorato5fda65f2009-09-25 09:12:16 -0700158 }
Jason Sams2222aa92010-10-10 17:58:25 -0700159
Jason Samse619de62012-05-08 18:40:58 -0700160 /**
161 * @deprecated in API 16
162 **/
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800163 public void setRenderScriptGL(RenderScriptGL rs) {
Romain Guya8551b12010-03-10 22:11:50 -0800164 mRS = rs;
165 }
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800166
Jason Samse619de62012-05-08 18:40:58 -0700167 /**
168 * @deprecated in API 16
169 **/
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800170 public RenderScriptGL getRenderScriptGL() {
171 return mRS;
172 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700173}