1/*
2 * Copyright (c) 2011, 2014, 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
26package sun.lwawt.macosx;
27
28import java.awt.*;
29import java.awt.image.*;
30import java.awt.print.PageFormat;
31import java.nio.ByteBuffer;
32
33import sun.java2d.*;
34import sun.java2d.loops.SurfaceType;
35
36public class CPrinterSurfaceData extends OSXSurfaceData{
37    public static final String DESC_INT_RGB_PQ = "Integer RGB Printer Quartz";
38//    public static final String DESC_INT_ARGB_PQ = "Integer ARGB Printer Quartz";
39
40//    public static final SurfaceType IntArgbPQ = SurfaceType.IntArgb.deriveSubType(DESC_INT_ARGB_PQ);
41    public static final SurfaceType IntRgbPQ = SurfaceType.IntRgb.deriveSubType(DESC_INT_RGB_PQ);
42
43    static SurfaceData createData(PageFormat pf, long context) {
44        return new CPrinterSurfaceData(CPrinterGraphicsConfig.getConfig(pf), context);
45    }
46
47    private CPrinterSurfaceData(GraphicsConfiguration gc, long context) {
48        super(IntRgbPQ, gc.getColorModel(), gc, gc.getBounds());
49        initOps(context, this.fGraphicsStates, this.fGraphicsStatesObject, gc.getBounds().width, gc.getBounds().height);
50    }
51
52    public SurfaceData getReplacement() {
53        return this;
54    }
55
56    private native void initOps(long context, ByteBuffer byteParameters, Object[] objectParameters, int width, int height);
57
58    public void enableFlushing() {
59        _flush();
60    }
61    native void _flush();
62
63    public Object getDestination() {
64        // this should never get called for the printer surface (see BufferStrategyPaintManager for one case of usage)
65        return null;
66    }
67
68    public Raster getRaster(int x, int y, int w, int h) {
69        BufferedImage dstImage = new BufferedImage(x + w, y + h, BufferedImage.TYPE_INT_ARGB_PRE);
70        return dstImage.getRaster();
71    }
72
73    public BufferedImage copyArea(SunGraphics2D sg2d, int x, int y, int w, int h, BufferedImage dstImage) {
74        // create the destination image if needed
75        if (dstImage == null) {
76            dstImage = getDeviceConfiguration().createCompatibleImage(w, h);
77        }
78
79        // copy
80        Graphics g = dstImage.createGraphics();
81        BufferedImage thisImage = getCompositingImage(w, h);
82        g.drawImage(thisImage, 0, 0, w, h, x, y, x+w, y+h, null);
83        g.dispose();
84
85        return dstImage;
86    }
87
88    public boolean xorSurfacePixels(SunGraphics2D sg2d, BufferedImage srcPixels, int x, int y, int w, int h, int colorXOR) {
89        throw new InternalError("not implemented yet");
90    }
91}
92