12
12
import android .os .Handler ;
13
13
import android .os .Message ;
14
14
import android .util .Log ;
15
- import android .view .SurfaceHolder ;
16
15
import processing .core .PConstants ;
17
16
import processing .core .PApplet ;
18
17
import processing .core .PImage ;
22
21
23
22
@ SuppressWarnings ("deprecation" )
24
23
public class Capture extends PImage implements PConstants ,
25
- SurfaceHolder . Callback , CameraHandlerCallback , SurfaceTexture .OnFrameAvailableListener {
24
+ CameraHandlerCallback , SurfaceTexture .OnFrameAvailableListener {
26
25
27
26
private static final boolean DEBUG = true ;
28
27
@@ -72,14 +71,20 @@ public Capture(final PApplet applet, int width, int height) {
72
71
height = 1280 ;
73
72
}
74
73
init (width , height , ARGB );
75
-
74
+
76
75
applet .registerMethod ("pause" , this );
77
76
applet .registerMethod ("resume" , this );
78
77
glView = (GLSurfaceView ) applet .getSurfaceView ();
79
78
pg = (PGraphicsOpenGL )applet .g ;
80
79
// customTexture = new Texture(pg, width, height);
81
80
// customTexture.invertedY(true);
82
- log ("cusotm texture address = " + customTexture .get (0 ));
81
+ glView .queueEvent (new Runnable () {
82
+ @ Override
83
+ public void run () {
84
+ createSurfaceTexture ();
85
+ prepareFrameBuffers ();
86
+ }
87
+ });
83
88
// pg.setCache(this, customTexture);
84
89
applet .runOnUiThread (new Runnable () {
85
90
@ Override
@@ -133,11 +138,7 @@ public void resume() {
133
138
glView .queueEvent (new Runnable () {
134
139
@ Override
135
140
public void run () {
136
- mFullScreen = new FullFrameRect (
137
- new Texture2dProgram (Texture2dProgram .ProgramType .TEXTURE_EXT ));
138
- mTextureId = mFullScreen .createTextureObject ();
139
- mSurfaceTexture = new SurfaceTexture (mTextureId );
140
- mSurfaceTexture .setOnFrameAvailableListener (Capture .this );
141
+ createSurfaceTexture ();
141
142
prepareFrameBuffers ();
142
143
143
144
//If camera is not null, the activity was started already and we're coming back from a pause.
@@ -153,23 +154,7 @@ public void run() {
153
154
}
154
155
});
155
156
}
156
-
157
- @ Override
158
- public void surfaceCreated (SurfaceHolder holder ) {
159
- log ("surfaceCreated" );
160
- }
161
-
162
- @ Override
163
- public void surfaceChanged (SurfaceHolder holder , int format , int width ,
164
- int height ) {
165
- log ("surfaceChanged" );
166
- }
167
-
168
- @ Override
169
- public void surfaceDestroyed (SurfaceHolder holder ) {
170
- log ("surface destroyed" );
171
- }
172
-
157
+
173
158
public static String [] list () {
174
159
//The following check has to be commented to make list() method static
175
160
// if (applet.getPackageManager().hasSystemFeature(
@@ -336,8 +321,16 @@ public void run() {
336
321
}
337
322
});
338
323
}
324
+
325
+ private void createSurfaceTexture () {
326
+ mFullScreen = new FullFrameRect (
327
+ new Texture2dProgram (Texture2dProgram .ProgramType .TEXTURE_EXT ));
328
+ mTextureId = mFullScreen .createTextureObject ();
329
+ mSurfaceTexture = new SurfaceTexture (mTextureId );
330
+ mSurfaceTexture .setOnFrameAvailableListener (Capture .this );
331
+ }
339
332
340
- public void prepareFrameBuffers () {
333
+ private void prepareFrameBuffers () {
341
334
342
335
GLES20 .glActiveTexture (GLES20 .GL_TEXTURE0 );
343
336
0 commit comments