< prev index next >

src/java.desktop/unix/native/libawt_xawt/awt/awt_GraphicsEnv.c

Print this page
rev 56362 : 8231445: check ZALLOC return values in awt coding


 149     }
 150     return 0;
 151 }
 152 
 153 static AwtGraphicsConfigDataPtr
 154 findWithTemplate(XVisualInfo *vinfo,
 155                  long mask)
 156 {
 157 
 158     XVisualInfo *visualList;
 159     XColor color;
 160     AwtGraphicsConfigDataPtr defaultConfig;
 161     int visualsMatched, i;
 162 
 163     visualList = XGetVisualInfo(awt_display,
 164                                 mask, vinfo, &visualsMatched);
 165     if (visualList) {
 166         int id = -1;
 167         VisualID defaultVisual = XVisualIDFromVisual(DefaultVisual(awt_display, vinfo->screen));
 168         defaultConfig = ZALLOC(_AwtGraphicsConfigData);




 169         for (i = 0; i < visualsMatched; i++) {
 170             memcpy(&defaultConfig->awt_visInfo, &visualList[i], sizeof(XVisualInfo));
 171             defaultConfig->awt_depth = visualList[i].depth;
 172 
 173             /* we can't use awtJNI_CreateColorData here, because it'll pull,
 174                SystemColor, which in turn will cause toolkit to be reinitialized */
 175             if (awtCreateX11Colormap(defaultConfig)) {
 176                 if (visualList[i].visualid == defaultVisual) {
 177                     id = i;
 178                     break;
 179                 } else if (-1 == id) {
 180                     // Keep 1st match for fallback
 181                     id = i;
 182                 }
 183             }
 184         }
 185         if (-1 != id) {
 186             memcpy(&defaultConfig->awt_visInfo, &visualList[id], sizeof(XVisualInfo));
 187             defaultConfig->awt_depth = visualList[id].depth;
 188             /* Allocate white and black pixels for this visual */


 430                                                     "XRenderFindVisualFormat");
 431             if (xrenderFindVisualFormat == NULL) {
 432                 DTRACE_PRINTLN1("Can't find 'XRenderFindVisualFormat' in libXrender (%s)", dlerror());
 433             }
 434         } else {
 435             DTRACE_PRINTLN1("Can't load libXrender (%s)", dlerror());
 436         }
 437     } else {
 438         DTRACE_PRINTLN("RENDER extension NOT available");
 439     }
 440 
 441     for (i = 0; i < nTrue; i++) {
 442         if (XVisualIDFromVisual(pVITrue[i].visual) ==
 443             XVisualIDFromVisual(defaultConfig->awt_visInfo.visual) ||
 444             pVITrue[i].depth == 12) {
 445             /* Skip the non-supported 12-bit TrueColor visual */
 446             continue;
 447         } else {
 448             ind = nConfig++;
 449         }
 450         graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData);
 451         graphicsConfigs [ind]->awt_depth = pVITrue [i].depth;




 452         memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVITrue [i],
 453                 sizeof (XVisualInfo));
 454         if (xrenderFindVisualFormat != NULL) {
 455             XRenderPictFormat *format = xrenderFindVisualFormat (awt_display,
 456                                                                  pVITrue [i].visual);
 457             if (format &&
 458                 format->type == PictTypeDirect &&
 459                 format->direct.alphaMask)
 460             {
 461                 DTRACE_PRINTLN1("GraphicsConfig[%d] supports Translucency", ind);
 462                 graphicsConfigs [ind]->isTranslucencySupported = 1;
 463                 memcpy(&graphicsConfigs [ind]->renderPictFormat, format,
 464                         sizeof(*format));
 465             } else {
 466                 DTRACE_PRINTLN1(format ?
 467                                 "GraphicsConfig[%d] has no Translucency support" :
 468                                 "Error calling 'XRenderFindVisualFormat'", ind);
 469             }
 470        }
 471     }
 472 
 473     if (xrenderLibHandle != NULL) {
 474         dlclose(xrenderLibHandle);
 475         xrenderLibHandle = NULL;
 476     }
 477 
 478     for (i = 0; i < n8p; i++) {
 479         if (XVisualIDFromVisual(pVI8p[i].visual) ==
 480             XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) {
 481             continue;
 482         } else {
 483             ind = nConfig++;
 484         }
 485         graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData);
 486         graphicsConfigs [ind]->awt_depth = pVI8p [i].depth;




 487         memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI8p [i],
 488                 sizeof (XVisualInfo));
 489     }
 490 
 491     for (i = 0; i < n12p; i++) {
 492         if (XVisualIDFromVisual(pVI12p[i].visual) ==
 493             XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) {
 494             continue;
 495         } else {
 496             ind = nConfig++;
 497         }
 498         graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData);
 499         graphicsConfigs [ind]->awt_depth = pVI12p [i].depth;




 500         memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI12p [i],
 501                 sizeof (XVisualInfo));
 502     }
 503 
 504     for (i = 0; i < n8s; i++) {
 505         if (XVisualIDFromVisual(pVI8s[i].visual) ==
 506             XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) {
 507             continue;
 508         } else {
 509             ind = nConfig++;
 510         }
 511         graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData);
 512         graphicsConfigs [ind]->awt_depth = pVI8s [i].depth;




 513         memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI8s [i],
 514                 sizeof (XVisualInfo));
 515     }
 516 
 517     for (i = 0; i < n8gs; i++) {
 518         if (XVisualIDFromVisual(pVI8gs[i].visual) ==
 519             XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) {
 520             continue;
 521         } else {
 522             ind = nConfig++;
 523         }
 524         graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData);
 525         graphicsConfigs [ind]->awt_depth = pVI8gs [i].depth;




 526         memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI8gs [i],
 527                 sizeof (XVisualInfo));
 528     }
 529 
 530     for (i = 0; i < n8sg; i++) {
 531         if (XVisualIDFromVisual(pVI8sg[i].visual) ==
 532             XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) {
 533             continue;
 534         } else {
 535             ind = nConfig++;
 536         }
 537         graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData);
 538         graphicsConfigs [ind]->awt_depth = pVI8sg [i].depth;




 539         memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI8sg [i],
 540                 sizeof (XVisualInfo));
 541     }
 542 
 543     for (i = 0; i < n1sg; i++) {
 544         if (XVisualIDFromVisual(pVI1sg[i].visual) ==
 545             XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) {
 546             continue;
 547         } else {
 548             ind = nConfig++;
 549         }
 550         graphicsConfigs [ind] = ZALLOC (_AwtGraphicsConfigData);
 551         graphicsConfigs [ind]->awt_depth = pVI1sg [i].depth;




 552         memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI1sg [i],
 553                 sizeof (XVisualInfo));
 554     }
 555 




 556     if (n8p != 0)
 557        XFree (pVI8p);
 558     if (n12p != 0)
 559        XFree (pVI12p);
 560     if (n8s != 0)
 561        XFree (pVI8s);
 562     if (n8gs != 0)
 563        XFree (pVI8gs);
 564     if (n8sg != 0)
 565        XFree (pVI8sg);
 566     if (n1sg != 0)
 567        XFree (pVI1sg);
 568 
 569     screenDataPtr->numConfigs = nConfig;
 570     screenDataPtr->configs = graphicsConfigs;
 571 
 572     AWT_UNLOCK ();
 573 }
 574 
 575 #ifndef HEADLESS
 576 
 577 /*
 578  * Checks if Xinerama is running and perform Xinerama-related initialization.
 579  */
 580 static void xineramaInit(void) {
 581     char* XinExtName = "XINERAMA";
 582     int32_t major_opcode, first_event, first_error;
 583     Bool gotXinExt = False;
 584     void* libHandle = NULL;
 585     int32_t locNumScr = 0;
 586     XineramaScreenInfo *xinInfo;
 587     char* XineramaQueryScreensName = "XineramaQueryScreens";
 588 
 589     gotXinExt = XQueryExtension(awt_display, XinExtName, &major_opcode,
 590                                 &first_event, &first_error);




 149     }
 150     return 0;
 151 }
 152 
 153 static AwtGraphicsConfigDataPtr
 154 findWithTemplate(XVisualInfo *vinfo,
 155                  long mask)
 156 {
 157 
 158     XVisualInfo *visualList;
 159     XColor color;
 160     AwtGraphicsConfigDataPtr defaultConfig;
 161     int visualsMatched, i;
 162 
 163     visualList = XGetVisualInfo(awt_display,
 164                                 mask, vinfo, &visualsMatched);
 165     if (visualList) {
 166         int id = -1;
 167         VisualID defaultVisual = XVisualIDFromVisual(DefaultVisual(awt_display, vinfo->screen));
 168         defaultConfig = ZALLOC(_AwtGraphicsConfigData);
 169         if (defaultConfig == NULL) {
 170             XFree(visualList);
 171             return NULL;
 172         }
 173         for (i = 0; i < visualsMatched; i++) {
 174             memcpy(&defaultConfig->awt_visInfo, &visualList[i], sizeof(XVisualInfo));
 175             defaultConfig->awt_depth = visualList[i].depth;
 176 
 177             /* we can't use awtJNI_CreateColorData here, because it'll pull,
 178                SystemColor, which in turn will cause toolkit to be reinitialized */
 179             if (awtCreateX11Colormap(defaultConfig)) {
 180                 if (visualList[i].visualid == defaultVisual) {
 181                     id = i;
 182                     break;
 183                 } else if (-1 == id) {
 184                     // Keep 1st match for fallback
 185                     id = i;
 186                 }
 187             }
 188         }
 189         if (-1 != id) {
 190             memcpy(&defaultConfig->awt_visInfo, &visualList[id], sizeof(XVisualInfo));
 191             defaultConfig->awt_depth = visualList[id].depth;
 192             /* Allocate white and black pixels for this visual */


 434                                                     "XRenderFindVisualFormat");
 435             if (xrenderFindVisualFormat == NULL) {
 436                 DTRACE_PRINTLN1("Can't find 'XRenderFindVisualFormat' in libXrender (%s)", dlerror());
 437             }
 438         } else {
 439             DTRACE_PRINTLN1("Can't load libXrender (%s)", dlerror());
 440         }
 441     } else {
 442         DTRACE_PRINTLN("RENDER extension NOT available");
 443     }
 444 
 445     for (i = 0; i < nTrue; i++) {
 446         if (XVisualIDFromVisual(pVITrue[i].visual) ==
 447             XVisualIDFromVisual(defaultConfig->awt_visInfo.visual) ||
 448             pVITrue[i].depth == 12) {
 449             /* Skip the non-supported 12-bit TrueColor visual */
 450             continue;
 451         } else {
 452             ind = nConfig++;
 453         }
 454         graphicsConfigs[ind] = ZALLOC (_AwtGraphicsConfigData);
 455         if (graphicsConfigs[ind] == NULL) {
 456             JNU_ThrowOutOfMemoryError(env, "allocation in getAllConfigs failed");
 457             goto cleanup;
 458         }
 459         graphicsConfigs[ind]->awt_depth = pVITrue [i].depth;
 460         memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVITrue [i],
 461                 sizeof (XVisualInfo));
 462         if (xrenderFindVisualFormat != NULL) {
 463             XRenderPictFormat *format = xrenderFindVisualFormat (awt_display,
 464                                                                  pVITrue [i].visual);
 465             if (format &&
 466                 format->type == PictTypeDirect &&
 467                 format->direct.alphaMask)
 468             {
 469                 DTRACE_PRINTLN1("GraphicsConfig[%d] supports Translucency", ind);
 470                 graphicsConfigs [ind]->isTranslucencySupported = 1;
 471                 memcpy(&graphicsConfigs [ind]->renderPictFormat, format,
 472                         sizeof(*format));
 473             } else {
 474                 DTRACE_PRINTLN1(format ?
 475                                 "GraphicsConfig[%d] has no Translucency support" :
 476                                 "Error calling 'XRenderFindVisualFormat'", ind);
 477             }
 478        }
 479     }
 480 
 481     if (xrenderLibHandle != NULL) {
 482         dlclose(xrenderLibHandle);
 483         xrenderLibHandle = NULL;
 484     }
 485 
 486     for (i = 0; i < n8p; i++) {
 487         if (XVisualIDFromVisual(pVI8p[i].visual) ==
 488             XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) {
 489             continue;
 490         } else {
 491             ind = nConfig++;
 492         }
 493         graphicsConfigs[ind] = ZALLOC (_AwtGraphicsConfigData);
 494         if (graphicsConfigs[ind] == NULL) {
 495             JNU_ThrowOutOfMemoryError(env, "allocation in getAllConfigs failed");
 496             goto cleanup;
 497         }
 498         graphicsConfigs[ind]->awt_depth = pVI8p [i].depth;
 499         memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI8p [i],
 500                 sizeof (XVisualInfo));
 501     }
 502 
 503     for (i = 0; i < n12p; i++) {
 504         if (XVisualIDFromVisual(pVI12p[i].visual) ==
 505             XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) {
 506             continue;
 507         } else {
 508             ind = nConfig++;
 509         }
 510         graphicsConfigs[ind] = ZALLOC (_AwtGraphicsConfigData);
 511         if (graphicsConfigs[ind] == NULL) {
 512             JNU_ThrowOutOfMemoryError(env, "allocation in getAllConfigs failed");
 513             goto cleanup;
 514         }
 515         graphicsConfigs[ind]->awt_depth = pVI12p [i].depth;
 516         memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI12p [i],
 517                 sizeof (XVisualInfo));
 518     }
 519 
 520     for (i = 0; i < n8s; i++) {
 521         if (XVisualIDFromVisual(pVI8s[i].visual) ==
 522             XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) {
 523             continue;
 524         } else {
 525             ind = nConfig++;
 526         }
 527         graphicsConfigs[ind] = ZALLOC (_AwtGraphicsConfigData);
 528         if (graphicsConfigs[ind] == NULL) {
 529             JNU_ThrowOutOfMemoryError(env, "allocation in getAllConfigs failed");
 530             goto cleanup;
 531         }
 532         graphicsConfigs[ind]->awt_depth = pVI8s [i].depth;
 533         memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI8s [i],
 534                 sizeof (XVisualInfo));
 535     }
 536 
 537     for (i = 0; i < n8gs; i++) {
 538         if (XVisualIDFromVisual(pVI8gs[i].visual) ==
 539             XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) {
 540             continue;
 541         } else {
 542             ind = nConfig++;
 543         }
 544         graphicsConfigs[ind] = ZALLOC (_AwtGraphicsConfigData);
 545         if (graphicsConfigs[ind] == NULL) {
 546             JNU_ThrowOutOfMemoryError(env, "allocation in getAllConfigs failed");
 547             goto cleanup;
 548         }
 549         graphicsConfigs[ind]->awt_depth = pVI8gs [i].depth;
 550         memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI8gs [i],
 551                 sizeof (XVisualInfo));
 552     }
 553 
 554     for (i = 0; i < n8sg; i++) {
 555         if (XVisualIDFromVisual(pVI8sg[i].visual) ==
 556             XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) {
 557             continue;
 558         } else {
 559             ind = nConfig++;
 560         }
 561         graphicsConfigs[ind] = ZALLOC (_AwtGraphicsConfigData);
 562         if (graphicsConfigs[ind] == NULL) {
 563             JNU_ThrowOutOfMemoryError(env, "allocation in getAllConfigs failed");
 564             goto cleanup;
 565         }
 566         graphicsConfigs[ind]->awt_depth = pVI8sg [i].depth;
 567         memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI8sg [i],
 568                 sizeof (XVisualInfo));
 569     }
 570 
 571     for (i = 0; i < n1sg; i++) {
 572         if (XVisualIDFromVisual(pVI1sg[i].visual) ==
 573             XVisualIDFromVisual(defaultConfig->awt_visInfo.visual)) {
 574             continue;
 575         } else {
 576             ind = nConfig++;
 577         }
 578         graphicsConfigs[ind] = ZALLOC (_AwtGraphicsConfigData);
 579         if (graphicsConfigs[ind] == NULL) {
 580             JNU_ThrowOutOfMemoryError(env, "allocation in getAllConfigs failed");
 581             goto cleanup;
 582         }
 583         graphicsConfigs[ind]->awt_depth = pVI1sg [i].depth;
 584         memcpy (&graphicsConfigs [ind]->awt_visInfo, &pVI1sg [i],
 585                 sizeof (XVisualInfo));
 586     }
 587 
 588     screenDataPtr->numConfigs = nConfig;
 589     screenDataPtr->configs = graphicsConfigs;
 590 
 591 cleanup:
 592     if (n8p != 0)
 593        XFree (pVI8p);
 594     if (n12p != 0)
 595        XFree (pVI12p);
 596     if (n8s != 0)
 597        XFree (pVI8s);
 598     if (n8gs != 0)
 599        XFree (pVI8gs);
 600     if (n8sg != 0)
 601        XFree (pVI8sg);
 602     if (n1sg != 0)
 603        XFree (pVI1sg);



 604 
 605     AWT_UNLOCK ();
 606 }
 607 
 608 #ifndef HEADLESS
 609 
 610 /*
 611  * Checks if Xinerama is running and perform Xinerama-related initialization.
 612  */
 613 static void xineramaInit(void) {
 614     char* XinExtName = "XINERAMA";
 615     int32_t major_opcode, first_event, first_error;
 616     Bool gotXinExt = False;
 617     void* libHandle = NULL;
 618     int32_t locNumScr = 0;
 619     XineramaScreenInfo *xinInfo;
 620     char* XineramaQueryScreensName = "XineramaQueryScreens";
 621 
 622     gotXinExt = XQueryExtension(awt_display, XinExtName, &major_opcode,
 623                                 &first_event, &first_error);


< prev index next >