X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fgraphics%2FSurface.java;h=ebf4670fd656024da0e7d13514f865955e01ffaf;hp=6beebacc52e30d33ce173cbbb7ecbfab3762176a;hb=05d23fde131a7d19b378c632c6cc6b7924d8ab4d;hpb=0db31fc0dc88749cd8022790fd475df8b7b06c27 diff --git a/src/org/ibex/graphics/Surface.java b/src/org/ibex/graphics/Surface.java index 6beebac..ebf4670 100644 --- a/src/org/ibex/graphics/Surface.java +++ b/src/org/ibex/graphics/Surface.java @@ -7,8 +7,7 @@ package org.ibex.graphics; import org.ibex.js.*; import org.ibex.util.*; import org.ibex.plat.*; - -import org.ibex.core.*; // FIXME +import org.ibex.core.*; /** * A Surface, as described in the Ibex Reference. @@ -16,14 +15,14 @@ import org.ibex.core.*; // FIXME * 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 //////////////////////////////////////////////////////////////////////////////// private static final JS T = JSU.T; private static final JS F = JSU.F; - /** all instances of Surface which need to be refreshed by the Scheduler */ + /** all instances of Surface which need to be refreshed by the Platform.Scheduler */ public static Vec allSurfaces = new Vec(); /** When set to true, render() should abort as soon as possible and restart the rendering process */ @@ -67,6 +66,7 @@ public abstract class Surface extends PixelBuffer implements Callable { // 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 @@ -96,7 +96,7 @@ public abstract class Surface extends PixelBuffer implements Callable { if (button == 1) new Message("_Press1", T, root); else if (button == 2) new Message("_Press2", T, root); else if (button == 3) { - Scheduler.add(new Callable() { public Object run(Object o) throws JSExn { + Platform.Scheduler.add(new Callable() { public Object run(Object o) throws JSExn { Platform.clipboardReadEnabled = true; try { root.putAndTriggerTraps(JSU.S("_Press3"), T); @@ -135,7 +135,7 @@ public abstract class Surface extends PixelBuffer implements Callable { } private final static JS MOVE = JSU.S("_Move"); - /** we enqueue ourselves in the Scheduler when we have a Move message to deal with */ + /** we enqueue ourselves in the Platform.Scheduler when we have a Move message to deal with */ private Callable mover = new Callable() { public Object run(Object o) { if (mousex == newmousex && mousey == newmousey) return null; @@ -158,7 +158,7 @@ public abstract class Surface extends PixelBuffer implements Callable { protected final void Move(final int newmousex, final int newmousey) { this.newmousex = newmousex; this.newmousey = newmousey; - Scheduler.add(mover); + Platform.Scheduler.add(mover); } protected final void HScroll(int pixels) { new Message("_HScroll", JSU.N(pixels), root); } @@ -173,12 +173,12 @@ public abstract class Surface extends PixelBuffer implements Callable { pendingHeight = height; syncRootBoxToSurface = true; abort = true; - Scheduler.renderAll(); + Refresh(); } // FEATURE: can we avoid creating objects here? protected final void PosChange(final int x, final int y) { - Scheduler.add(new Callable() { public Object run(Object o) throws JSExn { + Platform.Scheduler.add(new Callable() { public Object run(Object o) throws JSExn { root.x = x; root.y = y; root.putAndTriggerTrapsAndCatchExceptions(JSU.S("PosChange"), T); @@ -196,8 +196,8 @@ public abstract class Surface extends PixelBuffer implements Callable { protected final void Focused(boolean b) { new Message("Focused", b ? T : F, root); } private boolean scheduled = false; - public void Refresh() { if (!scheduled) Scheduler.add(this); scheduled = true; } - public Object run(Object o) { scheduled = false; Scheduler.renderAll(); return null; } + public void Refresh() { if (!scheduled) Platform.Scheduler.add(this); scheduled = true; } + public Object run(Object o) { scheduled = false; Platform.Scheduler.renderAll(); return null; } public final void setMaximized(boolean b) { if (b != maximized) _setMaximized(maximized = b); } public final void setMinimized(boolean b) { if (b != minimized) _setMinimized(minimized = b); } @@ -216,10 +216,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 @@ -290,8 +289,8 @@ public abstract class Surface extends PixelBuffer 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 @@ -318,7 +317,7 @@ public abstract class Surface extends PixelBuffer implements Callable { this.boxContainingMouse = boxContainingMouse; this.name = name; this.value = value; - Scheduler.add(this); + Platform.Scheduler.add(this); } public Object run(Object o) throws JSExn { @@ -353,25 +352,42 @@ public abstract class Surface extends PixelBuffer 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() { @@ -394,10 +410,11 @@ 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(); + //screenDirtyRegions.dirty(x, y, w, h); + //Refresh(); + blit(x,y,w,h); } public void dirty(int x, int y, int w, int h) { @@ -405,9 +422,11 @@ public abstract class Surface extends PixelBuffer 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); + } } }