jdk/src/solaris/classes/sun/java2d/x11/X11SurfaceData.java
author ceisserer
Fri, 28 May 2010 11:37:44 -0700
changeset 5579 1a5e995a710b
parent 4250 e88776b21913
child 5580 629274e4c99f
permissions -rw-r--r--
6307603: [X11] Use RENDER extension for complex operations done in software Reviewed-by: bae, igor, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1999-2007 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.java2d.x11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.GraphicsDevice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Composite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.GraphicsConfiguration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.color.ColorSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Transparency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.image.BufferedImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.image.ColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.image.ComponentColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.image.DirectColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.image.IndexColorModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.image.Raster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.peer.ComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.awt.SunHints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import sun.awt.SunToolkit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import sun.awt.X11ComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import sun.awt.X11GraphicsConfig;
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 4250
diff changeset
    49
import sun.awt.X11GraphicsEnvironment;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import sun.awt.image.PixelConverter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import sun.font.X11TextRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import sun.java2d.InvalidPipeException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import sun.java2d.SunGraphics2D;
1739
ed98610896e7 6708580: Java applications slow when EXA enabled
tdv
parents: 2
diff changeset
    54
import sun.java2d.SunGraphicsEnvironment;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import sun.java2d.SurfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import sun.java2d.SurfaceDataProxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import sun.java2d.loops.SurfaceType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import sun.java2d.loops.CompositeType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import sun.java2d.loops.RenderLoops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import sun.java2d.loops.GraphicsPrimitive;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import sun.java2d.loops.XORComposite;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import sun.java2d.loops.Blit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import sun.java2d.pipe.ValidatePipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
import sun.java2d.pipe.PixelToShapeConverter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
import sun.java2d.pipe.TextPipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
import sun.java2d.pipe.Region;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 4250
diff changeset
    68
