blob: f024bf685b5ad6c8046ad9ede8d4f2e8e48a7214 [file] [log] [blame]
Jack Palevich60aa3ea2009-05-26 13:45:08 -07001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
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;
28import android.util.Log;
29import android.view.Surface;
30import android.view.SurfaceHolder;
31import android.view.SurfaceView;
32
Jason Samse29d4712009-07-23 15:19:03 -070033/**
34 * @hide
35 *
36 **/
Jack Palevich60aa3ea2009-05-26 13:45:08 -070037public class RSSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
38 private SurfaceHolder mSurfaceHolder;
39
40 /**
41 * Standard View constructor. In order to render something, you
42 * must call {@link #setRenderer} to register a renderer.
43 */
44 public RSSurfaceView(Context context) {
45 super(context);
46 init();
Jason Samsf29ca502009-06-23 12:22:47 -070047 Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
Jack Palevich60aa3ea2009-05-26 13:45:08 -070048 }
49
50 /**
51 * Standard View constructor. In order to render something, you
52 * must call {@link #setRenderer} to register a renderer.
53 */
54 public RSSurfaceView(Context context, AttributeSet attrs) {
55 super(context, attrs);
56 init();
Jason Samsf29ca502009-06-23 12:22:47 -070057 Log.v(RenderScript.LOG_TAG, "RSSurfaceView");
Jack Palevich60aa3ea2009-05-26 13:45:08 -070058 }
59
60 private void init() {
61 // Install a SurfaceHolder.Callback so we get notified when the
62 // underlying surface is created and destroyed
63 SurfaceHolder holder = getHolder();
64 holder.addCallback(this);
65 holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
66 }
67
68 /**
69 * This method is part of the SurfaceHolder.Callback interface, and is
70 * not normally called or subclassed by clients of RSSurfaceView.
71 */
72 public void surfaceCreated(SurfaceHolder holder) {
Jason Samsf29ca502009-06-23 12:22:47 -070073 Log.v(RenderScript.LOG_TAG, "surfaceCreated");
Jack Palevich60aa3ea2009-05-26 13:45:08 -070074 mSurfaceHolder = holder;
75 //mGLThread.surfaceCreated();
76 }
77
78 /**
79 * 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 surfaceDestroyed(SurfaceHolder holder) {
83 // Surface will be destroyed when we return
Jason Samsf29ca502009-06-23 12:22:47 -070084 Log.v(RenderScript.LOG_TAG, "surfaceDestroyed");
Jack Palevich60aa3ea2009-05-26 13:45:08 -070085 //mGLThread.surfaceDestroyed();
86 }
87
88 /**
89 * This method is part of the SurfaceHolder.Callback interface, and is
90 * not normally called or subclassed by clients of RSSurfaceView.
91 */
92 public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
Jason Samsf29ca502009-06-23 12:22:47 -070093 Log.v(RenderScript.LOG_TAG, "surfaceChanged");
Jack Palevich60aa3ea2009-05-26 13:45:08 -070094
95 //mGLThread.onWindowResize(w, h);
96 }
97
98 /**
99 * Inform the view that the activity is paused. The owner of this view must
100 * call this method when the activity is paused. Calling this method will
101 * pause the rendering thread.
102 * Must not be called before a renderer has been set.
103 */
104 public void onPause() {
Jason Samsf29ca502009-06-23 12:22:47 -0700105 Log.v(RenderScript.LOG_TAG, "onPause");
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700106 //mGLThread.onPause();
107 }
108
109 /**
110 * Inform the view that the activity is resumed. The owner of this view must
111 * call this method when the activity is resumed. Calling this method will
112 * recreate the OpenGL display and resume the rendering
113 * thread.
114 * Must not be called before a renderer has been set.
115 */
116 public void onResume() {
Jason Samsf29ca502009-06-23 12:22:47 -0700117 Log.v(RenderScript.LOG_TAG, "onResume");
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700118 //mGLThread.onResume();
119 }
120
121 /**
122 * Queue a runnable to be run on the GL rendering thread. This can be used
123 * to communicate with the Renderer on the rendering thread.
124 * Must not be called before a renderer has been set.
125 * @param r the runnable to be run on the GL rendering thread.
126 */
127 public void queueEvent(Runnable r) {
Jason Samsf29ca502009-06-23 12:22:47 -0700128 Log.v(RenderScript.LOG_TAG, "queueEvent");
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700129 //mGLThread.queueEvent(r);
130 }
131
132 /**
133 * This method is used as part of the View class and is not normally
134 * called or subclassed by clients of RSSurfaceView.
135 * Must not be called before a renderer has been set.
136 */
137 @Override
138 protected void onDetachedFromWindow() {
139 super.onDetachedFromWindow();
140 //mGLThread.requestExitAndWait();
141 }
142
143 // ----------------------------------------------------------------------
144
145 public RenderScript createRenderScript() {
Jason Samsf29ca502009-06-23 12:22:47 -0700146 Log.v(RenderScript.LOG_TAG, "createRenderScript 1");
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700147 Surface sur = null;
148 while ((sur == null) || (mSurfaceHolder == null)) {
149 sur = getHolder().getSurface();
150 }
Jason Samsf29ca502009-06-23 12:22:47 -0700151 Log.v(RenderScript.LOG_TAG, "createRenderScript 2");
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700152 RenderScript rs = new RenderScript(sur);
Jason Samsf29ca502009-06-23 12:22:47 -0700153 Log.v(RenderScript.LOG_TAG, "createRenderScript 3 rs");
Jack Palevich60aa3ea2009-05-26 13:45:08 -0700154 return rs;
155 }
156
157}
158