1 /*
   2  * Copyright (c) 2019, 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 package sun.java2d.metal;
  26 
  27 import sun.java2d.InvalidPipeException;
  28 import sun.java2d.SunGraphics2D;
  29 import sun.java2d.loops.CompositeType;
  30 import sun.java2d.loops.GraphicsPrimitive;
  31 import sun.java2d.loops.GraphicsPrimitiveMgr;
  32 import sun.java2d.loops.SurfaceType;
  33 import sun.java2d.pipe.BufferedMaskFill;
  34 
  35 import java.awt.*;
  36 
  37 import static sun.java2d.loops.CompositeType.SrcNoEa;
  38 import static sun.java2d.loops.CompositeType.SrcOver;
  39 import static sun.java2d.loops.SurfaceType.*;
  40 
  41 class MTLMaskFill extends BufferedMaskFill {
  42 
  43     static void register() {
  44         GraphicsPrimitive[] primitives = {
  45             new MTLMaskFill(AnyColor,                  SrcOver),
  46             new MTLMaskFill(OpaqueColor,               SrcNoEa),
  47             new MTLMaskFill(GradientPaint,             SrcOver),
  48             new MTLMaskFill(OpaqueGradientPaint,       SrcNoEa),
  49             new MTLMaskFill(LinearGradientPaint,       SrcOver),
  50             new MTLMaskFill(OpaqueLinearGradientPaint, SrcNoEa),
  51             new MTLMaskFill(RadialGradientPaint,       SrcOver),
  52             new MTLMaskFill(OpaqueRadialGradientPaint, SrcNoEa),
  53             new MTLMaskFill(TexturePaint,              SrcOver),
  54             new MTLMaskFill(OpaqueTexturePaint,        SrcNoEa),
  55         };
  56         GraphicsPrimitiveMgr.register(primitives);
  57     }
  58 
  59     protected MTLMaskFill(SurfaceType srcType, CompositeType compType) {
  60         super(MTLRenderQueue.getInstance(),
  61               srcType, compType, MTLSurfaceData.MTLSurface);
  62     }
  63 
  64     @Override
  65     protected native void maskFill(int x, int y, int w, int h,
  66                                    int maskoff, int maskscan, int masklen,
  67                                    byte[] mask);
  68 
  69     @Override
  70     protected void validateContext(SunGraphics2D sg2d,
  71                                    Composite comp, int ctxflags)
  72     {
  73         MTLSurfaceData dstData;
  74         try {
  75             dstData = (MTLSurfaceData) sg2d.surfaceData;
  76         } catch (ClassCastException e) {
  77             throw new InvalidPipeException("wrong surface data type: " +
  78                                            sg2d.surfaceData);
  79         }
  80 
  81         MTLContext.validateContext(dstData, dstData,
  82                                    sg2d.getCompClip(), comp,
  83                                    null, sg2d.paint, sg2d, ctxflags);
  84     }
  85 }