2004/01/13 19:27:17
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:44:26 +0000 (07:44 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:44:26 +0000 (07:44 +0000)
darcs-hash:20040130074426-2ba56-9cf62ff5f44fae9f105269b67a9283c016692096.gz

src/org/xwt/Platform.java
src/org/xwt/Scheduler.java
src/org/xwt/plat/Darwin.java
src/org/xwt/plat/OpenGL.java
src/org/xwt/plat/Win32.java
src/org/xwt/plat/X11.cc
src/org/xwt/plat/X11.java
src/org/xwt/translators/Freetype.java

index e364a50..0d02cd0 100644 (file)
@@ -271,12 +271,14 @@ public abstract class Platform {
         public DefaultGlyph(org.xwt.Font f, char c) { super(f, c); }
         public Picture getPicture() {
             if (p == null && isLoaded) {
-                p = createPicture(null);
+                Picture p = createPicture(null);
                 p.data = new int[data.length];
                 for(int i=0; i<data.length; i++) p.data[i] = (data[i] & 0xff) << 24;
-                data = null;
+                this.data = null;
                 p.width = this.width;
                 p.height = this.height;
+                p.isLoaded = true;
+                this.p = p;
             }
             return p;
         }
index 58b6a8b..8cbbb35 100644 (file)
@@ -60,7 +60,7 @@ public class Scheduler {
 
     protected static Queue runnable = new Queue(50);
     public void defaultRun() {
-        while(true) {
+        try {while(true) {
             currentTask = (Task)runnable.remove(true);
             try {
                 synchronized(this) {
@@ -86,6 +86,8 @@ public class Scheduler {
                 Log.info(Scheduler.class, e);
             }
             // if an Error is thrown it will cause the engine to quit
+}        } catch (Throwable t) {
+            t.printStackTrace();
         }
     }
 }
index b0a16a7..f3dd670 100644 (file)
@@ -5,6 +5,7 @@ package org.xwt.plat;
 
 import gnu.gcj.RawData;
 import org.xwt.util.*;
+import org.xwt.js.*;
 import org.xwt.*;
 import java.util.*;
 
@@ -319,9 +320,9 @@ public class Darwin extends POSIX {
         else
             return /*new QZCarbonSufrace(b,framed)*/ null;
     }
-    protected Picture _createPicture() {
+    protected Picture _createPicture(JS r) {
         if(openGL != null)
-            return openGL._createPicture(true);
+            return openGL._createPicture(r, true);
         else
             return /*new QZCarbonPicture(data,w,h);*/ null;
     }
index a55f9a4..8abd903 100644 (file)
@@ -3,6 +3,7 @@
 
 package org.xwt.plat;
 import org.xwt.*;
+import org.xwt.js.*;
 import org.xwt.util.*;
 
 abstract class OpenGL {
@@ -118,10 +119,10 @@ abstract class OpenGL {
         return oglp.realPicture;
     }
     
-    public Picture _createPicture(boolean alphaOnly) { return new OpenGLPicture(alphaOnly); }
+    public Picture _createPicture(JS r, boolean alphaOnly) { return new OpenGLPicture(r, alphaOnly); }
 
     public static class OpenGLPicture extends Picture {
-        public OpenGLPicture(boolean a) { alphaOnly = a; }
+        public OpenGLPicture(JS r, boolean a) { super(r); alphaOnly = a; }
         boolean alphaOnly;
         GLPicture realPicture = null;
     }
@@ -133,7 +134,7 @@ abstract class OpenGL {
         public OpenGLGlyph(org.xwt.Font f, char c) { super(f, c); }
         Picture getPicture() {
             if (p == null && isLoaded) {
-                p = new OpenGLPicture(true);
+                p = new OpenGLPicture(null, true);
                 p.data = new int[data.length];
                 for(int i=0; i<data.length; i++) p.data[i] = (data[i] & 0xff) << 24;
                 data = null;
index 3140898..d40d9df 100644 (file)
@@ -4,6 +4,7 @@ package org.xwt.plat;
 import org.xwt.*;
 import org.xwt.util.*;
 import java.util.*;
+import org.xwt.js.*;
 import java.io.*;
 
 /** Platform specific code for GCJ-compiled Win32 binaries */
@@ -56,7 +57,7 @@ public class Win32 extends GCJ {
     protected String getDescriptiveName() { return "GCJ Win32 Binary"; }
     protected Surface _createSurface(Box b, boolean framed) { return new Win32Surface(b, framed); }
     protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { return new Win32PixelBuffer(w, h, (Win32Surface)owner); }
-    protected Picture _createPicture() { return new Win32Picture(); }
+    protected Picture _createPicture(JS r) { return new Win32Picture(r); }
     protected native int _getScreenWidth();
     protected native int _getScreenHeight();
     protected boolean _supressDirtyOnResize() { return false; }
@@ -197,7 +198,6 @@ public class Win32 extends GCJ {
 
     public static class Win32Picture extends Picture {
         int w = 0, h = 0;
-        int[] data = null;
 
         /** the Win32 bitmap version of this Picture */
         int hbitmap = -1;
@@ -217,6 +217,7 @@ public class Win32 extends GCJ {
         /** dc of the mask */
         int maskdc = -1;
 
+        public Win32Picture(JS r) { super(r); }
         public int getWidth() { return w; };
         public int getHeight() { return h; };
         public int[] getData() { return data; }
index 8012340..6b5c370 100644 (file)
@@ -123,38 +123,43 @@ void org::xwt::plat::X11$X11PixelBuffer::slowDrawPicture(org::xwt::Picture* s,
             int source_green = (sourcepixel & 0x0000FF00) >> 8;
             int source_blue = (sourcepixel & 0x000000FF);
             int red = 0, blue = 0, green = 0;
-            
+            int targetpixel;
             if (alpha == 0x00) continue;
             if (alpha != 0xFF) {
-                int targetpixel;
                 switch (xi->bits_per_pixel) {
                 case 8: targetpixel = (int)(*current_pixel); break;
+                case 15:
                 case 16: targetpixel = (int)(*((uint16_t*)current_pixel)); break;
-                case 24: targetpixel = (((int)*current_pixel) << 16) | (((int)*(current_pixel + 1)) << 8) | (((int)*(current_pixel + 2))); break;
+
+                // FIXME assumes endianness...
+                case 24: targetpixel =
+                           (((int)*current_pixel) << 16) |
+                           (((int)*(current_pixel + 1)) << 8) |
+                           (((int)*(current_pixel + 2))); break;
                 case 32: targetpixel = *((int*)current_pixel); break;
                 default: org::xwt::Platform::criticalAbort(JvNewStringLatin1("ERROR: bpp not a multiple of 8!"));
                 }
-                
                 targetpixel -= colormap_info->base_pixel;
-                
+
                 // if you're on some wierd display that isn't either RGB or BGR, that's your problem, not mine
                 if (colormap_info->red_mult > colormap_info->green_mult && colormap_info->green_mult > colormap_info->blue_mult) {
                     red = targetpixel / colormap_info->red_mult;
                     green = (targetpixel - red * colormap_info->red_mult) / colormap_info->green_mult;
-                    blue = (targetpixel - red * colormap_info->red_mult - green * colormap_info->green_mult) / colormap_info->blue_mult;
+                    blue = (targetpixel-red * colormap_info->red_mult-green * colormap_info->green_mult)/colormap_info->blue_mult;
                 } else {
                     blue = targetpixel / colormap_info->blue_mult;
                     green = (targetpixel - blue * colormap_info->blue_mult) / colormap_info->green_mult;
-                    red = (targetpixel - blue * colormap_info->blue_mult - green * colormap_info->green_mult) / colormap_info->red_mult;
+                    red = (targetpixel-blue * colormap_info->blue_mult-green * colormap_info->green_mult)/colormap_info->red_mult;
                 }
             }
-            
-            red = ((source_red * colormap_info->red_max * alpha) + (red * 0xFF * (0xFF - alpha))) / (0xFF * 0xFF);
-            green = ((source_green * colormap_info->green_max * alpha) + (green * 0xFF * (0xFF - alpha))) / (0xFF * 0xFF);
-            blue = ((source_blue * colormap_info->blue_max * alpha) + (blue * 0xFF * (0xFF - alpha))) / (0xFF * 0xFF);
-            uint32_t destpixel = red * colormap_info->red_mult + green * colormap_info->green_mult +
-                blue * colormap_info->blue_mult + colormap_info->base_pixel;
-
+            red = ((source_red * (colormap_info->red_max) * alpha) + (red * 0xFF * (0xFF - alpha))) / (0xFF * 0xFF);
+            green = ((source_green * (colormap_info->green_max) * alpha)+(green * 0xFF * (0xFF - alpha))) / (0xFF * 0xFF);
+            blue = ((source_blue * (colormap_info->blue_max) * alpha) + (blue * 0xFF * (0xFF - alpha))) / (0xFF * 0xFF);
+            uint32_t destpixel =
+              (red * colormap_info->red_mult) +
+              (green * colormap_info->green_mult) +
+              (blue * colormap_info->blue_mult) +
+              colormap_info->base_pixel;
             switch (xi->bits_per_pixel) {
             case 8: *current_pixel = (char)(destpixel & 0xFF); break;
             case 16: *((uint16_t*)current_pixel) = (uint16_t)destpixel; break;
index a770994..d845f25 100644 (file)
@@ -6,6 +6,7 @@ import java.net.*;
 import java.lang.reflect.*;
 import java.io.*;
 import java.util.*;
+import org.xwt.js.*;
 import org.xwt.util.*;
 import org.xwt.*;
 
@@ -33,7 +34,7 @@ public class X11 extends POSIX {
 
     protected String _getAltKeyName() { return System.getProperty("os.name", "").indexOf("SunOS") != -1 ? "Meta" : "Alt"; }
 
-    protected Picture _createPicture() { return new X11Picture(); }
+    protected Picture _createPicture(JS r) { return new X11Picture(r); }
     protected PixelBuffer _createPixelBuffer(int w, int h, Surface owner) { return new X11PixelBuffer(w, h); }
     protected Surface _createSurface(Box b, boolean framed) { return new X11Surface(b, framed); }
     protected boolean _needsAutoClick() { return true; }
@@ -97,15 +98,13 @@ public class X11 extends POSIX {
      */
     public static class X11Picture extends Picture {
         
-        int width;
-        int height;
-        int[] data = null;
         public X11PixelBuffer doublebuf = null;
 
         public int getWidth() { return width; }
         public int getHeight() { return height; }
 
         boolean initialized = false;
+        public X11Picture(JS r) { super(r); }
         public void init() {
             if (initialized) return;
             initialized = true;
@@ -174,7 +173,9 @@ public class X11 extends POSIX {
            cx2 = Math.min(dx + source.width, cx2); 
            cy2 = Math.min(dy + source.height, cy2); 
            if (cx1 >= cx2 || cy1 >= cy2) return;
-            slowDrawPicture(((Platform.DefaultGlyph)source).getPicture(), dx, dy, cx1, cy1, cx2, cy2, rgb, true);
+            X11Picture pic = (X11Picture)((Platform.DefaultGlyph)source).getPicture();
+            pic.init();
+            slowDrawPicture(pic, dx, dy, cx1, cy1, cx2, cy2, rgb, true);
         }
         public void drawPicture(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2) {
            cx1 = Math.max(dx, cx1);
index 7fc5447..b7e71d1 100644 (file)
@@ -57,6 +57,7 @@ public class Freetype {
             glyph.data = new byte[glyph.width * glyph.height];
             int addr = vm.getUserInfo(5);
             vm.copyin(addr, glyph.data, glyph.width * glyph.height);
+            glyph.isLoaded = true;
             
         } catch (Exception e) {
             Log.info(this, e);