aboutsummaryrefslogtreecommitdiff
path: root/src/share/native/sun/java2d/loops/GraphicsPrimitiveMgr.c
blob: a36a2885747fe4edf52829624ee97e55feedc797 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
/*
 * Copyright 2000-2006 Sun Microsystems, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Sun designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Sun in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */

#include "jni_util.h"
#include "jlong.h"

#include "sun_java2d_loops_GraphicsPrimitiveMgr.h"

#include "Region.h"
#include "GraphicsPrimitiveMgr.h"
#include "AlphaMacros.h"

static char *InitName = "<init>";
static char *InitSig =  ("(JLsun/java2d/loops/SurfaceType;"
                         "Lsun/java2d/loops/CompositeType;"
                         "Lsun/java2d/loops/SurfaceType;)V");

static char *RegisterName =     "register";
static char *RegisterSig =      "([Lsun/java2d/loops/GraphicsPrimitive;)V";

static jclass GraphicsPrimitiveMgr;
static jclass GraphicsPrimitive;

static jmethodID RegisterID;
static jfieldID pNativePrimID;
static jfieldID pixelID;
static jfieldID eargbID;
static jfieldID clipRegionID;
static jfieldID compositeID;
static jfieldID lcdTextContrastID;
static jfieldID valueID;
static jfieldID xorPixelID;
static jfieldID xorColorID;
static jfieldID alphaMaskID;
static jfieldID ruleID;
static jfieldID extraAlphaID;

static jfieldID m00ID;
static jfieldID m01ID;
static jfieldID m02ID;
static jfieldID m10ID;
static jfieldID m11ID;
static jfieldID m12ID;

static jboolean InitPrimTypes(JNIEnv *env);
static jboolean InitSurfaceTypes(JNIEnv *env, jclass SurfaceType);
static jboolean InitCompositeTypes(JNIEnv *env, jclass CompositeType);

jfieldID path2DTypesID;
jfieldID path2DNumTypesID;
jfieldID path2DWindingRuleID;
jfieldID path2DFloatCoordsID;
jfieldID sg2dStrokeHintID;
jint sunHints_INTVAL_STROKE_PURE;

/*
 * Class:     sun_java2d_loops_GraphicsPrimitiveMgr
 * Method:    initIDs
 * Signature: (Ljava/lang/Class;Ljava/lang/Class;Ljava/lang/Class;Ljava/lang/Class;Ljava/lang/Class;Ljava/lang/Class;Ljava/lang/Class;)V
 */
