Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/java2d/pipe/SpanClipRenderer.java
38918 views
/*1* Copyright (c) 1998, 1999, 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 java.awt.geom.PathIterator;30import sun.java2d.SunGraphics2D;3132/**33* This class uses a Region iterator to modify the extents of alpha34* tiles created during Shape rendering based upon a non-rectangular35* clipping path.36*/37public class SpanClipRenderer implements CompositePipe38{39CompositePipe outpipe;4041static Class RegionClass = Region.class;42static Class RegionIteratorClass = RegionIterator.class;4344static {45initIDs(RegionClass, RegionIteratorClass);46}4748static native void initIDs(Class rc, Class ric);4950public SpanClipRenderer(CompositePipe pipe) {51outpipe = pipe;52}5354class SCRcontext {55RegionIterator iterator;56Object outcontext;57int band[];58byte tile[];5960public SCRcontext(RegionIterator ri, Object outctx) {61iterator = ri;62outcontext = outctx;63band = new int[4];64}65}6667public Object startSequence(SunGraphics2D sg, Shape s, Rectangle devR,68int[] abox) {69RegionIterator ri = sg.clipRegion.getIterator();7071return new SCRcontext(ri, outpipe.startSequence(sg, s, devR, abox));72}7374public boolean needTile(Object ctx, int x, int y, int w, int h) {75SCRcontext context = (SCRcontext) ctx;76return (outpipe.needTile(context.outcontext, x, y, w, h));77}7879public void renderPathTile(Object ctx,80byte[] atile, int offset, int tsize,81int x, int y, int w, int h,82ShapeSpanIterator sr) {83renderPathTile(ctx, atile, offset, tsize, x, y, w, h);84}8586public void renderPathTile(Object ctx,87byte[] atile, int offset, int tsize,88int x, int y, int w, int h) {89SCRcontext context = (SCRcontext) ctx;90RegionIterator ri = context.iterator.createCopy();91int[] band = context.band;92band[0] = x;93band[1] = y;94band[2] = x + w;95band[3] = y + h;96if (atile == null) {97int size = w * h;98atile = context.tile;99if (atile != null && atile.length < size) {100atile = null;101}102if (atile == null) {103atile = new byte[size];104context.tile = atile;105}106offset = 0;107tsize = w;108fillTile(ri, atile, offset, tsize, band);109} else {110eraseTile(ri, atile, offset, tsize, band);111}112113if (band[2] > band[0] && band[3] > band[1]) {114offset += (band[1] - y) * tsize + (band[0] - x);115outpipe.renderPathTile(context.outcontext,116atile, offset, tsize,117band[0], band[1],118band[2] - band[0],119band[3] - band[1]);120}121}122123public native void fillTile(RegionIterator ri,124byte[] alpha, int offset, int tsize,125int[] band);126127public native void eraseTile(RegionIterator ri,128byte[] alpha, int offset, int tsize,129int[] band);130131public void skipTile(Object ctx, int x, int y) {132SCRcontext context = (SCRcontext) ctx;133outpipe.skipTile(context.outcontext, x, y);134}135136public void endSequence(Object ctx) {137SCRcontext context = (SCRcontext) ctx;138outpipe.endSequence(context.outcontext);139}140}141142143