1/* 2 * Copyright (c) 2012, 2013, 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. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24#include "MyCanvas.h" 25#include "jawt_md.h" 26 27/* 28 * Class: MyCanvas 29 * Method: paint 30 * Signature: (Ljava/awt/Graphics;)V 31 */ 32JNIEXPORT void JNICALL Java_MyCanvas_paint 33(JNIEnv* env, jobject canvas, jobject graphics) 34{ 35 JAWT awt; 36 JAWT_DrawingSurface* ds; 37 JAWT_DrawingSurfaceInfo* dsi; 38 JAWT_X11DrawingSurfaceInfo* dsi_x11; 39 jboolean result; 40 jint lock; 41 GC gc; 42 jobject ref; 43 44 /* Get the AWT */ 45 awt.version = JAWT_VERSION_1_4; 46 if (JAWT_GetAWT(env, &awt) == JNI_FALSE) { 47 printf("AWT Not found\n"); 48 return; 49 } 50 51 /* Lock the AWT */ 52 awt.Lock(env); 53 54 /* Unlock the AWT */ 55 awt.Unlock(env); 56 57 /* Get the drawing surface */ 58 ds = awt.GetDrawingSurface(env, canvas); 59 if (ds == NULL) { 60 printf("NULL drawing surface\n"); 61 return; 62 } 63 64 /* Lock the drawing surface */ 65 lock = ds->Lock(ds); 66 printf("Lock value %d\n", (int)lock); 67 if((lock & JAWT_LOCK_ERROR) != 0) { 68 printf("Error locking surface\n"); 69 awt.FreeDrawingSurface(ds); 70 return; 71 } 72 73 /* Get the drawing surface info */ 74 dsi = ds->GetDrawingSurfaceInfo(ds); 75 if (dsi == NULL) { 76 printf("Error getting surface info\n"); 77 ds->Unlock(ds); 78 awt.FreeDrawingSurface(ds); 79 return; 80 } 81 82 /* Get the platform-specific drawing info */ 83 dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo; 84 85 /* Now paint */ 86 gc = XCreateGC(dsi_x11->display, dsi_x11->drawable, 0, 0); 87 XSetForeground(dsi_x11->display, gc, 0); 88 XFillRectangle(dsi_x11->display, dsi_x11->drawable, gc, 89 5, 5, 90, 90); 90 XFreeGC(dsi_x11->display, gc); 91 ref = awt.GetComponent(env, (void*)(dsi_x11->drawable)); 92 if (!(*env)->IsSameObject(env, ref, canvas)) { 93 printf("Error! Different objects!\n"); 94 } 95 96 /* Free the drawing surface info */ 97 ds->FreeDrawingSurfaceInfo(dsi); 98 99 /* Unlock the drawing surface */ 100 ds->Unlock(ds); 101 102 /* Free the drawing surface */ 103 awt.FreeDrawingSurface(ds); 104} 105