Path: blob/master/src/java.desktop/share/classes/sun/java2d/pipe/SpanClipRenderer.java
41159 views
/*1* Copyright (c) 1998, 2018, 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.pipe;2627import java.awt.Rectangle;28import java.awt.Shape;29import sun.java2d.SunGraphics2D;3031/**32* This class uses a Region iterator to modify the extents of alpha33* tiles created during Shape rendering based upon a non-rectangular34* clipping path.35*/36public class SpanClipRenderer implements CompositePipe37{38CompositePipe outpipe;3940static Class<?> RegionClass = Region.class;41static Class<?> RegionIteratorClass = RegionIterator.class;4243static {44initIDs(RegionClass, RegionIteratorClass);45}4647static native void initIDs(Class<?> rc, Class<?> ric);4849public SpanClipRenderer(CompositePipe pipe) {50outpipe = pipe;51}5253class SCRcontext {54RegionIterator iterator;55Object outcontext;56int[] band;57byte[] tile;5859public SCRcontext(RegionIterator ri, Object outctx) {60iterator = ri;61outcontext = outctx;62band = new int[4];63}64}6566public Object startSequence(SunGraphics2D sg, Shape s, Rectangle devR,67int[] abox) {68RegionIterator ri = sg.clipRegion.getIterator();6970return new SCRcontext(ri, outpipe.startSequence(sg, s, devR, abox));71}7273public boolean needTile(Object ctx, int x, int y, int w, int h) {74SCRcontext context = (SCRcontext) ctx;75return (outpipe.needTile(context.outcontext, x, y, w, h));76}7778public void renderPathTile(Object ctx,79byte[] atile, int offset, int tsize,80int x, int y, int w, int h,81ShapeSpanIterator sr) {82renderPathTile(ctx, atile, offset, tsize, x, y, w, h);83}8485public void renderPathTile(Object ctx,86byte[] atile, int offset, int tsize,87int x, int y, int w, int h) {88SCRcontext context = (SCRcontext) ctx;89RegionIterator ri = context.iterator.createCopy();90int[] band = context.band;91band[0] = x;92band[1] = y;93band[2] = x + w;94band[3] = y + h;95if (atile == null) {96int size = w * h;97atile = context.tile;98if (atile != null && atile.length < size) {99atile = null;100}101if (atile == null) {102atile = new byte[size];103context.tile = atile;104}105offset = 0;106tsize = w;107fillTile(ri, atile, offset, tsize, band);108} else {109eraseTile(ri, atile, offset, tsize, band);110}111112if (band[2] > band[0] && band[3] > band[1]) {113offset += (band[1] - y) * tsize + (band[0] - x);114outpipe.renderPathTile(context.outcontext,115atile, offset, tsize,116band[0], band[1],117band[2] - band[0],118band[3] - band[1]);119}120}121122public native void fillTile(RegionIterator ri,123byte[] alpha, int offset, int tsize,124int[] band);125126public native void eraseTile(RegionIterator ri,127byte[] alpha, int offset, int tsize,128int[] band);129130public void skipTile(Object ctx, int x, int y) {131SCRcontext context = (SCRcontext) ctx;132outpipe.skipTile(context.outcontext, x, y);133}134135public void endSequence(Object ctx) {136SCRcontext context = (SCRcontext) ctx;137outpipe.endSequence(context.outcontext);138}139}140141142