src/solaris/classes/sun/font/XRGlyphCacheEntry.java

Print this page
rev 6829 : Fix Xrender backend on  64-bit Big-endian architectures


  52         yOff = (int) Math.round(getYAdvance());
  53     }
  54 
  55     public int getXOff() {
  56         return xOff;
  57     }
  58 
  59     public int getYOff() {
  60         return yOff;
  61     }
  62 
  63     public void setGlyphSet(int glyphSet) {
  64         this.glyphSet = glyphSet;
  65     }
  66 
  67     public int getGlyphSet() {
  68         return glyphSet;
  69     }
  70 
  71     public static int getGlyphID(long glyphInfoPtr) {
  72         return (int) StrikeCache.unsafe.getInt(glyphInfoPtr + StrikeCache.cacheCellOffset);




  73     }
  74 
  75     public static void setGlyphID(long glyphInfoPtr, int id) {
  76         StrikeCache.unsafe.putInt(glyphInfoPtr + StrikeCache.cacheCellOffset, id);







  77     }
  78 
  79     public int getGlyphID() {
  80         return getGlyphID(glyphInfoPtr);
  81     }
  82 
  83     public void setGlyphID(int id) {
  84         setGlyphID(glyphInfoPtr, id);
  85     }
  86 
  87     public float getXAdvance() {
  88         return StrikeCache.unsafe.getFloat(glyphInfoPtr + StrikeCache.xAdvanceOffset);
  89     }
  90 
  91     public float getYAdvance() {
  92         return StrikeCache.unsafe.getFloat(glyphInfoPtr + StrikeCache.yAdvanceOffset);
  93     }
  94 
  95     public int getSourceRowBytes() {
  96         return StrikeCache.unsafe.getShort(glyphInfoPtr + StrikeCache.rowBytesOffset);
  97     }
  98 
  99     public int getWidth() {
 100         return StrikeCache.unsafe.getShort(glyphInfoPtr + StrikeCache.widthOffset);
 101     }
 102 
 103     public int getHeight() {
 104         return StrikeCache.unsafe.getShort(glyphInfoPtr + StrikeCache.heightOffset);
 105     }
 106 
 107     public void writePixelData(ByteArrayOutputStream os, boolean uploadAsLCD) {
 108         long pixelDataAddress;
 109         if (StrikeCache.nativeAddressSize == 4) {
 110             pixelDataAddress = 0xffffffff & StrikeCache.unsafe.getInt(glyphInfoPtr + StrikeCache.pixelDataOffset);
 111         } else {
 112             pixelDataAddress = StrikeCache.unsafe.getLong(glyphInfoPtr + StrikeCache.pixelDataOffset);
 113         }
 114         if (pixelDataAddress == 0L) {
 115             return;
 116         }
 117 
 118         int width = getWidth();
 119         int height = getHeight();
 120         int rowBytes = getSourceRowBytes();
 121         int paddedWidth = getPaddedWidth(uploadAsLCD);
 122 
 123         if (!uploadAsLCD) {
 124             for (int line = 0; line < height; line++) {
 125                 for(int x = 0; x < paddedWidth; x++) {
 126                     if(x < width) {
 127                         os.write(StrikeCache.unsafe.getByte(pixelDataAddress + (line * rowBytes + x)));
 128                     }else {
 129                          /*pad to multiple of 4 bytes per line*/
 130                          os.write(0);
 131                     }
 132                 }
 133             }




  52         yOff = (int) Math.round(getYAdvance());
  53     }
  54 
  55     public int getXOff() {
  56         return xOff;
  57     }
  58 
  59     public int getYOff() {
  60         return yOff;
  61     }
  62 
  63     public void setGlyphSet(int glyphSet) {
  64         this.glyphSet = glyphSet;
  65     }
  66 
  67     public int getGlyphSet() {
  68         return glyphSet;
  69     }
  70 
  71     public static int getGlyphID(long glyphInfoPtr) {
  72         // We need to access the GlyphID with Unsafe.getAddress() because the corresponding field
  73         // in the underlying C data-structure is of type 'void*' (see field 'cellInfo' of struct
  74         // 'GlyphInfo' in src/share/native/sun/font/fontscalerdefs.h).
  75         // On 64-bit Big-endian architectures it would be wrong to access this field with Unsafe.getInt().
  76         return (int) StrikeCache.unsafe.getAddress(glyphInfoPtr + StrikeCache.cacheCellOffset);
  77     }
  78 
  79     public static void setGlyphID(long glyphInfoPtr, int id) {
  80         // We need to access the GlyphID with Unsafe.putAddress() because the corresponding field
  81         // in the underlying C data-structure is of type 'void*' (see field 'cellInfo' of struct
  82         // 'GlyphInfo' in src/share/native/sun/font/fontscalerdefs.h).
  83         // On 64-bit Big-endian architectures it would be wrong to write this field with Unsafe.putInt()
  84         // because it is also accessed from native code as a 'long' (see
  85         // Java_sun_java2d_xr_XRBackendNative_XRAddGlyphsNative() in
  86         // src/solaris/native/sun/java2d/x11/XRBackendNative.c)
  87         StrikeCache.unsafe.putAddress(glyphInfoPtr + StrikeCache.cacheCellOffset, (long)id);
  88     }
  89 
  90     public int getGlyphID() {
  91         return getGlyphID(glyphInfoPtr);
  92     }
  93 
  94     public void setGlyphID(int id) {
  95         setGlyphID(glyphInfoPtr, id);
  96     }
  97 
  98     public float getXAdvance() {
  99         return StrikeCache.unsafe.getFloat(glyphInfoPtr + StrikeCache.xAdvanceOffset);
 100     }
 101 
 102     public float getYAdvance() {
 103         return StrikeCache.unsafe.getFloat(glyphInfoPtr + StrikeCache.yAdvanceOffset);
 104     }
 105 
 106     public int getSourceRowBytes() {
 107         return StrikeCache.unsafe.getShort(glyphInfoPtr + StrikeCache.rowBytesOffset);
 108     }
 109 
 110     public int getWidth() {
 111         return StrikeCache.unsafe.getShort(glyphInfoPtr + StrikeCache.widthOffset);
 112     }
 113 
 114     public int getHeight() {
 115         return StrikeCache.unsafe.getShort(glyphInfoPtr + StrikeCache.heightOffset);
 116     }
 117 
 118     public void writePixelData(ByteArrayOutputStream os, boolean uploadAsLCD) {
 119         long pixelDataAddress = StrikeCache.unsafe.getAddress(glyphInfoPtr + StrikeCache.pixelDataOffset);





 120         if (pixelDataAddress == 0L) {
 121             return;
 122         }
 123 
 124         int width = getWidth();
 125         int height = getHeight();
 126         int rowBytes = getSourceRowBytes();
 127         int paddedWidth = getPaddedWidth(uploadAsLCD);
 128 
 129         if (!uploadAsLCD) {
 130             for (int line = 0; line < height; line++) {
 131                 for(int x = 0; x < paddedWidth; x++) {
 132                     if(x < width) {
 133                         os.write(StrikeCache.unsafe.getByte(pixelDataAddress + (line * rowBytes + x)));
 134                     }else {
 135                          /*pad to multiple of 4 bytes per line*/
 136                          os.write(0);
 137                     }
 138                 }
 139             }