blob: 506f1af8e07c0e50b481d6a81d08eda15b18a52f [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/**
Jason Samse619de62012-05-08 18:40:58 -070033 * @deprecated in API 16
Alex Sakhartchouk93c47f12011-11-11 11:49:45 -080034 * The Surface View for a graphics renderscript (RenderScriptGL) to draw on.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080035 *
36 * <div class="special reference">
37 * <h3>Developer Guides</h3>
38 * <p>For more information about creating an application that uses Renderscript, read the
39 * <a href="{@docRoot}guide/topics/graphics/renderscript.html">Renderscript</a> developer guide.</p>
40 * </div>
Stephen Hinesb11e3d22011-01-11 19:30:58 -080041 */
Jack Palevich60aa3ea2009-05-26 13:45:08 -070042public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
43 private SurfaceHolder mSurfaceHolder;
Jason Sams704ff642010-02-09 16:05:07 -080044 private RenderScriptGL mRS;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070045
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070046 /**
Jason Samse619de62012-05-08 18:40:58 -070047 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070048 * Standard View constructor. In order to render something, you
Stephen Hinesb11e3d22011-01-11 19:30:58 -080049 * must call {@link android.opengl.GLSurfaceView#setRenderer} to
50 * register a renderer.
Jack Palevich60aa3ea2009-05-26 13:45:08 -070051 */
52 public RSSurfaceView(Context context) {
53 super(context);
54 init();
Jason Sams66b27712009-09-25 15:25:00 -070055 //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
Jack Palevich60aa3ea2009-05-26 13:45:08 -070056 }
57
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070058 /**
Jason Samse619de62012-05-08 18:40:58 -070059 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070060 * Standard View constructor. In order to render something, you
Stephen Hinesb11e3d22011-01-11 19:30:58 -080061 * must call {@link android.opengl.GLSurfaceView#setRenderer} to
62 * register a renderer.
Jack Palevich60aa3ea2009-05-26 13:45:08 -070063 */
64 public RSSurfaceView(Context context, AttributeSet attrs) {
65 super(context, attrs);
66 init();
Jason Sams66b27712009-09-25 15:25:00 -070067 //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
Jack Palevich60aa3ea2009-05-26 13:45:08 -070068 }
69
70 private void init() {
71 // Install a SurfaceHolder.Callback so we get notified when the
72 // underlying surface is created and destroyed
73 SurfaceHolder holder = getHolder();
74 holder.addCallback(this);
Jack Palevich60aa3ea2009-05-26 13:45:08 -070075 }
76
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070077 /**
Jason Samse619de62012-05-08 18:40:58 -070078 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070079 * This method is part of the SurfaceHolder.Callback interface, and is
80 * not normally called or subclassed by clients of RSSurfaceView.
81 */
82 public void surfaceCreated(SurfaceHolder holder) {
Jack Palevich60aa3ea2009-05-26 13:45:08 -070083 mSurfaceHolder = holder;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070084 }
85
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070086 /**
Jason Samse619de62012-05-08 18:40:58 -070087 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070088 * This method is part of the SurfaceHolder.Callback interface, and is
89 * not normally called or subclassed by clients of RSSurfaceView.
90 */
Alex Sakhartchouk38da5082011-11-15 14:21:58 -080091 public void surfaceDestroyed(SurfaceHolder holder) {
92 synchronized (this) {
93 // Surface will be destroyed when we return
94 if (mRS != null) {
95 mRS.setSurface(null, 0, 0);
96 }
Jason Samsefd9b6fb2009-11-03 13:58:36 -080097 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -070098 }
99
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700100 /**
Jason Samse619de62012-05-08 18:40:58 -0700101 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700102 * This method is part of the SurfaceHolder.Callback interface, and is
103 * not normally called or subclassed by clients of RSSurfaceView.
104 */
Alex Sakhartchouk38da5082011-11-15 14:21:58 -0800105 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
106 synchronized (this) {
107 if (mRS != null) {
108 mRS.setSurface(holder, w, h);
109 }
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800110 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700111 }
112
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700113 /**
Jason Samse619de62012-05-08 18:40:58 -0700114 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700115 * Inform the view that the activity is paused. The owner of this view must
116 * call this method when the activity is paused. Calling this method will
117 * pause the rendering thread.
118 * Must not be called before a renderer has been set.
119 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800120 public void pause() {
Jason Sams65e7aa52009-09-24 17:38:20 -0700121 if(mRS != null) {
122 mRS.pause();
123 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700124 }
125
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700126 /**
Jason Samse619de62012-05-08 18:40:58 -0700127 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700128 * Inform the view that the activity is resumed. The owner of this view must
129 * call this method when the activity is resumed. Calling this method will
130 * recreate the OpenGL display and resume the rendering
131 * thread.
132 * Must not be called before a renderer has been set.
133 */
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800134 public void resume() {
Jason Sams65e7aa52009-09-24 17:38:20 -0700135 if(mRS != null) {
136 mRS.resume();
137 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700138 }
139
Jason Samse619de62012-05-08 18:40:58 -0700140 /**
141 * @deprecated in API 16
142 **/
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800143 public RenderScriptGL createRenderScriptGL(RenderScriptGL.SurfaceConfig sc) {
Shih-wei Liao6b32fab2010-12-10 01:03:59 -0800144 RenderScriptGL rs = new RenderScriptGL(this.getContext(), sc);
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800145 setRenderScriptGL(rs);
146 return rs;
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700147 }
148
Jason Samse619de62012-05-08 18:40:58 -0700149 /**
150 * @deprecated in API 16
151 **/
Alex Sakhartchouk38da5082011-11-15 14:21:58 -0800152 public void destroyRenderScriptGL() {
153 synchronized (this) {
154 mRS.destroy();
155 mRS = null;
156 }
Joe Onorato5fda65f12009-09-25 09:12:16 -0700157 }
Jason Sams2222aa92010-10-10 17:58:25 -0700158
Jason Samse619de62012-05-08 18:40:58 -0700159 /**
160 * @deprecated in API 16
161 **/
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800162 public void setRenderScriptGL(RenderScriptGL rs) {
Romain Guya8551b12010-03-10 22:11:50 -0800163 mRS = rs;
164 }
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800165
Jason Samse619de62012-05-08 18:40:58 -0700166 /**
167 * @deprecated in API 16
168 **/
Jason Samsbf6ef8d72010-12-06 15:59:59 -0800169 public RenderScriptGL getRenderScriptGL() {
170 return mRS;
171 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700172}