new PixelBuffer API (mainly tons of renames)
[org.ibex.core.git] / src / org / ibex / graphics / Surface.java
index 6beebac..7658ec5 100644 (file)
@@ -16,7 +16,7 @@ import org.ibex.core.*;  // FIXME
  *  Platform subclasses should include an inner class subclass of
  *  Surface to return from the Platform._createSurface() method
  */
  *  Platform subclasses should include an inner class subclass of
  *  Surface to return from the Platform._createSurface() method
  */
-public abstract class Surface extends PixelBuffer implements Callable {
+public abstract class Surface implements Callable {
 
     // Static Data ////////////////////////////////////////////////////////////////////////////////
 
 
     // Static Data ////////////////////////////////////////////////////////////////////////////////
 
@@ -67,6 +67,7 @@ public abstract class Surface extends PixelBuffer implements Callable {
     
     // Methods to be overridden by subclasses ///////////////////////////////////////////////////////
 
     
     // Methods to be overridden by subclasses ///////////////////////////////////////////////////////
 
+    public abstract PixelBuffer getPixelBuffer();      ///< returns a PixelBuffer representing this Surface
     public abstract void toBack();                     ///< should push surface to the back of the stacking order
     public abstract void toFront();                    ///< should pull surface to the front of the stacking order
     public abstract void syncCursor();                 ///< set the actual cursor to this.cursor if they do not match
     public abstract void toBack();                     ///< should push surface to the back of the stacking order
     public abstract void toFront();                    ///< should pull surface to the front of the stacking order
     public abstract void syncCursor();                 ///< set the actual cursor to this.cursor if they do not match
@@ -216,10 +217,9 @@ public abstract class Surface extends PixelBuffer 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
 
     public static Surface fromBox(Box b) {
         // FIXME use a hash table here
@@ -290,8 +290,8 @@ public abstract class Surface extends PixelBuffer implements Callable {
             if (y+h > root.height) h = root.height - y;
             if (w <= 0 || h <= 0) continue;
 
             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
             
             if (abort) {
                 // x,y,w,h is only partially reconstructed, so we must be careful not to re-blit it
@@ -353,25 +353,42 @@ public abstract class Surface extends PixelBuffer implements Callable {
 
     // Default PixelBuffer implementation /////////////////////////////////////////////////////////
 
 
     // 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 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 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);
             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) {
         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);
             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() {
         }
 
         public void render() {
@@ -394,7 +411,7 @@ public abstract class Surface extends PixelBuffer 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();
         public final void Dirty(int x, int y, int w, int h) {
             screenDirtyRegions.dirty(x, y, w, h);
             Scheduler.renderAll();
@@ -405,9 +422,11 @@ public abstract class Surface extends PixelBuffer implements Callable {
             super.dirty(x, y, w, h);
         }
 
             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);
         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);
+        }
     }
 
 }
     }
 
 }