Path: blob/master/src/java.desktop/share/classes/sun/java2d/pipe/GeneralCompositePipe.java
41159 views
/*1* Copyright (c) 1997, 2002, 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.AlphaComposite;28import java.awt.CompositeContext;29import java.awt.PaintContext;30import java.awt.Rectangle;31import java.awt.Shape;32import java.awt.RenderingHints;33import java.awt.image.ColorModel;34import java.awt.image.BufferedImage;35import java.awt.image.Raster;36import java.awt.image.WritableRaster;37import sun.awt.image.BufImgSurfaceData;38import sun.java2d.SunGraphics2D;39import sun.java2d.SurfaceData;40import sun.java2d.loops.Blit;41import sun.java2d.loops.MaskBlit;42import sun.java2d.loops.CompositeType;4344public class GeneralCompositePipe implements CompositePipe {45class TileContext {46SunGraphics2D sunG2D;47PaintContext paintCtxt;48CompositeContext compCtxt;49ColorModel compModel;50Object pipeState;5152public TileContext(SunGraphics2D sg, PaintContext pCtx,53CompositeContext cCtx, ColorModel cModel) {54sunG2D = sg;55paintCtxt = pCtx;56compCtxt = cCtx;57compModel = cModel;58}59}6061public Object startSequence(SunGraphics2D sg, Shape s, Rectangle devR,62int[] abox) {63RenderingHints hints = sg.getRenderingHints();64ColorModel model = sg.getDeviceColorModel();65PaintContext paintContext =66sg.paint.createContext(model, devR, s.getBounds2D(),67sg.cloneTransform(),68hints);69CompositeContext compositeContext =70sg.composite.createContext(paintContext.getColorModel(), model,71hints);72return new TileContext(sg, paintContext, compositeContext, model);73}7475public boolean needTile(Object ctx, int x, int y, int w, int h) {76return true;77}7879/**80* GeneralCompositePipe.renderPathTile works with custom composite operator81* provided by an application82*/83public void renderPathTile(Object ctx,84byte[] atile, int offset, int tilesize,85int x, int y, int w, int h) {86TileContext context = (TileContext) ctx;87PaintContext paintCtxt = context.paintCtxt;88CompositeContext compCtxt = context.compCtxt;89SunGraphics2D sg = context.sunG2D;9091Raster srcRaster = paintCtxt.getRaster(x, y, w, h);92ColorModel paintModel = paintCtxt.getColorModel();9394Raster dstRaster;95Raster dstIn;96WritableRaster dstOut;9798SurfaceData sd = sg.getSurfaceData();99dstRaster = sd.getRaster(x, y, w, h);100if (dstRaster instanceof WritableRaster && atile == null) {101dstOut = (WritableRaster) dstRaster;102dstOut = dstOut.createWritableChild(x, y, w, h, 0, 0, null);103dstIn = dstOut;104} else {105dstIn = dstRaster.createChild(x, y, w, h, 0, 0, null);106dstOut = dstIn.createCompatibleWritableRaster();107}108109compCtxt.compose(srcRaster, dstIn, dstOut);110111if (dstRaster != dstOut && dstOut.getParent() != dstRaster) {112if (dstRaster instanceof WritableRaster && atile == null) {113((WritableRaster) dstRaster).setDataElements(x, y, dstOut);114} else {115ColorModel cm = sg.getDeviceColorModel();116BufferedImage resImg =117new BufferedImage(cm, dstOut,118cm.isAlphaPremultiplied(),119null);120SurfaceData resData = BufImgSurfaceData.createData(resImg);121if (atile == null) {122Blit blit = Blit.getFromCache(resData.getSurfaceType(),123CompositeType.SrcNoEa,124sd.getSurfaceType());125blit.Blit(resData, sd, AlphaComposite.Src, null,1260, 0, x, y, w, h);127} else {128MaskBlit blit = MaskBlit.getFromCache(resData.getSurfaceType(),129CompositeType.SrcNoEa,130sd.getSurfaceType());131blit.MaskBlit(resData, sd, AlphaComposite.Src, null,1320, 0, x, y, w, h,133atile, offset, tilesize);134}135}136}137}138139public void skipTile(Object ctx, int x, int y) {140return;141}142143public void endSequence(Object ctx) {144TileContext context = (TileContext) ctx;145if (context.paintCtxt != null) {146context.paintCtxt.dispose();147}148if (context.compCtxt != null) {149context.compCtxt.dispose();150}151}152153}154155156