1 /**
   2  * Copyright (c) 2007, 2012 Oracle and/or its affiliates. All rights reserved.
   3  * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
   4  *
   5  *
   6  *
   7  *
   8  *
   9  *
  10  *
  11  *
  12  *
  13  *
  14  *
  15  *
  16  *
  17  *
  18  *
  19  *
  20  *
  21  *
  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  */
  32 JNIEXPORT 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 }