001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Oleg V. Khaschansky
019: * @version $Revision$
020: */package org.apache.harmony.awt.gl.linux;
021:
022: import java.awt.geom.AffineTransform;
023: import java.awt.geom.Rectangle2D;
024: import java.awt.*;
025: import java.awt.image.ColorModel;
026: import java.awt.image.BufferedImage;
027: import java.awt.image.WritableRaster;
028: import java.awt.image.AffineTransformOp;
029:
030: import org.apache.harmony.awt.gl.*;
031: import org.apache.harmony.awt.gl.render.Blitter;
032: import org.apache.harmony.awt.gl.render.JavaBlitter;
033: import org.apache.harmony.awt.gl.render.NativeImageBlitter;
034: import org.apache.harmony.awt.nativebridge.linux.X11;
035: import org.apache.harmony.awt.nativebridge.linux.X11Defs;
036:
037: import org.apache.harmony.awt.internal.nls.Messages;
038:
039: public class XBlitter implements Blitter {
040:
041: static final XBlitter inst = new XBlitter();
042:
043: public static XBlitter getInstance() {
044: return inst;
045: }
046:
047: public void blit(int srcX, int srcY, Surface srcSurf, int dstX,
048: int dstY, Surface dstSurf, int width, int height,
049: AffineTransform sysxform, AffineTransform xform,
050: Composite comp, Color bgcolor, MultiRectArea clip) {
051:
052: if (xform == null) {
053: blit(srcX, srcY, srcSurf, dstX, dstY, dstSurf, width,
054: height, sysxform, comp, bgcolor, clip);
055: } else {
056: double scaleX = xform.getScaleX();
057: double scaleY = xform.getScaleY();
058: double scaledX = dstX / scaleX;
059: double scaledY = dstY / scaleY;
060: AffineTransform at = new AffineTransform();
061: at.setToTranslation(scaledX, scaledY);
062: xform.concatenate(at);
063: sysxform.concatenate(xform);
064: blit(srcX, srcY, srcSurf, 0, 0, dstSurf, width, height,
065: sysxform, comp, bgcolor, clip);
066: }
067: }
068:
069: public void blit(int srcX, int srcY, Surface srcSurf, int dstX,
070: int dstY, Surface dstSurf, int width, int height,
071: AffineTransform sysxform, Composite comp, Color bgcolor,
072: MultiRectArea clip) {
073:
074: if (srcSurf.isNativeDrawable()) {
075: double matrix[] = null;
076: if (sysxform != null) {
077: int type = sysxform.getType();
078: switch (type) {
079:
080: case AffineTransform.TYPE_TRANSLATION:
081: dstX += sysxform.getTranslateX();
082: dstY += sysxform.getTranslateY();
083: case AffineTransform.TYPE_IDENTITY:
084: break;
085:
086: default:
087: matrix = new double[6];
088: sysxform.getMatrix(matrix);
089: Rectangle transDstBounds = JavaBlitter.getBounds2D(
090: sysxform,
091: new Rectangle(dstX, dstY, width, height))
092: .getBounds();
093: dstX = transDstBounds.x;
094: dstY = transDstBounds.y;
095:
096: Rectangle transSrcBounds = JavaBlitter.getBounds2D(
097: sysxform,
098: new Rectangle(srcX, srcY, width, height))
099: .getBounds();
100: srcX = transSrcBounds.x;
101: srcY = transSrcBounds.y;
102: width = transSrcBounds.width;
103: height = transSrcBounds.height;
104:
105: }
106:
107: }
108:
109: long dstSurfStruct = dstSurf.getSurfaceDataPtr();
110: long srcSurfStruct = srcSurf.getSurfaceDataPtr();
111: int clipRects[] = null;
112: int numVertex = 0;
113: if (clip != null) {
114: clipRects = clip.rect;
115: numVertex = clipRects[0] - 1;
116: }
117:
118: if (comp instanceof AlphaComposite) {
119: AlphaComposite ac = (AlphaComposite) comp;
120: int compType = ac.getRule();
121: float alpha = ac.getAlpha();
122:
123: if (srcSurf instanceof ImageSurface) {
124: Object data = srcSurf.getData();
125:
126: int dirtyRegions[] = ((ImageSurface) srcSurf)
127: .getDirtyRegions();
128: int regCount = 0;
129: if (dirtyRegions != null)
130: regCount = dirtyRegions[0] - 1;
131:
132: boolean hasBackground = false;
133: int bgc = 0;
134:
135: if (bgcolor != null
136: && srcSurf.getTransparency() != Transparency.OPAQUE) {
137: hasBackground = true;
138: bgc = bgcolor.getRGB();
139: }
140:
141: synchronized (data) {
142: bltImage(srcX, srcY, srcSurfStruct, srcSurf
143: .getData(), dstX, dstY, dstSurfStruct,
144: width, height, hasBackground, bgc,
145: compType, alpha, matrix, clipRects,
146: numVertex, srcSurf.invalidated(),
147: dirtyRegions, regCount);
148: }
149: srcSurf.validate();
150: } else {
151: bltPixmap(srcX, srcY, srcSurfStruct, dstX, dstY,
152: dstSurfStruct, width, height, compType,
153: alpha, matrix, clipRects, numVertex);
154: }
155: } else if (comp instanceof XORComposite) {
156: XORComposite xcomp = (XORComposite) comp;
157: if (srcSurf instanceof ImageSurface) {
158: Object data = srcSurf.getData();
159:
160: int dirtyRegions[] = ((ImageSurface) srcSurf)
161: .getDirtyRegions();
162: int regCount = 0;
163: if (dirtyRegions != null)
164: regCount = dirtyRegions[0] - 1;
165:
166: synchronized (data) {
167: xorImage(srcX, srcY, srcSurfStruct, data, dstX,
168: dstY, dstSurfStruct, width, height,
169: xcomp.getXORColor().getRGB(), matrix,
170: clipRects, numVertex, srcSurf
171: .invalidated(), dirtyRegions,
172: regCount);
173: }
174: srcSurf.validate();
175: } else {
176: xorPixmap(srcX, srcY, srcSurfStruct, dstX, dstY,
177: dstSurfStruct, width, height, xcomp
178: .getXORColor().getRGB(), matrix,
179: clipRects, numVertex);
180: }
181: } else {
182: // awt.17=Unknown Composite type : {0}
183: throw new IllegalArgumentException(Messages.getString(
184: "awt.17", //$NON-NLS-1$
185: comp.getClass()));
186: }
187: } else {
188: BufferedImage bi;
189: if (srcSurf.getTransparency() == Transparency.OPAQUE) {
190: bi = new BufferedImage(srcSurf.getWidth(), srcSurf
191: .getHeight(), BufferedImage.TYPE_INT_RGB);
192: } else {
193: bi = new BufferedImage(srcSurf.getWidth(), srcSurf
194: .getHeight(), BufferedImage.TYPE_INT_ARGB);
195: }
196: Surface tmpSurf = AwtImageBackdoorAccessor.getInstance()
197: .getImageSurface(bi);
198: JavaBlitter.getInstance().blit(0, 0, srcSurf, 0, 0,
199: tmpSurf, srcSurf.getWidth(), srcSurf.getHeight(),
200: AlphaComposite.Src, null, null);
201: blit(srcX, srcY, tmpSurf, dstX, dstY, dstSurf, width,
202: height, comp, bgcolor, clip);
203: }
204: }
205:
206: // Native methods
207:
208: public void blit(int srcX, int srcY, Surface srcSurf, int dstX,
209: int dstY, Surface dstSurf, int width, int height,
210: Composite comp, Color bgcolor, MultiRectArea clip) {
211:
212: blit(srcX, srcY, srcSurf, dstX, dstY, dstSurf, width, height,
213: null, comp, bgcolor, clip);
214: }
215:
216: private native void bltImage(int srcX, int srcY,
217: long srsSurfDataPtr, Object srcData, int dstX, int dstY,
218: long dstSurfDataPtr, int width, int height,
219: boolean hasBackground, int bgcolor, int compType,
220: float alpha, double matrix[], int clip[], int numVertex,
221: boolean invalidated, int[] dirtyRegions, int regCount);
222:
223: private native void bltPixmap(int srcX, int srcY,
224: long srsSurfDataPtr, int dstX, int dstY,
225: long dstSurfDataPtr, int width, int height, int compType,
226: float alpha, double matrix[], int clip[], int numVertex);
227:
228: private native void xorImage(int srcX, int srcY,
229: long srsSurfDataPtr, Object srcData, int dstX, int dstY,
230: long dstSurfDataPtr, int width, int height, int xorcolor,
231: double matrix[], int clip[], int numVertex,
232: boolean invalidated, int[] dirtyRegions, int regCount);
233:
234: private native void xorPixmap(int srcX, int srcY,
235: long srsSurfDataPtr, int dstX, int dstY,
236: long dstSurfDataPtr, int width, int height, int xorcolor,
237: double matrix[], int clip[], int numVertex);
238: }
|