1/*
2 * Copyright (c) 2007, 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
26package sun.java2d.d3d;
27
28import java.awt.Transparency;
29import java.awt.geom.Path2D;
30import sun.java2d.InvalidPipeException;
31import sun.java2d.SunGraphics2D;
32import sun.java2d.loops.GraphicsPrimitive;
33import sun.java2d.pipe.BufferedPaints;
34import sun.java2d.pipe.BufferedRenderPipe;
35import sun.java2d.pipe.RenderQueue;
36import sun.java2d.pipe.SpanIterator;
37import sun.java2d.pipe.ParallelogramPipe;
38import static sun.java2d.pipe.BufferedOpCodes.*;
39
40class D3DRenderer extends BufferedRenderPipe {
41
42    D3DRenderer(RenderQueue rq) {
43        super(rq);
44    }
45
46    @Override
47    protected void validateContext(SunGraphics2D sg2d) {
48        int ctxflags =
49            sg2d.paint.getTransparency() == Transparency.OPAQUE ?
50                D3DContext.SRC_IS_OPAQUE : D3DContext.NO_CONTEXT_FLAGS;
51        D3DSurfaceData dstData;
52        try {
53            dstData = (D3DSurfaceData)sg2d.surfaceData;
54        } catch (ClassCastException e) {
55            throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
56        }
57        D3DContext.validateContext(dstData, dstData,
58                                   sg2d.getCompClip(), sg2d.composite,
59                                   null, sg2d.paint, sg2d, ctxflags);
60    }
61
62    @Override
63    protected void validateContextAA(SunGraphics2D sg2d) {
64        int ctxflags = D3DContext.NO_CONTEXT_FLAGS;
65        D3DSurfaceData dstData;
66        try {
67            dstData = (D3DSurfaceData)sg2d.surfaceData;
68        } catch (ClassCastException e) {
69            throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
70        }
71        D3DContext.validateContext(dstData, dstData,
72                                   sg2d.getCompClip(), sg2d.composite,
73                                   null, sg2d.paint, sg2d, ctxflags);
74    }
75
76    void copyArea(SunGraphics2D sg2d,
77                  int x, int y, int w, int h, int dx, int dy)
78    {
79        rq.lock();
80        try {
81            int ctxflags =
82                sg2d.surfaceData.getTransparency() == Transparency.OPAQUE ?
83                    D3DContext.SRC_IS_OPAQUE : D3DContext.NO_CONTEXT_FLAGS;
84            D3DSurfaceData dstData;
85            try {
86                dstData = (D3DSurfaceData)sg2d.surfaceData;
87            } catch (ClassCastException e) {
88                throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);
89            }
90            D3DContext.validateContext(dstData, dstData,
91                                       sg2d.getCompClip(), sg2d.composite,
92                                       null, null, null, ctxflags);
93
94            rq.ensureCapacity(28);
95            buf.putInt(COPY_AREA);
96            buf.putInt(x).putInt(y).putInt(w).putInt(h);
97            buf.putInt(dx).putInt(dy);
98        } finally {
99            rq.unlock();
100        }
101    }
102
103    protected native void drawPoly(int[] xPoints, int[] yPoints,
104                                   int nPoints, boolean isClosed,
105                                   int transX, int transY);
106
107    D3DRenderer traceWrap() {
108        return new Tracer(this);
109    }
110
111    private class Tracer extends D3DRenderer {
112        private D3DRenderer d3dr;
113        Tracer(D3DRenderer d3dr) {
114            super(d3dr.rq);
115            this.d3dr = d3dr;
116        }
117        public ParallelogramPipe getAAParallelogramPipe() {
118            final ParallelogramPipe realpipe = d3dr.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("D3DFillAAParallelogram");
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("D3DDrawAAParallelogram");
141                    realpipe.drawParallelogram(sg2d,
142                                               ux1, uy1, ux2, uy2,
143                                               x, y, dx1, dy1, dx2, dy2,
144                                               lw1, lw2);
145                }
146            };
147        }
148
149        protected void validateContext(SunGraphics2D sg2d) {
150            d3dr.validateContext(sg2d);
151        }
152        public void drawLine(SunGraphics2D sg2d,
153                             int x1, int y1, int x2, int y2)
154        {
155            GraphicsPrimitive.tracePrimitive("D3DDrawLine");
156            d3dr.drawLine(sg2d, x1, y1, x2, y2);
157        }
158        public void drawRect(SunGraphics2D sg2d, int x, int y, int w, int h) {
159            GraphicsPrimitive.tracePrimitive("D3DDrawRect");
160            d3dr.drawRect(sg2d, x, y, w, h);
161        }
162        protected void drawPoly(SunGraphics2D sg2d,
163                                int[] xPoints, int[] yPoints,
164                                int nPoints, boolean isClosed)
165        {
166            GraphicsPrimitive.tracePrimitive("D3DDrawPoly");
167            d3dr.drawPoly(sg2d, xPoints, yPoints, nPoints, isClosed);
168        }
169        public void fillRect(SunGraphics2D sg2d, int x, int y, int w, int h) {
170            GraphicsPrimitive.tracePrimitive("D3DFillRect");
171            d3dr.fillRect(sg2d, x, y, w, h);
172        }
173        protected void drawPath(SunGraphics2D sg2d,
174                                Path2D.Float p2df, int transx, int transy)
175        {
176            GraphicsPrimitive.tracePrimitive("D3DDrawPath");
177            d3dr.drawPath(sg2d, p2df, transx, transy);
178        }
179        protected void fillPath(SunGraphics2D sg2d,
180                                Path2D.Float p2df, int transx, int transy)
181        {
182            GraphicsPrimitive.tracePrimitive("D3DFillPath");
183            d3dr.fillPath(sg2d, p2df, transx, transy);
184        }
185        protected void fillSpans(SunGraphics2D sg2d, SpanIterator si,
186                                 int transx, int transy)
187        {
188            GraphicsPrimitive.tracePrimitive("D3DFillSpans");
189            d3dr.fillSpans(sg2d, si, transx, transy);
190        }
191        public void fillParallelogram(SunGraphics2D sg2d,
192                                      double ux1, double uy1,
193                                      double ux2, double uy2,
194                                      double x, double y,
195                                      double dx1, double dy1,
196                                      double dx2, double dy2)
197        {
198            GraphicsPrimitive.tracePrimitive("D3DFillParallelogram");
199            d3dr.fillParallelogram(sg2d,
200                                   ux1, uy1, ux2, uy2,
201                                   x, y, dx1, dy1, dx2, dy2);
202        }
203        public void drawParallelogram(SunGraphics2D sg2d,
204                                      double ux1, double uy1,
205                                      double ux2, double uy2,
206                                      double x, double y,
207                                      double dx1, double dy1,
208                                      double dx2, double dy2,
209                                      double lw1, double lw2)
210        {
211            GraphicsPrimitive.tracePrimitive("D3DDrawParallelogram");
212            d3dr.drawParallelogram(sg2d,
213                                   ux1, uy1, ux2, uy2,
214                                   x, y, dx1, dy1, dx2, dy2, lw1, lw2);
215        }
216        public void copyArea(SunGraphics2D sg2d,
217                             int x, int y, int w, int h, int dx, int dy)
218        {
219            GraphicsPrimitive.tracePrimitive("D3DCopyArea");
220            d3dr.copyArea(sg2d, x, y, w, h, dx, dy);
221        }
222    }
223}
224