JNIEXPORT void JNICALL
Java_sun_java2d_loops_GraphicsPrimitiveMgr_initIDs
    (JNIEnv *env, jclass GPMgr,
     jclass GP, jclass ST, jclass CT,
     jclass SG2D, jclass Color, jclass AT,
     jclass XORComp, jclass AlphaComp,
     jclass Path2D, jclass Path2DFloat,
     jclass SHints)
{
    jfieldID fid;
    initAlphaTables();
    GraphicsPrimitiveMgr = (*env)->NewGlobalRef(env, GPMgr);
    GraphicsPrimitive = (*env)->NewGlobalRef(env, GP);
    if (GraphicsPrimitiveMgr == NULL || GraphicsPrimitive == NULL) {
        JNU_ThrowOutOfMemoryError(env, "creating global refs");
        return;
    }
    if (!InitPrimTypes(env) ||
        !InitSurfaceTypes(env, ST) ||
        !InitCompositeTypes(env, CT))
    {
        return;
    }
    RegisterID = (*env)->GetStaticMethodID(env, GPMgr,
                                           RegisterName, RegisterSig);
    pNativePrimID = (*env)->GetFieldID(env, GP, "pNativePrim", "J");
    pixelID = (*env)->GetFieldID(env, SG2D, "pixel", "I");
    eargbID = (*env)->GetFieldID(env, SG2D, "eargb", "I");
    clipRegionID = (*env)->GetFieldID(env, SG2D, "clipRegion",
                                      "Lsun/java2d/pipe/Region;");
    compositeID = (*env)->GetFieldID(env, SG2D, "composite",
                                     "Ljava/awt/Composite;");
    lcdTextContrastID =
        (*env)->GetFieldID(env, SG2D, "lcdTextContrast", "I");
    valueID = (*env)->GetFieldID(env, Color, "value", "I");
    xorPixelID = (*env)->GetFieldID(env, XORComp, "xorPixel", "I");
    xorColorID = (*env)->GetFieldID(env, XORComp, "xorColor",
                                    "Ljava/awt/Color;");
    alphaMaskID = (*env)->GetFieldID(env, XORComp, "alphaMask", "I");
    ruleID = (*env)->GetFieldID(env, AlphaComp, "rule", "I");
    extraAlphaID = (*env)->GetFieldID(env, AlphaComp, "extraAlpha", "F");


    m00ID = (*env)->GetFieldID(env, AT, "m00", "D");
    m01ID = (*env)->GetFieldID(env, AT, "m01", "D");
    m02ID = (*env)->GetFieldID(env, AT, "m02", "D");
    m10ID = (*env)->GetFieldID(env, AT, "m10", "D");
    m11ID = (*env)->GetFieldID(env, AT, "m11", "D");
    m12ID = (*env)->GetFieldID(env, AT, "m12", "D");

    path2DTypesID = (*env)->GetFieldID(env, Path2D, "pointTypes", "[B");
    path2DNumTypesID = (*env)->GetFieldID(env, Path2D, "numTypes", "I");
    path2DWindingRuleID = (*env)->GetFieldID(env, Path2D, "windingRule", "I");
    path2DFloatCoordsID = (*env)->GetFieldID(env, Path2DFloat,
                                             "floatCoords", "[F");
    sg2dStrokeHintID = (*env)->GetFieldID(env, SG2D, "strokeHint", "I");
    fid = (*env)->GetStaticFieldID(env, SHints, "INTVAL_STROKE_PURE", "I");
    sunHints_INTVAL_STROKE_PURE = (*env)->GetStaticIntField(env, SHints, fid);

}

void GrPrim_RefineBounds(SurfaceDataBounds *bounds, jint transX, jint transY,
                         jfloat *coords,  jint maxCoords)
{
    jint xmin, ymin, xmax, ymax;
    if (maxCoords > 1) {
        xmin = xmax = transX + (jint)(*coords++ + 0.5);
        ymin = ymax = transY + (jint)(*coords++ + 0.5);
        for (;maxCoords > 1; maxCoords -= 2) {
            jint x = transX + (jint)(*coords++ + 0.5);
            jint y = transY + (jint)(*coords++ + 0.5);
            if (xmin > x) xmin = x;
            if (ymin > y) ymin = y;
            if (xmax < x) xmax = x;
            if (ymax < y) ymax = y;
        }
        if (++xmax < xmin) xmax--;
        if (++ymax < ymin) ymax--;
        if (bounds->x1 < xmin) bounds->x1 = xmin;
        if (bounds->y1 < ymin) bounds->y1 = ymin;
        if (bounds->x2 > xmax) bounds->x2 = xmax;
        if (bounds->y2 > ymax) bounds->y2 = ymax;
    } else {
        bounds->x2 = bounds->x1;
        bounds->y2 = bounds->y1;
    }
}

/*
 * Class:     sun_java2d_loops_GraphicsPrimitiveMgr
 * Method:    registerNativeLoops
 * Signature: ()V
 */
