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 compositionResumeRequested(int width
, int height
) {
90 public void surfaceChanged(int width
, int height
) {
93 queue
.add(RenderCommand
.SIZE_CHANGED
);
96 public void surfaceCreated() {
97 queue
.add(RenderCommand
.SURFACE_CREATED
);
100 private GLSurfaceView
.Renderer
getRenderer() {
101 return controller
.getView().getRenderer();
104 private void doShutdown() {
105 controller
.disposeGLContext();
109 private void doRenderFrame() {
110 synchronized (this) {
111 renderQueued
= false;
113 if (controller
.getEGLSurface() == null) {
116 GLSurfaceView
.Renderer renderer
= getRenderer();
117 if (renderer
!= null) {
118 renderer
.onDrawFrame((GL10
) controller
.getGL());
120 controller
.swapBuffers();
123 private void doSizeChanged() {
124 GLSurfaceView
.Renderer renderer
= getRenderer();
125 if (renderer
!= null) {
126 renderer
.onSurfaceChanged((GL10
) controller
.getGL(), width
, height
);
130 private void doSurfaceCreated() {
131 if (!controller
.hasSurface()) {
132 controller
.initGLContext();
136 private void doSurfaceDestroyed() {
137 controller
.disposeGLContext();
140 public enum RenderCommand
{