1 /*
   2  * Copyright (c) 1998, 2016, 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  /*
  27  * @author Jim Graham
  28  * @author Charlton Innovations, Inc.
  29  */
  30 
  31 package sun.java2d.loops;
  32 
  33 import sun.java2d.loops.GraphicsPrimitive;
  34 import sun.java2d.pipe.SpanIterator;
  35 import sun.java2d.SunGraphics2D;
  36 import sun.java2d.SurfaceData;
  37 
  38 /**
  39  * FillSpans
  40  * 1) draw solid color onto destination surface
  41  * 2) rectangular areas to fill come from SpanIterator
  42  */
  43 public class FillSpans extends GraphicsPrimitive
  44 {
  45     public static final String methodSignature = "FillSpans(...)".toString();
  46 
  47     public static final int primTypeID = makePrimTypeID();
  48 
  49     public static FillSpans locate(SurfaceType srctype,
  50                                    CompositeType comptype,
  51                                    SurfaceType dsttype)
  52     {
  53         return (FillSpans)
  54             GraphicsPrimitiveMgr.locate(primTypeID,
  55                                         srctype, comptype, dsttype);
  56     }
  57 
  58     protected FillSpans(SurfaceType srctype,
  59                         CompositeType comptype,
  60                         SurfaceType dsttype)
  61     {
  62         super(methodSignature, primTypeID, srctype, comptype, dsttype);
  63     }
  64 
  65     public FillSpans(long pNativePrim,
  66                      SurfaceType srctype,
  67                      CompositeType comptype,
  68                      SurfaceType dsttype)
  69     {
  70         super(pNativePrim, methodSignature, primTypeID, srctype, comptype, dsttype);
  71     }
  72 
  73     private native void FillSpans(SunGraphics2D sg2d, SurfaceData dest,
  74                                   int pixel, long pIterator, SpanIterator si);
  75 
  76     /**
  77      * All FillSpan implementors must have this invoker method
  78      */
  79     public void FillSpans(SunGraphics2D sg2d, SurfaceData dest,
  80                           SpanIterator si)
  81     {
  82         FillSpans(sg2d, dest, sg2d.pixel, si.getNativeIterator(), si);
  83     }
  84 
  85     public GraphicsPrimitive makePrimitive(SurfaceType srctype,
  86                                            CompositeType comptype,
  87                                            SurfaceType dsttype)
  88     {
  89         // REMIND: iterate with a FillRect primitive?
  90         throw new InternalError("FillSpans not implemented for "+
  91                                 srctype+" with "+comptype);
  92     }
  93 
  94     public GraphicsPrimitive traceWrap() {
  95         return new TraceFillSpans(this);
  96     }
  97 
  98     private static class TraceFillSpans extends FillSpans {
  99         FillSpans target;
 100 
 101         public TraceFillSpans(FillSpans target) {
 102             super(target.getSourceType(),
 103                   target.getCompositeType(),
 104                   target.getDestType());
 105             this.target = target;
 106         }
 107 
 108         public GraphicsPrimitive traceWrap() {
 109             return this;
 110         }
 111 
 112         public void FillSpans(SunGraphics2D sg2d, SurfaceData dest,
 113                               SpanIterator si)
 114         {
 115             tracePrimitive(target);
 116             target.FillSpans(sg2d, dest, si);
 117         }
 118     }
 119 }