Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / android / source / src / java / org / mozilla / gecko / gfx / RenderControllerThread.java
blob06f82f158366bb645c791f95fc6b7ae512bd4dc9
1 package org.mozilla.gecko.gfx;
3 import android.opengl.GLSurfaceView;
5 import java.util.concurrent.LinkedBlockingQueue;
7 import javax.microedition.khronos.opengles.GL10;
9 /**
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;
17 private int width;
18 private int height;
20 public RenderControllerThread(GLController controller) {
21 this.controller = controller;
24 @Override
25 public void run() {
26 while (true) {
27 RenderCommand command;
28 try {
29 command = queue.take();
30 execute(command);
31 if (command == RenderCommand.SHUTDOWN) {
32 return;
34 } catch (InterruptedException exception) {
35 throw new RuntimeException(exception);
40 void execute(RenderCommand command) {
41 switch (command) {
42 case SHUTDOWN:
43 doShutdown();
44 break;
45 case RENDER_FRAME:
46 doRenderFrame();
47 break;
48 case SIZE_CHANGED:
49 doSizeChanged();
50 break;
51 case SURFACE_CREATED:
52 doSurfaceCreated();
53 break;
54 case SURFACE_DESTROYED:
55 doSurfaceDestroyed();
56 break;
60 public void shutdown() {
61 queue.add(RenderCommand.SHUTDOWN);
64 @Override
65 public void compositorCreated() {
69 @Override
70 public void renderRequested() {
71 synchronized (this) {
72 if (!renderQueued) {
73 queue.add(RenderCommand.RENDER_FRAME);
74 renderQueued = true;
79 @Override
80 public void compositionPauseRequested() {
81 queue.add(RenderCommand.SURFACE_DESTROYED);
84 @Override
85 public void compositionResumeRequested(int width, int height) {
89 @Override
90 public void surfaceChanged(int width, int height) {
91 this.width = width;
92 this.height = 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();
106 controller = null;
109 private void doRenderFrame() {
110 synchronized (this) {
111 renderQueued = false;
113 if (controller.getEGLSurface() == null) {
114 return;
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 {
141 SHUTDOWN,
142 RECREATE_SURFACE,
143 RENDER_FRAME,
144 SIZE_CHANGED,
145 SURFACE_CREATED,
146 SURFACE_DESTROYED,