JNIEXPORT void JNICALL
Java_sun_java2d_loops_GraphicsPrimitiveMgr_registerNativeLoops
    (JNIEnv *env, jclass GPMgr)
{
    RegisterFunc RegisterAnyByte;
    RegisterFunc RegisterByteBinary1Bit;
    RegisterFunc RegisterByteBinary2Bit;
    RegisterFunc RegisterByteBinary4Bit;
    RegisterFunc RegisterByteIndexed;
    RegisterFunc RegisterByteGray;
    RegisterFunc RegisterIndex8Gray;
    RegisterFunc RegisterIndex12Gray;
    RegisterFunc RegisterAnyShort;
    RegisterFunc RegisterUshort555Rgb;
    RegisterFunc RegisterUshort565Rgb;
    RegisterFunc RegisterUshort4444Argb;
    RegisterFunc RegisterUshort555Rgbx;
    RegisterFunc RegisterUshortGray;
    RegisterFunc RegisterUshortIndexed;
    RegisterFunc RegisterAny3Byte;
    RegisterFunc RegisterThreeByteBgr;
    RegisterFunc RegisterAnyInt;
    RegisterFunc RegisterIntArgb;
    RegisterFunc RegisterIntArgbPre;
    RegisterFunc RegisterIntArgbBm;
    RegisterFunc RegisterIntRgb;
    RegisterFunc RegisterIntBgr;
    RegisterFunc RegisterIntRgbx;
    RegisterFunc RegisterAny4Byte;
    RegisterFunc RegisterFourByteAbgr;
    RegisterFunc RegisterFourByteAbgrPre;

    RegisterAnyByte(env);
    RegisterByteBinary1Bit(env);
    RegisterByteBinary2Bit(env);
    RegisterByteBinary4Bit(env);
    RegisterByteIndexed(env);
    RegisterByteGray(env);
    RegisterIndex8Gray(env);
    RegisterIndex12Gray(env);
    RegisterAnyShort(env);
    RegisterUshort555Rgb(env);
    RegisterUshort565Rgb(env);
    RegisterUshort4444Argb(env);
    RegisterUshort555Rgbx(env);
    RegisterUshortGray(env);
    RegisterUshortIndexed(env);
    RegisterAny3Byte(env);
    RegisterThreeByteBgr(env);
    RegisterAnyInt(env);
    RegisterIntArgb(env);
    RegisterIntArgbPre(env);
    RegisterIntArgbBm(env);
    RegisterIntRgb(env);
    RegisterIntBgr(env);
    RegisterIntRgbx(env);
    RegisterAny4Byte(env);
    RegisterFourByteAbgr(env);
    RegisterFourByteAbgrPre(env);
}

#define _StartOf(T)     ((T *) (&T##s))
#define _NumberOf(T)    (sizeof(T##s) / sizeof(T))
#define _EndOf(T)       (_StartOf(T) + _NumberOf(T))

#define PrimTypeStart   _StartOf(PrimitiveType)
#define PrimTypeEnd     _EndOf(PrimitiveType)

#define SurfTypeStart   _StartOf(SurfaceType)
#define SurfTypeEnd     _EndOf(SurfaceType)

#define CompTypeStart   _StartOf(CompositeType)
#define CompTypeEnd     _EndOf(CompositeType)

/*
 * This function initializes the global collection of PrimitiveType
 * structures by retrieving the necessary Java Class object and the
 * associated methodID of the necessary constructor.
 *
 * See PrimitiveTypes.* below.
 */
static jboolean InitPrimTypes(JNIEnv *env)
{
    jboolean ok = JNI_TRUE;
    PrimitiveType *pPrimType;
    jclass cl;

    for (pPrimType = PrimTypeStart; pPrimType < PrimTypeEnd; pPrimType++) {
        cl = (*env)->FindClass(env, pPrimType->ClassName);
        if (cl == NULL) {
            ok = JNI_FALSE;
            break;
        }
        pPrimType->ClassObject = (*env)->NewGlobalRef(env, cl);
        pPrimType->Constructor =
            (*env)->GetMethodID(env, cl, InitName, InitSig);

        (*env)->DeleteLocalRef(env, cl);
        if (pPrimType->ClassObject == NULL ||
            pPrimType->Constructor == NULL)
        {
            ok = JNI_FALSE;
            break;
        }
    }

    if (!ok) {
        for (pPrimType = PrimTypeStart; pPrimType < PrimTypeEnd; pPrimType++) {
            if (pPrimType->ClassObject != NULL) {
                (*env)->DeleteGlobalRef(env, pPrimType->ClassObject);
                pPrimType->ClassObject = NULL;
            }
            pPrimType->Constructor = NULL;
        }
    }

    return ok;
}

/*
 * This function initializes the global collection of SurfaceType
 * or CompositeType structures by retrieving the corresponding Java
 * object stored as a static field on the Java Class.
 *
 * See SurfaceTypes.* below.
 * See CompositeeTypes.* below.
 */
