4632N/A/*
4632N/A * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
4632N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4632N/A *
4632N/A * This code is free software; you can redistribute it and/or modify it
4632N/A * under the terms of the GNU General Public License version 2 only, as
4632N/A * published by the Free Software Foundation. Oracle designates this
4632N/A * particular file as subject to the "Classpath" exception as provided
4632N/A * by Oracle in the LICENSE file that accompanied this code.
4632N/A *
4632N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4632N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4632N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4632N/A * version 2 for more details (a copy is included in the LICENSE file that
4632N/A * accompanied this code).
4632N/A *
4632N/A * You should have received a copy of the GNU General Public License version
4632N/A * 2 along with this work; if not, write to the Free Software Foundation,
4632N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4632N/A *
4632N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4632N/A * or visit www.oracle.com if you need additional information or have any
4632N/A * questions.
4632N/A */
4632N/A
4632N/Apackage sun.java2d;
4632N/A
4632N/Aimport java.awt.*;
4632N/Aimport java.awt.geom.*;
4632N/Aimport java.awt.image.*;
4632N/Aimport java.nio.*;
4632N/A
4632N/Aimport sun.awt.image.*;
4632N/Aimport sun.java2d.loops.*;
4632N/Aimport sun.java2d.pipe.*;
4632N/Aimport sun.lwawt.macosx.*;
4632N/A
4632N/Apublic class CRenderer implements PixelDrawPipe, PixelFillPipe, ShapeDrawPipe, DrawImagePipe {
4632N/A native static void init();
4632N/A
4632N/A // cache of the runtime options
4632N/A static {
4632N/A init(); // initialize coordinate tables for shapes
4632N/A }
4632N/A
4632N/A native void doLine(SurfaceData sData, float x1, float y1, float x2, float y2);
4632N/A
4632N/A public void drawLine(SunGraphics2D sg2d, int x1, int y1, int x2, int y2) {
4632N/A drawLine(sg2d, (float) x1, (float) y1, (float) x2, (float) y2);
4632N/A }
4632N/A
4632N/A Line2D lineToShape;
4632N/A
4632N/A public void drawLine(SunGraphics2D sg2d, float x1, float y1, float x2, float y2) {
4632N/A OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
4632N/A if ((sg2d.strokeState != SunGraphics2D.STROKE_CUSTOM) && (OSXSurfaceData.IsSimpleColor(sg2d.paint))) {
4632N/A surfaceData.doLine(this, sg2d, x1, y1, x2, y2);
4632N/A } else {
4632N/A if (lineToShape == null) {
4632N/A synchronized (this) {
4632N/A if (lineToShape == null) {
4632N/A lineToShape = new Line2D.Float();
4632N/A }
4632N/A }
4632N/A }
4632N/A synchronized (lineToShape) {
4632N/A lineToShape.setLine(x1, y1, x2, y2);
4632N/A drawfillShape(sg2d, sg2d.stroke.createStrokedShape(lineToShape), true, true);
4632N/A }
4632N/A }
4632N/A }
4632N/A
4632N/A native void doRect(SurfaceData sData, float x, float y, float width, float height, boolean isfill);
4632N/A
4632N/A public void drawRect(SunGraphics2D sg2d, int x, int y, int width, int height) {
4632N/A drawRect(sg2d, (float) x, (float) y, (float) width, (float) height);
4632N/A }
4632N/A
4632N/A Rectangle2D rectToShape;
4632N/A
4632N/A public void drawRect(SunGraphics2D sg2d, float x, float y, float width, float height) {
4632N/A if ((width < 0) || (height < 0)) return;
4632N/A
4632N/A OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
4632N/A if ((sg2d.strokeState != SunGraphics2D.STROKE_CUSTOM) && (OSXSurfaceData.IsSimpleColor(sg2d.paint))) {
4632N/A surfaceData.doRect(this, sg2d, x, y, width, height, false);
4632N/A } else {
4632N/A if (rectToShape == null) {
4632N/A synchronized (this) {
4632N/A if (rectToShape == null) {
4632N/A rectToShape = new Rectangle2D.Float();
4632N/A }
4632N/A }
4632N/A }
4632N/A synchronized (rectToShape) {
4632N/A rectToShape.setRect(x, y, width, height);
4632N/A drawfillShape(sg2d, sg2d.stroke.createStrokedShape(rectToShape), true, true);
4632N/A }
4632N/A }
4632N/A }
4632N/A
4632N/A public void fillRect(SunGraphics2D sg2d, int x, int y, int width, int height) {
4632N/A fillRect(sg2d, (float) x, (float) y, (float) width, (float) height);
4632N/A }
4632N/A
4632N/A public void fillRect(SunGraphics2D sg2d, float x, float y, float width, float height) {
4632N/A if ((width >= 0) && (height >= 0)) {
4632N/A OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
4632N/A surfaceData.doRect(this, sg2d, x, y, width, height, true);
4632N/A }
4632N/A }
4632N/A
4632N/A native void doRoundRect(SurfaceData sData, float x, float y, float width, float height, float arcW, float arcH, boolean isfill);
4632N/A
4632N/A public void drawRoundRect(SunGraphics2D sg2d, int x, int y, int width, int height, int arcWidth, int arcHeight) {
4632N/A drawRoundRect(sg2d, (float) x, (float) y, (float) width, (float) height, (float) arcWidth, (float) arcHeight);
4632N/A }
4632N/A
4632N/A RoundRectangle2D roundrectToShape;
4632N/A
4632N/A public void drawRoundRect(SunGraphics2D sg2d, float x, float y, float width, float height, float arcWidth, float arcHeight) {
4632N/A if ((width < 0) || (height < 0)) return;
4632N/A
4632N/A OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
4632N/A if ((sg2d.strokeState != SunGraphics2D.STROKE_CUSTOM) && (OSXSurfaceData.IsSimpleColor(sg2d.paint))) {
4632N/A surfaceData.doRoundRect(this, sg2d, x, y, width, height, arcWidth, arcHeight, false);
4632N/A } else {
4632N/A if (roundrectToShape == null) {
4632N/A synchronized (this) {
4632N/A if (roundrectToShape == null) {
4632N/A roundrectToShape = new RoundRectangle2D.Float();
4632N/A }
4632N/A }
4632N/A }
4632N/A synchronized (roundrectToShape) {
4632N/A roundrectToShape.setRoundRect(x, y, width, height, arcWidth, arcHeight);
4632N/A drawfillShape(sg2d, sg2d.stroke.createStrokedShape(roundrectToShape), true, true);
4632N/A }
4632N/A }
4632N/A }
4632N/A
4632N/A public void fillRoundRect(SunGraphics2D sg2d, int x, int y, int width, int height, int arcWidth, int arcHeight) {
4632N/A fillRoundRect(sg2d, (float) x, (float) y, (float) width, (float) height, (float) arcWidth, (float) arcHeight);
4632N/A }
4632N/A
4632N/A public void fillRoundRect(SunGraphics2D sg2d, float x, float y, float width, float height, float arcWidth, float arcHeight) {
4632N/A if ((width < 0) || (height < 0)) return;
4632N/A OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
4632N/A surfaceData.doRoundRect(this, sg2d, x, y, width, height, arcWidth, arcHeight, true);
4632N/A }
4632N/A
4632N/A native void doOval(SurfaceData sData, float x, float y, float width, float height, boolean isfill);
4632N/A
4632N/A public void drawOval(SunGraphics2D sg2d, int x, int y, int width, int height) {
4632N/A drawOval(sg2d, (float) x, (float) y, (float) width, (float) height);
4632N/A }
4632N/A
4632N/A Ellipse2D ovalToShape;
4632N/A
4632N/A public void drawOval(SunGraphics2D sg2d, float x, float y, float width, float height) {
4632N/A if ((width < 0) || (height < 0)) return;
4632N/A
4632N/A OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
4632N/A if ((sg2d.strokeState != SunGraphics2D.STROKE_CUSTOM) && (OSXSurfaceData.IsSimpleColor(sg2d.paint))) {
4632N/A surfaceData.doOval(this, sg2d, x, y, width, height, false);
4632N/A } else {
4632N/A if (ovalToShape == null) {
4632N/A synchronized (this) {
4632N/A if (ovalToShape == null) {
4632N/A ovalToShape = new Ellipse2D.Float();
4632N/A }
4632N/A }
4632N/A }
4632N/A synchronized (ovalToShape) {
4632N/A ovalToShape.setFrame(x, y, width, height);
4632N/A drawfillShape(sg2d, sg2d.stroke.createStrokedShape(ovalToShape), true, true);
4632N/A }
4632N/A }
4632N/A }
4632N/A
4632N/A public void fillOval(SunGraphics2D sg2d, int x, int y, int width, int height) {
4632N/A fillOval(sg2d, (float) x, (float) y, (float) width, (float) height);
4632N/A }
4632N/A
4632N/A public void fillOval(SunGraphics2D sg2d, float x, float y, float width, float height) {
4632N/A if ((width < 0) || (height < 0)) return;
4632N/A OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
4632N/A surfaceData.doOval(this, sg2d, x, y, width, height, true);
4632N/A }
4632N/A
4632N/A native void doArc(SurfaceData sData, float x, float y, float width, float height, float angleStart, float angleExtent, int type, boolean isfill);
4632N/A
4632N/A public void drawArc(SunGraphics2D sg2d, int x, int y, int width, int height, int startAngle, int arcAngle) {
4632N/A drawArc(sg2d, x, y, width, height, startAngle, arcAngle, Arc2D.OPEN);
4632N/A }
4632N/A
4632N/A Arc2D arcToShape;
4632N/A
4632N/A public void drawArc(SunGraphics2D sg2d, float x, float y, float width, float height, float startAngle, float arcAngle, int type) {
4632N/A if ((width < 0) || (height < 0)) return;
4632N/A
4632N/A OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
4632N/A if ((sg2d.strokeState != SunGraphics2D.STROKE_CUSTOM) && (OSXSurfaceData.IsSimpleColor(sg2d.paint))) {
4632N/A surfaceData.doArc(this, sg2d, x, y, width, height, startAngle, arcAngle, type, false);
4632N/A } else {
4632N/A if (arcToShape == null) {
4632N/A synchronized (this) {
4632N/A if (arcToShape == null) {
4632N/A arcToShape = new Arc2D.Float();
4632N/A }
4632N/A }
4632N/A }
4632N/A synchronized (arcToShape) {
4632N/A arcToShape.setArc(x, y, width, height, startAngle, arcAngle, type);
4632N/A drawfillShape(sg2d, sg2d.stroke.createStrokedShape(arcToShape), true, true);
4632N/A }
4632N/A }
4632N/A }
4632N/A
4632N/A public void fillArc(SunGraphics2D sg2d, int x, int y, int width, int height, int startAngle, int arcAngle) {
4632N/A fillArc(sg2d, x, y, width, height, startAngle, arcAngle, Arc2D.PIE);
4632N/A }
4632N/A
4632N/A public void fillArc(SunGraphics2D sg2d, float x, float y, float width, float height, float startAngle, float arcAngle, int type) {
4632N/A if ((width < 0) || (height < 0)) return;
4632N/A
4632N/A OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
4632N/A surfaceData.doArc(this, sg2d, x, y, width, height, startAngle, arcAngle, type, true);
4632N/A }
4632N/A
4632N/A native void doPoly(SurfaceData sData, int[] xpoints, int[] ypoints, int npoints, boolean ispolygon, boolean isfill);
4632N/A
4632N/A public void drawPolyline(SunGraphics2D sg2d, int xpoints[], int ypoints[], int npoints) {
4632N/A OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
4632N/A if ((sg2d.strokeState != SunGraphics2D.STROKE_CUSTOM) && (OSXSurfaceData.IsSimpleColor(sg2d.paint))) {
4632N/A surfaceData.doPolygon(this, sg2d, xpoints, ypoints, npoints, false, false);
4632N/A } else {
4632N/A GeneralPath polyToShape = new GeneralPath();
4632N/A polyToShape.moveTo(xpoints[0], ypoints[0]);
4632N/A for (int i = 1; i < npoints; i++) {
4632N/A polyToShape.lineTo(xpoints[i], ypoints[i]);
4632N/A }
4632N/A drawfillShape(sg2d, sg2d.stroke.createStrokedShape(polyToShape), true, true);
4632N/A }
4632N/A }
4632N/A
4632N/A public void drawPolygon(SunGraphics2D sg2d, int xpoints[], int ypoints[], int npoints) {
4632N/A OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
4632N/A if ((sg2d.strokeState != SunGraphics2D.STROKE_CUSTOM) && (OSXSurfaceData.IsSimpleColor(sg2d.paint))) {
4632N/A surfaceData.doPolygon(this, sg2d, xpoints, ypoints, npoints, true, false);
4632N/A } else {
4632N/A GeneralPath polyToShape = new GeneralPath();
4632N/A polyToShape.moveTo(xpoints[0], ypoints[0]);
4632N/A for (int i = 1; i < npoints; i++) {
4632N/A polyToShape.lineTo(xpoints[i], ypoints[i]);
4632N/A }
4632N/A polyToShape.lineTo(xpoints[0], ypoints[0]);
4632N/A drawfillShape(sg2d, sg2d.stroke.createStrokedShape(polyToShape), true, true);
4632N/A }
4632N/A }
4632N/A
4632N/A public void fillPolygon(SunGraphics2D sg2d, int xpoints[], int ypoints[], int npoints) {
4632N/A OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
4632N/A surfaceData.doPolygon(this, sg2d, xpoints, ypoints, npoints, true, true);
4632N/A }
4632N/A
4632N/A native void doShape(SurfaceData sData, int length, FloatBuffer coordinates, IntBuffer types, int windingRule, boolean isfill, boolean shouldApplyOffset);
4632N/A
4632N/A void drawfillShape(SunGraphics2D sg2d, Shape s, boolean isfill, boolean shouldApplyOffset) {
4632N/A if (s == null) { throw new NullPointerException(); }
4632N/A
4632N/A OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
4632N/A // TODO:
4632N/A boolean sOptimizeShapes = true;
4632N/A if (sOptimizeShapes && OSXSurfaceData.IsSimpleColor(sg2d.paint)) {
4632N/A if (s instanceof Rectangle2D) {
4632N/A Rectangle2D rectangle = (Rectangle2D) s;
4632N/A
4632N/A float x = (float) rectangle.getX();
4632N/A float y = (float) rectangle.getY();
4632N/A float w = (float) rectangle.getWidth();
4632N/A float h = (float) rectangle.getHeight();
4632N/A if (isfill) {
4632N/A fillRect(sg2d, x, y, w, h);
4632N/A } else {
4632N/A drawRect(sg2d, x, y, w, h);
4632N/A }
4632N/A } else if (s instanceof Ellipse2D) {
4632N/A Ellipse2D ellipse = (Ellipse2D) s;
4632N/A
4632N/A float x = (float) ellipse.getX();
4632N/A float y = (float) ellipse.getY();
4632N/A float w = (float) ellipse.getWidth();
4632N/A float h = (float) ellipse.getHeight();
4632N/A
4632N/A if (isfill) {
4632N/A fillOval(sg2d, x, y, w, h);
4632N/A } else {
4632N/A drawOval(sg2d, x, y, w, h);
4632N/A }
4632N/A } else if (s instanceof Arc2D) {
4632N/A Arc2D arc = (Arc2D) s;
4632N/A
4632N/A float x = (float) arc.getX();
4632N/A float y = (float) arc.getY();
4632N/A float w = (float) arc.getWidth();
4632N/A float h = (float) arc.getHeight();
4632N/A float as = (float) arc.getAngleStart();
4632N/A float ae = (float) arc.getAngleExtent();
4632N/A
4632N/A if (isfill) {
4632N/A fillArc(sg2d, x, y, w, h, as, ae, arc.getArcType());
4632N/A } else {
4632N/A drawArc(sg2d, x, y, w, h, as, ae, arc.getArcType());
4632N/A }
4632N/A } else if (s instanceof RoundRectangle2D) {
4632N/A RoundRectangle2D roundrect = (RoundRectangle2D) s;
4632N/A
4632N/A float x = (float) roundrect.getX();
4632N/A float y = (float) roundrect.getY();
4632N/A float w = (float) roundrect.getWidth();
4632N/A float h = (float) roundrect.getHeight();
4632N/A float aw = (float) roundrect.getArcWidth();
4632N/A float ah = (float) roundrect.getArcHeight();
4632N/A
4632N/A if (isfill) {
4632N/A fillRoundRect(sg2d, x, y, w, h, aw, ah);
4632N/A } else {
4632N/A drawRoundRect(sg2d, x, y, w, h, aw, ah);
4632N/A }
4632N/A } else if (s instanceof Line2D) {
4632N/A Line2D line = (Line2D) s;
4632N/A
4632N/A float x1 = (float) line.getX1();
4632N/A float y1 = (float) line.getY1();
4632N/A float x2 = (float) line.getX2();
4632N/A float y2 = (float) line.getY2();
4632N/A
4632N/A drawLine(sg2d, x1, y1, x2, y2);
4632N/A } else if (s instanceof Point2D) {
4632N/A Point2D point = (Point2D) s;
4632N/A
4632N/A float x = (float) point.getX();
4632N/A float y = (float) point.getY();
4632N/A
4632N/A drawLine(sg2d, x, y, x, y);
4632N/A } else {
4632N/A GeneralPath gp;
4632N/A
4632N/A if (s instanceof GeneralPath) {
4632N/A gp = (GeneralPath) s;
4632N/A } else {
4632N/A gp = new GeneralPath(s);
4632N/A }
4632N/A
4632N/A PathIterator pi = gp.getPathIterator(null);
4632N/A if (pi.isDone() == false) {
4632N/A surfaceData.drawfillShape(this, sg2d, gp, isfill, shouldApplyOffset);
4632N/A }
4632N/A }
4632N/A } else {
4632N/A GeneralPath gp;
4632N/A
4632N/A if (s instanceof GeneralPath) {
4632N/A gp = (GeneralPath) s;
4632N/A } else {
4632N/A gp = new GeneralPath(s);
4632N/A }
4632N/A
4632N/A PathIterator pi = gp.getPathIterator(null);
4632N/A if (pi.isDone() == false) {
4632N/A surfaceData.drawfillShape(this, sg2d, gp, isfill, shouldApplyOffset);
4632N/A }
4632N/A }
4632N/A }
4632N/A
4632N/A public void draw(SunGraphics2D sg2d, Shape s) {
4632N/A OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
4632N/A if ((sg2d.strokeState != SunGraphics2D.STROKE_CUSTOM) && (OSXSurfaceData.IsSimpleColor(sg2d.paint))) {
4632N/A drawfillShape(sg2d, s, false, true);
4632N/A } else {
4632N/A drawfillShape(sg2d, sg2d.stroke.createStrokedShape(s), true, true);
4632N/A }
4632N/A }
4632N/A
4632N/A public void fill(SunGraphics2D sg2d, Shape s) {
4632N/A drawfillShape(sg2d, s, true, false);
4632N/A }
4632N/A
4632N/A native void doImage(SurfaceData sData, SurfaceData img, boolean fliph, boolean flipv, int w, int h, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh);
4632N/A
4632N/A // Copy img to scaled sg2d @ x,y with width height
4632N/A public boolean scaleImage(SunGraphics2D sg2d, Image img, int x, int y, int width, int height, Color bgColor) {
4632N/A OSXSurfaceData surfaceData = (OSXSurfaceData) sg2d.getSurfaceData();
4632N/A
4632N/A int sx = 0;
4632N/A int sy = 0;
4632N/A int iw = img.getWidth(null);
4632N/A int ih = img.getHeight(null);
4632N/A
4632N/A return scaleImage(sg2d, img, x, y, x + width, y + height, sx, sy, sx + iw, sy + ih, bgColor);
4632N/A }
4632N/A
4632N/A // Copy img, clipped to sx1, sy1 by sx2, sy2 to dx1, dy2 by dx2, dy2
4632N/A public boolean scaleImage(SunGraphics2D sg2d, Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgColor) {
4632N/A
4632N/A // System.err.println("scaleImage");
4632N/A // System.err.println(" sx1="+sx1+", sy1="+sy1+", sx2="+sx2+", sy2="+sy2);
4632N/A // System.err.println(" dx1="+dx1+", dy1="+dy1+", dx2="+dx2+", dy2="+dy2);
4632N/A
4632N/A int srcW, srcH, dstW, dstH;
4632N/A int srcX, srcY, dstX, dstY;
4632N/A boolean srcWidthFlip = false;
4632N/A boolean srcHeightFlip = false;
4632N/A boolean dstWidthFlip = false;
4632N/A boolean dstHeightFlip = false;
4632N/A
4632N/A if (sx2 > sx1) {
4632N/A srcW = sx2 - sx1;
4632N/A srcX = sx1;
4632N/A } else {
4632N/A srcWidthFlip = true;
4632N/A srcW = sx1 - sx2;
4632N/A srcX = sx2;
4632N/A }
4632N/A if (sy2 > sy1) {
4632N/A srcH = sy2 - sy1;
4632N/A srcY = sy1;
4632N/A } else {
4632N/A srcHeightFlip = true;
4632N/A srcH = sy1 - sy2;
4632N/A srcY = sy2;
4632N/A }
4632N/A if (dx2 > dx1) {
4632N/A dstW = dx2 - dx1;
4632N/A dstX = dx1;
4632N/A } else {
4632N/A dstW = dx1 - dx2;
4632N/A dstWidthFlip = true;
4632N/A dstX = dx2;
4632N/A }
4632N/A if (dy2 > dy1) {
4632N/A dstH = dy2 - dy1;
4632N/A dstY = dy1;
4632N/A } else {
4632N/A dstH = dy1 - dy2;
4632N/A dstHeightFlip = true;
4632N/A dstY = dy2;
4632N/A }
4632N/A if (srcW <= 0 || srcH <= 0) { return true; }
4632N/A
4632N/A boolean flipv = (srcHeightFlip != dstHeightFlip);
4632N/A boolean fliph = (srcWidthFlip != dstWidthFlip);
4632N/A
4632N/A return blitImage(sg2d, img, fliph, flipv, srcX, srcY, srcW, srcH, dstX, dstY, dstW, dstH, bgColor);
4632N/A }
4632N/A
4632N/A protected boolean blitImage(SunGraphics2D sg2d, Image img, boolean fliph, boolean flipv, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh, Color bgColor) {
4632N/A CPrinterSurfaceData surfaceData = (CPrinterSurfaceData)sg2d.getSurfaceData();
4632N/A OSXOffScreenSurfaceData imgSurfaceData = (OSXOffScreenSurfaceData) OSXOffScreenSurfaceData.createNewSurface((BufferedImage)img);
4632N/A surfaceData.blitImage(this, sg2d, imgSurfaceData, fliph, flipv, sx, sy, sw, sh, dx, dy, dw, dh, bgColor);
4632N/A return true;
4632N/A }
4632N/A
4632N/A // Copy img to sg2d @ x, y
4632N/A protected boolean copyImage(SunGraphics2D sg2d, Image img, int dx, int dy, Color bgColor) {
4632N/A if (img == null) { return true; }
4632N/A
4632N/A int sx = 0;
4632N/A int sy = 0;
4632N/A int width = img.getWidth(null);
4632N/A int height = img.getHeight(null);
4632N/A
4632N/A return blitImage(sg2d, img, false, false, sx, sy, width, height, dx, dy, width, height, bgColor);
4632N/A }
4632N/A
4632N/A // Copy img, clipped to sx, sy with width, height to sg2d @ dx, dy
4632N/A protected boolean copyImage(SunGraphics2D sg2d, Image img, int dx, int dy, int sx, int sy, int width, int height, Color bgColor) {
4632N/A return blitImage(sg2d, img, false, false, sx, sy, width, height, dx, dy, width, height, bgColor);
4632N/A }
4632N/A
4632N/A protected void transformImage(SunGraphics2D sg2d, Image img, int x, int y, BufferedImageOp op, AffineTransform xf, Color bgColor) {
4632N/A if (img != null) {
4632N/A int iw = img.getWidth(null);
4632N/A int ih = img.getHeight(null);
4632N/A
4632N/A if ((op != null) && (img instanceof BufferedImage)) {
4632N/A if (((BufferedImage) img).getType() == BufferedImage.TYPE_CUSTOM) {
4632N/A // BufferedImageOp can not handle custom images
4632N/A BufferedImage dest = null;
4632N/A dest = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_ARGB_PRE);
4632N/A Graphics g = dest.createGraphics();
4632N/A g.drawImage(img, 0, 0, null);
4632N/A g.dispose();
4632N/A img = op.filter(dest, null);
4632N/A } else {
4632N/A // sun.awt.image.BufImgSurfaceData.createData((BufferedImage)img).finishLazyDrawing();
4632N/A img = op.filter((BufferedImage) img, null);
4632N/A }
4632N/A
4632N/A iw = img.getWidth(null);
4632N/A ih = img.getHeight(null);
4632N/A }
4632N/A
4632N/A if (xf != null) {
4632N/A AffineTransform reset = sg2d.getTransform();
4632N/A sg2d.transform(xf);
4632N/A scaleImage(sg2d, img, x, y, x + iw, y + ih, 0, 0, iw, ih, bgColor);
4632N/A sg2d.setTransform(reset);
4632N/A } else {
4632N/A scaleImage(sg2d, img, x, y, x + iw, y + ih, 0, 0, iw, ih, bgColor);
4632N/A }
4632N/A } else {
4632N/A throw new NullPointerException();
4632N/A }
4632N/A }
4632N/A
4632N/A // copied from DrawImage.java
4632N/A protected boolean imageReady(sun.awt.image.ToolkitImage sunimg, ImageObserver observer) {
4632N/A if (sunimg.hasError()) {
4632N/A if (observer != null) {
4632N/A observer.imageUpdate(sunimg, ImageObserver.ERROR | ImageObserver.ABORT, -1, -1, -1, -1);
4632N/A }
4632N/A return false;
4632N/A }
4632N/A return true;
4632N/A }
4632N/A
4632N/A // copied from DrawImage.java
4632N/A public boolean copyImage(SunGraphics2D sg2d, Image img, int x, int y, Color bgColor, ImageObserver observer) {
4632N/A if (img == null) { throw new NullPointerException(); }
4632N/A
4632N/A if (!(img instanceof sun.awt.image.ToolkitImage)) { return copyImage(sg2d, img, x, y, bgColor); }
4632N/A
4632N/A sun.awt.image.ToolkitImage sunimg = (sun.awt.image.ToolkitImage) img;
4632N/A if (!imageReady(sunimg, observer)) { return false; }
4632N/A ImageRepresentation ir = sunimg.getImageRep();
4632N/A return ir.drawToBufImage(sg2d, sunimg, x, y, bgColor, observer);
4632N/A }
4632N/A
4632N/A // copied from DrawImage.java
4632N/A public boolean copyImage(SunGraphics2D sg2d, Image img, int dx, int dy, int sx, int sy, int width, int height, Color bgColor, ImageObserver observer) {
4632N/A if (img == null) { throw new NullPointerException(); }
4632N/A
4632N/A if (!(img instanceof sun.awt.image.ToolkitImage)) { return copyImage(sg2d, img, dx, dy, sx, sy, width, height, bgColor); }
4632N/A
4632N/A sun.awt.image.ToolkitImage sunimg = (sun.awt.image.ToolkitImage) img;
4632N/A if (!imageReady(sunimg, observer)) { return false; }
4632N/A ImageRepresentation ir = sunimg.getImageRep();
4632N/A return ir.drawToBufImage(sg2d, sunimg, dx, dy, (dx + width), (dy + height), sx, sy, (sx + width), (sy + height), null, observer);
4632N/A }
4632N/A
4632N/A // copied from DrawImage.java
4632N/A public boolean scaleImage(SunGraphics2D sg2d, Image img, int x, int y, int width, int height, Color bgColor, ImageObserver observer) {
4632N/A if (img == null) { throw new NullPointerException(); }
4632N/A
4632N/A if (!(img instanceof sun.awt.image.ToolkitImage)) { return scaleImage(sg2d, img, x, y, width, height, bgColor); }
4632N/A
4632N/A sun.awt.image.ToolkitImage sunimg = (sun.awt.image.ToolkitImage) img;
4632N/A if (!imageReady(sunimg, observer)) { return false; }
4632N/A ImageRepresentation ir = sunimg.getImageRep();
4632N/A return ir.drawToBufImage(sg2d, sunimg, x, y, width, height, bgColor, observer);
4632N/A }
4632N/A
4632N/A // copied from DrawImage.java
4632N/A public boolean scaleImage(SunGraphics2D sg2d, Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, Color bgColor, ImageObserver observer) {
4632N/A if (img == null) { throw new NullPointerException(); }
4632N/A
4632N/A if (!(img instanceof sun.awt.image.ToolkitImage)) { return scaleImage(sg2d, img, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgColor); }
4632N/A
4632N/A sun.awt.image.ToolkitImage sunimg = (sun.awt.image.ToolkitImage) img;
4632N/A if (!imageReady(sunimg, observer)) { return false; }
4632N/A ImageRepresentation ir = sunimg.getImageRep();
4632N/A return ir.drawToBufImage(sg2d, sunimg, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, bgColor, observer);
4632N/A }
4632N/A
4632N/A // copied from DrawImage.java
4632N/A public boolean transformImage(SunGraphics2D sg2d, Image img, AffineTransform atfm, ImageObserver observer) {
4632N/A if (img == null) { throw new NullPointerException(); }
4632N/A
4632N/A if (!(img instanceof sun.awt.image.ToolkitImage)) {
4632N/A transformImage(sg2d, img, 0, 0, null, atfm, null);
4632N/A return true;
4632N/A }
4632N/A
4632N/A sun.awt.image.ToolkitImage sunimg = (sun.awt.image.ToolkitImage) img;
4632N/A if (!imageReady(sunimg, observer)) { return false; }
4632N/A ImageRepresentation ir = sunimg.getImageRep();
4632N/A return ir.drawToBufImage(sg2d, sunimg, atfm, observer);
4632N/A }
4632N/A
4632N/A // copied from DrawImage.java
4632N/A public void transformImage(SunGraphics2D sg2d, BufferedImage img, BufferedImageOp op, int x, int y) {
4632N/A if (img != null) {
4632N/A transformImage(sg2d, img, x, y, op, null, null);
4632N/A } else {
4632N/A throw new NullPointerException();
4632N/A }
4632N/A }
4632N/A
4632N/A public CRenderer traceWrap() {
4632N/A return new Tracer();
4632N/A }
4632N/A
4632N/A public static class Tracer extends CRenderer {
4632N/A void doLine(SurfaceData sData, float x1, float y1, float x2, float y2) {
4632N/A GraphicsPrimitive.tracePrimitive("QuartzLine");
4632N/A super.doLine(sData, x1, y1, x2, y2);
4632N/A }
4632N/A
4632N/A void doRect(SurfaceData sData, float x, float y, float width, float height, boolean isfill) {
4632N/A GraphicsPrimitive.tracePrimitive("QuartzRect");
4632N/A super.doRect(sData, x, y, width, height, isfill);
4632N/A }
4632N/A
4632N/A void doRoundRect(SurfaceData sData, float x, float y, float width, float height, float arcW, float arcH, boolean isfill) {
4632N/A GraphicsPrimitive.tracePrimitive("QuartzRoundRect");
4632N/A super.doRoundRect(sData, x, y, width, height, arcW, arcH, isfill);
4632N/A }
4632N/A
4632N/A void doOval(SurfaceData sData, float x, float y, float width, float height, boolean isfill) {
4632N/A GraphicsPrimitive.tracePrimitive("QuartzOval");
4632N/A super.doOval(sData, x, y, width, height, isfill);
4632N/A }
4632N/A
4632N/A void doArc(SurfaceData sData, float x, float y, float width, float height, float angleStart, float angleExtent, int type, boolean isfill) {
4632N/A GraphicsPrimitive.tracePrimitive("QuartzArc");
4632N/A super.doArc(sData, x, y, width, height, angleStart, angleExtent, type, isfill);
4632N/A }
4632N/A
4632N/A void doPoly(SurfaceData sData, int[] xpoints, int[] ypoints, int npoints, boolean ispolygon, boolean isfill) {
4632N/A GraphicsPrimitive.tracePrimitive("QuartzDoPoly");
4632N/A super.doPoly(sData, xpoints, ypoints, npoints, ispolygon, isfill);
4632N/A }
4632N/A
4632N/A void doShape(SurfaceData sData, int length, FloatBuffer coordinates, IntBuffer types, int windingRule, boolean isfill, boolean shouldApplyOffset) {
4632N/A GraphicsPrimitive.tracePrimitive("QuartzFillOrDrawShape");
4632N/A super.doShape(sData, length, coordinates, types, windingRule, isfill, shouldApplyOffset);
4632N/A }
4632N/A
4632N/A void doImage(SurfaceData sData, SurfaceData img, boolean fliph, boolean flipv, int w, int h, int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh) {
4632N/A GraphicsPrimitive.tracePrimitive("QuartzDrawImage");
4632N/A super.doImage(sData, img, fliph, flipv, w, h, sx, sy, sw, sh, dx, dy, dw, dh);
4632N/A }
4632N/A }
4632N/A}