1 /* 2 * Copyright (c) 2011, 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 #import <JavaNativeFoundation/JavaNativeFoundation.h> 27 28 #import "AWTSurfaceLayers.h" 29 30 JNIEXPORT JAWT_DrawingSurfaceInfo* JNICALL awt_DrawingSurface_GetDrawingSurfaceInfo 31 (JAWT_DrawingSurface* ds) 32 { 33 JAWT_DrawingSurfaceInfo* dsi = (JAWT_DrawingSurfaceInfo*)malloc(sizeof(JAWT_DrawingSurfaceInfo)); 34 35 JNIEnv *env = ds->env; 36 jobject target = ds->target; 37 38 static JNF_CLASS_CACHE(jc_Component, "java/awt/Component"); 39 static JNF_MEMBER_CACHE(jf_peer, jc_Component, "peer", "Ljava/awt/peer/ComponentPeer;"); 40 jobject peer = JNFGetObjectField(env, target, jf_peer); 41 42 static JNF_CLASS_CACHE(jc_ComponentPeer, "sun/lwawt/LWComponentPeer"); 43 static JNF_MEMBER_CACHE(jf_platformComponent, jc_ComponentPeer, 44 "platformComponent", "Lsun/lwawt/PlatformComponent;"); 45 jobject platformComponent = JNFGetObjectField(env, peer, jf_platformComponent); 46 47 static JNF_CLASS_CACHE(jc_PlatformComponent, "sun/lwawt/macosx/CPlatformComponent"); 48 static JNF_MEMBER_CACHE(jm_getPointer, jc_PlatformComponent, "getPointer", "()J"); 49 AWTSurfaceLayers *surfaceLayers = jlong_to_ptr(JNFCallLongMethod(env, platformComponent, jm_getPointer)); 50 // REMIND: assert(surfaceLayers) 51 52 dsi->platformInfo = surfaceLayers; 53 dsi->ds = ds; 54 55 static JNF_MEMBER_CACHE(jf_x, jc_Component, "x", "I"); 56 static JNF_MEMBER_CACHE(jf_y, jc_Component, "y", "I"); 57 static JNF_MEMBER_CACHE(jf_width, jc_Component, "width", "I"); 58 static JNF_MEMBER_CACHE(jf_height, jc_Component, "height", "I"); 59 60 dsi->bounds.x = JNFGetIntField(env, target, jf_x); 61 dsi->bounds.y = JNFGetIntField(env, target, jf_y); 62 dsi->bounds.width = JNFGetIntField(env, target, jf_width); 63 dsi->bounds.height = JNFGetIntField(env, target, jf_height); 64 65 dsi->clipSize = 1; 66 dsi->clip = &(dsi->bounds); 67 68 return dsi; 69 } 70 71 JNIEXPORT jint JNICALL awt_DrawingSurface_Lock 72 (JAWT_DrawingSurface* ds) 73 { 74 // TODO: implement 75 return 0; 76 } 77 78 JNIEXPORT void JNICALL awt_DrawingSurface_Unlock 79 (JAWT_DrawingSurface* ds) 80 { 81 // TODO: implement 82 } 83 84 JNIEXPORT void JNICALL awt_DrawingSurface_FreeDrawingSurfaceInfo 85 (JAWT_DrawingSurfaceInfo* dsi) 86 { 87 free(dsi); 88 } 89 90 JNIEXPORT JAWT_DrawingSurface* JNICALL awt_GetDrawingSurface 91 (JNIEnv* env, jobject target) 92 { 93 JAWT_DrawingSurface* ds = (JAWT_DrawingSurface*)malloc(sizeof(JAWT_DrawingSurface)); 94 95 // TODO: "target instanceof" check 96 97 ds->env = env; 98 ds->target = (*env)->NewGlobalRef(env, target); 99 ds->Lock = awt_DrawingSurface_Lock; 100 ds->GetDrawingSurfaceInfo = awt_DrawingSurface_GetDrawingSurfaceInfo; 101 ds->FreeDrawingSurfaceInfo = awt_DrawingSurface_FreeDrawingSurfaceInfo; 102 ds->Unlock = awt_DrawingSurface_Unlock; 103 104 return ds; 105 } 106 107 JNIEXPORT void JNICALL awt_FreeDrawingSurface 108 (JAWT_DrawingSurface* ds) 109 { 110 JNIEnv *env = ds->env; 111 (*env)->DeleteGlobalRef(env, ds->target); 112 free(ds); 113 } 114 115 JNIEXPORT void JNICALL awt_Lock 116 (JNIEnv* env) 117 { 118 // TODO: implement 119 } 120 121 JNIEXPORT void JNICALL awt_Unlock 122 (JNIEnv* env) 123 { 124 // TODO: implement 125 } 126 127 JNIEXPORT jobject JNICALL awt_GetComponent 128 (JNIEnv* env, void* platformInfo) 129 { 130 // TODO: implement 131 return NULL; 132 }