Skip to content

Commit 6958c29

Browse files
committed
add comment
1 parent 09b5dea commit 6958c29

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

canvasgl/src/main/java/com/chillingvan/canvasgl/glview/texture/BaseGLCanvasTextureView.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@
1414
import com.chillingvan.canvasgl.glview.GLView;
1515

1616
/**
17-
* Created by Chilling on 2016/11/11.
17+
*
18+
* From init to run: onSizeChange --> onSurfaceTextureAvailable --> createGLThread --> createSurface --> onSurfaceCreated --> onSurfaceChanged
19+
* From pause to run: onResume --> createSurface --> onSurfaceChanged
20+
* From stop to run: onResume --> onSurfaceTextureAvailable --> createGLThread --> createSurface --> onSurfaceCreated --> onSurfaceChanged
1821
*/
19-
2022
abstract class BaseGLCanvasTextureView extends BaseGLTextureView implements GLViewRenderer {
2123

2224

canvasgl/src/main/java/com/chillingvan/canvasgl/glview/texture/BaseGLTextureView.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@
4040
* Can make it not opaque by setOpaque(false).
4141
*
4242
* The surface of canvasGL is provided by TextureView.
43+
*
44+
* onSurfaceTextureSizeChanged onResume onPause onSurfaceTextureDestroyed onSurfaceTextureUpdated
45+
* From init to run: onSizeChanged --> onSurfaceTextureAvailable --> createGLThread --> createSurface
46+
* From run to pause: onPause --> destroySurface
47+
* From pause to run: onResume --> createSurface
48+
* From run to stop: onPause --> destroySurface --> onSurfaceTextureDestroyed --> EGLHelper.finish --> GLThread.exit
49+
* From stop to run: onResume --> onSurfaceTextureAvailable --> createGLThread --> createSurface
4350
*/
4451
abstract class BaseGLTextureView extends TextureView implements TextureView.SurfaceTextureListener {
4552

@@ -239,6 +246,9 @@ public void run() {
239246
cacheEvents.clear();
240247
}
241248

249+
/**
250+
* surface inited or updated.
251+
*/
242252
private void freshSurface(int width, int height) {
243253
surfaceCreated();
244254
surfaceChanged(width, height);
@@ -255,6 +265,9 @@ public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int h
255265
}
256266
}
257267

268+
/**
269+
* This will be called when windows detached. Activity onPause will cause window detached.
270+
*/
258271
@Override
259272
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
260273
Loggers.d("BaseGLTextureView", "onSurfaceTextureDestroyed: ");

canvasgl/src/main/java/com/chillingvan/canvasgl/glview/texture/GLSurfaceTextureProducerView.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
/**
3838
* This will generate a texture which is in the eglContext of the CanvasGL. And the texture can be used outside.
3939
* For example, the generated texture can be used in camera preview texture or {@link GLSharedContextView}.
40+
*
41+
* From pause to run: onResume --> createSurface --> onSurfaceChanged
4042
*/
4143
public abstract class GLSurfaceTextureProducerView extends GLSharedContextView {
4244
private static final String TAG = "GLSurfaceTextureProduce";
@@ -93,7 +95,7 @@ public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int hei
9395
@Override
9496
public void onSurfaceChanged(int width, int height) {
9597
super.onSurfaceChanged(width, height);
96-
Loggers.d(TAG, "onSizeChanged: ");
98+
Loggers.d(TAG, "onSurfaceChanged: ");
9799
producedRawTexture = new RawTexture(width, height, false, producedTextureTarget);
98100
if (!producedRawTexture.isLoaded()) {
99101
producedRawTexture.prepare(mCanvas.getGlCanvas());

canvasgl/src/main/java/com/chillingvan/canvasgl/glview/texture/gles/GLThread.java

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
import javax.microedition.khronos.opengles.GL;
4444

4545
/**
46-
* Created by Chilling on 2016/10/30.
46+
* Create GL Context --> Create Surface
47+
* And then draw with OpenGL and finally eglSwap to update the screen.
4748
*/
48-
4949
public class GLThread extends Thread {
5050
private static final String TAG = "GLThread";
5151
public final static boolean LOG_RENDERER_DRAW_FRAME = false;
@@ -65,7 +65,6 @@ public class GLThread extends Thread {
6565
private Object mSurface;
6666

6767
private OnCreateGLContextListener onCreateGLContextListener;
68-
private boolean mPreserveEGLContextOnPause = true;
6968

7069

7170
// Once the thread is started, all accesses to the following member
@@ -135,11 +134,6 @@ public void run() {
135134
}
136135

137136

138-
public void setPreserveEGLContextOnPause(boolean mPreserveEGLContextOnPause) {
139-
this.mPreserveEGLContextOnPause = mPreserveEGLContextOnPause;
140-
}
141-
142-
143137
/**
144138
* This private method should only be called inside a
145139
* synchronized(sGLThreadManager) block.
@@ -218,16 +212,6 @@ private void guardedRun() throws InterruptedException {
218212
stopEglSurfaceLocked();
219213
}
220214

221-
// When pausing, optionally release the EGL Context:
222-
if (pausing && mHaveEglContext) {
223-
boolean preserveEglContextOnPause = mPreserveEGLContextOnPause;
224-
if (!preserveEglContextOnPause) {
225-
stopEglContextLocked();
226-
FileLogger.i(TAG, "releasing EGL context because paused tid=" + getId());
227-
}
228-
}
229-
230-
231215
// Have we lost the SurfaceView surface?
232216
if ((!mHasSurface) && (!mWaitingForSurface)) {
233217
FileLogger.i(TAG, "noticed surfaceView surface lost tid=" + getId());
@@ -362,6 +346,7 @@ private void guardedRun() throws InterruptedException {
362346
createGlInterface = false;
363347
}
364348

349+
// Make sure context and surface are created
365350
if (createEglContext) {
366351
FileLogger.w("GLThread", "onSurfaceCreated");
367352
mRenderer.onSurfaceCreated();

0 commit comments

Comments
 (0)