diff options
| author | rolfwr <rolfwr@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-10-22 17:46:09 +0000 |
|---|---|---|
| committer | rolfwr <rolfwr@138bc75d-0d04-0410-961f-82ee72b054a4> | 2000-10-22 17:46:09 +0000 |
| commit | e2d342dffa63aea98643515fd3b8c782ee8bd15e (patch) | |
| tree | 1165199489e8bc851f2bb5c11ff0228f3667453e /libjava/gnu/awt/j2d | |
| parent | cfed8d62a245d6113c86f79ffb2e4f09b2becc8d (diff) | |
| download | ppe42-gcc-e2d342dffa63aea98643515fd3b8c782ee8bd15e.tar.gz ppe42-gcc-e2d342dffa63aea98643515fd3b8c782ee8bd15e.zip | |
* Makefile.am: Added rules for libgcjx library.
* Makefile.in: Rebuilt.
* configure.in: Added check for X.
* configure: Rebuilt.
* gnu/awt/LightweightRedirector.java: New file.
* gnu/awt/j2d/AbstractGraphicsState.java: New file.
* gnu/awt/j2d/DirectRasterGraphics.java: New file.
* gnu/awt/j2d/Graphics2DImpl.java: New file.
* gnu/awt/j2d/IntegerGraphicsState.java: New file.
* gnu/awt/j2d/MappedRaster.java: New file.
* gnu/awt/xlib/XCanvasPeer.java: New file.
* gnu/awt/xlib/XEventLoop.java: New file.
* gnu/awt/xlib/XEventQueue.java: New file.
* gnu/awt/xlib/XFontMetrics.java: New file.
* gnu/awt/xlib/XFramePeer.java: New file.
* gnu/awt/xlib/XGraphics.java: New file.
* gnu/awt/xlib/XGraphicsConfiguration.java: New file.
* gnu/awt/xlib/XPanelPeer.java: New file.
* gnu/awt/xlib/XToolkit.java: New file.
* gnu/gcj/xlib/Clip.java: New file.
* gnu/gcj/xlib/Colormap.java: New file.
* gnu/gcj/xlib/Display.java: New file.
* gnu/gcj/xlib/Drawable.java: New file.
* gnu/gcj/xlib/Font.java: New file.
* gnu/gcj/xlib/GC.java: New file.
* gnu/gcj/xlib/Pixmap.java: New file.
* gnu/gcj/xlib/Screen.java: New file.
* gnu/gcj/xlib/Visual.java: New file.
* gnu/gcj/xlib/WMSizeHints.java: New file.
* gnu/gcj/xlib/Window.java: New file.
* gnu/gcj/xlib/WindowAttributes.java: New file.
* gnu/gcj/xlib/XAnyEvent.java: New file.
* gnu/gcj/xlib/XButtonEvent.java: New file.
* gnu/gcj/xlib/XColor.java: New file.
* gnu/gcj/xlib/XConfigureEvent.java: New file.
* gnu/gcj/xlib/XConnectException.java: New file.
* gnu/gcj/xlib/XEvent.java: New file.
* gnu/gcj/xlib/XException.java: New file.
* gnu/gcj/xlib/XExposeEvent.java: New file.
* gnu/gcj/xlib/XID.java: New file.
* gnu/gcj/xlib/XImage.java: New file.
* gnu/gcj/xlib/XUnmapEvent.java: New file.
* gnu/gcj/xlib/natClip.cc: New file.
* gnu/gcj/xlib/natColormap.cc: New file.
* gnu/gcj/xlib/natDisplay.cc: New file.
* gnu/gcj/xlib/natDrawable.cc: New file.
* gnu/gcj/xlib/natFont.cc: New file.
* gnu/gcj/xlib/natGC.cc: New file.
* gnu/gcj/xlib/natPixmap.cc: New file.
* gnu/gcj/xlib/natScreen.cc: New file.
* gnu/gcj/xlib/natVisual.cc: New file.
* gnu/gcj/xlib/natWMSizeHints.cc: New file.
* gnu/gcj/xlib/natWindow.cc: New file.
* gnu/gcj/xlib/natWindowAttributes.cc: New file.
* gnu/gcj/xlib/natXAnyEvent.cc: New file.
* gnu/gcj/xlib/natXButtonEvent.cc: New file.
* gnu/gcj/xlib/natXColor.cc: New file.
* gnu/gcj/xlib/natXConfigureEvent.cc: New file.
* gnu/gcj/xlib/natXException.cc: New file.
* gnu/gcj/xlib/natXExposeEvent.cc: New file.
* gnu/gcj/xlib/natXImage.cc: New file.
* gnu/gcj/xlib/natXUnmapEvent.cc: New file.
* java/awt/EventDispatchThread.java: Start thead on creation.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@37005 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/gnu/awt/j2d')
| -rw-r--r-- | libjava/gnu/awt/j2d/AbstractGraphicsState.java | 128 | ||||
| -rw-r--r-- | libjava/gnu/awt/j2d/DirectRasterGraphics.java | 82 | ||||
| -rw-r--r-- | libjava/gnu/awt/j2d/Graphics2DImpl.java | 454 | ||||
| -rw-r--r-- | libjava/gnu/awt/j2d/IntegerGraphicsState.java | 409 | ||||
| -rw-r--r-- | libjava/gnu/awt/j2d/MappedRaster.java | 72 |
5 files changed, 1145 insertions, 0 deletions
diff --git a/libjava/gnu/awt/j2d/AbstractGraphicsState.java b/libjava/gnu/awt/j2d/AbstractGraphicsState.java new file mode 100644 index 00000000000..e3b3ec61599 --- /dev/null +++ b/libjava/gnu/awt/j2d/AbstractGraphicsState.java @@ -0,0 +1,128 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.awt.j2d; + +import java.awt.Color; +import java.awt.Image; +import java.awt.Shape; +import java.awt.Rectangle; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.GraphicsConfiguration; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.image.ImageObserver; + +/** + * Base class for graphics state objects (State pattern, GOF book) + * that represents the current pipeline configuration. The Graphics2D + * object forwards most of the requests to the state object. The + * Graphics2D object itself only administers properties that are not + * specific for a certain state. + */ +public abstract class AbstractGraphicsState implements Cloneable +{ + Graphics2DImpl frontend; + + public void setFrontend(Graphics2DImpl frontend) + { + this.frontend = frontend; + } + + public void dispose() + { + frontend = null; + } + + // -------- Graphics methods: + + public abstract void setColor(Color color); + + public abstract void setPaintMode(); + + public abstract void setXORMode(Color altColor); + + public abstract void setFont(Font font); + + public abstract FontMetrics getFontMetrics(Font font); + + public abstract void setClip(Shape clip); + + public abstract Shape getClip(); + public abstract Rectangle getClipBounds(); + + public abstract void copyArea(int x, int y, + int width, int height, + int dx, int dy); + + public abstract void drawLine(int x1, int y1, + int x2, int y2); + + public abstract void fillRect(int x, int y, + int width, int height); + + public abstract void clearRect(int x, int y, + int width, int height); + + public abstract void drawRoundRect(int x, int y, + int width, int height, + int arcWidth, int arcHeight); + + public abstract void fillRoundRect(int x, int y, + int width, int height, + int arcWidth, int arcHeight); + + public abstract void drawOval(int x, int y, + int width, int height); + + public abstract void fillOval(int x, int y, + int width, int height); + + public abstract void drawArc(int x, int y, + int width, int height, + int startAngle, int arcAngle); + + public abstract void fillArc(int x, int y, + int width, int height, + int startAngle, int arcAngle); + + public abstract void drawPolyline(int[] xPoints, int[] yPoints,int nPoints); + + public abstract void drawPolygon(int[] xPoints, int[] yPoints, int nPoints); + + public abstract void fillPolygon(int[] xPoints, int[] yPoints, int nPoints); + + public abstract boolean drawImage(Image image, int x, int y, + ImageObserver observer); + + + // -------- Graphics2D methods: + + public abstract void draw(Shape shape); + + public abstract void fill(Shape shape); + + public abstract boolean hit(Rectangle rect, Shape text, boolean onStroke); + + public abstract void drawString(String text, int x, int y); + + public abstract void drawString(String text, float x, float y); + + public abstract void translate(int x, int y); + + public abstract void translate(double tx, double ty); + + public abstract void rotate(double theta); + + public abstract void rotate(double theta, double x, double y); + + public abstract void scale(double scaleX, double scaleY); + + public abstract void shear(double shearX, double shearY); +} diff --git a/libjava/gnu/awt/j2d/DirectRasterGraphics.java b/libjava/gnu/awt/j2d/DirectRasterGraphics.java new file mode 100644 index 00000000000..6bbdbd1d23e --- /dev/null +++ b/libjava/gnu/awt/j2d/DirectRasterGraphics.java @@ -0,0 +1,82 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.awt.j2d; + +import java.awt.Color; +import java.awt.Image; +import java.awt.Shape; +import java.awt.Rectangle; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.GraphicsConfiguration; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.image.Raster; +import java.awt.image.ImageObserver; + +/** + * Interface for a simple pixel based backend graphics object that + * does not handle translation/transforms, curves, nor advanced + * compositing. + */ +public interface DirectRasterGraphics extends Cloneable +{ + public void dispose(); + + public void setColor(Color color); + + public void setPaintMode(); + + public void setXORMode(Color altColor); + + public void setFont(Font font); + + public FontMetrics getFontMetrics(Font font); + + // supports rects, multi-rects and polygons + public void setClip(Shape clip); + + public void copyArea(int x, int y, int width, int height, + int dx, int dy); + + public void drawLine(int x1, int y1, int x2, int y2); + + public void drawRect(int x, int y, int width, int height); + + public void fillRect(int x, int y, int width, int height); + + public void drawArc(int x, int y, int width, int height, + int startAngle, int arcAngle); + + public void fillArc(int x, int y, int width, int height, + int startAngle, int arcAngle); + + public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints); + + public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints); + + public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints); + + public void drawString(String str, int x, int y); + + public boolean drawImage(Image image, int x, int y, + ImageObserver observer); + + /** + * Map the data for screen pixels in the requested bounds to a + * raster object. This gives read/write access to the screen + * pixels, allowing neat alpha and composite tricks. + */ + public MappedRaster mapRaster(Rectangle bounds); + + /** + * Detach previously mapped pixel data from a raster object. + */ + public void unmapRaster(MappedRaster mappedRaster); +} diff --git a/libjava/gnu/awt/j2d/Graphics2DImpl.java b/libjava/gnu/awt/j2d/Graphics2DImpl.java new file mode 100644 index 00000000000..7c08295c027 --- /dev/null +++ b/libjava/gnu/awt/j2d/Graphics2DImpl.java @@ -0,0 +1,454 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.awt.j2d; + +import java.awt.Color; +import java.awt.Image; +import java.awt.Shape; +import java.awt.Rectangle; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.GraphicsConfiguration; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Paint; +import java.awt.RenderingHints; +import java.awt.geom.AffineTransform; +import java.awt.image.ImageObserver; + +/** + * Delegates almost all work to a state object, that allows us to + * hot-swap rendering strategies based on state changes inflicted on + * this Graphics object. This class keeps track of properties that are + * not affected by the state, (such as clip shape, + * foreground/background color, font, etc.). + * + * <p>The far front-end of the rendering pipeline consists of the + * Graphics2D API. In the far back-end, lies the native graphics + * libraries. In most cases the native graphics libraries only have + * direct support for a subset of the properties of Graphics2D. To + * make up missing features in the native graphics libraries, the + * pipeline between the front-end and the back-end need to translate + * drawing request to primitive operations that are supported by the + * back-end. E.g. for X11, drawing a straight line will translate to + * an XDrawLine, drawing a bezier curve will trigger flattening of the + * curve and will result in a call to XDrawLines. + * + * <p>This is the basic strategy for the rendering pipeline: Whenever + * a graphics property change occurs, that causes the current pipeline + * to be insufficient, amend or replace parts of the pipeline so that + * the pipeline will once again be able to translate requests to the + * set of primitives supported by the native graphics library. + * + * <p>Most graphics libraries share common subsets of + * functionality. To be able to reuse pieces of the rendering pipeline + * for several backends, we define interfaces that describe subsets of + * characteristics supported by the backends. A wrapper for the native + * library can implement several interfaces to describe its range of + * functionality. + * + * <p>Typically, most painting is done with a graphics object with + * simple properties. Unless one is using a complex Look & Feel, the + * painting of Swing components will never require affine transforms, + * alpha blending, non-rectangular clipping, etc. When graphics + * objects are created, they start off in a state where all the + * properties are simple. Most graphics objects experience only + * trivial property changes, and never leave this simple state. It is + * therefore wise to ensure that the rendering pipeline for this + * initial state is lean and as much as possible plugs directly into + * the backend. + * + * <p>The initial state for graphics object of most raster displays + * would call for two levels of indirection: + * + * <pre> + * Graphics2D object ---> IntegerGraphicsState ---> DirectRasterGraphics + * </pre> + */ +public class Graphics2DImpl extends Graphics2D implements Cloneable +{ + GraphicsConfiguration config; + + AbstractGraphicsState state; + + Color fg; + Color bg; + + Font font; + + public Graphics2DImpl(GraphicsConfiguration config) + { + this.config = config; + } + + public void setState(AbstractGraphicsState state) + { + this.state = state; + this.state.setFrontend(this); + } + + public Object clone() + { + Graphics2DImpl gfxCopy = (Graphics2DImpl) super.clone(); + AbstractGraphicsState stateCopy = + (AbstractGraphicsState) state.clone(); + gfxCopy.setState(stateCopy); + + return gfxCopy; + } + + + // -------- Graphics methods: + + public Graphics create() + { + Graphics2DImpl gfxCopy = (Graphics2DImpl) clone(); + return gfxCopy; + } + + public Color getColor() + { + return fg; + } + + public void setColor(Color color) + { + fg = color; + state.setColor(color); + } + + public void setPaintMode() + { + state.setPaintMode(); + } + + public void setXORMode(Color altColor) + { + state.setXORMode(altColor); + } + + public Font getFont() + { + return font; + } + + public void setFont(Font font) + { + this.font = font; + state.setFont(font); + } + + public FontMetrics getFontMetrics(Font font) + { + return state.getFontMetrics(font); + } + + public Rectangle getClipBounds() + { + return state.getClipBounds(); + } + + public void clipRect(int x, int y, int width, int height) + { + Shape clip = state.getClip(); + if (clip instanceof Rectangle) + { + Rectangle clipRect = (Rectangle) clip; + clip = clipRect.intersection(new Rectangle(x, y, width, height)); + setClip(clip); + return; + } + + String msg = + "intersecting current clip shape " + clip + " with new rectangle " + + "has not been implemented yet"; + throw new UnsupportedOperationException(msg); + } + + public void setClip(int x, int y, int width, int height) + { + Rectangle clip = new Rectangle(x, y, width, height); + setClip(clip); + } + + public Shape getClip() + { + return state.getClip(); + } + + public void setClip(Shape clip) + { + state.setClip(clip); + } + + public void copyArea(int x, int y, int width, int height, + int dx, int dy) + { + state.copyArea(x, y, width, height, dx, dy); + } + + public void drawLine(int x1, int y1, int x2, int y2) + { + state.drawLine(x1, y1, x2, y2); + } + + public void fillRect(int x, int y, int width, int height) + { + state.fillRect(x, y, width, height); + } + + public void clearRect(int x, int y, int width, int height) + { + state.clearRect(x, y, width, height); + } + + public void drawRoundRect(int x, int y, int width, int height, + int arcWidth, int arcHeight) + { + state.drawRoundRect(x, y, width, height, arcWidth, arcHeight); + } + + public void fillRoundRect(int x, int y, int width, int height, + int arcWidth, int arcHeight) + { + state.fillRoundRect(x, y, width, height, arcWidth, arcHeight); + } + + public void drawOval(int x, int y, int width, int height) + { + state.drawOval(x, y, width, height); + } + + public void fillOval(int x, int y, int width, int height) + { + state.fillOval(x, y, width, height); + } + + public void drawArc(int x, int y, int width, int height, + int startAngle, int arcAngle) + { + state.drawArc(x, y, width, height, startAngle, arcAngle); + } + + public void fillArc(int x, int y, int width, int height, + int startAngle, int arcAngle) + { + state.fillArc(x, y, width, height, startAngle, arcAngle); + } + + public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) + { + state.drawPolyline(xPoints, yPoints, nPoints); + } + + public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) + { + state.drawPolygon(xPoints, yPoints, nPoints); + } + + public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) + { + state.fillPolygon(xPoints, yPoints, nPoints); + } + + public boolean drawImage(Image image, int x, int y, + ImageObserver observer) + { + return state.drawImage(image, x, y, observer); + } + + public boolean drawImage(Image img, int x, int y, + int width, int height, + ImageObserver observer) + { + throw new UnsupportedOperationException("not implemented yet"); + } + + public boolean drawImage(Image img, int x, int y, Color bgcolor, + ImageObserver observer) + { + throw new UnsupportedOperationException("not implemented yet"); + } + + public boolean drawImage(Image img, int x, int y, + int width, int height, Color bgcolor, + ImageObserver observer) + { + throw new UnsupportedOperationException("not implemented yet"); + } + + public boolean drawImage(Image img, + int dx1, int dy1, int dx2, int dy2, + int sx1, int sy1, int sx2, int sy2, + ImageObserver observer) + { + throw new UnsupportedOperationException("not implemented yet"); + } + + public boolean drawImage(Image img, + int dx1, int dy1, int dx2, int dy2, + int sx1, int sy1, int sx2, int sy2, + Color bgcolor, ImageObserver observer) + { + throw new UnsupportedOperationException("not implemented yet"); + } + + public void dispose() + { + AbstractGraphicsState lState = state; + + state = null; + config = null; + font = null; + fg = null; + bg = null; + + if (lState != null) + lState.dispose(); + } + + + + // -------- Graphics2D methods: + + public void draw(Shape shape) + { + state.draw(shape); + } + + public boolean drawImage(Image image, AffineTransform xform, + ImageObserver obs) + { + throw new UnsupportedOperationException("not implemented yet"); + } + + + public void drawString(String text, int x, int y) + { + state.drawString(text, x, y); + } + + public void drawString(String text, float x, float y) + { + state.drawString(text, x, y); + } + + public void fill(Shape shape) + { + state.fill(shape); + } + + public boolean hit(Rectangle rect, Shape text, boolean onStroke) + { + return state.hit(rect, text, onStroke); + } + + public GraphicsConfiguration getDeviceConfiguration() + { + return config; + } + + public void setPaint(Paint paint) + { + throw new UnsupportedOperationException("not implemented yet"); + } + + public void setRenderingHint(RenderingHints.Key hintKey, + Object hintValue) + { + throw new UnsupportedOperationException("not implemented yet"); + } + + public Object getRenderingHint(RenderingHints.Key hintKey) + { + throw new UnsupportedOperationException("not implemented yet"); + } + + public RenderingHints getRenderingHints() + { + throw new UnsupportedOperationException("not implemented yet"); + } + + public void translate(int x, int y) + { + state.translate(x, y); + } + + public void translate(double tx, double ty) + { + state.translate(tx, ty); + } + + public void rotate(double theta) + { + state.rotate(theta); + } + + public void rotate(double theta, double x, double y) + { + state.rotate(theta, x, y); + } + + public void scale(double scaleX, double scaleY) + { + state.scale(scaleX, scaleY); + } + + public void shear(double shearX, double shearY) + { + state.shear(shearX, shearY); + } + + public void transform(AffineTransform Tx) + { + throw new UnsupportedOperationException("not implemented yet"); + } + + public void setTransform(AffineTransform Tx) + { + throw new UnsupportedOperationException("not implemented yet"); + } + + public AffineTransform getTransform() + { + throw new UnsupportedOperationException("not implemented yet"); + } + + public Paint getPaint() + { + throw new UnsupportedOperationException("not implemented yet"); + } + + public void setBackground(Color color) + { + bg = color; + } + + public Color getBackground() + { + return bg; + } + + public void clip(Shape shape) + { + Shape clip = state.getClip(); + + if ((shape instanceof Rectangle) && (clip instanceof Rectangle)) + { + clip = ((Rectangle) clip).intersection((Rectangle) shape); + state.setClip(clip); + return; + } + + String msg = + "intersecting current clip shape " + clip + " with new shape " + shape + + "has not been implemented yet"; + throw new UnsupportedOperationException(msg); + } +} diff --git a/libjava/gnu/awt/j2d/IntegerGraphicsState.java b/libjava/gnu/awt/j2d/IntegerGraphicsState.java new file mode 100644 index 00000000000..923720e06ae --- /dev/null +++ b/libjava/gnu/awt/j2d/IntegerGraphicsState.java @@ -0,0 +1,409 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.awt.j2d; + +import java.awt.Color; +import java.awt.Image; +import java.awt.Shape; +import java.awt.Rectangle; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.GraphicsConfiguration; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.image.BufferedImage; +import java.awt.image.ImageObserver; +import java.awt.image.Raster; +import java.awt.image.WritableRaster; +import java.awt.image.ColorModel; + +/** + * IntegerGraphicsState is one of several graphics state + * implementations. This graphics state is used when the graphics + * object has simple properties, (coordinate translation only, no + * transform) and the backend supports integer coordinates (pixel + * based). For primitive paint operations, this object translates the + * coordinates and forwards the request to the backend. For requests + * to draw arbitrary shapes and paths, this object translates the + * requests to primitive drawing operations supported by the + * backend. IntegerGraphicsState is meant to support the most common + * state of an graphics object. The degree of functionality is roughly + * equivalent with the old java.awt.Graphics API. + */ +public class IntegerGraphicsState extends AbstractGraphicsState +{ + int tx; + int ty; + + DirectRasterGraphics directGfx; + Shape clip; + + public IntegerGraphicsState(DirectRasterGraphics directGfx) + { + this.directGfx = directGfx; + } + + public Object clone() + { + IntegerGraphicsState clone = (IntegerGraphicsState) super.clone(); + clone.directGfx = (DirectRasterGraphics) directGfx.clone(); + + return clone; + } + + public void dispose() + { + DirectRasterGraphics lDeviceGfx = directGfx; + + directGfx = null; + + if (lDeviceGfx != null) + lDeviceGfx.dispose(); + + super.dispose(); + } + + + // -------- Graphics methods: + + public void setColor(Color color) + { + directGfx.setColor(color); + } + + public void setPaintMode() + { + directGfx.setPaintMode(); + } + + public void setXORMode(Color altColor) + { + directGfx.setXORMode(altColor); + } + + public void setFont(Font font) + { + directGfx.setFont(font); + } + + public FontMetrics getFontMetrics(Font font) + { + return directGfx.getFontMetrics(font); + } + + public void setClip(Shape clip) + { + if (clip instanceof Rectangle) + { + Rectangle clipRect = (Rectangle) clip.clone(); + clipRect.x += tx; + clipRect.y += ty; + + this.clip = clipRect; + + directGfx.setClip(clipRect); + return; + } + + String msg = + "translating clip shape " + clip + " into device " + + "coordinate space has not been implemented yet"; + + throw new UnsupportedOperationException(msg); + } + + public Shape getClip() + { + if (clip instanceof Rectangle) + { + Rectangle clipRect = (Rectangle) clip; + clipRect.x -= tx; + clipRect.y -= ty; + return clipRect; + } + + String msg = + "translating clip shape " + clip + " into user " + + "coordinate space has not been implemented yet"; + + throw new UnsupportedOperationException(msg); + } + + public Rectangle getClipBounds() + { + Rectangle clipRect = clip.getBounds(); + + clipRect.x -= tx; + clipRect.y -= ty; + return clipRect; + } + + public void copyArea(int x, int y, + int width, int height, + int dx, int dy) + { + directGfx.copyArea(x+tx, y+ty, width, height, dx, dy); + } + + public void drawLine(int x1, int y1, + int x2, int y2) + { + directGfx.drawLine(x1+tx, y1+ty, x2+tx, y2+ty); + } + + public void fillRect(int x, int y, + int width, int height) + { + directGfx.fillRect(x+tx, y+ty, width, height); + } + + public void clearRect(int x, int y, + int width, int height) + { + directGfx.setColor(frontend.getBackground()); + directGfx.fillRect(x+tx, y+ty, width, height); + directGfx.setColor(frontend.getColor()); + } + + public void drawRoundRect(int x, int y, + int width, int height, + int arcWidth, int arcHeight) + { + throw new UnsupportedOperationException("not implemented yet"); + } + + public void fillRoundRect(int x, int y, + int width, int height, + int arcWidth, int arcHeight) + { + throw new UnsupportedOperationException("not implemented yet"); + } + + public void drawOval(int x, int y, + int width, int height) + { + throw new UnsupportedOperationException("not implemented yet"); + } + + public void fillOval(int x, int y, + int width, int height) + { + throw new UnsupportedOperationException("not implemented yet"); + } + + public void drawArc(int x, int y, + int width, int height, + int startAngle, int arcAngle) + { + directGfx.drawArc(x+tx, y+ty, width, height, startAngle, arcAngle); + } + + public void fillArc(int x, int y, + int width, int height, + int startAngle, int arcAngle) + { + directGfx.fillArc(x+tx, y+ty, width, height, startAngle, arcAngle); + } + + public void drawPolyline(int[] xPoints, int[] yPoints, int nPoints) + { + if ((tx == 0) || (ty == 0)) + { + directGfx.drawPolyline(xPoints, yPoints, nPoints); + return; + } + + throw new UnsupportedOperationException("translate not implemented"); + } + + public void drawPolygon(int[] xPoints, int[] yPoints, int nPoints) + { + if ((tx == 0) || (ty == 0)) + { + directGfx.drawPolygon(xPoints, yPoints, nPoints); + return; + } + + throw new UnsupportedOperationException("translate not implemented"); + } + + public void fillPolygon(int[] xPoints, int[] yPoints, int nPoints) + { + if ((tx == 0) || (ty == 0)) + { + directGfx.fillPolygon(xPoints, yPoints, nPoints); + return; + } + + throw new UnsupportedOperationException("translate not implemented"); + } + + public boolean drawImage(Image image, int x, int y, + ImageObserver observer) + { + x += tx; + y += ty; + + if (image instanceof BufferedImage) + { + BufferedImage bImage = (BufferedImage) image; + Object config = + bImage.getProperty("java.awt.GraphicsConfiguration"); + + if (config == frontend.config) + return directGfx.drawImage(image, x, y, observer); + + int width = image.getWidth(null); + int height = image.getHeight(null); + + Rectangle bounds = new Rectangle(x, y, width, height); + + MappedRaster mr = directGfx.mapRaster(bounds); + + // manipulate raster here... + ColorModel colorModel = mr.getColorModel(); + WritableRaster raster = mr.getRaster(); + + int xEnd = x + width; + int yEnd = y + height; + + // FIXME: Use the following code only as a fallback. It's SLOW! + + Object rgbElem = null; + for (int yy=0; yy<height; yy++) + { + for (int xx=0; xx<width; xx++) + { + int srgb = bImage.getRGB(xx, yy); + int sa = ((srgb >>> 24) & 0xff) + 1; + int sr = ((srgb >>> 16) & 0xff) + 1; + int sg = ((srgb >>> 8) & 0xff) + 1; + int sb = (srgb & 0xff) + 1; + + rgbElem = raster.getDataElements(xx+x, yy+y, rgbElem); + int drgb = colorModel.getRGB(rgbElem); + int dr = ((drgb >>> 16) & 0xff) + 1; + int dg = ((drgb >>> 8) & 0xff) + 1; + int db = (drgb & 0xff) + 1; + int da = 256 - sa; + + dr = ((sr*sa + dr*da) >>> 8) - 1; + dg = ((sg*sa + dg*da) >>> 8) - 1; + db = ((sb*sa + db*da) >>> 8) - 1; + + drgb = (dr<<16) | (dg<<8) | db; + + rgbElem = colorModel.getDataElements(drgb, rgbElem); + + raster.setDataElements(xx+x, yy+y, rgbElem); + } + } + directGfx.unmapRaster(mr); + return true; + + } + throw new UnsupportedOperationException("drawing image " + image + + "not implemented"); + } + + + // -------- Graphics2D methods: + + public void draw(Shape shape) + { + if (shape instanceof Rectangle) + { + Rectangle rect = (Rectangle) shape; + directGfx.drawRect(rect.x+tx, rect.y+ty, rect.width, rect.height); + return; + } + + throw new UnsupportedOperationException("shape not implemented"); + } + + public void fill(Shape shape) + { + if (shape instanceof Rectangle) + { + Rectangle rect = (Rectangle) shape; + directGfx.fillRect(rect.x+tx, rect.y+ty, rect.width, rect.height); + return; + } + + throw new UnsupportedOperationException("not implemented"); + } + + public boolean hit(Rectangle rect, Shape text, + boolean onStroke) + { + throw new UnsupportedOperationException("not implemented"); + } + + public void drawString(String text, int x, int y) + { + directGfx.drawString(text, x+tx, y+ty); + } + + public void drawString(String text, float x, float y) + { + drawString(text, (int) x, (int) y); + } + + public void translate(int x, int y) + { + tx += x; + ty += y; + } + + public void translate(double tx, double ty) + { + if ((tx == 0) && (ty == 0)) + return; + + needAffineTransform(); + } + + public void rotate(double theta) + { + if (theta == 0) + return; + + needAffineTransform(); + } + + public void rotate(double theta, double x, double y) + { + if (theta == 0) + return; + + needAffineTransform(); + } + + public void scale(double scaleX, double scaleY) + { + if ((scaleX == 1) && (scaleY == 1)) + return; + + needAffineTransform(); + } + + public void shear(double shearX, double shearY) + { + if ((shearX == 0) && (shearY == 0)) + return; + + needAffineTransform(); + } + + private void needAffineTransform() + { + throw new UnsupportedOperationException("state with affine " + + "transform not implemented"); + } +} diff --git a/libjava/gnu/awt/j2d/MappedRaster.java b/libjava/gnu/awt/j2d/MappedRaster.java new file mode 100644 index 00000000000..eb41eecf9ad --- /dev/null +++ b/libjava/gnu/awt/j2d/MappedRaster.java @@ -0,0 +1,72 @@ +/* Copyright (C) 2000 Free Software Foundation + + This file is part of libgcj. + +This software is copyrighted work licensed under the terms of the +Libgcj License. Please consult the file "LIBGCJ_LICENSE" for +details. */ + +package gnu.awt.j2d; + +import java.awt.image.WritableRaster; +import java.awt.image.ColorModel; + +/* The raster and associated properties of a mapped screen region. + * The compositing capabilities of backends are often insufficient. + * The backend may not support alpha blending, or may not support some + * other special compositing rule. This means that compositing must + * sometimes be done within the rendering pipeline. The general + * compositing operation consists of combining new color and alpha + * values with existing color values on the drawing surface, to find + * the new color values for the drawing surface. The way the values + * are combined, determines what kind of compositing operation that is + * performed. The default compositing operation is alpha compositing. + * + * <p>In order to perform alpha compositing and other compositing + * operations, we need access to the color values of the imagery that + * has already been drawn on the drawing surface. The + * DirectRasterGraphics interface must therefore contain methods that + * makes it possible to gain access to the pixel values of the drawing + * surface. The methods are modeled after the POSIX mmap() and + * munmap() functions. But, instead of mapping and unmapping portions + * of data from a file descriptor to memory, the methods in + * DirectRasterGraphics maps and unmaps portions of the drawing + * surface to data arrays within writable raster objects. A call to + * mapRaster() will return a writable raster object, encapsulating the + * image data of the drawing surface in the requested domain. The data + * encapsulated by this raster object can be modified using the + * WritableRaster API, or the data buffers can be retrieved from the + * raster, so that the data arrays can be manipulated directly. When + * the raster image has been modified as desired, the data can be + * resynchronized with the drawing surface by calling mapRaster(). + * + * <p>As with mmap() and munmap() the methods may work by direct + * manipulation of shared memory, (i.e. the raster object directly + * wraps the actual image data of the drawing surface), or may make a + * private copy that is resynched when the raster is unmapped. The + * backend may choose to implement either mechanism, and the pipeline + * code should not care what mechanism is actually used. This design + * allows us to make full use of speedups such as X shared memory + * extentions when available. + */ +public class MappedRaster +{ + WritableRaster raster; + ColorModel cm; + + public MappedRaster(WritableRaster raster, ColorModel cm) + { + this.raster = raster; + this.cm = cm; + } + + public final WritableRaster getRaster() + { + return raster; + } + + public final ColorModel getColorModel() + { + return cm; + } +} |