public abstract class X11SurfaceData extends XSurfaceData {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    X11ComponentPeer peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    X11GraphicsConfig graphicsConfig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private RenderLoops solidloops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    protected int depth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private static native void initIDs(Class xorComp, boolean tryDGA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    protected native void initSurface(int depth, int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                                      long drawable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        DESC_INT_BGR_X11        = "Integer BGR Pixmap";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        DESC_INT_RGB_X11        = "Integer RGB Pixmap";
2807
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
    83
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
    84
    public static final String
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
    85
        DESC_4BYTE_ABGR_PRE_X11 = "4 byte ABGR Pixmap with pre-multplied alpha";
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
    86
    public static final String
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
    87
        DESC_INT_ARGB_PRE_X11   = "Integer ARGB Pixmap with pre-multiplied " +
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
    88
                                  "alpha";
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
    89
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        DESC_BYTE_IND_OPQ_X11   = "Byte Indexed Opaque Pixmap";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        DESC_INT_BGR_X11_BM     = "Integer BGR Pixmap with 1-bit transp";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        DESC_INT_RGB_X11_BM     = "Integer RGB Pixmap with 1-bit transp";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        DESC_BYTE_IND_X11_BM    = "Byte Indexed Pixmap with 1-bit transp";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        DESC_BYTE_GRAY_X11      = "Byte Gray Opaque Pixmap";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        DESC_INDEX8_GRAY_X11    = "Index8 Gray Opaque Pixmap";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        DESC_BYTE_GRAY_X11_BM   = "Byte Gray Opaque Pixmap with 1-bit transp";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        DESC_INDEX8_GRAY_X11_BM = "Index8 Gray Opaque Pixmap with 1-bit transp";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        DESC_3BYTE_RGB_X11      = "3 Byte RGB Pixmap";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        DESC_3BYTE_BGR_X11      = "3 Byte BGR Pixmap";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        DESC_3BYTE_RGB_X11_BM   = "3 Byte RGB Pixmap with 1-bit transp";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        DESC_3BYTE_BGR_X11_BM   = "3 Byte BGR Pixmap with 1-bit transp";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        DESC_USHORT_555_RGB_X11 = "Ushort 555 RGB Pixmap";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        DESC_USHORT_565_RGB_X11 = "Ushort 565 RGB Pixmap";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        DESC_USHORT_555_RGB_X11_BM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                                = "Ushort 555 RGB Pixmap with 1-bit transp";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        DESC_USHORT_565_RGB_X11_BM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                                = "Ushort 565 RGB Pixmap with 1-bit transp";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        DESC_USHORT_INDEXED_X11 = "Ushort Indexed Pixmap";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    public static final String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        DESC_USHORT_INDEXED_X11_BM = "Ushort Indexed Pixmap with 1-bit transp";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public static final SurfaceType IntBgrX11 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        SurfaceType.IntBgr.deriveSubType(DESC_INT_BGR_X11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public static final SurfaceType IntRgbX11 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        SurfaceType.IntRgb.deriveSubType(DESC_INT_RGB_X11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
2807
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   142
    public static final SurfaceType FourByteAbgrPreX11 =
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   143
        SurfaceType.FourByteAbgrPre.deriveSubType(DESC_4BYTE_ABGR_PRE_X11);
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   144
    public static final SurfaceType IntArgbPreX11 =
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   145
        SurfaceType.IntArgbPre.deriveSubType(DESC_INT_ARGB_PRE_X11);
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   146
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public static final SurfaceType ThreeByteRgbX11 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        SurfaceType.ThreeByteRgb.deriveSubType(DESC_3BYTE_RGB_X11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public static final SurfaceType ThreeByteBgrX11 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        SurfaceType.ThreeByteBgr.deriveSubType(DESC_3BYTE_BGR_X11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public static final SurfaceType UShort555RgbX11 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        SurfaceType.Ushort555Rgb.deriveSubType(DESC_USHORT_555_RGB_X11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public static final SurfaceType UShort565RgbX11 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        SurfaceType.Ushort565Rgb.deriveSubType(DESC_USHORT_565_RGB_X11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public static final SurfaceType UShortIndexedX11 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        SurfaceType.UshortIndexed.deriveSubType(DESC_USHORT_INDEXED_X11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    public static final SurfaceType ByteIndexedOpaqueX11 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        SurfaceType.ByteIndexedOpaque.deriveSubType(DESC_BYTE_IND_OPQ_X11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    public static final SurfaceType ByteGrayX11 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        SurfaceType.ByteGray.deriveSubType(DESC_BYTE_GRAY_X11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public static final SurfaceType Index8GrayX11 =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        SurfaceType.Index8Gray.deriveSubType(DESC_INDEX8_GRAY_X11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    // Bitmap surface types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    public static final SurfaceType IntBgrX11_BM =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        SurfaceType.Custom.deriveSubType(DESC_INT_BGR_X11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                                         PixelConverter.Xbgr.instance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public static final SurfaceType IntRgbX11_BM =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        SurfaceType.Custom.deriveSubType(DESC_INT_RGB_X11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                                         PixelConverter.Xrgb.instance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public static final SurfaceType ThreeByteRgbX11_BM =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        SurfaceType.Custom.deriveSubType(DESC_3BYTE_RGB_X11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                                         PixelConverter.Xbgr.instance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public static final SurfaceType ThreeByteBgrX11_BM =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        SurfaceType.Custom.deriveSubType(DESC_3BYTE_BGR_X11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                                         PixelConverter.Xrgb.instance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public static final SurfaceType UShort555RgbX11_BM =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        SurfaceType.Custom.deriveSubType(DESC_USHORT_555_RGB_X11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                                         PixelConverter.Ushort555Rgb.instance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    public static final SurfaceType UShort565RgbX11_BM =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        SurfaceType.Custom.deriveSubType(DESC_USHORT_565_RGB_X11_BM,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                                         PixelConverter.Ushort565Rgb.instance);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public static final SurfaceType UShortIndexedX11_BM =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        SurfaceType.Custom.deriveSubType(DESC_USHORT_INDEXED_X11_BM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public static final SurfaceType ByteIndexedX11_BM =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        SurfaceType.Custom.deriveSubType(DESC_BYTE_IND_X11_BM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public static final SurfaceType ByteGrayX11_BM =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        SurfaceType.Custom.deriveSubType(DESC_BYTE_GRAY_X11_BM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public static final SurfaceType Index8GrayX11_BM =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        SurfaceType.Custom.deriveSubType(DESC_INDEX8_GRAY_X11_BM);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    private static Boolean accelerationEnabled = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public Raster getRaster(int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        throw new InternalError("not implemented yet");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    protected X11Renderer x11pipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    protected PixelToShapeConverter x11txpipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    protected static TextPipe x11textpipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    protected static boolean dgaAvailable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    static {
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 4250
diff changeset
   214
       if (!isX11SurfaceDataInitialized() &&
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 4250
diff changeset
   215
           !GraphicsEnvironment.isHeadless()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            // If a screen magnifier is present, don't attempt to use DGA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            String magPresent = (String) java.security.AccessController.doPrivileged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                (new sun.security.action.GetPropertyAction("javax.accessibility.screen_magnifier_present"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            boolean tryDGA = magPresent == null || !"true".equals(magPresent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            initIDs(XORComposite.class, tryDGA);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            String xtextpipe = (String) java.security.AccessController.doPrivileged
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                (new sun.security.action.GetPropertyAction("sun.java2d.xtextpipe"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            if (xtextpipe == null || "true".startsWith(xtextpipe)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                if ("true".equals(xtextpipe)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    // Only verbose if they use the full string "true"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    System.out.println("using X11 text renderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                x11textpipe = new X11TextRenderer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                if (GraphicsPrimitive.tracingEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    x11textpipe = ((X11TextRenderer) x11textpipe).traceWrap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                if ("false".equals(xtextpipe)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                    // Only verbose if they use the full string "false"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                    System.out.println("using DGA text renderer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                x11textpipe = solidTextRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            dgaAvailable = isDgaAvailable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            if (isAccelerationEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                X11PMBlitLoops.register();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                X11PMBlitBgLoops.register();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            }
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 4250
diff changeset
   248
       }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Returns true if we can use DGA on any of the screens
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public static native boolean isDgaAvailable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
1739
ed98610896e7 6708580: Java applications slow when EXA enabled
tdv
parents: 2
diff changeset
   256
    /**
ed98610896e7 6708580: Java applications slow when EXA enabled
tdv
parents: 2
diff changeset
   257
     * Returns true if shared memory pixmaps are available
ed98610896e7 6708580: Java applications slow when EXA enabled
tdv
parents: 2
diff changeset
   258
     */
ed98610896e7 6708580: Java applications slow when EXA enabled
tdv
parents: 2
diff changeset
   259
    private static native boolean isShmPMAvailable();
ed98610896e7 6708580: Java applications slow when EXA enabled
tdv
parents: 2
diff changeset
   260
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public static boolean isAccelerationEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if (accelerationEnabled == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            if (GraphicsEnvironment.isHeadless()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                accelerationEnabled = Boolean.FALSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                String prop =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    (String) java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                        new sun.security.action.GetPropertyAction("sun.java2d.pmoffscreen"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                if (prop != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                    // true iff prop==true, false otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                    accelerationEnabled = Boolean.valueOf(prop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                } else {
1739
ed98610896e7 6708580: Java applications slow when EXA enabled
tdv
parents: 2
diff changeset
   274
                    boolean isDisplayLocal = false;
ed98610896e7 6708580: Java applications slow when EXA enabled
tdv
parents: 2
diff changeset
   275
                    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ed98610896e7 6708580: Java applications slow when EXA enabled
tdv
parents: 2
diff changeset
   276
                    if (ge instanceof SunGraphicsEnvironment) {
ed98610896e7 6708580: Java applications slow when EXA enabled
tdv
parents: 2
diff changeset
   277
                        isDisplayLocal = ((SunGraphicsEnvironment) ge).isDisplayLocal();
ed98610896e7 6708580: Java applications slow when EXA enabled
tdv
parents: 2
diff changeset
   278
                     }
ed98610896e7 6708580: Java applications slow when EXA enabled
tdv
parents: 2
diff changeset
   279
ed98610896e7 6708580: Java applications slow when EXA enabled
tdv
parents: 2
diff changeset
   280
                    // EXA based drivers tend to place pixmaps in VRAM, slowing down readbacks.
ed98610896e7 6708580: Java applications slow when EXA enabled
tdv
parents: 2
diff changeset
   281
                    // Don't use pixmaps if dga is available,
ed98610896e7 6708580: Java applications slow when EXA enabled
tdv
parents: 2
diff changeset
   282
                    // or we are local and shared memory Pixmaps are not available.
ed98610896e7 6708580: Java applications slow when EXA enabled
tdv
parents: 2
diff changeset
   283
                    accelerationEnabled =
ed98610896e7 6708580: Java applications slow when EXA enabled
tdv
parents: 2
diff changeset
   284
                        !(isDgaAvailable() || (isDisplayLocal && !isShmPMAvailable()));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        return accelerationEnabled.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public SurfaceDataProxy makeProxyFor(SurfaceData srcData) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return X11SurfaceDataProxy.createProxy(srcData, graphicsConfig);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public void validatePipe(SunGraphics2D sg2d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        if (sg2d.antialiasHint != SunHints.INTVAL_ANTIALIAS_ON &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            sg2d.paintState <= sg2d.PAINT_ALPHACOLOR &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            (sg2d.compositeState <= sg2d.COMP_ISCOPY ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
             sg2d.compositeState == sg2d.COMP_XOR))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            if (x11txpipe == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                 * Note: this is thread-safe since x11txpipe is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                 * second of the two pipes constructed in makePipes().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                 * In the rare case we are racing against another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                 * thread making new pipes, setting lazypipe is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                 * safe alternative to waiting for the other thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                sg2d.drawpipe = lazypipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                sg2d.fillpipe = lazypipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                sg2d.shapepipe = lazypipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                sg2d.imagepipe = lazypipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                sg2d.textpipe = lazypipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            if (sg2d.clipState == sg2d.CLIP_SHAPE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                // Do this to init textpipe correctly; we will override the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                // other non-text pipes below
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                // REMIND: we should clean this up eventually instead of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                // having this work duplicated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                super.validatePipe(sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                switch (sg2d.textAntialiasHint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                case SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                    /* equating to OFF which it is for us */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                case SunHints.INTVAL_TEXT_ANTIALIAS_OFF:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                    // Use X11 pipe even if DGA is available since DGA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                    // text slows everything down when mixed with X11 calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                    if (sg2d.compositeState == sg2d.COMP_ISCOPY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                        sg2d.textpipe = x11textpipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                        sg2d.textpipe = solidTextRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                case SunHints.INTVAL_TEXT_ANTIALIAS_ON:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                    // Remind: may use Xrender for these when composite is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                    // copy as above, or if remote X11.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                    sg2d.textpipe = aaTextRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                    switch (sg2d.getFontInfo().aaHint) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                    case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                    case SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VRGB:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                        sg2d.textpipe = lcdTextRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                    case SunHints.INTVAL_TEXT_ANTIALIAS_OFF:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                    // Use X11 pipe even if DGA is available since DGA
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                    // text slows everything down when mixed with X11 calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                    if (sg2d.compositeState == sg2d.COMP_ISCOPY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                        sg2d.textpipe = x11textpipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                        sg2d.textpipe = solidTextRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                    case SunHints.INTVAL_TEXT_ANTIALIAS_ON:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                        sg2d.textpipe = aaTextRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                    default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                        sg2d.textpipe = solidTextRenderer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            if (sg2d.transformState >= sg2d.TRANSFORM_TRANSLATESCALE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                sg2d.drawpipe = x11txpipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                sg2d.fillpipe = x11txpipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            } else if (sg2d.strokeState != sg2d.STROKE_THIN){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                sg2d.drawpipe = x11txpipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                sg2d.fillpipe = x11pipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                sg2d.drawpipe = x11pipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
                sg2d.fillpipe = x11pipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            sg2d.shapepipe = x11pipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            sg2d.imagepipe = imagepipe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            // This is needed for AA text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            // Note that even an X11TextRenderer can dispatch AA text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            // if a GlyphVector overrides the AA setting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            // We use getRenderLoops() rather than setting solidloops
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            // directly so that we get the appropriate loops in XOR mode.
4250
e88776b21913 6896068: SunGraphics2D exposes a reference to itself while non fully initialised.
neugens
parents: 2807
diff changeset
   391
            if (sg2d.loops == null) {
e88776b21913 6896068: SunGraphics2D exposes a reference to itself while non fully initialised.
neugens
parents: 2807
diff changeset
   392
                // assert(some pipe will always be a LoopBasedPipe)
e88776b21913 6896068: SunGraphics2D exposes a reference to itself while non fully initialised.
neugens
parents: 2807
diff changeset
   393
                sg2d.loops = getRenderLoops(sg2d);
e88776b21913 6896068: SunGraphics2D exposes a reference to itself while non fully initialised.
neugens
parents: 2807
diff changeset
   394
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            super.validatePipe(sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    public RenderLoops getRenderLoops(SunGraphics2D sg2d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        if (sg2d.paintState <= sg2d.PAINT_ALPHACOLOR &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            sg2d.compositeState <= sg2d.COMP_ISCOPY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            return solidloops;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        return super.getRenderLoops(sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    public GraphicsConfiguration getDeviceConfiguration() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        return graphicsConfig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * Method for instantiating a Window SurfaceData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    public static X11WindowSurfaceData createData(X11ComponentPeer peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
       X11GraphicsConfig gc = getGC(peer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
       return new X11WindowSurfaceData(peer, gc, gc.getSurfaceType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * Method for instantiating a Pixmap SurfaceData (offscreen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    public static X11PixmapSurfaceData createData(X11GraphicsConfig gc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                                                  int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                                                  ColorModel cm, Image image,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                                                  long drawable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                                                  int transparency)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        return new X11PixmapSurfaceData(gc, width, height, image,
2807
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   431
                                        getSurfaceType(gc, transparency, true),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                                        cm, drawable, transparency);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
5579
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 4250
diff changeset
   435
//    /**
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 4250
diff changeset
   436
//     * Initializes the native Ops pointer.
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 4250
diff changeset
   437
//     */
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 4250
diff changeset
   438
//    private native void initOps(X11ComponentPeer peer,
1a5e995a710b 6307603: [X11] Use RENDER extension for complex operations done in software
ceisserer
parents: 4250
diff changeset
   439
//                                X11GraphicsConfig gc, int depth);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    protected X11SurfaceData(X11ComponentPeer peer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                             X11GraphicsConfig gc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                             SurfaceType sType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                             ColorModel cm) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        super(sType, cm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        this.peer = peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        this.graphicsConfig = gc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        this.solidloops = graphicsConfig.getSolidLoops(sType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        this.depth = cm.getPixelSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        initOps(peer, graphicsConfig, depth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        if (isAccelerationEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            setBlitProxyKey(gc.getProxyKey());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    public static X11GraphicsConfig getGC(X11ComponentPeer peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            return (X11GraphicsConfig) peer.getGraphicsConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            GraphicsEnvironment env =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                GraphicsEnvironment.getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            GraphicsDevice gd = env.getDefaultScreenDevice();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            return (X11GraphicsConfig)gd.getDefaultConfiguration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * Returns a boolean indicating whether or not a copyArea from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * the given rectangle source coordinates might be incomplete
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * and result in X11 GraphicsExposure events being generated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * from XCopyArea.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * This method allows the SurfaceData copyArea method to determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * if it needs to set the GraphicsExposures attribute of the X11 GC
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * to True or False to receive or avoid the events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * @return true if there is any chance that an XCopyArea from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     *              given source coordinates could produce any X11
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     *              Exposure events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    public abstract boolean canSourceSendExposures(int x, int y, int w, int h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    public boolean copyArea(SunGraphics2D sg2d,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                            int x, int y, int w, int h, int dx, int dy)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        if (x11pipe == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            if (!isDrawableValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            makePipes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        CompositeType comptype = sg2d.imageComp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        if (sg2d.transformState < sg2d.TRANSFORM_TRANSLATESCALE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            (CompositeType.SrcOverNoEa.equals(comptype) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
             CompositeType.SrcNoEa.equals(comptype)))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            x += sg2d.transX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            y += sg2d.transY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            SunToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                boolean needExposures = canSourceSendExposures(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                long xgc = getBlitGC(sg2d.getCompClip(), needExposures);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                x11pipe.devCopyArea(getNativeOps(), xgc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                                    x, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                                    x + dx, y + dy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                                    w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                SunToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    public static SurfaceType getSurfaceType(X11GraphicsConfig gc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                                             int transparency)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    {
2807
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   516
        return getSurfaceType(gc, transparency, false);
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   517
    }
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   518
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   519
    public static SurfaceType getSurfaceType(X11GraphicsConfig gc,
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   520
                                             int transparency,
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   521
                                             boolean pixmapSurface)
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   522
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        boolean transparent = (transparency == Transparency.BITMASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        SurfaceType sType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        ColorModel cm = gc.getColorModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        switch (cm.getPixelSize()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        case 24:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            if (gc.getBitsPerPixel() == 24) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                if (cm instanceof DirectColorModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                    // 4517321: We will always use ThreeByteBgr for 24 bpp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                    // surfaces, regardless of the pixel masks reported by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                    // X11.  Despite ambiguity in the X11 spec in how 24 bpp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                    // surfaces are treated, it appears that the best
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                    // SurfaceType for these configurations (including
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                    // some Matrox Millenium and ATI Radeon boards) is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                    // ThreeByteBgr.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                    sType = transparent ? X11SurfaceData.ThreeByteBgrX11_BM : X11SurfaceData.ThreeByteBgrX11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                    throw new sun.java2d.InvalidPipeException("Unsupported bit " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                                                              "depth/cm combo: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                                                              cm.getPixelSize()  +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                                                              ", " + cm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            // Fall through for 32 bit case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        case 32:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            if (cm instanceof DirectColorModel) {
2807
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   549
                if (((SunToolkit)java.awt.Toolkit.getDefaultToolkit()
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   550
                     ).isTranslucencyCapable(gc) && !pixmapSurface)
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   551
                {
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   552
                    sType = X11SurfaceData.IntArgbPreX11;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                } else {
2807
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   554
                    if (((DirectColorModel)cm).getRedMask() == 0xff0000) {
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   555
                        sType = transparent ? X11SurfaceData.IntRgbX11_BM :
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   556
                                              X11SurfaceData.IntRgbX11;
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   557
                    } else {
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   558
                        sType = transparent ? X11SurfaceData.IntBgrX11_BM :
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   559
                                              X11SurfaceData.IntBgrX11;
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   560
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                }
2807
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   562
            } else if (cm instanceof ComponentColorModel) {
db01a7f6d657 6839999: Cumulative fix for 6762511 and 6838003
anthony
parents: 2760
diff changeset
   563
                   sType = X11SurfaceData.FourByteAbgrPreX11;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            } else {
2758
d2fbe9b5857a 6762511: Translucency is not working on Linux using Metacity
anthony
parents: 1739
diff changeset
   565
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                throw new sun.java2d.InvalidPipeException("Unsupported bit " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                                                          "depth/cm combo: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                                                          cm.getPixelSize()  +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                                                          ", " + cm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        case 15:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            sType = transparent ? X11SurfaceData.UShort555RgbX11_BM : X11SurfaceData.UShort555RgbX11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        case 16:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
            if ((cm instanceof DirectColorModel) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                (((DirectColorModel)cm).getGreenMask() == 0x3e0))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                // fix for 4352984: Riva128 on Linux
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                sType = transparent ? X11SurfaceData.UShort555RgbX11_BM : X11SurfaceData.UShort555RgbX11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                sType = transparent ? X11SurfaceData.UShort565RgbX11_BM : X11SurfaceData.UShort565RgbX11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        case  12:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            if (cm instanceof IndexColorModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                sType = transparent ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                    X11SurfaceData.UShortIndexedX11_BM :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                    X11SurfaceData.UShortIndexedX11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                throw new sun.java2d.InvalidPipeException("Unsupported bit " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                                                          "depth: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                                                          cm.getPixelSize() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                                                          " cm="+cm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        case 8:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            if (cm.getColorSpace().getType() == ColorSpace.TYPE_GRAY &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                cm instanceof ComponentColorModel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                sType = transparent ? X11SurfaceData.ByteGrayX11_BM : X11SurfaceData.ByteGrayX11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            } else if (cm instanceof IndexColorModel &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                       isOpaqueGray((IndexColorModel)cm)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                sType = transparent ? X11SurfaceData.Index8GrayX11_BM : X11SurfaceData.Index8GrayX11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                sType = transparent ? X11SurfaceData.ByteIndexedX11_BM : X11SurfaceData.ByteIndexedOpaqueX11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            throw new sun.java2d.InvalidPipeException("Unsupported bit " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                                                      "depth: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                                                      cm.getPixelSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        return sType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    public void invalidate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        if (isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            setInvalid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            super.invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * The following methods and variables are used to keep the Java-level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * context state in sync with the native X11 GC associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * X11SurfaceData object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    private static native void XSetCopyMode(long xgc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    private static native void XSetXorMode(long xgc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    private static native void XSetForeground(long xgc, int pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    private long xgc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    private Region validatedClip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    private XORComposite validatedXorComp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    private int xorpixelmod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    private int validatedPixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
    private boolean validatedExposures = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    public final long getRenderGC(Region clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                                  int compState, Composite comp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                                  int pixel)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        return getGC(clip, compState, comp, pixel, validatedExposures);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    public final long getBlitGC(Region clip, boolean needExposures) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        return getGC(clip, SunGraphics2D.COMP_ISCOPY, null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                     validatedPixel, needExposures);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    final long getGC(Region clip,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                     int compState, Composite comp,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                     int pixel, boolean needExposures)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        // assert SunToolkit.isAWTLockHeldByCurrentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        if (!isValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            throw new InvalidPipeException("bounds changed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        // validate clip
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        if (clip != validatedClip) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            validatedClip = clip;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            if (clip != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                XSetClip(xgc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                         clip.getLoX(), clip.getLoY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                         clip.getHiX(), clip.getHiY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                         (clip.isRectangular() ? null : clip));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                XResetClip(xgc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        // validate composite
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        if (compState == SunGraphics2D.COMP_ISCOPY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            if (validatedXorComp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                validatedXorComp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                xorpixelmod = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                XSetCopyMode(xgc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            if (validatedXorComp != comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                validatedXorComp = (XORComposite)comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                xorpixelmod = validatedXorComp.getXorPixel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                XSetXorMode(xgc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        // validate pixel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        pixel ^= xorpixelmod;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        if (pixel != validatedPixel) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            validatedPixel = pixel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            XSetForeground(xgc, pixel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        if (validatedExposures != needExposures) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            validatedExposures = needExposures;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            XSetGraphicsExposures(xgc, needExposures);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        return xgc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    public synchronized void makePipes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        if (x11pipe == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            SunToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                xgc = XCreateGC(getNativeOps());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                SunToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            x11pipe = X11Renderer.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            x11txpipe = new PixelToShapeConverter(x11pipe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    public static class X11WindowSurfaceData extends X11SurfaceData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        public X11WindowSurfaceData(X11ComponentPeer peer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                                    X11GraphicsConfig gc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                                    SurfaceType sType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            super(peer, gc, sType, peer.getColorModel());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            if (isDrawableValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                makePipes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        public SurfaceData getReplacement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            return peer.getSurfaceData();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
            Rectangle r = peer.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            r.x = r.y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        public boolean canSourceSendExposures(int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
         * Returns destination Component associated with this SurfaceData.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        public Object getDestination() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            return peer.getTarget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    public static class X11PixmapSurfaceData extends X11SurfaceData {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        Image                   offscreenImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        int                     width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        int                     height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        int                     transparency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        public X11PixmapSurfaceData(X11GraphicsConfig gc,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                                    int width, int height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                                    Image image,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                                    SurfaceType sType, ColorModel cm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                                    long drawable, int transparency)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            super(null, gc, sType, cm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            this.width = width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            this.height = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            offscreenImage = image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            this.transparency = transparency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            initSurface(depth, width, height, drawable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
            makePipes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        public SurfaceData getReplacement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            return restoreContents(offscreenImage);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
         * Need this since the surface data is created with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
         * the color model of the target GC, which is always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
         * opaque. But in SunGraphics2D.blitSD we choose loops
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
         * based on the transparency on the source SD, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
         * it could choose wrong loop (blit instead of blitbg,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
         * for example).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        public int getTransparency() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            return transparency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        public Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            return new Rectangle(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        public boolean canSourceSendExposures(int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            return (x < 0 || y < 0 || (x+w) > width || (y+h) > height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        public void flush() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
             * We need to invalidate the surface before disposing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
             * native Drawable and GC.  This way if an application tries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
             * to render to an already flushed X11SurfaceData, we will notice
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
             * in the validate() method above that it has been invalidated,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
             * and we will avoid using those native resources that have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
             * already been disposed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            invalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            flushNativeSurface();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
         * Returns destination Image associated with this SurfaceData.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        public Object getDestination() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            return offscreenImage;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    private static LazyPipe lazypipe = new LazyPipe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    public static class LazyPipe extends ValidatePipe {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
        public boolean validate(SunGraphics2D sg2d) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            X11SurfaceData xsd = (X11SurfaceData) sg2d.surfaceData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
            if (!xsd.isDrawableValid()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
            xsd.makePipes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            return super.validate(sg2d);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
}