jdk/src/solaris/native/sun/awt/gtk2_interface.c
changeset 6513 83264865df37
parent 5506 202f599c92aa
child 7243 4678eab93673
--- a/jdk/src/solaris/native/sun/awt/gtk2_interface.c	Tue Sep 14 22:05:03 2010 +0400
+++ b/jdk/src/solaris/native/sun/awt/gtk2_interface.c	Thu Sep 16 09:07:03 2010 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -371,6 +371,16 @@
     return convertionBuffer;
 }
 
+static void throw_exception(JNIEnv *env, const char* name, const char* message)
+{
+    jclass class = (*env)->FindClass(env, name);
+
+    if (class != NULL)
+        (*env)->ThrowNew(env, class, message);
+
+    (*env)->DeleteLocalRef(env, class);
+}
+
 /* This is a workaround for the bug:
  * http://sourceware.org/bugzilla/show_bug.cgi?id=1814
  * (dlsym/dlopen clears dlerror state)
@@ -859,14 +869,26 @@
  * comparing results. This can be optimized by using subclassed pixmap and
  * doing the second drawing only if necessary.
 */
-void gtk2_init_painting(gint width, gint height)
+void gtk2_init_painting(JNIEnv *env, gint width, gint height)
 {
     GdkGC *gc;
+    GdkPixbuf *white, *black;
 
     init_containers();
 
     if (gtk2_pixbuf_width < width || gtk2_pixbuf_height < height)
     {
+        white = (*fp_gdk_pixbuf_new)(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
+        black = (*fp_gdk_pixbuf_new)(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
+
+        if (white == NULL || black == NULL)
+        {
+            snprintf(convertionBuffer, CONV_BUFFER_SIZE, "Couldn't create pixbuf of size %dx%d", width, height);
+            throw_exception(env, "java/lang/RuntimeException", convertionBuffer);
+            fp_gdk_threads_leave();
+            return;
+        }
+
         if (gtk2_white_pixmap != NULL) {
             /* free old stuff */
             (*fp_g_object_unref)(gtk2_white_pixmap);
@@ -875,14 +897,12 @@
             (*fp_g_object_unref)(gtk2_black_pixbuf);
         }
 
-        gtk2_white_pixmap = (*fp_gdk_pixmap_new)
-                                (gtk2_window->window, width, height, -1);
-        gtk2_black_pixmap = (*fp_gdk_pixmap_new)
-                                (gtk2_window->window, width, height, -1);
-        gtk2_white_pixbuf = (*fp_gdk_pixbuf_new)(GDK_COLORSPACE_RGB, TRUE, 8,
-                                                 width, height);
-        gtk2_black_pixbuf = (*fp_gdk_pixbuf_new)(GDK_COLORSPACE_RGB, TRUE, 8,
-                                                 width, height);
+        gtk2_white_pixmap = (*fp_gdk_pixmap_new)(gtk2_window->window, width, height, -1);
+        gtk2_black_pixmap = (*fp_gdk_pixmap_new)(gtk2_window->window, width, height, -1);
+
+        gtk2_white_pixbuf = white;
+        gtk2_black_pixbuf = black;
+
         gtk2_pixbuf_width = width;
         gtk2_pixbuf_height = height;
     }