1 package org
.mozilla
.gecko
.gfx
;
3 import android
.opengl
.GLSurfaceView
;
5 import java
.util
.concurrent
.LinkedBlockingQueue
;
7 import javax
.microedition
.khronos
.opengles
.GL10
;
10 * Thread which controls the rendering to OpenGL context. Render commands are queued and
11 * processed and delegated by this thread.
13 public class RenderControllerThread
extends Thread
implements LayerView
.Listener
{
14 private LinkedBlockingQueue
<RenderCommand
> queue
= new LinkedBlockingQueue
<RenderCommand
>();
15 private GLController controller
;
16 private boolean renderQueued
= false;
20 public RenderControllerThread(GLController controller
) {
21 this.controller
= controller
;
27 RenderCommand command
;
29 command
= queue
.take();
31 if (command
== RenderCommand
.SHUTDOWN
) {
34 } catch (InterruptedException exception
) {
35 throw new RuntimeException(exception
);
40 void execute(RenderCommand command
) {
54 case SURFACE_DESTROYED
:
60 public void shutdown() {
61 queue
.add(RenderCommand
.SHUTDOWN
);
65 public void compositorCreated() {
70 public void renderRequested() {
73 queue
.add(RenderCommand
.RENDER_FRAME
);
80 public void compositionPauseRequested() {
81 queue
.add(RenderCommand
.SURFACE_DESTROYED
);
85 public void surfaceChanged(int width
, int height
) {
88 queue
.add(RenderCommand
.SIZE_CHANGED
);
91 public void surfaceCreated() {
92 queue
.add(RenderCommand
.SURFACE_CREATED
);
95 private GLSurfaceView
.Renderer
getRenderer() {
96 return controller
.getView().getRenderer();
99 private void doShutdown() {
100 controller
.disposeGLContext();
104 private void doRenderFrame() {
105 synchronized (this) {
106 renderQueued
= false;
108 if (controller
.getEGLSurface() == null) {
111 GLSurfaceView
.Renderer renderer
= getRenderer();
112 if (renderer
!= null) {
113 renderer
.onDrawFrame(controller
.getGL());
115 controller
.swapBuffers();
118 private void doSizeChanged() {
119 GLSurfaceView
.Renderer renderer
= getRenderer();
120 if (renderer
!= null) {
121 renderer
.onSurfaceChanged(controller
.getGL(), width
, height
);
125 private void doSurfaceCreated() {
126 if (!controller
.hasSurface()) {
127 controller
.initGLContext();
131 private void doSurfaceDestroyed() {
132 controller
.disposeGLContext();
135 public enum RenderCommand
{