Path: blob/master/src/java.desktop/share/classes/sun/java2d/opengl/OGLRenderer.java
41159 views
/*1* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.java2d.opengl;2627import java.awt.Transparency;28import java.awt.geom.Path2D;29import sun.java2d.InvalidPipeException;30import sun.java2d.SunGraphics2D;31import sun.java2d.loops.GraphicsPrimitive;32import sun.java2d.pipe.BufferedRenderPipe;33import sun.java2d.pipe.ParallelogramPipe;34import sun.java2d.pipe.RenderQueue;35import sun.java2d.pipe.SpanIterator;36import static sun.java2d.pipe.BufferedOpCodes.*;3738class OGLRenderer extends BufferedRenderPipe {3940OGLRenderer(RenderQueue rq) {41super(rq);42}4344@Override45protected void validateContext(SunGraphics2D sg2d) {46int ctxflags =47sg2d.paint.getTransparency() == Transparency.OPAQUE ?48OGLContext.SRC_IS_OPAQUE : OGLContext.NO_CONTEXT_FLAGS;49OGLSurfaceData dstData;50try {51dstData = (OGLSurfaceData)sg2d.surfaceData;52} catch (ClassCastException e) {53throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);54}55OGLContext.validateContext(dstData, dstData,56sg2d.getCompClip(), sg2d.composite,57null, sg2d.paint, sg2d, ctxflags);58}5960@Override61protected void validateContextAA(SunGraphics2D sg2d) {62int ctxflags = OGLContext.NO_CONTEXT_FLAGS;63OGLSurfaceData dstData;64try {65dstData = (OGLSurfaceData)sg2d.surfaceData;66} catch (ClassCastException e) {67throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);68}69OGLContext.validateContext(dstData, dstData,70sg2d.getCompClip(), sg2d.composite,71null, sg2d.paint, sg2d, ctxflags);72}7374void copyArea(SunGraphics2D sg2d,75int x, int y, int w, int h, int dx, int dy)76{77rq.lock();78try {79int ctxflags =80sg2d.surfaceData.getTransparency() == Transparency.OPAQUE ?81OGLContext.SRC_IS_OPAQUE : OGLContext.NO_CONTEXT_FLAGS;82OGLSurfaceData dstData;83try {84dstData = (OGLSurfaceData)sg2d.surfaceData;85} catch (ClassCastException e) {86throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);87}88OGLContext.validateContext(dstData, dstData,89sg2d.getCompClip(), sg2d.composite,90null, null, null, ctxflags);9192rq.ensureCapacity(28);93buf.putInt(COPY_AREA);94buf.putInt(x).putInt(y).putInt(w).putInt(h);95buf.putInt(dx).putInt(dy);96} finally {97rq.unlock();98}99}100101@Override102protected native void drawPoly(int[] xPoints, int[] yPoints,103int nPoints, boolean isClosed,104int transX, int transY);105106OGLRenderer traceWrap() {107return new Tracer(this);108}109110private class Tracer extends OGLRenderer {111private OGLRenderer oglr;112Tracer(OGLRenderer oglr) {113super(oglr.rq);114this.oglr = oglr;115}116public ParallelogramPipe getAAParallelogramPipe() {117final ParallelogramPipe realpipe = oglr.getAAParallelogramPipe();118return new ParallelogramPipe() {119public void fillParallelogram(SunGraphics2D sg2d,120double ux1, double uy1,121double ux2, double uy2,122double x, double y,123double dx1, double dy1,124double dx2, double dy2)125{126GraphicsPrimitive.tracePrimitive("OGLFillAAParallelogram");127realpipe.fillParallelogram(sg2d,128ux1, uy1, ux2, uy2,129x, y, dx1, dy1, dx2, dy2);130}131public void drawParallelogram(SunGraphics2D sg2d,132double ux1, double uy1,133double ux2, double uy2,134double x, double y,135double dx1, double dy1,136double dx2, double dy2,137double lw1, double lw2)138{139GraphicsPrimitive.tracePrimitive("OGLDrawAAParallelogram");140realpipe.drawParallelogram(sg2d,141ux1, uy1, ux2, uy2,142x, y, dx1, dy1, dx2, dy2,143lw1, lw2);144}145};146}147protected void validateContext(SunGraphics2D sg2d) {148oglr.validateContext(sg2d);149}150public void drawLine(SunGraphics2D sg2d,151int x1, int y1, int x2, int y2)152{153GraphicsPrimitive.tracePrimitive("OGLDrawLine");154oglr.drawLine(sg2d, x1, y1, x2, y2);155}156public void drawRect(SunGraphics2D sg2d, int x, int y, int w, int h) {157GraphicsPrimitive.tracePrimitive("OGLDrawRect");158oglr.drawRect(sg2d, x, y, w, h);159}160protected void drawPoly(SunGraphics2D sg2d,161int[] xPoints, int[] yPoints,162int nPoints, boolean isClosed)163{164GraphicsPrimitive.tracePrimitive("OGLDrawPoly");165oglr.drawPoly(sg2d, xPoints, yPoints, nPoints, isClosed);166}167public void fillRect(SunGraphics2D sg2d, int x, int y, int w, int h) {168GraphicsPrimitive.tracePrimitive("OGLFillRect");169oglr.fillRect(sg2d, x, y, w, h);170}171protected void drawPath(SunGraphics2D sg2d,172Path2D.Float p2df, int transx, int transy)173{174GraphicsPrimitive.tracePrimitive("OGLDrawPath");175oglr.drawPath(sg2d, p2df, transx, transy);176}177protected void fillPath(SunGraphics2D sg2d,178Path2D.Float p2df, int transx, int transy)179{180GraphicsPrimitive.tracePrimitive("OGLFillPath");181oglr.fillPath(sg2d, p2df, transx, transy);182}183protected void fillSpans(SunGraphics2D sg2d, SpanIterator si,184int transx, int transy)185{186GraphicsPrimitive.tracePrimitive("OGLFillSpans");187oglr.fillSpans(sg2d, si, transx, transy);188}189public void fillParallelogram(SunGraphics2D sg2d,190double ux1, double uy1,191double ux2, double uy2,192double x, double y,193double dx1, double dy1,194double dx2, double dy2)195{196GraphicsPrimitive.tracePrimitive("OGLFillParallelogram");197oglr.fillParallelogram(sg2d,198ux1, uy1, ux2, uy2,199x, y, dx1, dy1, dx2, dy2);200}201public void drawParallelogram(SunGraphics2D sg2d,202double ux1, double uy1,203double ux2, double uy2,204double x, double y,205double dx1, double dy1,206double dx2, double dy2,207double lw1, double lw2)208{209GraphicsPrimitive.tracePrimitive("OGLDrawParallelogram");210oglr.drawParallelogram(sg2d,211ux1, uy1, ux2, uy2,212x, y, dx1, dy1, dx2, dy2, lw1, lw2);213}214public void copyArea(SunGraphics2D sg2d,215int x, int y, int w, int h, int dx, int dy)216{217GraphicsPrimitive.tracePrimitive("OGLCopyArea");218oglr.copyArea(sg2d, x, y, w, h, dx, dy);219}220}221}222223224