Remove old autovect-branch by moving to "dead" directory.
[official-gcc.git] / old-autovect-branch / libjava / classpath / gnu / java / awt / peer / qt / QtRepaintThread.java
blob405505e9bc8f7d86aa812fbd259d017c9482fc39
1 /* QtRepaintThread.java -- Repaint thread implementation
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package gnu.java.awt.peer.qt;
40 /**
41 * This class does repainting of Component back-buffers. It is undesirable to
42 * do this directly from the paint callback in QtComponentPeer, because that
43 * is executed from the main thread. Thus, if a call is made at the same time
44 * which requires execution by the main thread, and this is sharing a lock with
45 * paint(), then a deadlock will occur, which must be avoided. In general,
46 * the main Qt thread should avoid calling into java code as far as possible.
49 public class QtRepaintThread extends Thread
51 static class RepaintComponent
53 public QtComponentPeer curr;
54 public RepaintComponent next;
55 public boolean paintAll;
56 public int x, y, w, h;
58 public RepaintComponent(QtComponentPeer p)
60 curr = p;
61 next = null;
62 paintAll = true;
65 public RepaintComponent(QtComponentPeer p, int x, int y, int w, int h)
67 this(p);
68 paintAll = false;
69 this.x = x;
70 this.y = y;
71 this.w = w;
72 this.h = h;
76 RepaintComponent component;
77 boolean busy;
79 public QtRepaintThread()
81 component = null;
84 public void run()
86 while( true )
88 try
90 busy = false;
91 // Wait for a repaint
92 sleep(100);
93 busy = true;
95 catch (InterruptedException ie)
97 while( component != null )
99 try
101 if( component.paintAll )
103 // update the back-buffer.
104 component.curr.paintBackBuffer();
105 component.curr.QtUpdate(); // trigger a native repaint event
107 else
109 component.curr.paintBackBuffer(component.x, component.y,
110 component.w, component.h);
111 component.curr.QtUpdateArea(component.x, component.y,
112 component.w, component.h);
115 catch (InterruptedException e)
118 component = component.next;
125 * Enqueue a component for repainting.
127 public synchronized void queueComponent(QtComponentPeer p)
129 if( component == null )
130 component = new RepaintComponent(p);
131 else
133 RepaintComponent r = component;
134 while( r.next != null ) r = r.next;
135 r.next = new RepaintComponent(p);
137 interrupt();
141 * Enqueue a component for repainting.
143 public synchronized void queueComponent(QtComponentPeer p, int x, int y,
144 int w, int h)
146 if( component == null )
147 component = new RepaintComponent(p, x, y, w, h);
148 else
150 RepaintComponent r = component;
151 while( r.next != null ) r = r.next;
152 r.next = new RepaintComponent(p, x, y, w, h);
154 interrupt();