33import android .annotation .TargetApi ;
44import android .content .Context ;
55import android .opengl .GLES20 ;
6- import android .opengl .GLSurfaceView ;
76import android .os .Build ;
87import android .util .SparseArray ;
98
@@ -79,7 +78,8 @@ public ARView(Context context) {
7978 setEGLContextClientVersion (2 );
8079 setEGLConfigChooser (8 , 8 , 8 , 8 , 16 , 0 ); // Alpha used for plane blending.
8180 setRenderer (this );
82- setRenderMode (GLSurfaceView .RENDERMODE_CONTINUOUSLY );
81+ setRenderMode (GLSurfaceView .RENDERMODE_WHEN_DIRTY );
82+ setPreserveEGLContextOnPause (true );
8383
8484 _displayRotationHelper = new DisplayRotationHelper (context );
8585 }
@@ -144,8 +144,6 @@ public void onSurfaceChanged(GL10 gl, int width, int height) {
144144
145145 @ Override
146146 public void onDrawFrame (GL10 gl ) {
147- GLES20 .glClear (GLES20 .GL_COLOR_BUFFER_BIT );
148-
149147 if (_shouldSendResize ) {
150148 // Fix for Samsung devices (S7-S9, manually send AR_WINDOW_RESIZED)
151149 WebViewApp webViewApp = WebViewApp .getCurrentApp ();
@@ -176,22 +174,12 @@ public void onDrawFrame(GL10 gl) {
176174 return ;
177175 }
178176
179- if (!_showCameraFrame ) {
180- return ;
181- }
182- _backgroundRenderer .draw (frame );
183-
184177 long currentTime = System .currentTimeMillis ();
185178 if (_timeOfLastDrawnCameraFrame == 0 ) {
186179 _timeOfLastDrawnCameraFrame = currentTime ;
187180 }
188- long timeSinceLastDrawnCameraFrame = currentTime - _timeOfLastDrawnCameraFrame ;
189- if (timeSinceLastDrawnCameraFrame < FRAME_UPDATE_TIMEOUT && !_drawNextCameraFrame ) {
190- return ;
191- }
192181
193182 _timeOfLastDrawnCameraFrame = currentTime ;
194- _drawNextCameraFrame = false ;
195183
196184 camera .getProjectionMatrix (_projectionMatrixArray , 0 , _arNear , _arFar );
197185 camera .getViewMatrix (_viewMatrixArray , 0 );
@@ -234,6 +222,13 @@ public void onDrawFrame(GL10 gl) {
234222 updatePlanes (updatedTrackables );
235223
236224 DeviceLog .debug (frame .toString ());
225+
226+ if (!_showCameraFrame ) {
227+ return ;
228+ }
229+
230+ GLES20 .glClear (GLES20 .GL_COLOR_BUFFER_BIT );
231+ _backgroundRenderer .draw (frame );
237232 }
238233 }
239234
@@ -325,6 +320,13 @@ public void restartSession(JSONObject properties) throws JSONException {
325320 _sessionRunning = true ;
326321
327322 _displayRotationHelper .onResume ();
323+
324+ postDelayed (new Runnable () {
325+ @ Override
326+ public void run () {
327+ requestRender ();
328+ }
329+ }, 200 );
328330 }
329331
330332 public void pauseSession () {
@@ -334,7 +336,7 @@ public void pauseSession() {
334336 }
335337
336338 public void setDrawNextCameraFrame () {
337- _drawNextCameraFrame = true ;
339+ requestRender () ;
338340 }
339341
340342 public boolean getShowCameraFrame () {
0 commit comments