1 /*
   2  * Copyright (c) 2000, 2008, 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 #include "jni_util.h"
  27 #include "jlong.h"
  28 
  29 #include "sun_java2d_loops_GraphicsPrimitiveMgr.h"
  30 
  31 #include "Region.h"
  32 #include "GraphicsPrimitiveMgr.h"
  33 #include "AlphaMacros.h"
  34 
  35 static char *InitName = "<init>";
  36 static char *InitSig =  ("(JLsun/java2d/loops/SurfaceType;"
  37                          "Lsun/java2d/loops/CompositeType;"
  38                          "Lsun/java2d/loops/SurfaceType;)V");
  39 
  40 static char *RegisterName =     "register";
  41 static char *RegisterSig =      "([Lsun/java2d/loops/GraphicsPrimitive;)V";
  42 
  43 static jclass GraphicsPrimitiveMgr;
  44 static jclass GraphicsPrimitive;
  45 
  46 static jmethodID RegisterID;
  47 static jfieldID pNativePrimID;
  48 static jfieldID pixelID;
  49 static jfieldID eargbID;
  50 static jfieldID clipRegionID;
  51 static jfieldID compositeID;
  52 static jfieldID lcdTextContrastID;
  53 static jfieldID xorPixelID;
  54 static jfieldID xorColorID;
  55 static jfieldID alphaMaskID;
  56 static jfieldID ruleID;
  57 static jfieldID extraAlphaID;
  58 
  59 static jfieldID m00ID;
  60 static jfieldID m01ID;
  61 static jfieldID m02ID;
  62 static jfieldID m10ID;
  63 static jfieldID m11ID;
  64 static jfieldID m12ID;
  65 
  66 static jmethodID getRgbID;
  67 
  68 static jboolean InitPrimTypes(JNIEnv *env);
  69 static jboolean InitSurfaceTypes(JNIEnv *env, jclass SurfaceType);
  70 static jboolean InitCompositeTypes(JNIEnv *env, jclass CompositeType);
  71 
  72 jfieldID path2DTypesID;
  73 jfieldID path2DNumTypesID;
  74 jfieldID path2DWindingRuleID;
  75 jfieldID path2DFloatCoordsID;
  76 jfieldID sg2dStrokeHintID;
  77 jint sunHints_INTVAL_STROKE_PURE;
  78 
  79 /*
  80  * Class:     sun_java2d_loops_GraphicsPrimitiveMgr
  81  * Method:    initIDs
  82  * Signature: (Ljava/lang/Class;Ljava/lang/Class;Ljava/lang/Class;Ljava/lang/Class;Ljava/lang/Class;Ljava/lang/Class;Ljava/lang/Class;)V
  83  */
  84 JNIEXPORT void JNICALL
  85 Java_sun_java2d_loops_GraphicsPrimitiveMgr_initIDs
  86     (JNIEnv *env, jclass GPMgr,
  87      jclass GP, jclass ST, jclass CT,
  88      jclass SG2D, jclass Color, jclass AT,
  89      jclass XORComp, jclass AlphaComp,
  90      jclass Path2D, jclass Path2DFloat,
  91      jclass SHints)
  92 {
  93     jfieldID fid;
  94     initAlphaTables();
  95     GraphicsPrimitiveMgr = (*env)->NewGlobalRef(env, GPMgr);
  96     GraphicsPrimitive = (*env)->NewGlobalRef(env, GP);
  97     if (GraphicsPrimitiveMgr == NULL || GraphicsPrimitive == NULL) {
  98         JNU_ThrowOutOfMemoryError(env, "creating global refs");
  99         return;
 100     }
 101     if (!InitPrimTypes(env) ||
 102         !InitSurfaceTypes(env, ST) ||
 103         !InitCompositeTypes(env, CT))
 104     {
 105         return;
 106     }
 107     RegisterID = (*env)->GetStaticMethodID(env, GPMgr,
 108                                            RegisterName, RegisterSig);
 109     pNativePrimID = (*env)->GetFieldID(env, GP, "pNativePrim", "J");
 110     pixelID = (*env)->GetFieldID(env, SG2D, "pixel", "I");
 111     eargbID = (*env)->GetFieldID(env, SG2D, "eargb", "I");
 112     clipRegionID = (*env)->GetFieldID(env, SG2D, "clipRegion",
 113                                       "Lsun/java2d/pipe/Region;");
 114     compositeID = (*env)->GetFieldID(env, SG2D, "composite",
 115                                      "Ljava/awt/Composite;");
 116     lcdTextContrastID =
 117         (*env)->GetFieldID(env, SG2D, "lcdTextContrast", "I");
 118     getRgbID = (*env)->GetMethodID(env, Color, "getRGB", "()I");
 119     xorPixelID = (*env)->GetFieldID(env, XORComp, "xorPixel", "I");
 120     xorColorID = (*env)->GetFieldID(env, XORComp, "xorColor",
 121                                     "Ljava/awt/Color;");
 122     alphaMaskID = (*env)->GetFieldID(env, XORComp, "alphaMask", "I");
 123     ruleID = (*env)->GetFieldID(env, AlphaComp, "rule", "I");
 124     extraAlphaID = (*env)->GetFieldID(env, AlphaComp, "extraAlpha", "F");
 125 
 126 
 127     m00ID = (*env)->GetFieldID(env, AT, "m00", "D");
 128     m01ID = (*env)->GetFieldID(env, AT, "m01", "D");
 129     m02ID = (*env)->GetFieldID(env, AT, "m02", "D");
 130     m10ID = (*env)->GetFieldID(env, AT, "m10", "D");
 131     m11ID = (*env)->GetFieldID(env, AT, "m11", "D");
 132     m12ID = (*env)->GetFieldID(env, AT, "m12", "D");
 133 
 134     path2DTypesID = (*env)->GetFieldID(env, Path2D, "pointTypes", "[B");
 135     path2DNumTypesID = (*env)->GetFieldID(env, Path2D, "numTypes", "I");
 136     path2DWindingRuleID = (*env)->GetFieldID(env, Path2D, "windingRule", "I");
 137     path2DFloatCoordsID = (*env)->GetFieldID(env, Path2DFloat,
 138                                              "floatCoords", "[F");
 139     sg2dStrokeHintID = (*env)->GetFieldID(env, SG2D, "strokeHint", "I");
 140     fid = (*env)->GetStaticFieldID(env, SHints, "INTVAL_STROKE_PURE", "I");
 141     sunHints_INTVAL_STROKE_PURE = (*env)->GetStaticIntField(env, SHints, fid);
 142 }
 143 
 144 void GrPrim_RefineBounds(SurfaceDataBounds *bounds, jint transX, jint transY,
 145                          jfloat *coords,  jint maxCoords)
 146 {
 147     jint xmin, ymin, xmax, ymax;
 148     if (maxCoords > 1) {
 149         xmin = xmax = transX + (jint)(*coords++ + 0.5);
 150         ymin = ymax = transY + (jint)(*coords++ + 0.5);
 151         for (;maxCoords > 1; maxCoords -= 2) {
 152             jint x = transX + (jint)(*coords++ + 0.5);
 153             jint y = transY + (jint)(*coords++ + 0.5);
 154             if (xmin > x) xmin = x;
 155             if (ymin > y) ymin = y;
 156             if (xmax < x) xmax = x;
 157             if (ymax < y) ymax = y;
 158         }
 159         if (++xmax < xmin) xmax--;
 160         if (++ymax < ymin) ymax--;
 161         if (bounds->x1 < xmin) bounds->x1 = xmin;
 162         if (bounds->y1 < ymin) bounds->y1 = ymin;
 163         if (bounds->x2 > xmax) bounds->x2 = xmax;
 164         if (bounds->y2 > ymax) bounds->y2 = ymax;
 165     } else {
 166         bounds->x2 = bounds->x1;
 167         bounds->y2 = bounds->y1;
 168     }
 169 }
 170 
 171 /*
 172  * Class:     sun_java2d_loops_GraphicsPrimitiveMgr
 173  * Method:    registerNativeLoops
 174  * Signature: ()V
 175  */
 176 JNIEXPORT void JNICALL
 177 Java_sun_java2d_loops_GraphicsPrimitiveMgr_registerNativeLoops
 178     (JNIEnv *env, jclass GPMgr)
 179 {
 180     RegisterFunc RegisterAnyByte;
 181     RegisterFunc RegisterByteBinary1Bit;
 182     RegisterFunc RegisterByteBinary2Bit;
 183     RegisterFunc RegisterByteBinary4Bit;
 184     RegisterFunc RegisterByteIndexed;
 185     RegisterFunc RegisterByteGray;
 186     RegisterFunc RegisterIndex8Gray;
 187     RegisterFunc RegisterIndex12Gray;
 188     RegisterFunc RegisterAnyShort;
 189     RegisterFunc RegisterUshort555Rgb;
 190     RegisterFunc RegisterUshort565Rgb;
 191     RegisterFunc RegisterUshort4444Argb;
 192     RegisterFunc RegisterUshort555Rgbx;
 193     RegisterFunc RegisterUshortGray;
 194     RegisterFunc RegisterUshortIndexed;
 195     RegisterFunc RegisterAny3Byte;
 196     RegisterFunc RegisterThreeByteBgr;
 197     RegisterFunc RegisterAnyInt;
 198     RegisterFunc RegisterIntArgb;
 199     RegisterFunc RegisterIntArgbPre;
 200     RegisterFunc RegisterIntArgbBm;
 201     RegisterFunc RegisterIntRgb;
 202     RegisterFunc RegisterIntBgr;
 203     RegisterFunc RegisterIntRgbx;
 204     RegisterFunc RegisterAny4Byte;
 205     RegisterFunc RegisterFourByteAbgr;
 206     RegisterFunc RegisterFourByteAbgrPre;
 207 
 208     RegisterAnyByte(env);
 209     RegisterByteBinary1Bit(env);
 210     RegisterByteBinary2Bit(env);
 211     RegisterByteBinary4Bit(env);
 212     RegisterByteIndexed(env);
 213     RegisterByteGray(env);
 214     RegisterIndex8Gray(env);
 215     RegisterIndex12Gray(env);
 216     RegisterAnyShort(env);
 217     RegisterUshort555Rgb(env);
 218     RegisterUshort565Rgb(env);
 219     RegisterUshort4444Argb(env);
 220     RegisterUshort555Rgbx(env);
 221     RegisterUshortGray(env);
 222     RegisterUshortIndexed(env);
 223     RegisterAny3Byte(env);
 224     RegisterThreeByteBgr(env);
 225     RegisterAnyInt(env);
 226     RegisterIntArgb(env);
 227     RegisterIntArgbPre(env);
 228     RegisterIntArgbBm(env);
 229     RegisterIntRgb(env);
 230     RegisterIntBgr(env);
 231     RegisterIntRgbx(env);
 232     RegisterAny4Byte(env);
 233     RegisterFourByteAbgr(env);
 234     RegisterFourByteAbgrPre(env);
 235 }
 236 
 237 #define _StartOf(T)     ((T *) (&T##s))
 238 #define _NumberOf(T)    (sizeof(T##s) / sizeof(T))
 239 #define _EndOf(T)       (_StartOf(T) + _NumberOf(T))
 240 
 241 #define PrimTypeStart   _StartOf(PrimitiveType)
 242 #define PrimTypeEnd     _EndOf(PrimitiveType)
 243 
 244 #define SurfTypeStart   _StartOf(SurfaceType)
 245 #define SurfTypeEnd     _EndOf(SurfaceType)
 246 
 247 #define CompTypeStart   _StartOf(CompositeType)
 248 #define CompTypeEnd     _EndOf(CompositeType)
 249 
 250 /*
 251  * This function initializes the global collection of PrimitiveType
 252  * structures by retrieving the necessary Java Class object and the
 253  * associated methodID of the necessary constructor.
 254  *
 255  * See PrimitiveTypes.* below.
 256  */
 257 static jboolean InitPrimTypes(JNIEnv *env)
 258 {
 259     jboolean ok = JNI_TRUE;
 260     PrimitiveType *pPrimType;
 261     jclass cl;
 262 
 263     for (pPrimType = PrimTypeStart; pPrimType < PrimTypeEnd; pPrimType++) {
 264         cl = (*env)->FindClass(env, pPrimType->ClassName);
 265         if (cl == NULL) {
 266             ok = JNI_FALSE;
 267             break;
 268         }
 269         pPrimType->ClassObject = (*env)->NewGlobalRef(env, cl);
 270         pPrimType->Constructor =
 271             (*env)->GetMethodID(env, cl, InitName, InitSig);
 272 
 273         (*env)->DeleteLocalRef(env, cl);
 274         if (pPrimType->ClassObject == NULL ||
 275             pPrimType->Constructor == NULL)
 276         {
 277             ok = JNI_FALSE;
 278             break;
 279         }
 280     }
 281 
 282     if (!ok) {
 283         for (pPrimType = PrimTypeStart; pPrimType < PrimTypeEnd; pPrimType++) {
 284             if (pPrimType->ClassObject != NULL) {
 285                 (*env)->DeleteGlobalRef(env, pPrimType->ClassObject);
 286                 pPrimType->ClassObject = NULL;
 287             }
 288             pPrimType->Constructor = NULL;
 289         }
 290     }
 291 
 292     return ok;
 293 }
 294 
 295 /*
 296  * This function initializes the global collection of SurfaceType
 297  * or CompositeType structures by retrieving the corresponding Java
 298  * object stored as a static field on the Java Class.
 299  *
 300  * See SurfaceTypes.* below.
 301  * See CompositeeTypes.* below.
 302  */
 303 static jboolean InitSimpleTypes
 304     (JNIEnv *env, jclass SimpleClass, char *SimpleSig,
 305      SurfCompHdr *pStart, SurfCompHdr *pEnd, jsize size)
 306 {
 307     jboolean ok = JNI_TRUE;
 308     SurfCompHdr *pHdr;
 309     jfieldID field;
 310     jobject obj;
 311 
 312     for (pHdr = pStart; pHdr < pEnd; pHdr = PtrAddBytes(pHdr, size)) {
 313         field = (*env)->GetStaticFieldID(env,
 314                                          SimpleClass,
 315                                          pHdr->Name,
 316                                          SimpleSig);
 317         if (field == NULL) {
 318             ok = JNI_FALSE;
 319             break;
 320         }
 321         obj = (*env)->GetStaticObjectField(env, SimpleClass, field);
 322         if (obj == NULL) {
 323             ok = JNI_FALSE;
 324             break;
 325         }
 326         pHdr->Object = (*env)->NewGlobalRef(env, obj);
 327         (*env)->DeleteLocalRef(env, obj);
 328         if (pHdr->Object == NULL) {
 329             ok = JNI_FALSE;
 330             break;
 331         }
 332     }
 333 
 334     if (!ok) {
 335         for (pHdr = pStart; pHdr < pEnd; pHdr = PtrAddBytes(pHdr, size)) {
 336             if (pHdr->Object != NULL) {
 337                 (*env)->DeleteGlobalRef(env, pHdr->Object);
 338                 pHdr->Object = NULL;
 339             }
 340         }
 341     }
 342 
 343     return ok;
 344 }
 345 
 346 static jboolean InitSurfaceTypes(JNIEnv *env, jclass ST)
 347 {
 348     return InitSimpleTypes(env, ST, "Lsun/java2d/loops/SurfaceType;",
 349                            (SurfCompHdr *) SurfTypeStart,
 350                            (SurfCompHdr *) SurfTypeEnd,
 351                            sizeof(SurfaceType));
 352 }
 353 
 354 static jboolean InitCompositeTypes(JNIEnv *env, jclass CT)
 355 {
 356     return InitSimpleTypes(env, CT, "Lsun/java2d/loops/CompositeType;",
 357                            (SurfCompHdr *) CompTypeStart,
 358                            (SurfCompHdr *) CompTypeEnd,
 359                            sizeof(CompositeType));
 360 }
 361 
 362 /*
 363  * This function registers a set of Java GraphicsPrimitive objects
 364  * based on information stored in an array of NativePrimitive structures.
 365  */
 366 jboolean RegisterPrimitives(JNIEnv *env,
 367                             NativePrimitive *pPrim,
 368                             jint NumPrimitives)
 369 {
 370     jarray primitives;
 371     int i;
 372 
 373     primitives = (*env)->NewObjectArray(env, NumPrimitives,
 374                                         GraphicsPrimitive, NULL);
 375     if (primitives == NULL) {
 376         return JNI_FALSE;
 377     }
 378 
 379     for (i = 0; i < NumPrimitives; i++, pPrim++) {
 380         jint srcflags, dstflags;
 381         jobject prim;
 382         PrimitiveType *pType = pPrim->pPrimType;
 383         SurfaceType *pSrc = pPrim->pSrcType;
 384         CompositeType *pComp = pPrim->pCompType;
 385         SurfaceType *pDst = pPrim->pDstType;
 386 
 387         pPrim->funcs.initializer = MapAccelFunction(pPrim->funcs_c.initializer);
 388 
 389         /*
 390          * Calculate the necessary SurfaceData lock flags for the
 391          * source and destination surfaces based on the information
 392          * stored in the PrimitiveType, SurfaceType, and CompositeType
 393          * structures.  The starting point is the values that are
 394          * already stored in the NativePrimitive structure.  These
 395          * flags are usually left as 0, but can be filled in by
 396          * native primitive loops that have special needs that are
 397          * not deducible from their declared attributes.
 398          */
 399         srcflags = pPrim->srcflags;
 400         dstflags = pPrim->dstflags;
 401         srcflags |= pType->srcflags;
 402         dstflags |= pType->dstflags;
 403         dstflags |= pComp->dstflags;
 404         if (srcflags & SD_LOCK_READ) srcflags |= pSrc->readflags;
 405         /* if (srcflags & SD_LOCK_WRITE) srcflags |= pSrc->writeflags; */
 406         if (dstflags & SD_LOCK_READ) dstflags |= pDst->readflags;
 407         if (dstflags & SD_LOCK_WRITE) dstflags |= pDst->writeflags;
 408         pPrim->srcflags = srcflags;
 409         pPrim->dstflags = dstflags;
 410 
 411         prim = (*env)->NewObject(env,
 412                                  pType->ClassObject,
 413                                  pType->Constructor,
 414                                  ptr_to_jlong(pPrim),
 415                                  pSrc->hdr.Object,
 416                                  pComp->hdr.Object,
 417                                  pDst->hdr.Object);
 418         if (prim == NULL) {
 419             break;
 420         }
 421         (*env)->SetObjectArrayElement(env, primitives, i, prim);
 422         (*env)->DeleteLocalRef(env, prim);
 423         if ((*env)->ExceptionCheck(env)) {
 424             break;
 425         }
 426     }
 427 
 428     if (i >= NumPrimitives) {
 429         /* No error - upcall to GraphicsPrimitiveMgr to register the
 430          * new primitives... */
 431         (*env)->CallStaticVoidMethod(env, GraphicsPrimitiveMgr, RegisterID,
 432                                      primitives);
 433     }
 434     (*env)->DeleteLocalRef(env, primitives);
 435 
 436     return !((*env)->ExceptionCheck(env));
 437 }
 438 
 439 JNIEXPORT NativePrimitive * JNICALL
 440 GetNativePrim(JNIEnv *env, jobject gp)
 441 {
 442     NativePrimitive *pPrim;
 443 
 444     pPrim = (NativePrimitive *) JNU_GetLongFieldAsPtr(env, gp, pNativePrimID);
 445     if (pPrim == NULL) {
 446         JNU_ThrowInternalError(env, "Non-native Primitive invoked natively");
 447     }
 448 
 449     return pPrim;
 450 }
 451 
 452 JNIEXPORT void JNICALL
 453 GrPrim_Sg2dGetCompInfo(JNIEnv *env, jobject sg2d,
 454                        NativePrimitive *pPrim, CompositeInfo *pCompInfo)
 455 {
 456     jobject comp;
 457 
 458     comp = (*env)->GetObjectField(env, sg2d, compositeID);
 459     (*pPrim->pCompType->getCompInfo)(env, pCompInfo, comp);
 460     (*env)->DeleteLocalRef(env, comp);
 461 }
 462 
 463 JNIEXPORT jint JNICALL
 464 GrPrim_CompGetXorColor(JNIEnv *env, jobject comp)
 465 {
 466     jobject color;
 467     jint rgb;
 468 
 469     color = (*env)->GetObjectField(env, comp, xorColorID);
 470     rgb = (*env)->CallIntMethod(env, color, getRgbID);
 471     (*env)->DeleteLocalRef(env, color);
 472 
 473     return rgb;
 474 }
 475 
 476 JNIEXPORT void JNICALL
 477 GrPrim_Sg2dGetClip(JNIEnv *env, jobject sg2d, SurfaceDataBounds *bounds)
 478 {
 479     jobject clip = (*env)->GetObjectField(env, sg2d, clipRegionID);
 480     Region_GetBounds(env, clip, bounds);
 481 }
 482 
 483 JNIEXPORT jint JNICALL
 484 GrPrim_Sg2dGetPixel(JNIEnv *env, jobject sg2d)
 485 {
 486     return (*env)->GetIntField(env, sg2d, pixelID);
 487 }
 488 
 489 JNIEXPORT jint JNICALL
 490 GrPrim_Sg2dGetEaRGB(JNIEnv *env, jobject sg2d)
 491 {
 492     return (*env)->GetIntField(env, sg2d, eargbID);
 493 }
 494 
 495 JNIEXPORT jint JNICALL
 496 GrPrim_Sg2dGetLCDTextContrast(JNIEnv *env, jobject sg2d)
 497 {
 498     return (*env)->GetIntField(env, sg2d, lcdTextContrastID);
 499 }
 500 
 501 /*
 502  * Helper function for CompositeTypes.Xor
 503  */
 504 JNIEXPORT void JNICALL
 505 GrPrim_CompGetXorInfo(JNIEnv *env, CompositeInfo *pCompInfo, jobject comp)
 506 {
 507     pCompInfo->rule = RULE_Xor;
 508     pCompInfo->details.xorPixel = (*env)->GetIntField(env, comp, xorPixelID);
 509     pCompInfo->alphaMask = (*env)->GetIntField(env, comp, alphaMaskID);
 510 }
 511 
 512 /*
 513  * Helper function for CompositeTypes.AnyAlpha
 514  */
 515 JNIEXPORT void JNICALL
 516 GrPrim_CompGetAlphaInfo(JNIEnv *env, CompositeInfo *pCompInfo, jobject comp)
 517 {
 518     pCompInfo->rule =
 519         (*env)->GetIntField(env, comp, ruleID);
 520     pCompInfo->details.extraAlpha =
 521         (*env)->GetFloatField(env, comp, extraAlphaID);
 522 }
 523 
 524 JNIEXPORT void JNICALL
 525 Transform_GetInfo(JNIEnv *env, jobject txform, TransformInfo *pTxInfo)
 526 {
 527     pTxInfo->dxdx = (*env)->GetDoubleField(env, txform, m00ID);
 528     pTxInfo->dxdy = (*env)->GetDoubleField(env, txform, m01ID);
 529     pTxInfo->tx   = (*env)->GetDoubleField(env, txform, m02ID);
 530     pTxInfo->dydx = (*env)->GetDoubleField(env, txform, m10ID);
 531     pTxInfo->dydy = (*env)->GetDoubleField(env, txform, m11ID);
 532     pTxInfo->ty   = (*env)->GetDoubleField(env, txform, m12ID);
 533 }
 534 
 535 JNIEXPORT void JNICALL
 536 Transform_transform(TransformInfo *pTxInfo, jdouble *pX, jdouble *pY)
 537 {
 538     jdouble x = *pX;
 539     jdouble y = *pY;
 540 
 541     *pX = pTxInfo->dxdx * x + pTxInfo->dxdy * y + pTxInfo->tx;
 542     *pY = pTxInfo->dydx * x + pTxInfo->dydy * y + pTxInfo->ty;
 543 }
 544 
 545 /*
 546  * External declarations for the pixelFor helper methods for the various
 547  * named surface types.  These functions are defined in the various
 548  * files that contain the loop functions for their type.
 549  */
 550 extern PixelForFunc PixelForByteBinary;
 551 extern PixelForFunc PixelForByteIndexed;
 552 extern PixelForFunc PixelForByteGray;
 553 extern PixelForFunc PixelForIndex8Gray;
 554 extern PixelForFunc PixelForIndex12Gray;
 555 extern PixelForFunc PixelForUshort555Rgb;
 556 extern PixelForFunc PixelForUshort555Rgbx;
 557 extern PixelForFunc PixelForUshort565Rgb;
 558 extern PixelForFunc PixelForUshort4444Argb;
 559 extern PixelForFunc PixelForUshortGray;
 560 extern PixelForFunc PixelForUshortIndexed;
 561 extern PixelForFunc PixelForIntArgbPre;
 562 extern PixelForFunc PixelForIntArgbBm;
 563 extern PixelForFunc PixelForIntBgr;
 564 extern PixelForFunc PixelForIntRgbx;
 565 extern PixelForFunc PixelForFourByteAbgr;
 566 extern PixelForFunc PixelForFourByteAbgrPre;
 567 
 568 /*
 569  * Definition and initialization of the globally accessible PrimitiveTypes.
 570  */
 571 struct _PrimitiveTypes PrimitiveTypes = {
 572     { "sun/java2d/loops/Blit", SD_LOCK_READ, SD_LOCK_WRITE, NULL, NULL},
 573     { "sun/java2d/loops/BlitBg", SD_LOCK_READ, SD_LOCK_WRITE, NULL, NULL},
 574     { "sun/java2d/loops/ScaledBlit", SD_LOCK_READ, SD_LOCK_WRITE, NULL, NULL},
 575     { "sun/java2d/loops/FillRect", 0, SD_LOCK_WRITE, NULL, NULL},
 576     { "sun/java2d/loops/FillSpans", 0, SD_LOCK_PARTIAL_WRITE, NULL, NULL},
 577     { "sun/java2d/loops/FillParallelogram", 0, SD_LOCK_PARTIAL_WRITE, NULL, NULL},
 578     { "sun/java2d/loops/DrawParallelogram", 0, SD_LOCK_PARTIAL_WRITE, NULL, NULL},
 579     { "sun/java2d/loops/DrawLine", 0, SD_LOCK_PARTIAL_WRITE, NULL, NULL},
 580     { "sun/java2d/loops/DrawRect", 0, SD_LOCK_PARTIAL_WRITE, NULL, NULL},
 581     { "sun/java2d/loops/DrawPolygons", 0, SD_LOCK_PARTIAL_WRITE, NULL, NULL},
 582     { "sun/java2d/loops/DrawPath", 0, SD_LOCK_PARTIAL_WRITE, NULL, NULL},
 583     { "sun/java2d/loops/FillPath", 0, SD_LOCK_PARTIAL_WRITE, NULL, NULL},
 584     { "sun/java2d/loops/MaskBlit", SD_LOCK_READ, SD_LOCK_RD_WR, NULL, NULL},
 585     { "sun/java2d/loops/MaskFill", 0, SD_LOCK_RD_WR, NULL, NULL},
 586     { "sun/java2d/loops/DrawGlyphList", 0, SD_LOCK_PARTIAL_WRITE |
 587                                            SD_LOCK_FASTEST, NULL, NULL},
 588     { "sun/java2d/loops/DrawGlyphListAA", 0, SD_LOCK_RD_WR | SD_LOCK_FASTEST, NULL, NULL},
 589     { "sun/java2d/loops/DrawGlyphListLCD", 0, SD_LOCK_RD_WR | SD_LOCK_FASTEST, NULL, NULL},
 590     { "sun/java2d/loops/TransformHelper", SD_LOCK_READ, 0, NULL, NULL}
 591 };
 592 
 593 /*
 594  * Definition and initialization of the globally accessible SurfaceTypes.
 595  */
 596 struct _SurfaceTypes SurfaceTypes = {
 597     { { "OpaqueColor", NULL}, NULL, 0, 0 },
 598     { { "AnyColor", NULL}, NULL, 0, 0 },
 599     { { "AnyByte", NULL}, NULL, 0, 0 },
 600     { { "ByteBinary1Bit", NULL},
 601       PixelForByteBinary, SD_LOCK_LUT, SD_LOCK_INVCOLOR },
 602     { { "ByteBinary2Bit", NULL},
 603       PixelForByteBinary, SD_LOCK_LUT, SD_LOCK_INVCOLOR },
 604     { { "ByteBinary4Bit", NULL},
 605       PixelForByteBinary, SD_LOCK_LUT, SD_LOCK_INVCOLOR },
 606     { { "ByteIndexed", NULL},
 607       PixelForByteIndexed, SD_LOCK_LUT, SD_LOCK_INVCOLOR },
 608     { { "ByteIndexedBm", NULL},
 609       PixelForByteIndexed, SD_LOCK_LUT, SD_LOCK_INVCOLOR },
 610     { { "ByteGray", NULL}, PixelForByteGray, 0, 0},
 611     { { "Index8Gray", NULL},
 612       PixelForIndex8Gray, SD_LOCK_LUT, SD_LOCK_INVGRAY },
 613     { { "Index12Gray", NULL},
 614       PixelForIndex12Gray, SD_LOCK_LUT, SD_LOCK_INVGRAY },
 615     { { "AnyShort", NULL}, NULL, 0, 0 },
 616     { { "Ushort555Rgb", NULL}, PixelForUshort555Rgb, 0, 0},
 617     { { "Ushort555Rgbx", NULL}, PixelForUshort555Rgbx, 0, 0},
 618     { { "Ushort565Rgb", NULL}, PixelForUshort565Rgb, 0, 0 },
 619     { { "Ushort4444Argb", NULL}, PixelForUshort4444Argb, 0, 0 },
 620     { { "UshortGray", NULL}, PixelForUshortGray, 0, 0},
 621     { { "UshortIndexed", NULL},
 622       PixelForUshortIndexed, SD_LOCK_LUT, SD_LOCK_INVCOLOR },
 623     { { "Any3Byte", NULL},  NULL, 0, 0 },
 624     { { "ThreeByteBgr", NULL},  NULL, 0, 0 },
 625     { { "AnyInt", NULL}, NULL, 0, 0 },
 626     { { "IntArgb", NULL},  NULL, 0, 0 },
 627     { { "IntArgbPre", NULL}, PixelForIntArgbPre, 0, 0},
 628     { { "IntArgbBm", NULL}, PixelForIntArgbBm, 0, 0},
 629     { { "IntRgb", NULL},  NULL, 0, 0 },
 630     { { "IntBgr", NULL}, PixelForIntBgr, 0, 0},
 631     { { "IntRgbx", NULL}, PixelForIntRgbx, 0, 0},
 632     { { "Any4Byte", NULL},  NULL, 0, 0 },
 633     { { "FourByteAbgr", NULL}, PixelForFourByteAbgr, 0, 0},
 634     { { "FourByteAbgrPre", NULL}, PixelForFourByteAbgrPre, 0, 0},
 635 };
 636 
 637 /*
 638  * Definition and initialization of the globally accessible CompositeTypes.
 639  */
 640 struct _CompositeTypes CompositeTypes = {
 641     { { "SrcNoEa", NULL}, NULL, 0},
 642     { { "SrcOverNoEa", NULL}, NULL, SD_LOCK_RD_WR },
 643     { { "SrcOverNoEa", NULL}, NULL, SD_LOCK_PARTIAL_WRITE }, /* SrcOverBmNoEa */
 644     { { "Src", NULL}, GrPrim_CompGetAlphaInfo, 0},
 645     { { "SrcOver", NULL}, GrPrim_CompGetAlphaInfo, SD_LOCK_RD_WR },
 646     { { "Xor", NULL}, GrPrim_CompGetXorInfo, SD_LOCK_RD_WR },
 647     { { "AnyAlpha", NULL}, GrPrim_CompGetAlphaInfo, SD_LOCK_RD_WR },
 648 };