static jboolean InitSimpleTypes
    (JNIEnv *env, jclass SimpleClass, char *SimpleSig,
     SurfCompHdr *pStart, SurfCompHdr *pEnd, jsize size)
{
    jboolean ok = JNI_TRUE;
    SurfCompHdr *pHdr;
    jfieldID field;
    jobject obj;

    for (pHdr = pStart; pHdr < pEnd; pHdr = PtrAddBytes(pHdr, size)) {
        field = (*env)->GetStaticFieldID(env,
                                         SimpleClass,
                                         pHdr->Name,
                                         SimpleSig);
        if (field == NULL) {
            ok = JNI_FALSE;
            break;
        }
        obj = (*env)->GetStaticObjectField(env, SimpleClass, field);
        if (obj == NULL) {
            ok = JNI_FALSE;
            break;
        }
        pHdr->Object = (*env)->NewGlobalRef(env, obj);
        (*env)->DeleteLocalRef(env, obj);
        if (pHdr->Object == NULL) {
            ok = JNI_FALSE;
            break;
        }
    }

    if (!ok) {
        for (pHdr = pStart; pHdr < pEnd; pHdr = PtrAddBytes(pHdr, size)) {
            if (pHdr->Object != NULL) {
                (*env)->DeleteGlobalRef(env, pHdr->Object);
                pHdr->Object = NULL;
            }
        }
    }

    return ok;
}

static jboolean InitSurfaceTypes(JNIEnv *env, jclass ST)
{
    return InitSimpleTypes(env, ST, "Lsun/java2d/loops/SurfaceType;",
                           (SurfCompHdr *) SurfTypeStart,
                           (SurfCompHdr *) SurfTypeEnd,
                           sizeof(SurfaceType));
}

static jboolean InitCompositeTypes(JNIEnv *env, jclass CT)
{
    return InitSimpleTypes(env, CT, "Lsun/java2d/loops/CompositeType;",
                           (SurfCompHdr *) CompTypeStart,
                           (SurfCompHdr *) CompTypeEnd,
                           sizeof(CompositeType));
}

/*
 * This function registers a set of Java GraphicsPrimitive objects
 * based on information stored in an array of NativePrimitive structures.
 */
jboolean RegisterPrimitives(JNIEnv *env,
                            NativePrimitive *pPrim,
                            jint NumPrimitives)
{
    jarray primitives;
    int i;

    primitives = (*env)->NewObjectArray(env, NumPrimitives,
                                        GraphicsPrimitive, NULL);
    if (primitives == NULL) {
        return JNI_FALSE;
    }

    for (i = 0; i < NumPrimitives; i++, pPrim++) {
        jint srcflags, dstflags;
        jobject prim;
        PrimitiveType *pType = pPrim->pPrimType;
        SurfaceType *pSrc = pPrim->pSrcType;
        CompositeType *pComp = pPrim->pCompType;
        SurfaceType *pDst = pPrim->pDstType;

        pPrim->funcs.initializer = MapAccelFunction(pPrim->funcs_c.initializer);

        /*
         * Calculate the necessary SurfaceData lock flags for the
         * source and destination surfaces based on the information
         * stored in the PrimitiveType, SurfaceType, and CompositeType
         * structures.  The starting point is the values that are
         * already stored in the NativePrimitive structure.  These
         * flags are usually left as 0, but can be filled in by
         * native primitive loops that have special needs that are
         * not deducible from their declared attributes.
         */
        srcflags = pPrim->srcflags;
        dstflags = pPrim->dstflags;
        srcflags |= pType->srcflags;
        dstflags |= pType->dstflags;
        dstflags |= pComp->dstflags;
        if (srcflags & SD_LOCK_READ) srcflags |= pSrc->readflags;
        /* if (srcflags & SD_LOCK_WRITE) srcflags |= pSrc->writeflags; */
        if (dstflags & SD_LOCK_READ) dstflags |= pDst->readflags;
        if (dstflags & SD_LOCK_WRITE) dstflags |= pDst->writeflags;
        pPrim->srcflags = srcflags;
        pPrim->dstflags = dstflags;

        prim = (*env)->NewObject(env,
                                 pType->ClassObject,
                                 pType->Constructor,
                                 ptr_to_jlong(pPrim),
                                 pSrc->hdr.Object,
                                 pComp->hdr.Object,
                                 pDst->hdr.Object);
        if (prim == NULL) {
            break;
        }
        (*env)->SetObjectArrayElement(env, primitives, i, prim);
        (*env)->DeleteLocalRef(env, prim);
        if ((*env)->ExceptionCheck(env)) {
            break;
        }
    }

    if (i >= NumPrimitives) {
        /* No error - upcall to GraphicsPrimitiveMgr to register the
         * new primitives... */
        (*env)->CallStaticVoidMethod(env, GraphicsPrimitiveMgr, RegisterID,
                                     primitives);
    }
    (*env)->DeleteLocalRef(env, primitives);

    return !((*env)->ExceptionCheck(env));
}

