Path: blob/master/src/java.desktop/macosx/classes/sun/java2d/metal/MTLRenderer.java
41159 views
/*1* Copyright (c) 2019, 2021, 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.metal;2627import sun.java2d.InvalidPipeException;28import sun.java2d.SunGraphics2D;29import sun.java2d.loops.GraphicsPrimitive;30import sun.java2d.pipe.BufferedRenderPipe;31import sun.java2d.pipe.ParallelogramPipe;32import sun.java2d.pipe.RenderQueue;33import sun.java2d.pipe.SpanIterator;3435import java.awt.Transparency;36import java.awt.geom.Path2D;3738import static sun.java2d.pipe.BufferedOpCodes.COPY_AREA;3940class MTLRenderer extends BufferedRenderPipe {4142MTLRenderer(RenderQueue rq) {43super(rq);44}4546@Override47protected void validateContext(SunGraphics2D sg2d) {48int ctxflags =49sg2d.paint.getTransparency() == Transparency.OPAQUE ?50MTLContext.SRC_IS_OPAQUE : MTLContext.NO_CONTEXT_FLAGS;51MTLSurfaceData dstData;52try {53dstData = (MTLSurfaceData)sg2d.surfaceData;54} catch (ClassCastException e) {55throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);56}57MTLContext.validateContext(dstData, dstData,58sg2d.getCompClip(), sg2d.composite,59null, sg2d.paint, sg2d, ctxflags);60}6162@Override63protected void validateContextAA(SunGraphics2D sg2d) {64int ctxflags = MTLContext.NO_CONTEXT_FLAGS;65MTLSurfaceData dstData;66try {67dstData = (MTLSurfaceData)sg2d.surfaceData;68} catch (ClassCastException e) {69throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);70}71MTLContext.validateContext(dstData, dstData,72sg2d.getCompClip(), sg2d.composite,73null, sg2d.paint, sg2d, ctxflags);74}7576void copyArea(SunGraphics2D sg2d,77int x, int y, int w, int h, int dx, int dy)78{79rq.lock();80try {81int ctxflags =82sg2d.surfaceData.getTransparency() == Transparency.OPAQUE ?83MTLContext.SRC_IS_OPAQUE : MTLContext.NO_CONTEXT_FLAGS;84MTLSurfaceData dstData;85try {86dstData = (MTLSurfaceData)sg2d.surfaceData;87} catch (ClassCastException e) {88throw new InvalidPipeException("wrong surface data type: " + sg2d.surfaceData);89}90MTLContext.validateContext(dstData, dstData,91sg2d.getCompClip(), sg2d.composite,92null, null, null, ctxflags);9394rq.ensureCapacity(28);95buf.putInt(COPY_AREA);96buf.putInt(x).putInt(y).putInt(w).putInt(h);97buf.putInt(dx).putInt(dy);98} finally {99rq.unlock();100}101}102103@Override104protected native void drawPoly(int[] xPoints, int[] yPoints,105int nPoints, boolean isClosed,106int transX, int transY);107108MTLRenderer traceWrap() {109return new Tracer(this);110}111112private class Tracer extends MTLRenderer {113private MTLRenderer mtlr;114Tracer(MTLRenderer mtlr) {115super(mtlr.rq);116this.mtlr = mtlr;117}118public ParallelogramPipe getAAParallelogramPipe() {119final ParallelogramPipe realpipe = mtlr.getAAParallelogramPipe();120return new ParallelogramPipe() {121public void fillParallelogram(SunGraphics2D sg2d,122double ux1, double uy1,123double ux2, double uy2,124double x, double y,125double dx1, double dy1,126double dx2, double dy2)127{128GraphicsPrimitive.tracePrimitive("MTLFillAAParallelogram");129realpipe.fillParallelogram(sg2d,130ux1, uy1, ux2, uy2,131x, y, dx1, dy1, dx2, dy2);132}133public void drawParallelogram(SunGraphics2D sg2d,134double ux1, double uy1,135double ux2, double uy2,136double x, double y,137double dx1, double dy1,138double dx2, double dy2,139double lw1, double lw2)140{141GraphicsPrimitive.tracePrimitive("MTLDrawAAParallelogram");142realpipe.drawParallelogram(sg2d,143ux1, uy1, ux2, uy2,144x, y, dx1, dy1, dx2, dy2,145lw1, lw2);146}147};148}149protected void validateContext(SunGraphics2D sg2d) {150mtlr.validateContext(sg2d);151}152public void drawLine(SunGraphics2D sg2d,153int x1, int y1, int x2, int y2)154{155GraphicsPrimitive.tracePrimitive("MTLDrawLine");156mtlr.drawLine(sg2d, x1, y1, x2, y2);157}158public void drawRect(SunGraphics2D sg2d, int x, int y, int w, int h) {159GraphicsPrimitive.tracePrimitive("MTLDrawRect");160mtlr.drawRect(sg2d, x, y, w, h);161}162protected void drawPoly(SunGraphics2D sg2d,163int[] xPoints, int[] yPoints,164int nPoints, boolean isClosed)165{166GraphicsPrimitive.tracePrimitive("MTLDrawPoly");167mtlr.drawPoly(sg2d, xPoints, yPoints, nPoints, isClosed);168}169public void fillRect(SunGraphics2D sg2d, int x, int y, int w, int h) {170GraphicsPrimitive.tracePrimitive("MTLFillRect");171mtlr.fillRect(sg2d, x, y, w, h);172}173protected void drawPath(SunGraphics2D sg2d,174Path2D.Float p2df, int transx, int transy)175{176GraphicsPrimitive.tracePrimitive("MTLDrawPath");177mtlr.drawPath(sg2d, p2df, transx, transy);178}179protected void fillPath(SunGraphics2D sg2d,180Path2D.Float p2df, int transx, int transy)181{182GraphicsPrimitive.tracePrimitive("MTLFillPath");183mtlr.fillPath(sg2d, p2df, transx, transy);184}185protected void fillSpans(SunGraphics2D sg2d, SpanIterator si,186int transx, int transy)187{188GraphicsPrimitive.tracePrimitive("MTLFillSpans");189mtlr.fillSpans(sg2d, si, transx, transy);190}191public void fillParallelogram(SunGraphics2D sg2d,192double ux1, double uy1,193double ux2, double uy2,194double x, double y,195double dx1, double dy1,196double dx2, double dy2)197{198GraphicsPrimitive.tracePrimitive("MTLFillParallelogram");199mtlr.fillParallelogram(sg2d,200ux1, uy1, ux2, uy2,201x, y, dx1, dy1, dx2, dy2);202}203public void drawParallelogram(SunGraphics2D sg2d,204double ux1, double uy1,205double ux2, double uy2,206double x, double y,207double dx1, double dy1,208double dx2, double dy2,209double lw1, double lw2)210{211GraphicsPrimitive.tracePrimitive("MTLDrawParallelogram");212mtlr.drawParallelogram(sg2d,213ux1, uy1, ux2, uy2,214x, y, dx1, dy1, dx2, dy2, lw1, lw2);215}216public void copyArea(SunGraphics2D sg2d,217int x, int y, int w, int h, int dx, int dy)218{219GraphicsPrimitive.tracePrimitive("MTLCopyArea");220mtlr.copyArea(sg2d, x, y, w, h, dx, dy);221}222}223}224225226