Showing the changes to java/pkg/sun/java2d/pipe/SpanClipRenderer.java (1 of 18352 files). Show all
Unified · Split
| @@ -0,0 +1,141 @@ | |||
| 1 | /* | ||
| 2 | * Copyright (c) 1998, 1999, 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 | |||
| 26 | package sun.java2d.pipe; | ||
| 27 | |||
| 28 | import java.awt.Rectangle; | ||
| 29 | import java.awt.Shape; | ||
| 30 | import java.awt.geom.PathIterator; | ||
| 31 | import sun.java2d.SunGraphics2D; | ||
| 32 | |||
| 33 | /** | ||
| 34 | * This class uses a Region iterator to modify the extents of alpha | ||
| 35 | * tiles created during Shape rendering based upon a non-rectangular | ||
| 36 | * clipping path. | ||
| 37 | */ | ||
| 38 | public class SpanClipRenderer implements CompositePipe | ||
| 39 | { | ||
| 40 | CompositePipe outpipe; | ||
| 41 | |||
| 42 | static Class RegionClass = Region.class; | ||
| 43 | static Class RegionIteratorClass = RegionIterator.class; | ||
| 44 | |||
| 45 | static { | ||
| 46 | initIDs(RegionClass, RegionIteratorClass); | ||
| 47 | } | ||
| 48 | |||
| 49 | static native void initIDs(Class rc, Class ric); | ||
| 50 | |||
| 51 | public SpanClipRenderer(CompositePipe pipe) { | ||
| 52 | outpipe = pipe; | ||
| 53 | } | ||
| 54 | |||
| 55 | class SCRcontext { | ||
| 56 | RegionIterator iterator; | ||
| 57 | Object outcontext; | ||
| 58 | int band[]; | ||
| 59 | byte tile[]; | ||
| 60 | |||
| 61 | public SCRcontext(RegionIterator ri, Object outctx) { | ||
| 62 | iterator = ri; | ||
| 63 | outcontext = outctx; | ||
| 64 | band = new int[4]; | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | public Object startSequence(SunGraphics2D sg, Shape s, Rectangle devR, | ||
| 69 | int[] abox) { | ||
| 70 | RegionIterator ri = sg.clipRegion.getIterator(); | ||
| 71 | |||
| 72 | return new SCRcontext(ri, outpipe.startSequence(sg, s, devR, abox)); | ||
| 73 | } | ||
| 74 | |||
| 75 | public boolean needTile(Object ctx, int x, int y, int w, int h) { | ||
| 76 | SCRcontext context = (SCRcontext) ctx; | ||
| 77 | return (outpipe.needTile(context.outcontext, x, y, w, h)); | ||
| 78 | } | ||
| 79 | |||
| 80 | public void renderPathTile(Object ctx, | ||
| 81 | byte[] atile, int offset, int tsize, | ||
| 82 | int x, int y, int w, int h, | ||
| 83 | ShapeSpanIterator sr) { | ||
| 84 | renderPathTile(ctx, atile, offset, tsize, x, y, w, h); | ||
| 85 | } | ||
| 86 | |||
| 87 | public void renderPathTile(Object ctx, | ||
| 88 | byte[] atile, int offset, int tsize, | ||
| 89 | int x, int y, int w, int h) { | ||
| 90 | SCRcontext context = (SCRcontext) ctx; | ||
| 91 | RegionIterator ri = context.iterator.createCopy(); | ||
| 92 | int[] band = context.band; | ||
| 93 | band[0] = x; | ||
| 94 | band[1] = y; | ||
| 95 | band[2] = x + w; | ||
| 96 | band[3] = y + h; | ||
| 97 | if (atile == null) { | ||
| 98 | int size = w * h; | ||
| 99 | atile = context.tile; | ||
| 100 | if (atile != null && atile.length < size) { | ||
| 101 | atile = null; | ||
| 102 | } | ||
| 103 | if (atile == null) { | ||
| 104 | atile = new byte[size]; | ||
| 105 | context.tile = atile; | ||
| 106 | } | ||
| 107 | offset = 0; | ||
| 108 | tsize = w; | ||
| 109 | fillTile(ri, atile, offset, tsize, band); | ||
| 110 | } else { | ||
| 111 | eraseTile(ri, atile, offset, tsize, band); | ||
| 112 | } | ||
| 113 | |||
| 114 | if (band[2] > band[0] && band[3] > band[1]) { | ||
| 115 | offset += (band[1] - y) * tsize + (band[0] - x); | ||
| 116 | outpipe.renderPathTile(context.outcontext, | ||
| 117 | atile, offset, tsize, | ||
| 118 | band[0], band[1], | ||
| 119 | band[2] - band[0], | ||
| 120 | band[3] - band[1]); | ||
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | public native void fillTile(RegionIterator ri, | ||
| 125 | byte[] alpha, int offset, int tsize, | ||
| 126 | int[] band); | ||
| 127 | |||
| 128 | public native void eraseTile(RegionIterator ri, | ||
| 129 | byte[] alpha, int offset, int tsize, | ||
| 130 | int[] band); | ||
| 131 | |||
| 132 | public void skipTile(Object ctx, int x, int y) { | ||
| 133 | SCRcontext context = (SCRcontext) ctx; | ||
| 134 | outpipe.skipTile(context.outcontext, x, y); | ||
| 135 | } | ||
| 136 | |||
| 137 | public void endSequence(Object ctx) { | ||
| 138 | SCRcontext context = (SCRcontext) ctx; | ||
| 139 | outpipe.endSequence(context.outcontext); | ||
| 140 | } | ||
| 141 | } | ||