JNIEXPORT NativePrimitive * JNICALL
GetNativePrim(JNIEnv *env, jobject gp)
{
    NativePrimitive *pPrim;

    pPrim = (NativePrimitive *) JNU_GetLongFieldAsPtr(env, gp, pNativePrimID);
    if (pPrim == NULL) {
        JNU_ThrowInternalError(env, "Non-native Primitive invoked natively");
    }

    return pPrim;
}

JNIEXPORT void JNICALL
GrPrim_Sg2dGetCompInfo(JNIEnv *env, jobject sg2d,
                       NativePrimitive *pPrim, CompositeInfo *pCompInfo)
{
    jobject comp;

    comp = (*env)->GetObjectField(env, sg2d, compositeID);
    (*pPrim->pCompType->getCompInfo)(env, pCompInfo, comp);
    (*env)->DeleteLocalRef(env, comp);
}

JNIEXPORT jint JNICALL
GrPrim_CompGetXorColor(JNIEnv *env, jobject comp)
{
    jobject color;
    jint rgb;

    color = (*env)->GetObjectField(env, comp, xorColorID);
    rgb = (*env)->GetIntField(env, color, valueID);
    (*env)->DeleteLocalRef(env, color);

    return rgb;
}

JNIEXPORT void JNICALL
GrPrim_Sg2dGetClip(JNIEnv *env, jobject sg2d, SurfaceDataBounds *bounds)
{
    jobject clip = (*env)->GetObjectField(env, sg2d, clipRegionID);
    Region_GetBounds(env, clip, bounds);
}

JNIEXPORT jint JNICALL
GrPrim_Sg2dGetPixel(JNIEnv *env, jobject sg2d)
{
    return (*env)->GetIntField(env, sg2d, pixelID);
}

JNIEXPORT jint JNICALL
GrPrim_Sg2dGetEaRGB(JNIEnv *env, jobject sg2d)
{
    return (*env)->GetIntField(env, sg2d, eargbID);
}

jint GrPrim_ColorGetRGB(JNIEnv *env, jobject color)
{
    return (*env)->GetIntField(env, color, valueID);
}

JNIEXPORT jint JNICALL
GrPrim_Sg2dGetLCDTextContrast(JNIEnv *env, jobject sg2d)
{
    return (*env)->GetIntField(env, sg2d, lcdTextContrastID);
}

/*
 * Helper function for CompositeTypes.Xor
 */
JNIEXPORT void JNICALL
GrPrim_CompGetXorInfo(JNIEnv *env, CompositeInfo *pCompInfo, jobject comp)
{
    pCompInfo->rule = RULE_Xor;
    pCompInfo->details.xorPixel = (*env)->GetIntField(env, comp, xorPixelID);
    pCompInfo->alphaMask = (*env)->GetIntField(env, comp, alphaMaskID);
}

/*
 * Helper function for CompositeTypes.AnyAlpha
 */
JNIEXPORT void JNICALL
GrPrim_CompGetAlphaInfo(JNIEnv *env, CompositeInfo *pCompInfo, jobject comp)
{
    pCompInfo->rule =
        (*env)->GetIntField(env, comp, ruleID);
    pCompInfo->details.extraAlpha =
        (*env)->GetFloatField(env, comp, extraAlphaID);
}

