0N/A/*
2362N/A * Copyright (c) 1997, 2002, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.java2d.pipe;
0N/A
0N/Aimport java.awt.AlphaComposite;
0N/Aimport java.awt.CompositeContext;
0N/Aimport java.awt.PaintContext;
0N/Aimport java.awt.Rectangle;
0N/Aimport java.awt.Shape;
0N/Aimport java.awt.RenderingHints;
0N/Aimport java.awt.image.ColorModel;
0N/Aimport java.awt.image.BufferedImage;
0N/Aimport java.awt.image.Raster;
0N/Aimport java.awt.image.WritableRaster;
0N/Aimport sun.awt.image.BufImgSurfaceData;
0N/Aimport sun.java2d.SunGraphics2D;
0N/Aimport sun.java2d.SurfaceData;
0N/Aimport sun.java2d.loops.Blit;
0N/Aimport sun.java2d.loops.MaskBlit;
0N/Aimport sun.java2d.loops.CompositeType;
0N/A
0N/Apublic class GeneralCompositePipe implements CompositePipe {
0N/A class TileContext {
0N/A SunGraphics2D sunG2D;
0N/A PaintContext paintCtxt;
0N/A CompositeContext compCtxt;
0N/A ColorModel compModel;
0N/A Object pipeState;
0N/A
0N/A public TileContext(SunGraphics2D sg, PaintContext pCtx,
0N/A CompositeContext cCtx, ColorModel cModel) {
0N/A sunG2D = sg;
0N/A paintCtxt = pCtx;
0N/A compCtxt = cCtx;
0N/A compModel = cModel;
0N/A }
0N/A }
0N/A
0N/A public Object startSequence(SunGraphics2D sg, Shape s, Rectangle devR,
0N/A int[] abox) {
0N/A RenderingHints hints = sg.getRenderingHints();
0N/A ColorModel model = sg.getDeviceColorModel();
0N/A PaintContext paintContext =
0N/A sg.paint.createContext(model, devR, s.getBounds2D(),
0N/A sg.cloneTransform(),
0N/A hints);
0N/A CompositeContext compositeContext =
0N/A sg.composite.createContext(paintContext.getColorModel(), model,
0N/A hints);
0N/A return new TileContext(sg, paintContext, compositeContext, model);
0N/A }
0N/A
0N/A public boolean needTile(Object ctx, int x, int y, int w, int h) {
0N/A return true;
0N/A }
0N/A
0N/A /**
0N/A * GeneralCompositePipe.renderPathTile works with custom composite operator
0N/A * provided by an application
0N/A */
0N/A public void renderPathTile(Object ctx,
0N/A byte[] atile, int offset, int tilesize,
0N/A int x, int y, int w, int h) {
0N/A TileContext context = (TileContext) ctx;
0N/A PaintContext paintCtxt = context.paintCtxt;
0N/A CompositeContext compCtxt = context.compCtxt;
0N/A SunGraphics2D sg = context.sunG2D;
0N/A
0N/A Raster srcRaster = paintCtxt.getRaster(x, y, w, h);
0N/A ColorModel paintModel = paintCtxt.getColorModel();
0N/A
0N/A Raster dstRaster;
0N/A Raster dstIn;
0N/A WritableRaster dstOut;
0N/A
0N/A SurfaceData sd = sg.getSurfaceData();
0N/A dstRaster = sd.getRaster(x, y, w, h);
0N/A if (dstRaster instanceof WritableRaster && atile == null) {
0N/A dstOut = (WritableRaster) dstRaster;
0N/A dstOut = dstOut.createWritableChild(x, y, w, h, 0, 0, null);
0N/A dstIn = dstOut;
0N/A } else {
0N/A dstIn = dstRaster.createChild(x, y, w, h, 0, 0, null);
0N/A dstOut = dstIn.createCompatibleWritableRaster();
0N/A }
0N/A
0N/A compCtxt.compose(srcRaster, dstIn, dstOut);
0N/A
0N/A if (dstRaster != dstOut && dstOut.getParent() != dstRaster) {
0N/A if (dstRaster instanceof WritableRaster && atile == null) {
0N/A ((WritableRaster) dstRaster).setDataElements(x, y, dstOut);
0N/A } else {
0N/A ColorModel cm = sg.getDeviceColorModel();
0N/A BufferedImage resImg =
0N/A new BufferedImage(cm, dstOut,
0N/A cm.isAlphaPremultiplied(),
0N/A null);
0N/A SurfaceData resData = BufImgSurfaceData.createData(resImg);
0N/A if (atile == null) {
0N/A Blit blit = Blit.getFromCache(resData.getSurfaceType(),
0N/A CompositeType.SrcNoEa,
0N/A sd.getSurfaceType());
0N/A blit.Blit(resData, sd, AlphaComposite.Src, null,
0N/A 0, 0, x, y, w, h);
0N/A } else {
0N/A MaskBlit blit = MaskBlit.getFromCache(resData.getSurfaceType(),
0N/A CompositeType.SrcNoEa,
0N/A sd.getSurfaceType());
0N/A blit.MaskBlit(resData, sd, AlphaComposite.Src, null,
0N/A 0, 0, x, y, w, h,
0N/A atile, offset, tilesize);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A public void skipTile(Object ctx, int x, int y) {
0N/A return;
0N/A }
0N/A
0N/A public void endSequence(Object ctx) {
0N/A TileContext context = (TileContext) ctx;
0N/A if (context.paintCtxt != null) {
0N/A context.paintCtxt.dispose();
0N/A }
0N/A if (context.compCtxt != null) {
0N/A context.compCtxt.dispose();
0N/A }
0N/A }
0N/A
0N/A}