Path: blob/master/test/jdk/java/awt/JAWT/myfile.c
41149 views
/*1* Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223#include "MyCanvas.h"24#include "jawt_md.h"2526/*27* Class: MyCanvas28* Method: paint29* Signature: (Ljava/awt/Graphics;)V30*/31JNIEXPORT void JNICALL Java_MyCanvas_paint32(JNIEnv* env, jobject canvas, jobject graphics)33{34JAWT awt;35JAWT_DrawingSurface* ds;36JAWT_DrawingSurfaceInfo* dsi;37JAWT_X11DrawingSurfaceInfo* dsi_x11;38jboolean result;39jint lock;40GC gc;41jobject ref;4243/* Get the AWT */44awt.version = JAWT_VERSION_1_4;45if (JAWT_GetAWT(env, &awt) == JNI_FALSE) {46printf("AWT Not found\n");47return;48}4950/* Lock the AWT */51awt.Lock(env);5253/* Unlock the AWT */54awt.Unlock(env);5556/* Get the drawing surface */57ds = awt.GetDrawingSurface(env, canvas);58if (ds == NULL) {59printf("NULL drawing surface\n");60return;61}6263/* Lock the drawing surface */64lock = ds->Lock(ds);65printf("Lock value %d\n", (int)lock);66if((lock & JAWT_LOCK_ERROR) != 0) {67printf("Error locking surface\n");68awt.FreeDrawingSurface(ds);69return;70}7172/* Get the drawing surface info */73dsi = ds->GetDrawingSurfaceInfo(ds);74if (dsi == NULL) {75printf("Error getting surface info\n");76ds->Unlock(ds);77awt.FreeDrawingSurface(ds);78return;79}8081/* Get the platform-specific drawing info */82dsi_x11 = (JAWT_X11DrawingSurfaceInfo*)dsi->platformInfo;8384/* Now paint */85gc = XCreateGC(dsi_x11->display, dsi_x11->drawable, 0, 0);86XSetForeground(dsi_x11->display, gc, 0);87XFillRectangle(dsi_x11->display, dsi_x11->drawable, gc,885, 5, 90, 90);89XFreeGC(dsi_x11->display, gc);90ref = awt.GetComponent(env, (void*)(dsi_x11->drawable));91if (!(*env)->IsSameObject(env, ref, canvas)) {92printf("Error! Different objects!\n");93}9495/* Free the drawing surface info */96ds->FreeDrawingSurfaceInfo(dsi);9798/* Unlock the drawing surface */99ds->Unlock(ds);100101/* Free the drawing surface */102awt.FreeDrawingSurface(ds);103}104105106