< prev index next >

src/java.desktop/share/native/libawt/awt/image/BufImgSurfaceData.c

Print this page


   1 /*
   2  * Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "BufImgSurfaceData.h"
  27 #include <stdlib.h>
  28 
  29 #include "sun_awt_image_BufImgSurfaceData.h"
  30 
  31 #include "img_util_md.h"
  32 #include "jni_util.h"
  33 /* Define uintptr_t */
  34 #include "gdefs.h"

  35 
  36 /**
  37  * This include file contains support code for loops using the
  38  * SurfaceData interface to talk to an X11 drawable from native
  39  * code.
  40  */
  41 
  42 static LockFunc                 BufImg_Lock;
  43 static GetRasInfoFunc           BufImg_GetRasInfo;
  44 static ReleaseFunc              BufImg_Release;
  45 static DisposeFunc              BufImg_Dispose;
  46 
  47 static ColorData *BufImg_SetupICM(JNIEnv *env, BufImgSDOps *bisdo);
  48 
  49 static jfieldID         rgbID;
  50 static jfieldID         mapSizeID;
  51 static jfieldID         colorDataID;
  52 static jfieldID         pDataID;
  53 static jfieldID         allGrayID;
  54 


  63 Java_sun_awt_image_BufImgSurfaceData_initIDs
  64 (JNIEnv *env, jclass bisd, jclass icm, jclass cd)
  65 {
  66     if (sizeof(BufImgRIPrivate) > SD_RASINFO_PRIVATE_SIZE) {
  67         JNU_ThrowInternalError(env, "Private RasInfo structure too large!");
  68         return;
  69     }
  70 
  71     clsICMCD = (*env)->NewWeakGlobalRef(env, cd);
  72     JNU_CHECK_EXCEPTION(env);
  73     CHECK_NULL(initICMCDmID = (*env)->GetMethodID(env, cd, "<init>", "(J)V"));
  74     CHECK_NULL(pDataID = (*env)->GetFieldID(env, cd, "pData", "J"));
  75     CHECK_NULL(rgbID = (*env)->GetFieldID(env, icm, "rgb", "[I"));
  76     CHECK_NULL(allGrayID = (*env)->GetFieldID(env, icm, "allgrayopaque", "Z"));
  77     CHECK_NULL(mapSizeID = (*env)->GetFieldID(env, icm, "map_size", "I"));
  78     CHECK_NULL(colorDataID = (*env)->GetFieldID(env, icm, "colorData",
  79                                            "Lsun/awt/image/BufImgSurfaceData$ICMColorData;"));
  80 }
  81 
  82 /*
  83  * Class:     sun_java2d_SurfaceData
  84  * Method:    freeNativeICMData
  85  * Signature: (Ljava/awt/image/IndexColorModel;)V
  86  */
  87 JNIEXPORT void JNICALL
  88 Java_sun_awt_image_BufImgSurfaceData_freeNativeICMData
  89     (JNIEnv *env, jclass sd, jlong pData)
  90 {
  91     ColorData *cdata = (ColorData*)jlong_to_ptr(pData);
  92     freeICMColorData(cdata);
  93 }
  94 
  95 /*
  96  * Class:     sun_awt_image_BufImgSurfaceData
  97  * Method:    initOps
  98  * Signature: (Ljava/lang/Object;IIIII)V
  99  */
 100 JNIEXPORT void JNICALL
 101 Java_sun_awt_image_BufImgSurfaceData_initRaster(JNIEnv *env, jobject bisd,
 102                                                 jobject array,
 103                                                 jint offset, jint bitoffset,
 104                                                 jint width, jint height,
 105                                                 jint pixStr, jint scanStr,
 106                                                 jobject icm)
 107 {
 108     BufImgSDOps *bisdo =
 109         (BufImgSDOps*)SurfaceData_InitOps(env, bisd, sizeof(BufImgSDOps));
 110     if (bisdo == NULL) {
 111         JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
 112         return;
 113     }
 114     bisdo->sdOps.Lock = BufImg_Lock;
 115     bisdo->sdOps.GetRasInfo = BufImg_GetRasInfo;


 123     bisdo->scanStr = scanStr;
 124     bisdo->pixStr = pixStr;
 125     if (JNU_IsNull(env, icm)) {
 126         bisdo->lutarray = NULL;
 127         bisdo->lutsize = 0;
 128         bisdo->icm = NULL;
 129     } else {
 130         jobject lutarray = (*env)->GetObjectField(env, icm, rgbID);
 131         bisdo->lutarray = (*env)->NewWeakGlobalRef(env, lutarray);
 132         JNU_CHECK_EXCEPTION(env);
 133         bisdo->lutsize = (*env)->GetIntField(env, icm, mapSizeID);
 134         bisdo->icm = (*env)->NewWeakGlobalRef(env, icm);
 135     }
 136     bisdo->rasbounds.x1 = 0;
 137     bisdo->rasbounds.y1 = 0;
 138     bisdo->rasbounds.x2 = width;
 139     bisdo->rasbounds.y2 = height;
 140 }
 141 
 142 /*









 143  * Method for disposing native BufImgSD
 144  */
 145 static void BufImg_Dispose(JNIEnv *env, SurfaceDataOps *ops)
 146 {
 147     /* ops is assumed non-null as it is checked in SurfaceData_DisposeOps */
 148     BufImgSDOps *bisdo = (BufImgSDOps *)ops;
 149     (*env)->DeleteWeakGlobalRef(env, bisdo->array);
 150     if (bisdo->lutarray != NULL) {
 151         (*env)->DeleteWeakGlobalRef(env, bisdo->lutarray);
 152     }
 153     if (bisdo->icm != NULL) {
 154         (*env)->DeleteWeakGlobalRef(env, bisdo->icm);
 155     }
 156 }
 157 
 158 static jint BufImg_Lock(JNIEnv *env,
 159                         SurfaceDataOps *ops,
 160                         SurfaceDataRasInfo *pRasInfo,
 161                         jint lockflags)
 162 {


 356         cData->representsPrimaries = calculatePrimaryColorsApproximation(pRgb, cData->img_clr_tbl, 32);
 357         if (allGray == JNI_TRUE) {
 358             initInverseGrayLut(pRgb, bisdo->lutsize, cData);
 359         }
 360         (*env)->ReleasePrimitiveArrayCritical(env, bisdo->lutarray, pRgb,
 361                                               JNI_ABORT);
 362 
 363         initDitherTables(cData);
 364 
 365         if (JNU_IsNull(env, colorData)) {
 366             jlong pData = ptr_to_jlong(cData);
 367             colorData = (*env)->NewObjectA(env, clsICMCD, initICMCDmID, (jvalue *)&pData);
 368 
 369             if ((*env)->ExceptionCheck(env))
 370             {
 371                 free(cData);
 372                 return (ColorData*)NULL;
 373             }
 374 
 375             (*env)->SetObjectField(env, bisdo->icm, colorDataID, colorData);

 376         }
 377     }
 378 
 379     return cData;
 380 }
   1 /*
   2  * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "BufImgSurfaceData.h"
  27 #include <stdlib.h>
  28 
  29 #include "sun_awt_image_BufImgSurfaceData.h"
  30 
  31 #include "img_util_md.h"
  32 #include "jni_util.h"
  33 /* Define uintptr_t */
  34 #include "gdefs.h"
  35 #include "Disposer.h"
  36 
  37 /**
  38  * This include file contains support code for loops using the
  39  * SurfaceData interface to talk to an X11 drawable from native
  40  * code.
  41  */
  42 
  43 static LockFunc                 BufImg_Lock;
  44 static GetRasInfoFunc           BufImg_GetRasInfo;
  45 static ReleaseFunc              BufImg_Release;
  46 static DisposeFunc              BufImg_Dispose;
  47 
  48 static ColorData *BufImg_SetupICM(JNIEnv *env, BufImgSDOps *bisdo);
  49 
  50 static jfieldID         rgbID;
  51 static jfieldID         mapSizeID;
  52 static jfieldID         colorDataID;
  53 static jfieldID         pDataID;
  54 static jfieldID         allGrayID;
  55 


  64 Java_sun_awt_image_BufImgSurfaceData_initIDs
  65 (JNIEnv *env, jclass bisd, jclass icm, jclass cd)
  66 {
  67     if (sizeof(BufImgRIPrivate) > SD_RASINFO_PRIVATE_SIZE) {
  68         JNU_ThrowInternalError(env, "Private RasInfo structure too large!");
  69         return;
  70     }
  71 
  72     clsICMCD = (*env)->NewWeakGlobalRef(env, cd);
  73     JNU_CHECK_EXCEPTION(env);
  74     CHECK_NULL(initICMCDmID = (*env)->GetMethodID(env, cd, "<init>", "(J)V"));
  75     CHECK_NULL(pDataID = (*env)->GetFieldID(env, cd, "pData", "J"));
  76     CHECK_NULL(rgbID = (*env)->GetFieldID(env, icm, "rgb", "[I"));
  77     CHECK_NULL(allGrayID = (*env)->GetFieldID(env, icm, "allgrayopaque", "Z"));
  78     CHECK_NULL(mapSizeID = (*env)->GetFieldID(env, icm, "map_size", "I"));
  79     CHECK_NULL(colorDataID = (*env)->GetFieldID(env, icm, "colorData",
  80                                            "Lsun/awt/image/BufImgSurfaceData$ICMColorData;"));
  81 }
  82 
  83 /*













  84  * Class:     sun_awt_image_BufImgSurfaceData
  85  * Method:    initOps
  86  * Signature: (Ljava/lang/Object;IIIII)V
  87  */
  88 JNIEXPORT void JNICALL
  89 Java_sun_awt_image_BufImgSurfaceData_initRaster(JNIEnv *env, jobject bisd,
  90                                                 jobject array,
  91                                                 jint offset, jint bitoffset,
  92                                                 jint width, jint height,
  93                                                 jint pixStr, jint scanStr,
  94                                                 jobject icm)
  95 {
  96     BufImgSDOps *bisdo =
  97         (BufImgSDOps*)SurfaceData_InitOps(env, bisd, sizeof(BufImgSDOps));
  98     if (bisdo == NULL) {
  99         JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed.");
 100         return;
 101     }
 102     bisdo->sdOps.Lock = BufImg_Lock;
 103     bisdo->sdOps.GetRasInfo = BufImg_GetRasInfo;


 111     bisdo->scanStr = scanStr;
 112     bisdo->pixStr = pixStr;
 113     if (JNU_IsNull(env, icm)) {
 114         bisdo->lutarray = NULL;
 115         bisdo->lutsize = 0;
 116         bisdo->icm = NULL;
 117     } else {
 118         jobject lutarray = (*env)->GetObjectField(env, icm, rgbID);
 119         bisdo->lutarray = (*env)->NewWeakGlobalRef(env, lutarray);
 120         JNU_CHECK_EXCEPTION(env);
 121         bisdo->lutsize = (*env)->GetIntField(env, icm, mapSizeID);
 122         bisdo->icm = (*env)->NewWeakGlobalRef(env, icm);
 123     }
 124     bisdo->rasbounds.x1 = 0;
 125     bisdo->rasbounds.y1 = 0;
 126     bisdo->rasbounds.x2 = width;
 127     bisdo->rasbounds.y2 = height;
 128 }
 129 
 130 /*
 131  * Releases native structures associated with BufImgSurfaceData.ICMColorData.
 132  */
 133 static void BufImg_Dispose_ICMColorData(JNIEnv *env, jlong pData)
 134 {
 135     ColorData *cdata = (ColorData*)jlong_to_ptr(pData);
 136     freeICMColorData(cdata);
 137 }
 138 
 139 /*
 140  * Method for disposing native BufImgSD
 141  */
 142 static void BufImg_Dispose(JNIEnv *env, SurfaceDataOps *ops)
 143 {
 144     /* ops is assumed non-null as it is checked in SurfaceData_DisposeOps */
 145     BufImgSDOps *bisdo = (BufImgSDOps *)ops;
 146     (*env)->DeleteWeakGlobalRef(env, bisdo->array);
 147     if (bisdo->lutarray != NULL) {
 148         (*env)->DeleteWeakGlobalRef(env, bisdo->lutarray);
 149     }
 150     if (bisdo->icm != NULL) {
 151         (*env)->DeleteWeakGlobalRef(env, bisdo->icm);
 152     }
 153 }
 154 
 155 static jint BufImg_Lock(JNIEnv *env,
 156                         SurfaceDataOps *ops,
 157                         SurfaceDataRasInfo *pRasInfo,
 158                         jint lockflags)
 159 {


 353         cData->representsPrimaries = calculatePrimaryColorsApproximation(pRgb, cData->img_clr_tbl, 32);
 354         if (allGray == JNI_TRUE) {
 355             initInverseGrayLut(pRgb, bisdo->lutsize, cData);
 356         }
 357         (*env)->ReleasePrimitiveArrayCritical(env, bisdo->lutarray, pRgb,
 358                                               JNI_ABORT);
 359 
 360         initDitherTables(cData);
 361 
 362         if (JNU_IsNull(env, colorData)) {
 363             jlong pData = ptr_to_jlong(cData);
 364             colorData = (*env)->NewObjectA(env, clsICMCD, initICMCDmID, (jvalue *)&pData);
 365 
 366             if ((*env)->ExceptionCheck(env))
 367             {
 368                 free(cData);
 369                 return (ColorData*)NULL;
 370             }
 371 
 372             (*env)->SetObjectField(env, bisdo->icm, colorDataID, colorData);
 373             Disposer_AddRecord(env, colorData, BufImg_Dispose_ICMColorData, pData);
 374         }
 375     }
 376 
 377     return cData;
 378 }
< prev index next >