Index: modules/awt/src/main/native/gl/unix/XGraphics2D.cpp =================================================================== --- modules/awt/src/main/native/gl/unix/XGraphics2D.cpp (revision 0) +++ modules/awt/src/main/native/gl/unix/XGraphics2D.cpp (revision 0) @@ -0,0 +1,246 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Igor V. Stolyarov + * @version $Revision$ + */ +#include +#include + +#include +#include +#include + +#include "org_apache_harmony_awt_gl_linux_XGraphics2D.h" + +JNIEXPORT jlong JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_createGC(JNIEnv *env, jobject obj, jlong display, jlong drawable, jlong valuemask, jlong values) +{ + return (jlong)XCreateGC((Display *)display, (Drawable)drawable, (unsigned long)valuemask, (XGCValues *)values); +} + +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_freeGC +(JNIEnv *env, jobject obj, jlong display, jlong gc) +{ + return (jint)XFreeGC((Display *)display, (GC)gc); +} + +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_setFunction +(JNIEnv *env, jobject obj, jlong display, jlong gc, jint function) +{ + return (jint)XSetFunction((Display *)display, (GC)gc, function); +} + +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_setForeground +(JNIEnv *env, jobject obj, jlong display, jlong gc, jlong colormap, jint argb_val) +{ + XColor *color = (XColor *)malloc(sizeof(XColor)); + color->red = (unsigned short) ((argb_val & 0x00FF0000) >> 8); + color->green = (unsigned short) (argb_val & 0x0000FF00); + color->blue = (unsigned short) ((argb_val & 0x000000FF) << 8); + + int ret = XAllocColor((Display *)display, (Colormap)colormap, color); + + if(!ret) return ret; + + ret = XSetForeground((Display *)display, (GC)gc, color->pixel); + free(color); + + return ret; +} + +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_copyArea +(JNIEnv *env, jobject obj, jlong display, jlong src, jlong dst, jlong gc, jint src_x, jint src_y, +jint width, jint height, jint dst_x, jint dst_y) +{ + return XCopyArea((Display *)display, (Drawable)src, (Drawable)dst, (GC)gc, src_x, src_y, width, height, dst_x, dst_y); +} + +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_setClipMask +(JNIEnv *env, jobject obj, jlong display, jlong gc, jlong pixmap) +{ + return XSetClipMask((Display *)display, (GC)gc, (Pixmap)pixmap); +} + +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_setClipRectangles +(JNIEnv *env, jobject obj, jlong display, jlong gc, jint clip_x_origin, jint clip_y_origin, +jintArray vertices, jint num_verts) +{ + jint *verts = NULL; + XRectangle *rects = NULL; + int num_rects = 0; + + if(num_verts > 0){ + verts = (jint *)malloc(sizeof(jint)*num_verts); + env->GetIntArrayRegion(vertices, 1, num_verts, verts); + + num_rects = num_verts >> 2; + rects = (XRectangle *)malloc(sizeof(XRectangle) * num_rects); + + for (int i = 0, j = 0; i < num_verts; i += 4, j++) { + rects[j].x = (short)verts[i]; + rects[j].y = (short)verts[i + 1]; + rects[j].width = (unsigned short)(verts[i+2]-verts[i]+1); + rects[j].height = (unsigned short)(verts[i+3]-verts[i+1]+1); + } + } + + int ret = XSetClipRectangles((Display *)display, (GC)gc, clip_x_origin, clip_y_origin, rects, num_rects, Unsorted); + if(verts) free(verts); + if(rects) free(rects); + return ret; +} + +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_drawArc +(JNIEnv *env, jobject obj, jlong display, jlong drawable, jlong gc, jint x, jint y, jint width, jint height, jint startAngle, jint angle) +{ + return XDrawArc((Display *)display, (Drawable)drawable, (GC)gc, x ,y, width, height, startAngle, angle); +} + +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_drawLine +(JNIEnv *env, jobject obj, jlong display, jlong drawable, jlong gc, jint x1, jint y1, jint x2, jint y2) +{ + return XDrawLine((Display *)display, (Drawable)drawable, (GC)gc, x1, y1, x2, y2); +} + +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_drawLines +(JNIEnv *env, jobject obj, jlong display, jlong drawable, jlong gc, jshortArray points, jint num_points) +{ + jshort *verts = (jshort *)malloc(sizeof(jshort) * num_points); + env->GetShortArrayRegion(points, 0, num_points, verts); + + int ret = XDrawLines((Display *)display, (Drawable)drawable, (GC)gc, (XPoint *)verts, num_points >> 1, CoordModeOrigin); + if(verts) free(verts); + return ret; +} + +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_drawRectangle +(JNIEnv *env, jobject obj, jlong display, jlong drawable, jlong gc, jint x, jint y, jint width, jint height) +{ + return XDrawRectangle((Display *)display, (Drawable)drawable, (GC)gc, x, y, width, height); +} + +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_fillRectangles +(JNIEnv *env, jobject obj, jlong display, jlong drawable, jlong gc, jintArray vertices, jint num_verts) +{ + jint *verts = NULL; + XRectangle *rects = NULL; + int num_rects = 0; + + if(num_verts > 0){ + verts = (jint *)malloc(sizeof(jint)*num_verts); + env->GetIntArrayRegion(vertices, 1, num_verts, verts); + + num_rects = num_verts >> 2; + rects = (XRectangle *)malloc(sizeof(XRectangle) * num_rects); + + for (int i = 0, j = 0; i < num_verts; i += 4, j++) { + rects[j].x = (short)verts[i]; + rects[j].y = (short)verts[i + 1]; + rects[j].width = (unsigned short)(verts[i+2]-verts[i]+1); + rects[j].height = (unsigned short)(verts[i+3]-verts[i+1]+1); + } + + } + int ret = XFillRectangles((Display *)display, (Drawable)drawable, (GC)gc, rects, num_rects); + if(verts) free(verts); + if(rects) free(rects); + return ret; +} + +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_fillRectangle +(JNIEnv *env, jobject obj, jlong display, jlong drawable, jlong gc, jint x, jint y, jint width, jint height) +{ + return XFillRectangle((Display *)display, (Drawable)drawable, (GC)gc, x, y, width, height); +} + +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_fillPolygon +(JNIEnv *env, jobject obj, jlong display, jlong drawable, jlong gc, jshortArray points, jint num_points) +{ + jshort *verts = (jshort *)malloc(sizeof(jshort) * num_points); + env->GetShortArrayRegion(points, 0, num_points, verts); + + int ret = XFillPolygon((Display *)display, (Drawable)drawable, (GC)gc, (XPoint *)verts, num_points >> 1, Nonconvex, CoordModeOrigin); + if(verts) free(verts); + return ret; +} + +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_fillArc +(JNIEnv *env, jobject obj, jlong display, jlong drawable, jlong gc, jint x, jint y, jint width, jint height, jint startAngle, jint angle) +{ + return XFillArc((Display *)display, (Drawable)drawable, (GC)gc, x ,y, width, height, startAngle, angle); +} + +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_setStroke +(JNIEnv *env, jobject obj, jlong display, jlong gc, jint line_width, jint join_style, jint cap_style, +jint dash_offset, jbyteArray dashes, jint len) +{ + jbyte *dash_list = NULL; + XGCValues *values = (XGCValues *)malloc(sizeof(XGCValues)); + + values->line_width = line_width; + values->join_style = join_style; + values->cap_style = cap_style; + values->dash_offset = dash_offset; + + unsigned long mask = GCLineWidth | GCJoinStyle | GCCapStyle | GCDashOffset | GCLineStyle; + if(!len){ + values->line_style = LineSolid; + } else { + dash_list = (jbyte *)malloc(len); + env->GetByteArrayRegion(dashes, 0, len, dash_list); + values->line_style = LineOnOffDash; + } + + if(len == 1){ + values->dashes = *dash_list; + mask |= GCDashList; + } + + int ret = XChangeGC((Display *)display, (GC)gc, mask, values); + + if(!ret){ + if(dash_list) free(dash_list); + } + + free(values); + + if(len > 1){ + ret = XSetDashes((Display *)display, (GC)gc, dash_offset, (char *)dash_list, len); + free(dash_list); + } + + return ret; +} + + Index: modules/awt/src/main/native/gl/unix/exports.txt =================================================================== --- modules/awt/src/main/native/gl/unix/exports.txt (revision 606692) +++ modules/awt/src/main/native/gl/unix/exports.txt (working copy) @@ -16,3 +16,19 @@ Java_org_apache_harmony_awt_gl_render_NativeImageBlitter_xor Java_org_apache_harmony_awt_gl_ImageSurface_updateCache Java_org_apache_harmony_awt_gl_Surface_initIDs +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_copyArea +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_createGC +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_drawArc +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_drawLine +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_drawLines +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_drawRectangle +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_fillArc +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_fillPolygon +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_fillRectangle +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_fillRectangles +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_freeGC +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_setClipMask +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_setClipRectangles +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_setForeground +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_setFunction +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_setStroke Index: modules/awt/src/main/native/gl/unix/include/org_apache_harmony_awt_gl_linux_XGraphics2D.h =================================================================== --- modules/awt/src/main/native/gl/unix/include/org_apache_harmony_awt_gl_linux_XGraphics2D.h (revision 0) +++ modules/awt/src/main/native/gl/unix/include/org_apache_harmony_awt_gl_linux_XGraphics2D.h (revision 0) @@ -0,0 +1,165 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @author Igor V. Stolyarov + * @version $Revision$ + */ +/* + * THE FILE HAS BEEN AUTOGENERATED BY INTEL IJH TOOL. + * Please be aware that all changes made to this file manually + * will be overwritten by the tool if it runs again. + */ + +#include + + +/* Header for class org.apache.harmony.awt.gl.linux.XGraphics2D */ + +#ifndef _ORG_APACHE_HARMONY_AWT_GL_LINUX_XGRAPHICS2D +#define _ORG_APACHE_HARMONY_AWT_GL_LINUX_XGRAPHICS2D + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Native methods */ + +/* + * Method: org.apache.harmony.awt.gl.linux.XGraphics2D.createGC(JJJJ)J + */ +JNIEXPORT jlong JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_createGC(JNIEnv *, jobject, + jlong, jlong, jlong, jlong); + +/* + * Method: org.apache.harmony.awt.gl.linux.XGraphics2D.freeGC(JJ)I + */ +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_freeGC(JNIEnv *, jobject, + jlong, jlong); + +/* + * Method: org.apache.harmony.awt.gl.linux.XGraphics2D.setFunction(JJI)I + */ +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_setFunction(JNIEnv *, jobject, + jlong, jlong, jint); + +/* + * Method: org.apache.harmony.awt.gl.linux.XGraphics2D.setForeground(JJJI)I + */ +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_setForeground(JNIEnv *, jobject, + jlong, jlong, jlong, jint); + +/* + * Method: org.apache.harmony.awt.gl.linux.XGraphics2D.copyArea(JJJJIIIIII)I + */ +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_copyArea(JNIEnv *, jobject, + jlong, jlong, jlong, jlong, jint, jint, jint, jint, jint, jint); + +/* + * Method: org.apache.harmony.awt.gl.linux.XGraphics2D.setClipMask(JJJ)I + */ +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_setClipMask(JNIEnv *, jobject, + jlong, jlong, jlong); + +/* + * Method: org.apache.harmony.awt.gl.linux.XGraphics2D.setClipRectangles(JJII[III)I + */ +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_setClipRectangles(JNIEnv *, jobject, + jlong, jlong, jint, jint, jintArray, jint); + +/* + * Method: org.apache.harmony.awt.gl.linux.XGraphics2D.drawArc(JJJIIIIII)I + */ +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_drawArc(JNIEnv *, jobject, + jlong, jlong, jlong, jint, jint, jint, jint, jint, jint); + +/* + * Method: org.apache.harmony.awt.gl.linux.XGraphics2D.drawLine(JJJIIII)I + */ +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_drawLine(JNIEnv *, jobject, + jlong, jlong, jlong, jint, jint, jint, jint); + +/* + * Method: org.apache.harmony.awt.gl.linux.XGraphics2D.drawLines(JJJ[SI)I + */ +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_drawLines(JNIEnv *, jobject, + jlong, jlong, jlong, jshortArray, jint); + +/* + * Method: org.apache.harmony.awt.gl.linux.XGraphics2D.drawRectangle(JJJIIII)I + */ +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_drawRectangle(JNIEnv *, jobject, + jlong, jlong, jlong, jint, jint, jint, jint); + +/* + * Method: org.apache.harmony.awt.gl.linux.XGraphics2D.drawPolygon(JJJ[SI)I + */ +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_drawPolygon(JNIEnv *, jobject, + jlong, jlong, jlong, jshortArray, jint); + +/* + * Method: org.apache.harmony.awt.gl.linux.XGraphics2D.fillArc(JJJIIIIII)I + */ +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_fillArc(JNIEnv *, jobject, + jlong, jlong, jlong, jint, jint, jint, jint, jint, jint); + +/* + * Method: org.apache.harmony.awt.gl.linux.XGraphics2D.fillRectangles(JJJ[II)I + */ +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_fillRectangles(JNIEnv *, jobject, + jlong, jlong, jlong, jintArray, jint); + +/* + * Method: org.apache.harmony.awt.gl.linux.XGraphics2D.fillRectangle(JJJIIII)I + */ +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_fillRectangle(JNIEnv *, jobject, + jlong, jlong, jlong, jint, jint, jint, jint); + +/* + * Method: org.apache.harmony.awt.gl.linux.XGraphics2D.fillPolygon(JJJ[SI)I + */ +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_fillPolygon(JNIEnv *, jobject, + jlong, jlong, jlong, jshortArray, jint); + +/* + * Method: org.apache.harmony.awt.gl.linux.XGraphics2D.setStroke(JJIIII[BI)I + */ +JNIEXPORT jint JNICALL +Java_org_apache_harmony_awt_gl_linux_XGraphics2D_setStroke(JNIEnv *, jobject, + jlong, jlong, jint, jint, jint, jint, jbyteArray, jint); + +#ifdef __cplusplus +} +#endif + +#endif /* _ORG_APACHE_HARMONY_AWT_GL_LINUX_XGRAPHICS2D */ Index: modules/awt/src/main/native/gl/unix/makefile =================================================================== --- modules/awt/src/main/native/gl/unix/makefile (revision 606692) +++ modules/awt/src/main/native/gl/unix/makefile (working copy) @@ -17,7 +17,7 @@ PNG_DIR=$(HY_HDK)/../depends/libs/build/png -INCLUDES += -I$(SHARED)common -I$(SHAREDSUB)/include -I$(PNG_DIR) +INCLUDES += -I$(SHARED)common -I$(SHAREDSUB)/include -I$(PNG_DIR) -I/usr/X11R6/include -I/usr/include -Iinclude BUILDFILES = \ $(SHAREDSUB)/blitter.o \ @@ -25,6 +25,7 @@ $(SHAREDSUB)/LUTTables.o \ $(SHAREDSUB)/pngdecoder.o \ $(SHAREDSUB)/SurfaceDataStructure.o \ + XGraphics2D.o \ libpng.a ifneq ($(HY_ZIP_API),true) Index: modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/XGraphics2D.java =================================================================== --- modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/XGraphics2D.java (revision 606692) +++ modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/XGraphics2D.java (working copy) @@ -62,10 +62,14 @@ boolean nativeLines = true; boolean nativePaint = true; boolean transparentColor = false; - boolean scalingTransform = false; boolean simpleComposite = true; + boolean xor_mode = false; boolean indexModel = false; + + static{ + System.loadLibrary("gl"); + } public XGraphics2D(long drawable, int tx, int ty, MultiRectArea clip) { super(tx, ty, clip); @@ -125,8 +129,8 @@ return draw; } - private static final long createGC(long display, long win) { - return x11.XCreateGC(display, win, 0, 0); + private final long createGC(long display, long win) { + return createGC(display, win, 0L, 0L); } public GraphicsConfiguration getDeviceConfiguration() { @@ -138,7 +142,7 @@ x += transform.getTranslateX(); y += transform.getTranslateY(); - x11.XCopyArea(display, drawable, drawable, gc, x, y, width, height, dx+x, dy+y); + copyArea(display, drawable, drawable, gc, x, y, width, height, dx+x, dy+y); } // Caller should free native pointer to rects after using it @@ -159,18 +163,6 @@ return x11.createXRectangle(rects); } - protected void fillMultiRectAreaColor(MultiRectArea mra) { - if (transparentColor || !simpleComposite) { - super.fillMultiRectAreaColor(mra); - } else { - int vertices[] = mra.rect; - int nRects = (vertices[0]-1) >> 2; - X11.XRectangle xRects = createXRects(vertices); - x11.XFillRectangles(display, drawable, gc, xRects, nRects); - xRects.free(); - } - } - public void setPaint(Paint paint) { if (paint == null) return; @@ -211,22 +203,8 @@ argb_val = icm.getRGB(pixel); } - short xRed = (short) ((argb_val & 0x00FF0000) >> 8); - short xGreen = (short) (argb_val & 0x0000FF00); - short xBlue = (short) ((argb_val & 0x000000FF) << 8); + setForeground(display, gc, xConfig.xcolormap, argb_val); - // Create XColor - X11.XColor xcolor = x11.createXColor(true); - xcolor.set_red(xRed); - xcolor.set_green(xGreen); - xcolor.set_blue(xBlue); - - // Allocate cmap cell - x11.XAllocColor(display, xConfig.xcolormap, xcolor); - x11.XSetForeground(display, gc, xcolor.get_pixel()); - - // Cleanup - xcolor.free(); } public void dispose() { @@ -238,11 +216,11 @@ } if (gc != 0) { - x11.XFreeGC(display, gc); + freeGC(display, gc); gc = 0; } if (imageGC != 0) { - x11.XFreeGC(display, imageGC); + freeGC(display, imageGC); imageGC = 0; } } @@ -251,15 +229,14 @@ if (mra == null) { resetXClip(gc); } else { - int nRects = mra.getRectCount(); - X11.XRectangle xrects = createXRects(mra.rect); - x11.XSetClipRectangles(display, gc, 0, 0, xrects, nRects, X11Defs.Unsorted); - xrects.free(); + int vertices[] = mra.rect; + int numVert = vertices[0] - 1; + setClipRectangles(display, gc, 0, 0, vertices, numVert); } } void resetXClip(long gc) { - x11.XSetClipMask(display, gc, X11Defs.None); + setClipMask(display, gc, X11Defs.None); } void setXftClip(MultiRectArea mra) { @@ -288,10 +265,11 @@ } void setGCFunction(int func) { - x11.XSetFunction(display, gc, func); + setFunction(display, gc, func); } + void setImageGCFunction(int func) { // Note: works with imageGC - x11.XSetFunction(display, imageGC, func); + setFunction(display, imageGC, func); } Surface getSurface() { @@ -307,52 +285,27 @@ return; } - X11.XGCValues gcVals = x11.createXGCValues(true); - gcVals.set_line_width(Math.round(bs.getLineWidth())); - gcVals.set_join_style(bs.getLineJoin()); - gcVals.set_cap_style(bs.getEndCap()+1); - gcVals.set_dash_offset(Math.round(bs.getDashPhase())); + int line_width = (int)(bs.getLineWidth() + 0.5f); + int join_style = bs.getLineJoin(); + int cap_style = bs.getEndCap()+1; + int dash_offset = (int)(bs.getDashPhase() + 0.5f); - int n = 0; + float fdashes[] = bs.getDashArray(); - if (bs.getDashArray() == null) { - gcVals.set_line_style(X11Defs.LineSolid); - gcVals.set_dashes((byte)1); - } else { - gcVals.set_line_style(X11Defs.LineOnOffDash); + int len = 0; + byte bdashes[] = null; - n = bs.getDashArray().length; + if(fdashes != null){ + len = fdashes.length; + bdashes = new byte[len]; - if (n == 1) { - gcVals.set_dashes((byte)Math.round(bs.getDashArray()[0])); - } else { - long dashList = Utils.memaccess.malloc(n); - float[] dashArray = bs.getDashArray(); - for (int i = 0; i < n; i++) { - Utils.memaccess.setByte(dashList+i, (byte) Math.round(dashArray[i])); - } - x11.XSetDashes( - display, - gc, - Math.round(bs.getDashPhase()), - dashList, - bs.getDashArray().length - ); - Utils.memaccess.free(dashList); + for(int i = 0; i < len; i++){ + bdashes[i] = (byte)(fdashes[i] + 0.5f); } } - x11.XChangeGC( - display, - gc, - X11Defs.GCLineWidth | X11Defs.GCJoinStyle | - X11Defs.GCCapStyle | X11Defs.GCDashOffset | - X11Defs.GCLineStyle | (n==1 ? X11Defs.GCDashList : 0), - gcVals - ); + setStroke(display, gc, line_width, join_style, cap_style, dash_offset, bdashes, len); - gcVals.free(); - nativeLines = true; } else { nativeLines = false; @@ -361,225 +314,480 @@ public void setTransform(AffineTransform transform) { super.setTransform(transform); + } - if ((transform.getType() & AffineTransform.TYPE_MASK_SCALE) != 0) { - scalingTransform = true; + public void drawLine(int x1, int y1, int x2, int y2) { + if ( + nativeLines && nativePaint && + !transparentColor && simpleComposite + ) { + int type = transform.getType(); + if (type < 2) { + + int tx = (int) transform.getTranslateX(); + int ty = (int) transform.getTranslateY(); + + x1 += tx; + y1 += ty; + x2 += tx; + y2 += ty; + + drawLine(display, drawable, gc, x1, y1, x2, y2); + + if (xor_mode) { + XORComposite xor = (XORComposite)composite; + Color xorcolor = xor.getXORColor(); + xSetForeground(xorcolor.getRGB()); + drawLine(display, drawable, gc, x1, y1, x2, y2); + xSetForeground(fgColor.getRGB()); + } + } else { + + float points[] = new float[]{x1, y1, x2, y2}; + transform.transform(points, 0, points, 0, 2); + + x1 = (int)points[0]; + y1 = (int)points[1]; + x2 = (int)points[2]; + y2 = (int)points[3]; + + drawLine(display, drawable, gc, x1, y1, x2, y2); + + if (xor_mode) { + XORComposite xor = (XORComposite)composite; + Color xorcolor = xor.getXORColor(); + xSetForeground(xorcolor.getRGB()); + drawLine(display, drawable, gc, x1, y1, x2, y2); + xSetForeground(fgColor.getRGB()); + } + } } else { - scalingTransform = false; + super.drawLine(x1, y1, x2, y2); } } - public void drawLine(int x1, int y1, int x2, int y2) { + @Override + public void drawPolyline(int[] xpoints, int[] ypoints, int npoints) { if ( nativeLines && nativePaint && - !scalingTransform && !transparentColor && - simpleComposite + !transparentColor && simpleComposite ) { - float points[] = new float[]{x1, y1, x2, y2}; - transform.transform(points, 0, points, 0, 2); - x11.XDrawLine( - display, - drawable, - gc, - (int) points[0], (int) points[1], - (int) points[2], (int) points[3] - ); - if (composite instanceof XORComposite) { + + short points[] = new short[npoints << 1]; + + int type = transform.getType(); + if (type < 2) { + + int tx = (int) transform.getTranslateX(); + int ty = (int) transform.getTranslateY(); + + for (int idx = 0, i = 0; i < npoints; i++){ + points[idx++] = (short)(xpoints[i] + tx); + points[idx++] = (short)(ypoints[i] + ty); + } + + drawLines(display, drawable, gc, points, points.length); + } else { + + float fpoints[] = new float[npoints << 1]; + + for (int idx = 0, i = 0; i < npoints; i++){ + fpoints[idx++] = xpoints[i]; + fpoints[idx++] = ypoints[i]; + } + + transform.transform(fpoints, 0, fpoints, 0, npoints); + for (int i = 0; i < fpoints.length; i++) + points[i] = (short)(fpoints[i] + 0.5f); + + drawLines(display, drawable, gc, points, points.length); + } + + if (xor_mode) { XORComposite xor = (XORComposite)composite; Color xorcolor = xor.getXORColor(); xSetForeground(xorcolor.getRGB()); - x11.XDrawLine( - display, - drawable, - gc, - (int) points[0], (int) points[1], - (int) points[2], (int) points[3] - ); + drawLines(display, drawable, gc, points, points.length); xSetForeground(fgColor.getRGB()); } } else { - super.drawLine(x1, y1, x2, y2); + super.drawPolyline(xpoints, ypoints, npoints); } } + @Override public void drawPolygon(int[] xpoints, int[] ypoints, int npoints) { if ( nativeLines && nativePaint && - !scalingTransform && !transparentColor && - simpleComposite + !transparentColor && simpleComposite ) { - float points[] = new float[npoints<<1]; - int i; - for (i = 0; i < npoints; i++) { - points[i<<1] = xpoints[i]; - points[(i<<1) + 1] = ypoints[i]; - } - transform.transform(points, 0, points, 0, npoints); - // Create XPoint's - long xPoints = Utils.memaccess.malloc((npoints+1) << 2); // sizeof XPoint = 4 - long ptr = xPoints; + short points[] = new short[(npoints << 1) + 2]; - for (i = 0; i < npoints; i++) { - Utils.memaccess.setShort(ptr, (short) points[i<<1]); - Utils.memaccess.setShort(ptr+2, (short) points[(i<<1)+1]); - ptr += 4; // sizeof XPoint = 4 + int type = transform.getType(); + if (type < 2) { + + int tx = (int) transform.getTranslateX(); + int ty = (int) transform.getTranslateY(); + + int idx = 0; + for (int i = 0; i < npoints; i++){ + points[idx++] = (short)(xpoints[i] + tx); + points[idx++] = (short)(ypoints[i] + ty); + } + points[idx++] = (short)(xpoints[0] + tx); + points[idx++] = (short)(ypoints[0] + ty); + + drawLines(display, drawable, gc, points, points.length); + } else { + + float fpoints[] = new float[npoints << 1]; + + for (int idx = 0, i = 0; i < npoints; i++){ + fpoints[idx++] = xpoints[i]; + fpoints[idx++] = ypoints[i]; + } + + transform.transform(fpoints, 0, fpoints, 0, npoints); + int i = 0; + for (; i < fpoints.length; i++) + points[i] = (short)(fpoints[i] + 0.5f); + points[i++] = (short)(fpoints[0] + 0.5f); + points[i++] = (short)(fpoints[1] + 0.5f); + + drawLines(display, drawable, gc, points, points.length); } - // Add first point again to close path - Utils.memaccess.setShort(ptr, (short) points[0]); - Utils.memaccess.setShort(ptr+2, (short) points[1]); - x11.XDrawLines( - display, - drawable, - gc, - xPoints, - npoints+1, - X11Defs.CoordModeOrigin - ); - - if (composite instanceof XORComposite) { + if (xor_mode) { XORComposite xor = (XORComposite)composite; Color xorcolor = xor.getXORColor(); xSetForeground(xorcolor.getRGB()); - x11.XDrawLines( - display, - drawable, - gc, - xPoints, - npoints+1, - X11Defs.CoordModeOrigin - ); + drawLines(display, drawable, gc, points, points.length); xSetForeground(fgColor.getRGB()); } - - Utils.memaccess.free(xPoints); } else { super.drawPolygon(xpoints, ypoints, npoints); } } + @Override public void drawPolygon(Polygon polygon) { drawPolygon(polygon.xpoints, polygon.ypoints, polygon.npoints); } - public void drawPolyline(int[] xpoints, int[] ypoints, int npoints) { + @Override + public void drawRect(int x, int y, int width, int height) { if ( nativeLines && nativePaint && - !scalingTransform && !transparentColor && - simpleComposite + !transparentColor && simpleComposite ) { - float points[] = new float[npoints<<1]; - for (int i = 0; i < npoints; i++) { - points[i<<1] = xpoints[i]; - points[(i<<1) + 1] = ypoints[i]; - } - transform.transform(points, 0, points, 0, npoints); + int type = transform.getType(); + if (type < 2) { + x += (int)transform.getTranslateX(); + y += (int)transform.getTranslateY(); + drawRectangle(display, drawable, gc, x, y, width, height); - // Create XPoint's - long xPoints = Utils.memaccess.malloc((npoints) << 2); // sizeof XPoint = 4 - long ptr = xPoints; + if (xor_mode) { + XORComposite xor = (XORComposite)composite; + Color xorcolor = xor.getXORColor(); + xSetForeground(xorcolor.getRGB()); + drawRectangle(display, drawable, gc, x, y, width, height); + xSetForeground(fgColor.getRGB()); + } - for (int i = 0; i < npoints; i++) { - Utils.memaccess.setShort(ptr, (short) points[i<<1]); - Utils.memaccess.setShort(ptr+2, (short) points[(i<<1)+1]); - ptr += 4; // sizeof XPoint = 4 + } else if (type < 7) { + float points[] = new float[]{x, y, x + width - 1, y + height - 1}; + transform.transform(points, 0, points, 0, 2); + + if (points[0] < points[2]){ + x = (int)points[0]; + width = (int)(points[2] - points[0]) + 1; + } else { + x = (int)points[2]; + width = (int)(points[0] - points[2]) + 1; + } + + if (points[1] < points[3]){ + y = (int)points[1]; + height = (int)(points[3] - points[1]) + 1; + } else { + y = (int)points[3]; + height = (int)(points[1] - points[3]) + 1; + } + + drawRectangle(display, drawable, gc, x, y, width, height); + + if (xor_mode) { + XORComposite xor = (XORComposite)composite; + Color xorcolor = xor.getXORColor(); + xSetForeground(xorcolor.getRGB()); + drawRectangle(display, drawable, gc, x, y, width, height); + xSetForeground(fgColor.getRGB()); + } + } else { + float fpoints[] = new float[]{x, y, x + width - 1, y, x + width - 1, y + height - 1, x, y + height - 1}; + transform.transform(fpoints, 0, fpoints, 0, 4); + + short points[] = new short[fpoints.length + 2]; + + int i = 0; + for (; i < fpoints.length; i++) + points[i] = (short)(fpoints[i] + 0.5f); + points[i++] = (short)(fpoints[0] + 0.5f); + points[i++] = (short)(fpoints[1] + 0.5f); + + drawLines(display, drawable, gc, points, points.length); + + if (xor_mode) { + XORComposite xor = (XORComposite)composite; + Color xorcolor = xor.getXORColor(); + xSetForeground(xorcolor.getRGB()); + drawLines(display, drawable, gc, points, points.length); + xSetForeground(fgColor.getRGB()); + } } + } else { + super.drawRect(x, y, width, height); + } + } - x11.XDrawLines( + @Override + public void drawArc(int x, int y, int width, int height, int sa, int ea) { + if ( + nativeLines && nativePaint && + !transparentColor && simpleComposite && + transform.getType() < 2 + ) { + x += (int)transform.getTranslateX(); + y += (int)transform.getTranslateY(); + drawArc( display, drawable, gc, - xPoints, - npoints, - X11Defs.CoordModeOrigin + x, y, + width, height, + sa << 6, ea << 6 ); - if (composite instanceof XORComposite) { + if (xor_mode) { XORComposite xor = (XORComposite)composite; Color xorcolor = xor.getXORColor(); xSetForeground(xorcolor.getRGB()); - x11.XDrawLines( + drawArc( display, drawable, gc, - xPoints, - npoints, - X11Defs.CoordModeOrigin + x, y, + width, height, + sa << 6, ea << 6 ); xSetForeground(fgColor.getRGB()); } + } else { + super.drawArc(x, y, width, height, sa, ea); + } + } - Utils.memaccess.free(xPoints); + @Override + public void drawOval(int x, int y, int width, int height) { + drawArc(x, y, width, height, 0, 360); + } + + @Override + public void fillRect(int x, int y, int width, int height) { + if ( + nativeLines && nativePaint && + !transparentColor && simpleComposite + ) { + int type = transform.getType(); + if (type < 2) { + + x += (int)transform.getTranslateX(); + y += (int)transform.getTranslateY(); + fillRectangle(display, drawable, gc, x, y, width, height); + + if (xor_mode) { + XORComposite xor = (XORComposite)composite; + Color xorcolor = xor.getXORColor(); + xSetForeground(xorcolor.getRGB()); + fillRectangle(display, drawable, gc, x, y, width, height); + xSetForeground(fgColor.getRGB()); + } + + } else if (type < 7) { + float points[] = new float[]{x, y, x + width - 1, y + height - 1}; + transform.transform(points, 0, points, 0, 2); + + if (points[0] < points[2]){ + x = (int)points[0]; + width = (int)(points[2] - points[0]) + 1; + } else { + x = (int)points[2]; + width = (int)(points[0] - points[2]) + 1; + } + + if (points[1] < points[3]){ + y = (int)points[1]; + height = (int)(points[3] - points[1]) + 1; + } else { + y = (int)points[3]; + height = (int)(points[1] - points[3]) + 1; + } + + fillRectangle(display, drawable, gc, x, y, width, height); + + if (xor_mode) { + XORComposite xor = (XORComposite)composite; + Color xorcolor = xor.getXORColor(); + xSetForeground(xorcolor.getRGB()); + fillRectangle(display, drawable, gc, x, y, width, height); + xSetForeground(fgColor.getRGB()); + } + } else { + float points[] = new float[]{x, y, x + width - 1, y, x + width - 1, y + height - 1, x, y + height - 1}; + transform.transform(points, 0, points, 0, 4); + + short spoints[] = new short[points.length]; + for (int i = 0; i < points.length; i++) + spoints[i] = (short)(points[i] + 0.5f); + fillPolygon(display, drawable, gc, spoints, spoints.length); + + if (xor_mode) { + XORComposite xor = (XORComposite)composite; + Color xorcolor = xor.getXORColor(); + xSetForeground(xorcolor.getRGB()); + fillPolygon(display, drawable, gc, spoints, spoints.length); + xSetForeground(fgColor.getRGB()); + } + } } else { - super.drawPolyline(xpoints, ypoints, npoints); + super.fill(new Rectangle(x, y, width, height)); } } - public void drawRect(int x, int y, int width, int height) { + protected void fillMultiRectAreaColor(MultiRectArea mra) { if ( + nativeLines && nativePaint && + !transparentColor && simpleComposite + ) { + int vertices[] = mra.rect; + int numVert = vertices[0] - 1; + fillRectangles(display, drawable, gc, vertices, numVert); + + if (xor_mode) { + XORComposite xor = (XORComposite)composite; + Color xorcolor = xor.getXORColor(); + xSetForeground(xorcolor.getRGB()); + fillRectangles(display, drawable, gc, vertices, numVert); + xSetForeground(fgColor.getRGB()); + } + } else { + super.fillMultiRectAreaColor(mra); + } + } + + @Override + public void fillPolygon(Polygon p) { + fillPolygon(p.xpoints, p.ypoints, p.npoints); + } + + @Override + public void fillPolygon(int[] xpoints, int[] ypoints, int npoints ) { + if ( nativeLines && nativePaint && - !transparentColor && simpleComposite && - (transform.getType() & AffineTransform.TYPE_TRANSLATION) != 0 + !transparentColor && simpleComposite ) { - Point2D rectOrig = new Point2D.Float(x, y); - transform.transform(rectOrig, rectOrig); - x11.XDrawRectangle( - display, - drawable, - gc, - (int) rectOrig.getX(), (int) rectOrig.getY(), - width, height - ); + + short points[] = new short[npoints << 1]; + + int type = transform.getType(); + if (type < 2) { + + int tx = (int) transform.getTranslateX(); + int ty = (int) transform.getTranslateY(); + + for (int idx = 0, i = 0; i < npoints; i++){ + points[idx++] = (short)(xpoints[i] + tx); + points[idx++] = (short)(ypoints[i] + ty); + } + + fillPolygon(display, drawable, gc, points, points.length); + } else { + + float fpoints[] = new float[npoints << 1]; + + for (int idx = 0, i = 0; i < npoints; i++){ + fpoints[idx++] = xpoints[i]; + fpoints[idx++] = ypoints[i]; + + } + transform.transform(fpoints, 0, fpoints, 0, npoints); + + for (int i = 0; i < fpoints.length; i++) + points[i] = (short)(fpoints[i] + 0.5f); + + fillPolygon(display, drawable, gc, points, points.length); + } + + if (xor_mode) { + XORComposite xor = (XORComposite)composite; + Color xorcolor = xor.getXORColor(); + xSetForeground(xorcolor.getRGB()); + fillPolygon(display, drawable, gc, points, points.length); + xSetForeground(fgColor.getRGB()); + } } else { - super.drawRect(x, y, width, height); + super.fillPolygon(xpoints, ypoints, npoints); } } - public void drawArc(int x, int y, int width, int height, int sa, int ea) { + @Override + public void fillArc(int x, int y, int width, int height, int sa, int ea) { if ( nativeLines && nativePaint && - !scalingTransform && !transparentColor && - simpleComposite + !transparentColor && simpleComposite && + transform.getType() < 2 ) { - Point2D orig = new Point2D.Float(x, y); - transform.transform(orig, orig); - x11.XDrawArc( + x += (int)transform.getTranslateX(); + y += (int)transform.getTranslateY(); + fillArc( display, drawable, gc, - (int) orig.getX(), (int) orig.getY(), + x, y, width, height, sa << 6, ea << 6 ); - if (composite instanceof XORComposite) { + if (xor_mode) { XORComposite xor = (XORComposite)composite; Color xorcolor = xor.getXORColor(); xSetForeground(xorcolor.getRGB()); - x11.XDrawArc( + fillArc( display, drawable, gc, - (int) orig.getX(), (int) orig.getY(), + x, y, width, height, sa << 6, ea << 6 ); xSetForeground(fgColor.getRGB()); } } else { - super.drawArc(x, y, width, height, sa, ea); + super.fillArc(x, y, width, height, sa, ea); } } - public void drawOval(int x, int y, int width, int height) { - drawArc(x, y, width, height, 0, 360); + @Override + public void fillOval(int x, int y, int width, int height) { + fillArc(x, y, width, height, 0, 360); } @Override public void setXORMode(Color color) { super.setXORMode(color); - x11.XSetFunction(display, gc, X11Defs.GXxor); + setFunction(display, gc, X11Defs.GXxor); + xor_mode = true; simpleComposite = true; } @@ -590,6 +798,7 @@ public void setComposite(Composite composite) { super.setComposite(composite); + xor_mode = false; if (composite instanceof AlphaComposite) { AlphaComposite acomp = (AlphaComposite) composite; int rule = acomp.getRule(); @@ -598,26 +807,26 @@ switch(rule){ case AlphaComposite.CLEAR: case AlphaComposite.SRC_OUT: - x11.XSetFunction(display, gc, X11Defs.GXclear); + setFunction(display, gc, X11Defs.GXclear); simpleComposite = true; break; case AlphaComposite.SRC: case AlphaComposite.SRC_IN: - if(srca == 0.0f) x11.XSetFunction(display, gc, X11Defs.GXclear); - else x11.XSetFunction(display, gc, X11Defs.GXcopy); + if(srca == 0.0f) setFunction(display, gc, X11Defs.GXclear); + else setFunction(display, gc, X11Defs.GXcopy); simpleComposite = true; break; case AlphaComposite.DST: case AlphaComposite.DST_OVER: - x11.XSetFunction(display, gc, X11Defs.GXnoop); + setFunction(display, gc, X11Defs.GXnoop); simpleComposite = true; break; case AlphaComposite.SRC_ATOP: case AlphaComposite.SRC_OVER: - x11.XSetFunction(display, gc, X11Defs.GXcopy); + setFunction(display, gc, X11Defs.GXcopy); if(srca == 1.0f){ simpleComposite = true; }else{ @@ -628,9 +837,9 @@ case AlphaComposite.DST_IN: case AlphaComposite.DST_ATOP: if(srca != 0.0f){ - x11.XSetFunction(display, gc, X11Defs.GXnoop); + setFunction(display, gc, X11Defs.GXnoop); } else { - x11.XSetFunction(display, gc, X11Defs.GXclear); + setFunction(display, gc, X11Defs.GXclear); } simpleComposite = true; break; @@ -638,9 +847,9 @@ case AlphaComposite.DST_OUT: case AlphaComposite.XOR: if(srca != 1.0f){ - x11.XSetFunction(display, gc, X11Defs.GXnoop); + setFunction(display, gc, X11Defs.GXnoop); } else { - x11.XSetFunction(display, gc, X11Defs.GXclear); + setFunction(display, gc, X11Defs.GXclear); } simpleComposite = true; break; @@ -706,4 +915,41 @@ this.fill(sh); } + + // Native methods + + // GC methods + // Creating and Releasing + private native long createGC(long display, long drawable, long valuemask, long values); + private native int freeGC(long display, long gc); + + // Setting GC function + private native int setFunction(long display, long gc, int func); + + // Stroke (line attributes) + private native int setStroke(long display, long gc, int line_width, int join_style, int cap_style, int dash_offset, byte dashes[], int len); + + // Foreground + private native int setForeground(long display, long gc, long colormap, int argb_val); + + // Clipping + private native int setClipMask(long display, long gc, long pixmap); + private native int setClipRectangles(long display, long gc, int clip_x_origin, int clip_y_origin, int clip_rects[], int num_rects); + + // Drawing methods + + private native int drawArc(long display, long drawable, long gc, int x, int y, int width, int height, int startAngle, int angle); + private native int drawLine(long display, long drawable, long gc, int x1, int y1, int x2, int y2); + private native int drawLines(long display, long drawable, long gc, short points[], int numPoints); + private native int drawRectangle(long display, long drawable, long gc, int x, int y, int width, int height); + + // Filling methods + + private native int fillRectangles(long display, long drawable, long gc, int vertices[], int numVert); + private native int fillRectangle(long display, long drawable, long gc, int x, int y, int width, int height); + private native int fillPolygon(long display, long drawable, long gc, short points[], int numPoints); + private native int fillArc(long display, long drawable, long gc, int x, int y, int width, int height, int startAngle, int angle); + + private native int copyArea(long display, long src, long dst, long gc, int src_x, int src_y, int width, int height, int dst_x, int dst_y); + }