blob: 5db72d96fddc9a449bdf8dc9b85d7e82070ccd4c [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
Jack Palevich60aa3ea2009-05-26 13:45:08 -070019import android.content.Context;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070020import android.util.AttributeSet;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070021import android.view.SurfaceHolder;
22import android.view.SurfaceView;
23
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070024/**
Tim Murraya9084222013-04-05 22:06:43 +000025 * @hide
Jason Samse619de62012-05-08 18:40:58 -070026 * @deprecated in API 16
Alex Sakhartchouk93c47f12011-11-11 11:49:45 -080027 * The Surface View for a graphics renderscript (RenderScriptGL) to draw on.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080028 *
29 * <div class="special reference">
30 * <h3>Developer Guides</h3>
Tim Murrayc11e25c2013-04-09 11:01:01 -070031 * <p>For more information about creating an application that uses RenderScript, read the
32 * <a href="{@docRoot}guide/topics/renderscript/index.html">RenderScript</a> developer guide.</p>
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080033 * </div>
Stephen Hinesb11e3d22011-01-11 19:30:58 -080034 */
Jack Palevich60aa3ea2009-05-26 13:45:08 -070035public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
36 private SurfaceHolder mSurfaceHolder;
Jason Sams704ff642010-02-09 16:05:07 -080037 private RenderScriptGL mRS;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070038
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070039 /**
Jason Samse619de62012-05-08 18:40:58 -070040 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070041 * Standard View constructor. In order to render something, you
Stephen Hinesb11e3d22011-01-11 19:30:58 -080042 * must call {@link android.opengl.GLSurfaceView#setRenderer} to
43 * register a renderer.
Jack Palevich60aa3ea2009-05-26 13:45:08 -070044 */
45 public RSSurfaceView(Context context) {
46 super(context);
47 init();
Jason Sams66b27712009-09-25 15:25:00 -070048 //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
Jack Palevich60aa3ea2009-05-26 13:45:08 -070049 }
50
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070051 /**
Jason Samse619de62012-05-08 18:40:58 -070052 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070053 * Standard View constructor. In order to render something, you
Stephen Hinesb11e3d22011-01-11 19:30:58 -080054 * must call {@link android.opengl.GLSurfaceView#setRenderer} to
55 * register a renderer.
Jack Palevich60aa3ea2009-05-26 13:45:08 -070056 */
57 public RSSurfaceView(Context context, AttributeSet attrs) {
58 super(context, attrs);
59 init();
Jason Sams66b27712009-09-25 15:25:00 -070060 //Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
Jack Palevich60aa3ea2009-05-26 13:45:08 -070061 }
62
63 private void init() {
64 // Install a SurfaceHolder.Callback so we get notified when the
65 // underlying surface is created and destroyed
66 SurfaceHolder holder = getHolder();
67 holder.addCallback(this);
Jack Palevich60aa3ea2009-05-26 13:45:08 -070068 }
69
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070070 /**
Jason Samse619de62012-05-08 18:40:58 -070071 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070072 * This method is part of the SurfaceHolder.Callback interface, and is
73 * not normally called or subclassed by clients of RSSurfaceView.
74 */
75 public void surfaceCreated(SurfaceHolder holder) {
Jack Palevich60aa3ea2009-05-26 13:45:08 -070076 mSurfaceHolder = holder;
Jack Palevich60aa3ea2009-05-26 13:45:08 -070077 }
78
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070079 /**
Jason Samse619de62012-05-08 18:40:58 -070080 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070081 * This method is part of the SurfaceHolder.Callback interface, and is
82 * not normally called or subclassed by clients of RSSurfaceView.
83 */
Alex Sakhartchouk38da5082011-11-15 14:21:58 -080084 public void surfaceDestroyed(SurfaceHolder holder) {
85 synchronized (this) {
86 // Surface will be destroyed when we return
87 if (mRS != null) {
88 mRS.setSurface(null, 0, 0);
89 }
Jason Samsefd9b6fb2009-11-03 13:58:36 -080090 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -070091 }
92
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070093 /**
Jason Samse619de62012-05-08 18:40:58 -070094 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -070095 * This method is part of the SurfaceHolder.Callback interface, and is
96 * not normally called or subclassed by clients of RSSurfaceView.
97 */
Alex Sakhartchouk38da5082011-11-15 14:21:58 -080098 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
99 synchronized (this) {
100 if (mRS != null) {
101 mRS.setSurface(holder, w, h);
102 }
Jason Samsefd9b6fb2009-11-03 13:58:36 -0800103 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700104 }
105
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700106 /**
Jason Samse619de62012-05-08 18:40:58 -0700107 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700108 * Inform the view that the activity is paused. The owner of this view must
109 * call this method when the activity is paused. Calling this method will
110 * pause the rendering thread.
111 * Must not be called before a renderer has been set.
112 */
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800113 public void pause() {
Jason Sams65e7aa52009-09-24 17:38:20 -0700114 if(mRS != null) {
115 mRS.pause();
116 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700117 }
118
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700119 /**
Jason Samse619de62012-05-08 18:40:58 -0700120 * @deprecated in API 16
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700121 * Inform the view that the activity is resumed. The owner of this view must
122 * call this method when the activity is resumed. Calling this method will
123 * recreate the OpenGL display and resume the rendering
124 * thread.
125 * Must not be called before a renderer has been set.
126 */
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800127 public void resume() {
Jason Sams65e7aa52009-09-24 17:38:20 -0700128 if(mRS != null) {
129 mRS.resume();
130 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700131 }
132
Jason Samse619de62012-05-08 18:40:58 -0700133 /**
134 * @deprecated in API 16
135 **/
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800136 public RenderScriptGL createRenderScriptGL(RenderScriptGL.SurfaceConfig sc) {
Shih-wei Liao6b32fab2010-12-10 01:03:59 -0800137 RenderScriptGL rs = new RenderScriptGL(this.getContext(), sc);
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800138 setRenderScriptGL(rs);
139 return rs;
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700140 }
141
Jason Samse619de62012-05-08 18:40:58 -0700142 /**
143 * @deprecated in API 16
144 **/
Alex Sakhartchouk38da5082011-11-15 14:21:58 -0800145 public void destroyRenderScriptGL() {
146 synchronized (this) {
147 mRS.destroy();
148 mRS = null;
149 }
Joe Onorato5fda65f2009-09-25 09:12:16 -0700150 }
Jason Sams2222aa92010-10-10 17:58:25 -0700151
Jason Samse619de62012-05-08 18:40:58 -0700152 /**
153 * @deprecated in API 16
154 **/
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800155 public void setRenderScriptGL(RenderScriptGL rs) {
Romain Guya8551b12010-03-10 22:11:50 -0800156 mRS = rs;
157 }
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800158
Jason Samse619de62012-05-08 18:40:58 -0700159 /**
160 * @deprecated in API 16
161 **/
Jason Samsbf6ef8d2010-12-06 15:59:59 -0800162 public RenderScriptGL getRenderScriptGL() {
163 return mRS;
164 }
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700165}