1 /* 2 * Copyright (c) 2012, 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 "MyCanvas.h" 27 #include "jawt_md.h" 28 29 /* 30 * Class: MyCanvas 31 * Method: paint 32 * Signature: (Ljava/awt/Graphics;)V 33 */ 34 JNIEXPORT void JNICALL Java_MyCanvas_paint 35 (JNIEnv* env, jobject canvas, jobject graphics) 36 { 37 JAWT awt; 38 JAWT_DrawingSurface* ds; 39 JAWT_DrawingSurfaceInfo* dsi; 40 JAWT_X11DrawingSurfaceInfo* dsi_x11; 41 jboolean result; 42 jint lock; 43 GC gc; 44 jobject ref; 45 46 /* Get the AWT */ 47 awt.version = JAWT_VERSION_1_4; 48 if (JAWT_GetAWT(env, &awt) == JNI_FALSE) { 49 printf("AWT Not found\n"); 50 return; 51 } 52 53 /* Lock the AWT */ 54 awt.Lock(env); 55 56 /* Unlock the AWT */ 57 awt.Unlock(env); 58 59 /* Get the drawing surface */ 60 ds = awt.GetDrawingSurface(env, canvas); 61 if (ds == NULL) { 62 printf("NULL drawing surface\n"); 63 return; 64 } 65 66 /* Lock the drawing surface */ 67 lock = ds->Lock(ds); 68 printf("Lock value %d\n", (int)lock); 69 if((lock & JAWT_LOCK_ERROR) != 0) { 70 printf("Error locking surface\n"); 71 awt.FreeDrawingSurface(ds); 72 return; 73 } 74 75 /* Get the drawing surface info */ 76 dsi = ds->GetDrawingSurfaceInfo(ds); 77 if (dsi == NULL) { 78 printf("Error getting surface info\n"); 79 ds->Unlock(ds); 80 awt.FreeDrawingSurface(ds); 81 return; 82 } 83 84 /* Get the platform-specific drawing info */ 85 dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo; 86 87 /* Now paint */ 88 gc = XCreateGC(dsi_x11->display, dsi_x11->drawable, 0, 0); 89 XSetForeground(dsi_x11->display, gc, 0); 90 XFillRectangle(dsi_x11->display, dsi_x11->drawable, gc, 91 5, 5, 90, 90); 92 XFreeGC(dsi_x11->display, gc); 93 ref = awt.GetComponent(env, (void*)(dsi_x11->drawable)); 94 if (!(*env)->IsSameObject(env, ref, canvas)) { 95 printf("Error! Different objects!\n"); 96 } 97 98 /* Free the drawing surface info */ 99 ds->FreeDrawingSurfaceInfo(dsi); 100 101 /* Unlock the drawing surface */ 102 ds->Unlock(ds); 103 104 /* Free the drawing surface */ 105 awt.FreeDrawingSurface(ds); 106 }