1 /*
2  * Copyright (c) 2003, 2011, Oracle and/or its affiliates. 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.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package sun.java2d.opengl;
27 
28 import java.awt.Transparency;
29 import java.awt.geom.Path2D;
30 import sun.java2d.InvalidPipeException;
31 import sun.java2d.SunGraphics2D;
32 import sun.java2d.loops.GraphicsPrimitive;
33 import sun.java2d.pipe.BufferedRenderPipe;
34 import sun.java2d.pipe.ParallelogramPipe;
35 import sun.java2d.pipe.RenderQueue;
36 import sun.java2d.pipe.SpanIterator;
37 import static sun.java2d.pipe.BufferedOpCodes.*;
38 
39 class OGLRenderer extends BufferedRenderPipe {
40 
OGLRenderer(RenderQueue rq)41     OGLRenderer(RenderQueue rq) {
42         super(rq);
43     }
44 
45     @Override
validateContext(SunGraphics2D sg2d)46     protected void validateContext(SunGraphics2D sg2d) {
47         int ctxflags =
48             sg2d.paint.getTransparency() == Transparency.OPAQUE ?
49                 OGLContext.SRC_IS_OPAQUE : OGLContext.NO_CONTEXT_FLAGS;
50         OGLSurfaceData dstData;
51         try {
52             dstData = (OGLSurfaceData)sg2d.surfaceData;
53         } catch (ClassCastException e) {
54             throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
55         }
56         OGLContext.validateContext(dstData, dstData,
57                                    sg2d.getCompClip(), sg2d.composite,
58                                    null, sg2d.paint, sg2d, ctxflags);
59     }
60 
61     @Override
validateContextAA(SunGraphics2D sg2d)62     protected void validateContextAA(SunGraphics2D sg2d) {
63         int ctxflags = OGLContext.NO_CONTEXT_FLAGS;
64         OGLSurfaceData dstData;
65         try {
66             dstData = (OGLSurfaceData)sg2d.surfaceData;
67         } catch (ClassCastException e) {
68             throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
69         }
70         OGLContext.validateContext(dstData, dstData,
71                                    sg2d.getCompClip(), sg2d.composite,
72                                    null, sg2d.paint, sg2d, ctxflags);
73     }
74 
copyArea(SunGraphics2D sg2d, int x, int y, int w, int h, int dx, int dy)75     void copyArea(SunGraphics2D sg2d,
76                   int x, int y, int w, int h, int dx, int dy)
77     {
78         rq.lock();
79         try {
80             int ctxflags =
81                 sg2d.surfaceData.getTransparency() == Transparency.OPAQUE ?
82                     OGLContext.SRC_IS_OPAQUE : OGLContext.NO_CONTEXT_FLAGS;
83             OGLSurfaceData dstData;
84             try {
85                 dstData = (OGLSurfaceData)sg2d.surfaceData;
86             } catch (ClassCastException e) {
87                 throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
88             }
89             OGLContext.validateContext(dstData, dstData,
90                                        sg2d.getCompClip(), sg2d.composite,
91                                        null, null, null, ctxflags);
92 
93             rq.ensureCapacity(28);
94             buf.putInt(COPY_AREA);
95             buf.putInt(x).putInt(y).putInt(w).putInt(h);
96             buf.putInt(dx).putInt(dy);
97         } finally {
98             rq.unlock();
99         }
100     }
101 
102     @Override
drawPoly(int[] xPoints, int[] yPoints, int nPoints, boolean isClosed, int transX, int transY)103     protected native void drawPoly(int[] xPoints, int[] yPoints,
104                                    int nPoints, boolean isClosed,
105                                    int transX, int transY);
106 
traceWrap()107     OGLRenderer traceWrap() {
108         return new Tracer(this);
109     }
110 
111     private class Tracer extends OGLRenderer {
112         private OGLRenderer oglr;
Tracer(OGLRenderer oglr)113         Tracer(OGLRenderer oglr) {
114             super(oglr.rq);
115             this.oglr = oglr;
116         }
getAAParallelogramPipe()117         public ParallelogramPipe getAAParallelogramPipe() {
118             final ParallelogramPipe realpipe = oglr.getAAParallelogramPipe();
119             return new ParallelogramPipe() {
120                 public void fillParallelogram(SunGraphics2D sg2d,
121                                               double ux1, double uy1,
122                                               double ux2, double uy2,
123                                               double x, double y,
124                                               double dx1, double dy1,
125                                               double dx2, double dy2)
126                 {
127                     GraphicsPrimitive.tracePrimitive("OGLFillAAParallelogram");
128                     realpipe.fillParallelogram(sg2d,
129                                                ux1, uy1, ux2, uy2,
130                                                x, y, dx1, dy1, dx2, dy2);
131                 }
132                 public void drawParallelogram(SunGraphics2D sg2d,
133                                               double ux1, double uy1,
134                                               double ux2, double uy2,
135                                               double x, double y,
136                                               double dx1, double dy1,
137                                               double dx2, double dy2,
138                                               double lw1, double lw2)
139                 {
140                     GraphicsPrimitive.tracePrimitive("OGLDrawAAParallelogram");
141                     realpipe.drawParallelogram(sg2d,
142                                                ux1, uy1, ux2, uy2,
143                                                x, y, dx1, dy1, dx2, dy2,
144                                                lw1, lw2);
145                 }
146             };
147         }
validateContext(SunGraphics2D sg2d)148         protected void validateContext(SunGraphics2D sg2d) {
149             oglr.validateContext(sg2d);
150         }
drawLine(SunGraphics2D sg2d, int x1, int y1, int x2, int y2)151         public void drawLine(SunGraphics2D sg2d,
152                              int x1, int y1, int x2, int y2)
153         {
154             GraphicsPrimitive.tracePrimitive("OGLDrawLine");
155             oglr.drawLine(sg2d, x1, y1, x2, y2);
156         }
drawRect(SunGraphics2D sg2d, int x, int y, int w, int h)157         public void drawRect(SunGraphics2D sg2d, int x, int y, int w, int h) {
158             GraphicsPrimitive.tracePrimitive("OGLDrawRect");
159             oglr.drawRect(sg2d, x, y, w, h);
160         }
drawPoly(SunGraphics2D sg2d, int[] xPoints, int[] yPoints, int nPoints, boolean isClosed)161         protected void drawPoly(SunGraphics2D sg2d,
162                                 int[] xPoints, int[] yPoints,
163                                 int nPoints, boolean isClosed)
164         {
165             GraphicsPrimitive.tracePrimitive("OGLDrawPoly");
166             oglr.drawPoly(sg2d, xPoints, yPoints, nPoints, isClosed);
167         }
fillRect(SunGraphics2D sg2d, int x, int y, int w, int h)168         public void fillRect(SunGraphics2D sg2d, int x, int y, int w, int h) {
169             GraphicsPrimitive.tracePrimitive("OGLFillRect");
170             oglr.fillRect(sg2d, x, y, w, h);
171         }
drawPath(SunGraphics2D sg2d, Path2D.Float p2df, int transx, int transy)172         protected void drawPath(SunGraphics2D sg2d,
173                                 Path2D.Float p2df, int transx, int transy)
174         {
175             GraphicsPrimitive.tracePrimitive("OGLDrawPath");
176             oglr.drawPath(sg2d, p2df, transx, transy);
177         }
fillPath(SunGraphics2D sg2d, Path2D.Float p2df, int transx, int transy)178         protected void fillPath(SunGraphics2D sg2d,
179                                 Path2D.Float p2df, int transx, int transy)
180         {
181             GraphicsPrimitive.tracePrimitive("OGLFillPath");
182             oglr.fillPath(sg2d, p2df, transx, transy);
183         }
fillSpans(SunGraphics2D sg2d, SpanIterator si, int transx, int transy)184         protected void fillSpans(SunGraphics2D sg2d, SpanIterator si,
185                                  int transx, int transy)
186         {
187             GraphicsPrimitive.tracePrimitive("OGLFillSpans");
188             oglr.fillSpans(sg2d, si, transx, transy);
189         }
fillParallelogram(SunGraphics2D sg2d, double ux1, double uy1, double ux2, double uy2, double x, double y, double dx1, double dy1, double dx2, double dy2)190         public void fillParallelogram(SunGraphics2D sg2d,
191                                       double ux1, double uy1,
192                                       double ux2, double uy2,
193                                       double x, double y,
194                                       double dx1, double dy1,
195                                       double dx2, double dy2)
196         {
197             GraphicsPrimitive.tracePrimitive("OGLFillParallelogram");
198             oglr.fillParallelogram(sg2d,
199                                    ux1, uy1, ux2, uy2,
200                                    x, y, dx1, dy1, dx2, dy2);
201         }
drawParallelogram(SunGraphics2D sg2d, double ux1, double uy1, double ux2, double uy2, double x, double y, double dx1, double dy1, double dx2, double dy2, double lw1, double lw2)202         public void drawParallelogram(SunGraphics2D sg2d,
203                                       double ux1, double uy1,
204                                       double ux2, double uy2,
205                                       double x, double y,
206                                       double dx1, double dy1,
207                                       double dx2, double dy2,
208                                       double lw1, double lw2)
209         {
210             GraphicsPrimitive.tracePrimitive("OGLDrawParallelogram");
211             oglr.drawParallelogram(sg2d,
212                                    ux1, uy1, ux2, uy2,
213                                    x, y, dx1, dy1, dx2, dy2, lw1, lw2);
214         }
copyArea(SunGraphics2D sg2d, int x, int y, int w, int h, int dx, int dy)215         public void copyArea(SunGraphics2D sg2d,
216                              int x, int y, int w, int h, int dx, int dy)
217         {
218             GraphicsPrimitive.tracePrimitive("OGLCopyArea");
219             oglr.copyArea(sg2d, x, y, w, h, dx, dy);
220         }
221     }
222 }
223