1 /*
   2  * Copyright (c) 2010, 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.xr;
  27 
  28 import static sun.java2d.loops.CompositeType.SrcNoEa;
  29 import static sun.java2d.loops.CompositeType.SrcOver;
  30 
  31 import java.awt.Composite;
  32 
  33 import sun.awt.*;
  34 import sun.java2d.*;
  35 import sun.java2d.loops.*;
  36 import sun.java2d.pipe.Region;
  37 
  38 /**
  39  * For XRender there is no "blit", everything is just a fill with Repeat or Not.
  40  * So basically this just quite the same as MaskFill.
  41  *
  42  * @author Clemens Eisserer
  43  */
  44 public class XRMaskBlit extends MaskBlit {
  45     static void register() {
  46         GraphicsPrimitive[] primitives = {
  47                 new XRMaskBlit(XRSurfaceData.IntArgbPreX11, SrcOver,
  48                                XRSurfaceData.IntArgbPreX11),
  49                 new XRMaskBlit(XRSurfaceData.IntRgbX11, SrcOver,
  50                                XRSurfaceData.IntRgbX11),
  51                 new XRMaskBlit(XRSurfaceData.IntArgbPreX11, SrcNoEa,
  52                                XRSurfaceData.IntRgbX11),
  53                 new XRMaskBlit(XRSurfaceData.IntRgbX11, SrcNoEa,
  54                                XRSurfaceData.IntArgbPreX11)
  55                 };
  56         GraphicsPrimitiveMgr.register(primitives);
  57     }
  58 
  59     public XRMaskBlit(SurfaceType srcType, CompositeType compType,
  60             SurfaceType dstType) {
  61         super(srcType, CompositeType.AnyAlpha, dstType);
  62     }
  63 
  64     protected native void maskBlit(long srcXsdo, long dstxsdo, int srcx,
  65             int srcy, int dstx, int dsty, int w, int h, int maskoff,
  66             int maskscan, int masklen, byte[] mask);
  67 
  68     public void MaskBlit(SurfaceData src, SurfaceData dst, Composite comp,
  69             Region clip, int srcx, int srcy, int dstx, int dsty, int width,
  70             int height, byte[] mask, int maskoff, int maskscan) {
  71         if (width <= 0 || height <= 0) {
  72             return;
  73         }
  74 
  75         try {
  76             SunToolkit.awtLock();
  77 
  78             XRSurfaceData x11sd = (XRSurfaceData) src;
  79             x11sd.validateAsSource(null, XRUtils.RepeatNone, XRUtils.FAST);
  80 
  81             XRCompositeManager maskBuffer = x11sd.maskBuffer;
  82             XRSurfaceData x11dst = (XRSurfaceData) dst;
  83             x11dst.validateAsDestination(null, clip);
  84 
  85             int maskPict = maskBuffer.getMaskBuffer().
  86                          uploadMask(width, height, maskscan, maskoff, mask);
  87             maskBuffer.XRComposite(x11sd.getPicture(), maskPict, x11dst.getPicture(),
  88                                   srcx, srcy, 0, 0, dstx, dsty, width, height);
  89             maskBuffer.getMaskBuffer().clearUploadMask(maskPict, width, height);
  90         } finally {
  91             SunToolkit.awtUnlock();
  92         }
  93     }
  94 }