JNIEXPORT void JNICALL
Transform_GetInfo(JNIEnv *env, jobject txform, TransformInfo *pTxInfo)
{
    pTxInfo->dxdx = (*env)->GetDoubleField(env, txform, m00ID);
    pTxInfo->dxdy = (*env)->GetDoubleField(env, txform, m01ID);
    pTxInfo->tx   = (*env)->GetDoubleField(env, txform, m02ID);
    pTxInfo->dydx = (*env)->GetDoubleField(env, txform, m10ID);
    pTxInfo->dydy = (*env)->GetDoubleField(env, txform, m11ID);
    pTxInfo->ty   = (*env)->GetDoubleField(env, txform, m12ID);
}

JNIEXPORT void JNICALL
Transform_transform(TransformInfo *pTxInfo, jdouble *pX, jdouble *pY)
{
    jdouble x = *pX;
    jdouble y = *pY;

    *pX = pTxInfo->dxdx * x + pTxInfo->dxdy * y + pTxInfo->tx;
    *pY = pTxInfo->dydx * x + pTxInfo->dydy * y + pTxInfo->ty;
}

/*
 * External declarations for the pixelFor helper methods for the various
 * named surface types.  These functions are defined in the various
 * files that contain the loop functions for their type.
 */
extern PixelForFunc PixelForByteBinary;
extern PixelForFunc PixelForByteIndexed;
extern PixelForFunc PixelForByteGray;
extern PixelForFunc PixelForIndex8Gray;
extern PixelForFunc PixelForIndex12Gray;
extern PixelForFunc PixelForUshort555Rgb;
extern PixelForFunc PixelForUshort555Rgbx;
extern PixelForFunc PixelForUshort565Rgb;
extern PixelForFunc PixelForUshort4444Argb;
extern PixelForFunc PixelForUshortGray;
extern PixelForFunc PixelForUshortIndexed;
extern PixelForFunc PixelForIntArgbPre;
extern PixelForFunc PixelForIntArgbBm;
extern PixelForFunc PixelForIntBgr;
extern PixelForFunc PixelForIntRgbx;
extern PixelForFunc PixelForFourByteAbgr;
extern PixelForFunc PixelForFourByteAbgrPre;

/*
 * Definition and initialization of the globally accessible PrimitiveTypes.
 */
struct _PrimitiveTypes PrimitiveTypes = {
    { "sun/java2d/loops/Blit", SD_LOCK_READ, SD_LOCK_WRITE, NULL, NULL},
    { "sun/java2d/loops/BlitBg", SD_LOCK_READ, SD_LOCK_WRITE, NULL, NULL},
    { "sun/java2d/loops/ScaledBlit", SD_LOCK_READ, SD_LOCK_WRITE, NULL, NULL},
    { "sun/java2d/loops/FillRect", 0, SD_LOCK_WRITE, NULL, NULL},
    { "sun/java2d/loops/FillSpans", 0, SD_LOCK_PARTIAL_WRITE, NULL, NULL},
    { "sun/java2d/loops/DrawLine", 0, SD_LOCK_PARTIAL_WRITE, NULL, NULL},
    { "sun/java2d/loops/DrawRect", 0, SD_LOCK_PARTIAL_WRITE, NULL, NULL},
    { "sun/java2d/loops/DrawPolygons", 0, SD_LOCK_PARTIAL_WRITE, NULL, NULL},
    { "sun/java2d/loops/DrawPath", 0, SD_LOCK_PARTIAL_WRITE, NULL, NULL},
    { "sun/java2d/loops/FillPath", 0, SD_LOCK_PARTIAL_WRITE, NULL, NULL},
    { "sun/java2d/loops/MaskBlit", SD_LOCK_READ, SD_LOCK_RD_WR, NULL, NULL},
    { "sun/java2d/loops/MaskFill", 0, SD_LOCK_RD_WR, NULL, NULL},
    { "sun/java2d/loops/DrawGlyphList", 0, SD_LOCK_PARTIAL_WRITE |
                                           SD_LOCK_FASTEST, NULL, NULL},
    { "sun/java2d/loops/DrawGlyphListAA", 0, SD_LOCK_RD_WR | SD_LOCK_FASTEST, NULL, NULL},
    { "sun/java2d/loops/DrawGlyphListLCD", 0, SD_LOCK_RD_WR | SD_LOCK_FASTEST, NULL, NULL},
    { "sun/java2d/loops/TransformHelper", SD_LOCK_READ, 0, NULL, NULL}
};

