new PixelBuffer API (mainly tons of renames)
[org.ibex.core.git] / src / org / ibex / graphics / Surface.java
index 82ac330..7658ec5 100644 (file)
@@ -217,10 +217,9 @@ public abstract class Surface implements Callable {
         }
     }
 
-    public void dirty(int x, int y, int w, int h) {
-        dirtyRegions.dirty(x, y, w, h);
-        Refresh();
-    }
+    // This is how subclasses signal a 'shallow dirty', indicating that although the backbuffer is valid, the screen is not
+    public void Dirty(int x, int y, int w, int h) { dirty(x,y,w,h); }
+    public void dirty(int x, int y, int w, int h) { dirtyRegions.dirty(x, y, w, h); Refresh(); }
 
     public static Surface fromBox(Box b) {
         // FIXME use a hash table here
@@ -291,8 +290,8 @@ public abstract class Surface implements Callable {
             if (y+h > root.height) h = root.height - y;
             if (w <= 0 || h <= 0) continue;
 
-            root.render(0, 0, x, y, x + w, y + h, this, identity);
-            drawPicture(scarImage, 0, root.height - scarImage.height, x, y, x+w, y+h);
+            root.render(0, 0, x, y, x + w, y + h, this.getPixelBuffer(), identity);
+            getPixelBuffer().drawPicture(scarImage, 0, root.height - scarImage.height, x, y, x+w, y+h);
             
             if (abort) {
                 // x,y,w,h is only partially reconstructed, so we must be careful not to re-blit it
@@ -354,25 +353,42 @@ public abstract class Surface implements Callable {
 
     // Default PixelBuffer implementation /////////////////////////////////////////////////////////
 
-    public static abstract class DoubleBufferedSurface extends Surface {
+    public static abstract class DoubleBufferedSurface extends Surface implements PixelBuffer {
 
         public DoubleBufferedSurface(Box root) { super(root); }
         PixelBuffer backbuffer = Platform.createPixelBuffer(Platform.getScreenWidth(), Platform.getScreenHeight(), this);
         DirtyList screenDirtyRegions = new DirtyList();
 
+        public PixelBuffer getPixelBuffer() { return this; }
         public void drawPicture(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2) {
             screenDirtyRegions.dirty(cx1, cy1, cx2 - cx1, cy2 - cy1);
             backbuffer.drawPicture(source, dx, dy, cx1, cy1, cx2, cy2);
         }
 
-        public void drawGlyph(Font.Glyph source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int argb) {
+        public void drawGlyph(Font.Glyph source, int dx, int dy, int cx1, int cy1, int cx2, int cy2, int argb, int bc) {
             screenDirtyRegions.dirty(cx1, cy1, cx2 - cx1, cy2 - cy1);
-            backbuffer.drawGlyph(source, dx, dy, cx1, cy1, cx2, cy2, argb);
+            backbuffer.drawGlyph(source, dx, dy, cx1, cy1, cx2, cy2, argb, bc);
+        }
+
+        public void stroke(Polygon p, int color) {
+            // FIXME
+        }
+        
+        public void fill(Polygon p, Paint paint) {
+            // FIXME
+        }
+
+        public void drawLine(int x1, int y1, int x2, int y2, int color) {
+            screenDirtyRegions.dirty(x1, y1, x2, y2);
+            backbuffer.drawLine(x1, y1, x2, y2, color);
         }
 
+        public abstract void _fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int color);
         public void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int color) {
+            // we don't dirty trapezoid-fills since it's faster to just do them directly than to copy from the backbuffer
             screenDirtyRegions.dirty(Math.min(x1, x3), y1, Math.max(x2, x4) - Math.min(x1, x3), y2 - y1);
             backbuffer.fillTrapezoid(x1, x2, y1, x3, x4, y2, color);
+            //_fillTrapezoid(x1, x2, y1, x3, x4, y2, color);
         }
 
         public void render() {
@@ -395,7 +411,7 @@ public abstract class Surface implements Callable {
             }
         }
 
-        /** This is how subclasses signal a 'shallow dirty', indicating that although the backbuffer is valid, the screen is not */
+        // This is how subclasses signal a 'shallow dirty', indicating that although the backbuffer is valid, the screen is not
         public final void Dirty(int x, int y, int w, int h) {
             screenDirtyRegions.dirty(x, y, w, h);
             Scheduler.renderAll();
@@ -406,9 +422,11 @@ public abstract class Surface implements Callable {
             super.dirty(x, y, w, h);
         }
 
-        /** copies a region from the doublebuffer to this surface */
+        // copies a region from the doublebuffer to this surface
         public abstract void blit(PixelBuffer source, int sx, int sy, int dx, int dy, int dx2, int dy2);
-
+        protected void blit(int x, int y, int w, int h) {
+            blit(backbuffer, x, y, x, y, w + x, h + y);
+        }
     }
 
 }