J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package sun.java2d.opengl; |
| 27 | |
| 28 | import java.awt.Transparency; |
| 29 | import java.awt.geom.Path2D; |
| 30 | import sun.java2d.SunGraphics2D; |
| 31 | import sun.java2d.loops.GraphicsPrimitive; |
| 32 | import sun.java2d.pipe.BufferedRenderPipe; |
| 33 | import sun.java2d.pipe.RenderQueue; |
| 34 | import sun.java2d.pipe.SpanIterator; |
| 35 | import static sun.java2d.pipe.BufferedOpCodes.*; |
| 36 | |
| 37 | class OGLRenderer extends BufferedRenderPipe { |
| 38 | |
| 39 | OGLRenderer(RenderQueue rq) { |
| 40 | super(rq); |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | protected void validateContext(SunGraphics2D sg2d) { |
| 45 | int ctxflags = |
| 46 | sg2d.paint.getTransparency() == Transparency.OPAQUE ? |
| 47 | OGLContext.SRC_IS_OPAQUE : OGLContext.NO_CONTEXT_FLAGS; |
| 48 | OGLSurfaceData dstData = (OGLSurfaceData)sg2d.surfaceData; |
| 49 | OGLContext.validateContext(dstData, dstData, |
| 50 | sg2d.getCompClip(), sg2d.composite, |
| 51 | null, sg2d.paint, sg2d, ctxflags); |
| 52 | } |
| 53 | |
| 54 | void copyArea(SunGraphics2D sg2d, |
| 55 | int x, int y, int w, int h, int dx, int dy) |
| 56 | { |
| 57 | rq.lock(); |
| 58 | try { |
| 59 | int ctxflags = |
| 60 | sg2d.surfaceData.getTransparency() == Transparency.OPAQUE ? |
| 61 | OGLContext.SRC_IS_OPAQUE : OGLContext.NO_CONTEXT_FLAGS; |
| 62 | OGLSurfaceData dstData = (OGLSurfaceData)sg2d.surfaceData; |
| 63 | OGLContext.validateContext(dstData, dstData, |
| 64 | sg2d.getCompClip(), sg2d.composite, |
| 65 | null, null, null, ctxflags); |
| 66 | |
| 67 | rq.ensureCapacity(28); |
| 68 | buf.putInt(COPY_AREA); |
| 69 | buf.putInt(x).putInt(y).putInt(w).putInt(h); |
| 70 | buf.putInt(dx).putInt(dy); |
| 71 | } finally { |
| 72 | rq.unlock(); |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | protected native void drawPoly(int[] xPoints, int[] yPoints, |
| 78 | int nPoints, boolean isClosed, |
| 79 | int transX, int transY); |
| 80 | |
| 81 | OGLRenderer traceWrap() { |
| 82 | return new Tracer(this); |
| 83 | } |
| 84 | |
| 85 | private class Tracer extends OGLRenderer { |
| 86 | private OGLRenderer oglr; |
| 87 | Tracer(OGLRenderer oglr) { |
| 88 | super(oglr.rq); |
| 89 | this.oglr = oglr; |
| 90 | } |
| 91 | protected void validateContext(SunGraphics2D sg2d) { |
| 92 | oglr.validateContext(sg2d); |
| 93 | } |
| 94 | public void drawLine(SunGraphics2D sg2d, |
| 95 | int x1, int y1, int x2, int y2) |
| 96 | { |
| 97 | GraphicsPrimitive.tracePrimitive("OGLDrawLine"); |
| 98 | oglr.drawLine(sg2d, x1, y1, x2, y2); |
| 99 | } |
| 100 | public void drawRect(SunGraphics2D sg2d, int x, int y, int w, int h) { |
| 101 | GraphicsPrimitive.tracePrimitive("OGLDrawRect"); |
| 102 | oglr.drawRect(sg2d, x, y, w, h); |
| 103 | } |
| 104 | protected void drawPoly(SunGraphics2D sg2d, |
| 105 | int[] xPoints, int[] yPoints, |
| 106 | int nPoints, boolean isClosed) |
| 107 | { |
| 108 | GraphicsPrimitive.tracePrimitive("OGLDrawPoly"); |
| 109 | oglr.drawPoly(sg2d, xPoints, yPoints, nPoints, isClosed); |
| 110 | } |
| 111 | public void fillRect(SunGraphics2D sg2d, int x, int y, int w, int h) { |
| 112 | GraphicsPrimitive.tracePrimitive("OGLFillRect"); |
| 113 | oglr.fillRect(sg2d, x, y, w, h); |
| 114 | } |
| 115 | protected void drawPath(SunGraphics2D sg2d, |
| 116 | Path2D.Float p2df, int transx, int transy) |
| 117 | { |
| 118 | GraphicsPrimitive.tracePrimitive("OGLDrawPath"); |
| 119 | oglr.drawPath(sg2d, p2df, transx, transy); |
| 120 | } |
| 121 | protected void fillPath(SunGraphics2D sg2d, |
| 122 | Path2D.Float p2df, int transx, int transy) |
| 123 | { |
| 124 | GraphicsPrimitive.tracePrimitive("OGLFillPath"); |
| 125 | oglr.fillPath(sg2d, p2df, transx, transy); |
| 126 | } |
| 127 | protected void fillSpans(SunGraphics2D sg2d, SpanIterator si, |
| 128 | int transx, int transy) |
| 129 | { |
| 130 | GraphicsPrimitive.tracePrimitive("OGLFillSpans"); |
| 131 | oglr.fillSpans(sg2d, si, transx, transy); |
| 132 | } |
| 133 | public void copyArea(SunGraphics2D sg2d, |
| 134 | int x, int y, int w, int h, int dx, int dy) |
| 135 | { |
| 136 | GraphicsPrimitive.tracePrimitive("OGLCopyArea"); |
| 137 | oglr.copyArea(sg2d, x, y, w, h, dx, dy); |
| 138 | } |
| 139 | } |
| 140 | } |