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 27#import "PrinterSurfaceData.h" 28#import <JavaNativeFoundation/JavaNativeFoundation.h> 29 30 31//#define DEBUG 1 32#if defined DEBUG 33 #define PRINT(msg) {fprintf(stderr, "%s\n", msg);} 34#else 35 #define PRINT(msg) {} 36#endif 37 38static LockFunc PrintSD_Lock; 39static UnlockFunc PrintSD_Unlock; 40static GetRasInfoFunc PrintSD_GetRasInfo; 41static ReleaseFunc PrintSD_ReleaseRasInfo; 42static void flush(JNIEnv *env, QuartzSDOps *qsdo); 43 44static void PrintSD_startCGContext(JNIEnv *env, QuartzSDOps *qsdo, SDRenderType renderType) 45{ 46PRINT(" PrintSD_startCGContext") 47 48 if (qsdo->cgRef != NULL) 49 { 50 flush(env, qsdo); 51 52 SetUpCGContext(env, qsdo, renderType); 53 } 54} 55 56static void PrintSD_finishCGContext(JNIEnv *env, QuartzSDOps *qsdo) 57{ 58PRINT(" PrintSD_finishCGContext") 59 60 if (qsdo->cgRef != NULL) 61 { 62 CompleteCGContext(env, qsdo); 63 } 64} 65 66static void PrintSD_dispose(JNIEnv *env, SurfaceDataOps *sdo) 67{ 68PRINT(" PrintSD_dispose") 69 QuartzSDOps *qsdo = (QuartzSDOps *)sdo; 70 71 (*env)->DeleteGlobalRef(env, qsdo->javaGraphicsStatesObjects); 72 73 if (qsdo->graphicsStateInfo.batchedLines != NULL) 74 { 75 free(qsdo->graphicsStateInfo.batchedLines); 76 qsdo->graphicsStateInfo.batchedLines = NULL; 77 } 78 79 qsdo->BeginSurface = NULL; 80 qsdo->FinishSurface = NULL; 81} 82 83JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterSurfaceData_initOps(JNIEnv *env, jobject jthis, jlong nsRef, jobject jGraphicsState, jobjectArray jGraphicsStateObject, jint width, jint height) 84{ 85JNF_COCOA_ENTER(env); 86 87PRINT("Java_sun_lwawt_macosx_CPrinterSurfaceData_initOps") 88 89 PrintSDOps *psdo = (PrintSDOps*)SurfaceData_InitOps(env, jthis, sizeof(PrintSDOps)); 90 psdo->nsRef = (NSGraphicsContext*)jlong_to_ptr(nsRef); 91 psdo->width = width; 92 psdo->height = height; 93 94 QuartzSDOps *qsdo = (QuartzSDOps*)psdo; 95 qsdo->BeginSurface = PrintSD_startCGContext; 96 qsdo->FinishSurface = PrintSD_finishCGContext; 97 qsdo->cgRef = [psdo->nsRef graphicsPort]; 98 99 qsdo->javaGraphicsStates = (jint*)((*env)->GetDirectBufferAddress(env, jGraphicsState)); 100 qsdo->javaGraphicsStatesObjects = (*env)->NewGlobalRef(env, jGraphicsStateObject); 101 102 qsdo->graphicsStateInfo.batchedLines = NULL; 103 qsdo->graphicsStateInfo.batchedLinesCount = 0; 104 105 SurfaceDataOps *sdo = (SurfaceDataOps*)qsdo; 106 sdo->Lock = PrintSD_Lock; 107 sdo->Unlock = PrintSD_Unlock; 108 sdo->GetRasInfo = PrintSD_GetRasInfo; 109 sdo->Release = PrintSD_ReleaseRasInfo; 110 sdo->Setup = NULL; 111 sdo->Dispose = PrintSD_dispose; 112 113JNF_COCOA_EXIT(env); 114} 115 116static jint PrintSD_Lock(JNIEnv *env, SurfaceDataOps *sdo, SurfaceDataRasInfo *pRasInfo, jint lockflags) 117{ 118PRINT(" PrintSD_Lock") 119 jint status = SD_FAILURE; 120 121 //QuartzSDOps *qsdo = (QuartzSDOps*)sdo; 122 //PrintSD_startCGContext(env, qsdo, SD_Image); 123 124 status = SD_SUCCESS; 125 126 return status; 127} 128static void PrintSD_Unlock(JNIEnv *env, SurfaceDataOps *sdo, SurfaceDataRasInfo *pRasInfo) 129{ 130PRINT(" PrintSD_Unlock") 131 132 //QuartzSDOps *qsdo = (QuartzSDOps*)sdo; 133 //PrintSD_finishCGContext(env, qsdo); 134} 135static void PrintSD_GetRasInfo(JNIEnv *env, SurfaceDataOps *sdo, SurfaceDataRasInfo *pRasInfo) 136{ 137PRINT(" PrintSD_GetRasInfo") 138 PrintSDOps *psdo = (PrintSDOps*)sdo; 139 140 pRasInfo->pixelStride = 4; // ARGB 141 pRasInfo->scanStride = psdo->width * pRasInfo->pixelStride; 142 143 pRasInfo->rasBase = NULL; //psdo->dataForSun2D; 144} 145static void PrintSD_ReleaseRasInfo(JNIEnv *env, SurfaceDataOps *sdo, SurfaceDataRasInfo *pRasInfo) 146{ 147PRINT(" PrintSD_ReleaseRasInfo") 148 149 pRasInfo->pixelStride = 0; 150 pRasInfo->scanStride = 0; 151 pRasInfo->rasBase = NULL; 152} 153 154static void dataProvider_FreeSun2DPixels(void *info, const void *data, size_t size) 155{ 156PRINT("dataProvider_FreeSun2DPixels") 157 // CGBitmapFreeData(info); 158 free(info); 159} 160JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CPrinterSurfaceData__1flush 161 (JNIEnv *env, jobject jsurfacedata) 162{ 163 flush(env, (QuartzSDOps*)SurfaceData_GetOps(env, jsurfacedata)); 164} 165static void flush(JNIEnv *env, QuartzSDOps *qsdo) 166{ 167} 168