1 package org
.mozilla
.gecko
.gfx
;
3 import android
.opengl
.GLSurfaceView
;
5 import java
.util
.concurrent
.LinkedBlockingQueue
;
8 * Thread which controls the rendering to OpenGL context. Render commands are queued and
9 * processed and delegated by this thread.
11 public class RenderControllerThread
extends Thread
implements LayerView
.Listener
{
12 private LinkedBlockingQueue
<RenderCommand
> queue
= new LinkedBlockingQueue
<RenderCommand
>();
13 private GLController controller
;
14 private boolean renderQueued
= false;
18 public RenderControllerThread(GLController controller
) {
19 this.controller
= controller
;
25 RenderCommand command
;
27 command
= queue
.take();
29 if (command
== RenderCommand
.SHUTDOWN
) {
32 } catch (InterruptedException exception
) {
33 throw new RuntimeException(exception
);
38 void execute(RenderCommand command
) {
52 case SURFACE_DESTROYED
:
58 public void shutdown() {
59 queue
.add(RenderCommand
.SHUTDOWN
);
63 public void compositorCreated() {
68 public void renderRequested() {
71 queue
.add(RenderCommand
.RENDER_FRAME
);
78 public void compositionPauseRequested() {
79 queue
.add(RenderCommand
.SURFACE_DESTROYED
);
83 public void surfaceChanged(int width
, int height
) {
86 queue
.add(RenderCommand
.SIZE_CHANGED
);
89 public void surfaceCreated() {
90 queue
.add(RenderCommand
.SURFACE_CREATED
);
93 private GLSurfaceView
.Renderer
getRenderer() {
94 return controller
.getView().getRenderer();
97 private void doShutdown() {
98 controller
.disposeGLContext();
102 private void doRenderFrame() {
103 synchronized (this) {
104 renderQueued
= false;
106 if (controller
.getEGLSurface() == null) {
109 GLSurfaceView
.Renderer renderer
= getRenderer();
110 if (renderer
!= null) {
111 renderer
.onDrawFrame(controller
.getGL());
113 controller
.swapBuffers();
116 private void doSizeChanged() {
117 GLSurfaceView
.Renderer renderer
= getRenderer();
118 if (renderer
!= null) {
119 renderer
.onSurfaceChanged(controller
.getGL(), width
, height
);
123 private void doSurfaceCreated() {
124 if (!controller
.hasSurface()) {
125 controller
.initGLContext();
129 private void doSurfaceDestroyed() {
130 controller
.disposeGLContext();
133 public enum RenderCommand
{