From 8ca06b850fb51673a7cfe751643ea45ec528070d Mon Sep 17 00:00:00 2001 From: megacz Date: Fri, 30 Jan 2004 07:38:52 +0000 Subject: [PATCH] 2003/10/01 03:08:32 darcs-hash:20040130073852-2ba56-7957392c4db15a176f900b6a57d609d63bf7a161.gz --- src/org/xwt/PixelBuffer.java | 18 ++++++++---------- src/org/xwt/Surface.java | 7 +++++++ src/org/xwt/plat/AWT.java | 14 ++++++++++---- src/org/xwt/plat/OpenGL.java | 3 +++ src/org/xwt/plat/Win32.java | 2 ++ src/org/xwt/plat/X11.java | 3 +++ 6 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/org/xwt/PixelBuffer.java b/src/org/xwt/PixelBuffer.java index 065b027..9bb41be 100644 --- a/src/org/xwt/PixelBuffer.java +++ b/src/org/xwt/PixelBuffer.java @@ -21,22 +21,20 @@ package org.xwt; */ public abstract class PixelBuffer { - // FIXME: try to remove - /** returns the height of the PixelBuffer */ - public abstract int getHeight(); - - // FIXME: try to remove - /** returns the width of the PixelBuffer */ - public abstract int getWidth(); - - - /** Draw the region of source within s onto the region d on this PixelBuffer, scaling as needed */ public abstract void drawPicture(Picture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2); /** fill a trapezoid whose top and bottom edges are horizontal */ public abstract void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int color); + /** + * Same as drawPicture, but only uses the alpha channel of the Picture, and is allowed to destructively modify the RGB + * channels of the Picture in the process. This method may assume that the RGB channels of the image are all zero IFF it + * restores this invariant before returning. + */ + public abstract void drawPictureAlphaOnly(Picture source, int dx1, int dy1, int dx2, int dy2, + int sx1, int sy1, int sx2, int sy2, int rgb); + // FIXME: we want floats (inter-pixel spacing) for antialiasing, but this hoses the fastpath line drawing... argh! /** draws a line of width w; note that the coordinates here are post-transform */ public void drawLine(int x1, int y1, int x2, int y2, int w, int color, boolean capped) { diff --git a/src/org/xwt/Surface.java b/src/org/xwt/Surface.java index e4cf92d..b42ee0c 100644 --- a/src/org/xwt/Surface.java +++ b/src/org/xwt/Surface.java @@ -362,6 +362,13 @@ public abstract class Surface extends PixelBuffer { screenDirtyRegions.dirty(dx1, dy1, dx2 - dx1, dy2 - dy1); backbuffer.drawPicture(source, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2); } + public void drawPictureAlphaOnly(Picture source, + int dx1, int dy1, int dx2, int dy2, + int sx1, int sy1, int sx2, int sy2, + int argb) { + screenDirtyRegions.dirty(dx1, dy1, dx2 - dx1, dy2 - dy1); + backbuffer.drawPictureAlphaOnly(source, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, argb); } + public void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int 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); } diff --git a/src/org/xwt/plat/AWT.java b/src/org/xwt/plat/AWT.java index e186789..3dfd153 100644 --- a/src/org/xwt/plat/AWT.java +++ b/src/org/xwt/plat/AWT.java @@ -160,14 +160,20 @@ public class AWT extends JVM { public int getWidth() { return i == null ? 0 : i.getWidth(null); } public void setClip(int x, int y, int x2, int y2) { g.setClip(x, y, x2 - x, y2 - y); } - public void drawPicture(Picture source, int x, int y) { - drawPicture(source, x, y, x + source.getWidth(), y + source.getHeight(), 0, 0, source.getWidth(), source.getHeight()); - } - public void drawPicture(Picture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2) { g.drawImage(((AWTPicture)source).i, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null); } + public void drawPictureAlphaOnly(Picture source, int dx1, int dy1, int dx2, int dy2, + int sx1, int sy1, int sx2, int sy2, int rgb) { + AWTPicture p = (AWTPicture)source; + Graphics g = p.i.getGraphics(); + g.setXORMode(new Color(rgb)); + g.fillRect(0, 0, p.i.getWidth(null), p.i.getHeight(null)); + drawPicture(source, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2); + g.fillRect(0, 0, p.i.getWidth(null), p.i.getHeight(null)); + } + public void fillRect(int x, int y, int x2, int y2, int argb) { // FEATURE: use an LRU cache for Color objects } diff --git a/src/org/xwt/plat/OpenGL.java b/src/org/xwt/plat/OpenGL.java index 510693a..96d701d 100644 --- a/src/org/xwt/plat/OpenGL.java +++ b/src/org/xwt/plat/OpenGL.java @@ -80,6 +80,9 @@ abstract class OpenGL { //System.out.println("drawString(): " + text); } + public native void drawPictureAlphaOnly(Picture source, int dx1, int dy1, int dx2, int dy2, + int sx1, int sy1, int sx2, int sy2, int rgb); + public void drawPicture(org.xwt.Picture source, int x, int y) { activateContext(); GLPicture p = (GLPicture) source; diff --git a/src/org/xwt/plat/Win32.java b/src/org/xwt/plat/Win32.java index f006190..ba99a8e 100644 --- a/src/org/xwt/plat/Win32.java +++ b/src/org/xwt/plat/Win32.java @@ -264,6 +264,8 @@ public class Win32 extends GCJ { public native void setClip(int x, int y, int x2, int y2); public native void fillRect(int x, int y, int x2, int y2, int color); public native void drawPicture(Picture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2); + public native void drawPictureAlphaOnly(Picture source, int dx1, int dy1, int dx2, int dy2, + int sx1, int sy1, int sx2, int sy2, int rgb); public native void finalize(); public void drawPicture(Picture source, int x, int y) { drawPicture(source, x, y, x + source.getWidth(), y + source.getHeight(), 0, 0, source.getWidth(), source.getHeight()); diff --git a/src/org/xwt/plat/X11.java b/src/org/xwt/plat/X11.java index a8d948c..925593b 100644 --- a/src/org/xwt/plat/X11.java +++ b/src/org/xwt/plat/X11.java @@ -175,6 +175,9 @@ public class X11 extends POSIX { cliph = y2 - y; if (cliph < 0) cliph = 0; } + public native void drawPictureAlphaOnly(Picture source, int dx1, int dy1, int dx2, int dy2, + int sx1, int sy1, int sx2, int sy2, int rgb); + public void drawPicture(Picture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2) { if (!(dx2 - dx1 != sx2 - sx1 || dy2 - dy1 != sy2 - sy1) && ((X11Picture)source).doublebuf != null) fastDrawPicture(source, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2); -- 1.7.10.4