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 Igor V. Stolyarov
019: * @version $Revision$
020: * Created on 10.01.2006
021: *
022: */package org.apache.harmony.awt.gl.windows;
023:
024: import java.awt.AlphaComposite;
025: import java.awt.Color;
026: import java.awt.Composite;
027: import java.awt.Transparency;
028: import java.awt.geom.AffineTransform;
029: import java.awt.image.BufferedImage;
030:
031: import org.apache.harmony.awt.gl.AwtImageBackdoorAccessor;
032: import org.apache.harmony.awt.gl.MultiRectArea;
033: import org.apache.harmony.awt.gl.ImageSurface;
034: import org.apache.harmony.awt.gl.Surface;
035: import org.apache.harmony.awt.gl.XORComposite;
036: import org.apache.harmony.awt.gl.render.Blitter;
037: import org.apache.harmony.awt.gl.render.JavaBlitter;
038: import org.apache.harmony.awt.internal.nls.Messages;
039:
040: public class GDIBlitter implements Blitter {
041:
042: final static GDIBlitter inst = new GDIBlitter();
043:
044: public static GDIBlitter getInstance() {
045: return inst;
046: }
047:
048: public void blit(int srcX, int srcY, Surface srcSurf, int dstX,
049: int dstY, Surface dstSurf, int width, int height,
050: AffineTransform sysxform, AffineTransform xform,
051: Composite comp, Color bgcolor, MultiRectArea clip) {
052:
053: if (xform == null) {
054: blit(srcX, srcY, srcSurf, dstX, dstY, dstSurf, width,
055: height, sysxform, comp, bgcolor, clip);
056: } else {
057: double scaleX = xform.getScaleX();
058: double scaleY = xform.getScaleY();
059: double scaledX = dstX / scaleX;
060: double scaledY = dstY / scaleY;
061: AffineTransform at = new AffineTransform();
062: at.setToTranslation(scaledX, scaledY);
063: xform.concatenate(at);
064: sysxform.concatenate(xform);
065: blit(srcX, srcY, srcSurf, 0, 0, dstSurf, width, height,
066: sysxform, comp, bgcolor, clip);
067: }
068: }
069:
070: public void blit(int srcX, int srcY, Surface srcSurf, int dstX,
071: int dstY, Surface dstSurf, int width, int height,
072: AffineTransform sysxform, Composite comp, Color bgcolor,
073: MultiRectArea clip) {
074:
075: if (srcSurf.isNativeDrawable()) {
076: double matrix[] = null;
077: if (sysxform != null) {
078: int type = sysxform.getType();
079: switch (type) {
080: case AffineTransform.TYPE_TRANSLATION:
081: dstX += sysxform.getTranslateX();
082: dstY += sysxform.getTranslateY();
083: case AffineTransform.TYPE_IDENTITY:
084: break;
085: default:
086: matrix = new double[6];
087: sysxform.getMatrix(matrix);
088: }
089: }
090: long dstSurfStruct = dstSurf.getSurfaceDataPtr();
091: long srcSurfStruct = srcSurf.getSurfaceDataPtr();
092: int clipRects[] = null;
093: int numVertex = 0;
094: if (clip != null) {
095: clipRects = clip.rect;
096: numVertex = clipRects[0] - 1;
097: }
098:
099: if (comp instanceof AlphaComposite) {
100: AlphaComposite ac = (AlphaComposite) comp;
101: int compType = ac.getRule();
102: float alpha = ac.getAlpha();
103: if (srcSurf instanceof ImageSurface) {
104: Object data = srcSurf.getData();
105:
106: int dirtyRegions[] = ((ImageSurface) srcSurf)
107: .getDirtyRegions();
108: int regCount = 0;
109: if (dirtyRegions != null)
110: regCount = dirtyRegions[0] - 1;
111:
112: synchronized (data) {
113: if (bgcolor == null
114: || srcSurf.getTransparency() == Transparency.OPAQUE) {
115: bltImage(srcX, srcY, srcSurfStruct, srcSurf
116: .getData(), dstX, dstY,
117: dstSurfStruct, width, height,
118: compType, alpha, matrix, clipRects,
119: numVertex, srcSurf.invalidated(),
120: dirtyRegions, regCount);
121: } else {
122: bltBGImage(srcX, srcY, srcSurfStruct,
123: srcSurf.getData(), dstX, dstY,
124: dstSurfStruct, width, height,
125: bgcolor.getRGB(), compType, alpha,
126: matrix, clipRects, numVertex,
127: srcSurf.invalidated(),
128: dirtyRegions, regCount);
129: }
130: }
131: srcSurf.validate();
132: } else {
133: bltBitmap(srcX, srcY, srcSurfStruct, dstX, dstY,
134: dstSurfStruct, width, height, compType,
135: alpha, matrix, clipRects, numVertex);
136: }
137: } else if (comp instanceof XORComposite) {
138: XORComposite xcomp = (XORComposite) comp;
139: if (srcSurf instanceof ImageSurface) {
140: Object data = srcSurf.getData();
141:
142: int dirtyRegions[] = ((ImageSurface) srcSurf)
143: .getDirtyRegions();
144: int regCount = 0;
145: if (dirtyRegions != null)
146: regCount = dirtyRegions[0] - 1;
147:
148: synchronized (data) {
149: xorImage(srcX, srcY, srcSurfStruct, data, dstX,
150: dstY, dstSurfStruct, width, height,
151: xcomp.getXORColor().getRGB(), matrix,
152: clipRects, numVertex, srcSurf
153: .invalidated(), dirtyRegions,
154: regCount);
155: }
156: srcSurf.validate();
157: } else {
158: xorBitmap(srcX, srcY, srcSurfStruct, dstX, dstY,
159: dstSurfStruct, width, height, xcomp
160: .getXORColor().getRGB(), matrix,
161: clipRects, numVertex);
162: }
163: } else {
164: // awt.17=Unknown Composite type : {0}
165: throw new IllegalArgumentException(Messages.getString(
166: "awt.17", //$NON-NLS-1$
167: comp.getClass()));
168: }
169: } else {
170: BufferedImage bi;
171: if (srcSurf.getTransparency() == Transparency.OPAQUE) {
172: bi = new BufferedImage(srcSurf.getWidth(), srcSurf
173: .getHeight(), BufferedImage.TYPE_INT_RGB);
174: } else {
175: bi = new BufferedImage(srcSurf.getWidth(), srcSurf
176: .getHeight(), BufferedImage.TYPE_INT_ARGB);
177: }
178: Surface tmpSurf = AwtImageBackdoorAccessor.getInstance()
179: .getImageSurface(bi);
180: JavaBlitter.getInstance().blit(0, 0, srcSurf, 0, 0,
181: tmpSurf, srcSurf.getWidth(), srcSurf.getHeight(),
182: AlphaComposite.Src, null, null);
183: blit(srcX, srcY, tmpSurf, dstX, dstY, dstSurf, width,
184: height, sysxform, comp, bgcolor, clip);
185: }
186: }
187:
188: public void blit(int srcX, int srcY, Surface srcSurf, int dstX,
189: int dstY, Surface dstSurf, int width, int height,
190: Composite comp, Color bgcolor, MultiRectArea clip) {
191:
192: blit(srcX, srcY, srcSurf, dstX, dstY, dstSurf, width, height,
193: null, comp, bgcolor, clip);
194: }
195:
196: private native void bltBGImage(int srcX, int srcY,
197: long srsSurfDataPtr, Object srcData, int dstX, int dstY,
198: long dstSurfDataPtr, int width, int height, int bgcolor,
199: int compType, float alpha, double matrix[], int clip[],
200: int numVertex, boolean invalidated, int[] dirtyRegions,
201: int regCount);
202:
203: private native void bltImage(int srcX, int srcY,
204: long srsSurfDataPtr, Object srcData, int dstX, int dstY,
205: long dstSurfDataPtr, int width, int height, int compType,
206: float alpha, double matrix[], int clip[], int numVertex,
207: boolean invalidated, int[] dirtyRegions, int regCount);
208:
209: private native void bltBitmap(int srcX, int srcY,
210: long srsSurfDataPtr, int dstX, int dstY,
211: long dstSurfDataPtr, int width, int height, int compType,
212: float alpha, double matrix[], int clip[], int numVertex);
213:
214: private native void xorImage(int srcX, int srcY,
215: long srsSurfDataPtr, Object srcData, int dstX, int dstY,
216: long dstSurfDataPtr, int width, int height, int xorcolor,
217: double matrix[], int clip[], int numVertex,
218: boolean invalidated, int[] dirtyRegions, int regCount);
219:
220: private native void xorBitmap(int srcX, int srcY,
221: long srsSurfDataPtr, int dstX, int dstY,
222: long dstSurfDataPtr, int width, int height, int xorcolor,
223: double matrix[], int clip[], int numVertex);
224: }
|