/*
 * Definition and initialization of the globally accessible SurfaceTypes.
 */
struct _SurfaceTypes SurfaceTypes = {
    { { "OpaqueColor", NULL}, NULL, 0, 0 },
    { { "AnyColor", NULL}, NULL, 0, 0 },
    { { "AnyByte", NULL}, NULL, 0, 0 },
    { { "ByteBinary1Bit", NULL},
      PixelForByteBinary, SD_LOCK_LUT, SD_LOCK_INVCOLOR },
    { { "ByteBinary2Bit", NULL},
      PixelForByteBinary, SD_LOCK_LUT, SD_LOCK_INVCOLOR },
    { { "ByteBinary4Bit", NULL},
      PixelForByteBinary, SD_LOCK_LUT, SD_LOCK_INVCOLOR },
    { { "ByteIndexed", NULL},
      PixelForByteIndexed, SD_LOCK_LUT, SD_LOCK_INVCOLOR },
    { { "ByteIndexedBm", NULL},
      PixelForByteIndexed, SD_LOCK_LUT, SD_LOCK_INVCOLOR },
    { { "ByteGray", NULL}, PixelForByteGray, 0, 0},
    { { "Index8Gray", NULL},
      PixelForIndex8Gray, SD_LOCK_LUT, SD_LOCK_INVGRAY },
    { { "Index12Gray", NULL},
      PixelForIndex12Gray, SD_LOCK_LUT, SD_LOCK_INVGRAY },
    { { "AnyShort", NULL}, NULL, 0, 0 },
    { { "Ushort555Rgb", NULL}, PixelForUshort555Rgb, 0, 0},
    { { "Ushort555Rgbx", NULL}, PixelForUshort555Rgbx, 0, 0},
    { { "Ushort565Rgb", NULL}, PixelForUshort565Rgb, 0, 0 },
    { { "Ushort4444Argb", NULL}, PixelForUshort4444Argb, 0, 0 },
    { { "UshortGray", NULL}, PixelForUshortGray, 0, 0},
    { { "UshortIndexed", NULL},
      PixelForUshortIndexed, SD_LOCK_LUT, SD_LOCK_INVCOLOR },
    { { "Any3Byte", NULL},  NULL, 0, 0 },
    { { "ThreeByteBgr", NULL},  NULL, 0, 0 },
    { { "AnyInt", NULL}, NULL, 0, 0 },
    { { "IntArgb", NULL},  NULL, 0, 0 },
    { { "IntArgbPre", NULL}, PixelForIntArgbPre, 0, 0},
    { { "IntArgbBm", NULL}, PixelForIntArgbBm, 0, 0},
    { { "IntRgb", NULL},  NULL, 0, 0 },
    { { "IntBgr", NULL}, PixelForIntBgr, 0, 0},
    { { "IntRgbx", NULL}, PixelForIntRgbx, 0, 0},
    { { "Any4Byte", NULL},  NULL, 0, 0 },
    { { "FourByteAbgr", NULL}, PixelForFourByteAbgr, 0, 0},
    { { "FourByteAbgrPre", NULL}, PixelForFourByteAbgrPre, 0, 0},
};

/*
 * Definition and initialization of the globally accessible CompositeTypes.
 */
struct _CompositeTypes CompositeTypes = {
    { { "SrcNoEa", NULL}, NULL, 0},
    { { "SrcOverNoEa", NULL}, NULL, SD_LOCK_RD_WR },
    { { "SrcOverNoEa", NULL}, NULL, SD_LOCK_PARTIAL_WRITE }, /* SrcOverBmNoEa */
    { { "Src", NULL}, GrPrim_CompGetAlphaInfo, 0},
    { { "SrcOver", NULL}, GrPrim_CompGetAlphaInfo, SD_LOCK_RD_WR },
    { { "Xor", NULL}, GrPrim_CompGetXorInfo, SD_LOCK_RD_WR },
    { { "AnyAlpha", NULL}, GrPrim_CompGetAlphaInfo, SD_LOCK_RD_WR },
};