< prev index next >

src/java.desktop/unix/native/common/awt/X11Color.c

Print this page
rev 58017 : 8239124: Minimize the usage of AwtGraphicsConfigDataPtr in native
Reviewed-by: XXX
   1 /*
   2  * Copyright (c) 1995, 2019, 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


1246 
1247         if (awt_colormodel == NULL)
1248         {
1249             (*env)->PopLocalFrame(env, 0);
1250             return NULL;
1251         }
1252 
1253         /* Set pData field of ColorModel to point to ColorData */
1254         JNU_SetLongFieldFromPtr(env, awt_colormodel, g_CMpDataID,
1255                                 aData->color_data);
1256 
1257     }
1258 
1259     return (*env)->PopLocalFrame(env, awt_colormodel);
1260 }
1261 #endif /* !HEADLESS */
1262 
1263 extern jfieldID colorValueID;
1264 
1265 #ifndef HEADLESS
1266 int awtJNI_GetColorForVis (JNIEnv *env,jobject this, AwtGraphicsConfigDataPtr awt_data)
1267 {
1268     int col;
1269     jclass SYSCLR_class;
1270 
1271     if (!JNU_IsNull(env,this))
1272     {
1273         SYSCLR_class = (*env)->FindClass(env, "java/awt/SystemColor");
1274         CHECK_NULL_RETURN(SYSCLR_class, 0);
1275 
1276         if ((*env)->IsInstanceOf(env, this, SYSCLR_class)) {
1277                 /* SECURITY: This is safe, because there is no way
1278                  *           for client code to insert an object
1279                  *           that is a subclass of SystemColor
1280                  */
1281                 col = (int) JNU_CallMethodByName(env
1282                                           ,NULL
1283                                           ,this
1284                                           ,"getRGB"
1285                                           ,"()I").i;
1286                 JNU_CHECK_EXCEPTION_RETURN(env, 0);
1287         } else {
1288                 col = (int)(*env)->GetIntField(env,this,colorValueID);
1289         }
1290 
1291         if (awt_data->awt_cmap == (Colormap) NULL) {
1292             awtJNI_CreateColorData (env, awt_data, 1);
1293         }
1294 
1295         col = awt_data->AwtColorMatch(red(col), green(col), blue(col),
1296                                       awt_data);
1297         return col;
1298     }
1299 
1300     return 0;
1301 }
1302 
1303 void
1304 awt_allocate_systemrgbcolors (jint *rgbColors, int num_colors,
1305                               AwtGraphicsConfigDataPtr awtData) {
1306     int i, pixel;
1307     for (i = 0; i < num_colors; i++)
1308         pixel = alloc_col (awt_display, awtData->awt_cmap, red (rgbColors [i]),
1309                            green (rgbColors [i]), blue (rgbColors [i]), -1,
1310                            awtData);
1311 }
1312 
1313 int
1314 awtCreateX11Colormap(AwtGraphicsConfigDataPtr adata) {
1315     int screen = adata->awt_visInfo.screen;
1316     Colormap cmap = (Colormap)NULL;
1317 
1318     if (adata->awt_visInfo.visual == DefaultVisual(awt_display, screen)) {
1319         cmap = DefaultColormap(awt_display, screen);
1320     } else {
1321         Window root = RootWindow(awt_display, screen);
1322 


   1 /*
   2  * Copyright (c) 1995, 2020, 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


1246 
1247         if (awt_colormodel == NULL)
1248         {
1249             (*env)->PopLocalFrame(env, 0);
1250             return NULL;
1251         }
1252 
1253         /* Set pData field of ColorModel to point to ColorData */
1254         JNU_SetLongFieldFromPtr(env, awt_colormodel, g_CMpDataID,
1255                                 aData->color_data);
1256 
1257     }
1258 
1259     return (*env)->PopLocalFrame(env, awt_colormodel);
1260 }
1261 #endif /* !HEADLESS */
1262 
1263 extern jfieldID colorValueID;
1264 
1265 #ifndef HEADLESS





































1266 void
1267 awt_allocate_systemrgbcolors (jint *rgbColors, int num_colors,
1268                               AwtGraphicsConfigDataPtr awtData) {
1269     int i, pixel;
1270     for (i = 0; i < num_colors; i++)
1271         pixel = alloc_col (awt_display, awtData->awt_cmap, red (rgbColors [i]),
1272                            green (rgbColors [i]), blue (rgbColors [i]), -1,
1273                            awtData);
1274 }
1275 
1276 int
1277 awtCreateX11Colormap(AwtGraphicsConfigDataPtr adata) {
1278     int screen = adata->awt_visInfo.screen;
1279     Colormap cmap = (Colormap)NULL;
1280 
1281     if (adata->awt_visInfo.visual == DefaultVisual(awt_display, screen)) {
1282         cmap = DefaultColormap(awt_display, screen);
1283     } else {
1284         Window root = RootWindow(awt_display, screen);
1285 


< prev index next >