1 /*
   2  * Copyright (c) 1999, 2007, 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  * This include file contains information on how to use a SurfaceData
  28  * object from native code.
  29  */
  30 
  31 #ifndef _Included_SurfaceData
  32 #define _Included_SurfaceData
  33 
  34 #include <jni.h>
  35 
  36 #ifdef __cplusplus
  37 extern "C" {
  38 #endif
  39 
  40 /*
  41  * This structure is used to represent a rectangular bounding box
  42  * throughout various functions in the native SurfaceData API.
  43  *
  44  * All coordinates (x1 <= x < x2, y1 <= y < y2) are considered to
  45  * be inside these bounds.
  46  */
  47 typedef struct {
  48     jint x1;
  49     jint y1;
  50     jint x2;
  51     jint y2;
  52 } SurfaceDataBounds;
  53 
  54 #define SD_RASINFO_PRIVATE_SIZE         64
  55 
  56 /*
  57  * The SurfaceDataRasInfo structure is used to pass in and return various
  58  * pieces of information about the destination drawable.  In particular:
  59  *
  60  *      SurfaceDataBounds bounds;
  61  * [Needed for SD_LOCK_READ or SD_LOCK_WRITE]
  62  * The 2 dimensional bounds of the raster array that is needed.  Valid
  63  * memory locations are required at:
  64  *      *(pixeltype *) (((char *)rasBase) + y * scanStride + x * pixelStride)
  65  * for each x, y pair such that (bounds.x1 <= x < bounds.x2) and
  66  * (bounds.y1 <= y < bounds.y2).
  67  *
  68  *      void *rasBase;
  69  * [Requires SD_LOCK_READ or SD_LOCK_WRITE]
  70  * A pointer to the device space origin (0, 0) of the indicated raster
  71  * data.  This pointer may point to a location that is outside of the
  72  * allocated memory for the requested bounds and it may even point
  73  * outside of accessible memory.  Only the locations that fall within
  74  * the coordinates indicated by the requested bounds are guaranteed
  75  * to be accessible.
  76  *
  77  *      jint pixelBitOffset;
  78  * [Requires SD_LOCK_READ or SD_LOCK_WRITE]
  79  * The number of bits offset from the beginning of the first byte
  80  * of a scanline to the first bit of the first pixel on that scanline.
  81  * The bit offset must be less than 8 and it must be the same for each
  82  * scanline.  This field is only needed by image types which pack
  83  * multiple pixels into a byte, such as ByteBinary1Bit et al.  For
  84  * image types which use whole bytes (or shorts or ints) to store
  85  * their pixels, this field will always be 0.
  86  *
  87  *      jint pixelStride;
  88  * [Requires SD_LOCK_READ or SD_LOCK_WRITE]
  89  * The pixel stride is the distance in bytes from the data for one pixel
  90  * to the data for the pixel at the next x coordinate (x, y) => (x+1, y).
  91  * For data types that pack multiple pixels into a byte, such as
  92  * ByteBinary1Bit et al, this field will be 0 and the loops which
  93  * render to and from such data need to calculate their own offset
  94  * from the beginning of the scanline using the absolute x coordinate
  95  * combined with the pixelBitOffset field.
  96  * Bugfix 6220829 - this field used to be unsigned int, but some
  97  * primitives used negative pixel offsets and the corresponding
  98  * unsigned stride values caused the resulting pixel offset to
  99  * to always be a positive 32-bit quantity - causing problems on
 100  * 64-bit architectures.
 101  *
 102  *      jint scanStride;
 103  * [Requires SD_LOCK_READ or SD_LOCK_WRITE]
 104  * The scan stride is the distance in bytes from the data for one pixel
 105  * to the data for the pixel at the next y coordinate (x, y) => (x, y+1).
 106  * Bugfix 6220829 - this field used to be unsigned int, but some
 107  * primitives used negative pixel offsets and the corresponding
 108  * unsigned stride values caused the resulting pixel offset to
 109  * to always be a positive 32-bit quantity - causing problems on
 110  * 64-bit architectures.
 111  *
 112  *      unsigned int lutSize;
 113  * [Requires SD_LOCK_LUT]
 114  * The number of entries in the color lookup table.  The data beyond the
 115  * end of the map will be undefined.
 116  *
 117  *      jint *lutBase;
 118  * [Requires SD_LOCK_LUT]
 119  * A pointer to the beginning of the color lookup table for the colormap.
 120  * The color lookup table is formatted as an array of jint values each
 121  * representing the 32-bit ARGB color for the pixel representing by the
 122  * corresponding index.  The table is guaranteed to contain at least 256
 123  * valid memory locations even if the size of the map is smaller than 256.
 124  *
 125  *      unsigned char *invColorTable;
 126  * [Requires SD_LOCK_INVCOLOR]
 127  * A pointer to the beginning of the inverse color lookup table for the
 128  * colormap.  The inverse color lookup table is formatted as a 32x32x32
 129  * array of bytes indexed by RxGxB where each component is reduced to 5
 130  * bits of precision before indexing.
 131  *
 132  *      char *redErrTable;
 133  *      char *grnErrTable;
 134  *      char *bluErrTable;
 135  * [Requires SD_LOCK_INVCOLOR]
 136  * Pointers to the beginning of the ordered dither color error tables
 137  * for the colormap.  The error tables are formatted as an 8x8 array
 138  * of bytes indexed by coordinates using the formula [y & 7][x & 7].
 139  *
 140  *      int *invGrayTable;
 141  * [Requires SD_LOCK_INVGRAY]
 142  * A pointer to the beginning of the inverse gray lookup table for the
 143  * colormap.  The inverse color lookup table is formatted as an array
 144  * of 256 integers indexed by a byte gray level and storing an index
 145  * into the colormap of the closest matching gray pixel.
 146  *
 147  *      union priv {};
 148  * A buffer of private data for the SurfaceData implementation.
 149  * This field is a union of a data block of the desired default
 150  * size (SD_RASINFO_PRIVATE_SIZE) and a (void *) pointer that
 151  * ensures proper "strictest" alignment on all platforms.
 152  */
 153 typedef struct {
 154     SurfaceDataBounds   bounds;                 /* bounds of raster array */
 155     void                *rasBase;               /* Pointer to (0, 0) pixel */
 156     jint                pixelBitOffset;         /* bit offset to (0, *) pixel */
 157     jint                pixelStride;            /* bytes to next X pixel */
 158     jint                scanStride;             /* bytes to next Y pixel */
 159     unsigned int        lutSize;                /* # colors in colormap */
 160     jint                *lutBase;               /* Pointer to colormap[0] */
 161     unsigned char       *invColorTable;         /* Inverse color table */
 162     char                *redErrTable;           /* Red ordered dither table */
 163     char                *grnErrTable;           /* Green ordered dither table */
 164     char                *bluErrTable;           /* Blue ordered dither table */
 165     int                 *invGrayTable;          /* Inverse gray table */
 166     union {
 167         void            *align;                 /* ensures strict alignment */
 168         char            data[SD_RASINFO_PRIVATE_SIZE];
 169     } priv;
 170 } SurfaceDataRasInfo;
 171 
 172 typedef struct _SurfaceDataOps SurfaceDataOps;
 173 
 174 /*
 175  * This function is used to lock a particular region of a particular
 176  * destination.  Once this method is called, no changes of any of the
 177  * data returned by any of the other SurfaceData vectored functions
 178  * may change until a corresponding call to Release is made.
 179  *
 180  * The env parameter should be the JNIEnv of the surrounding JNI context.
 181  *
 182  * The ops parameter should be a pointer to the ops object upon which
 183  * this function is being invoked.
 184  *
 185  * The rasInfo parameter should be a pointer to a SurfaceDataRasInfo
 186  * structure in which the bounds have been initialized to the maximum
 187  * bounds of the raster data that will need to be accessed later.
 188  *
 189  * The lockflags parameter should indicate which information will be
 190  * needed by the caller.  The various flags which may be OR'd together
 191  * may consist of any of the following:
 192  *      SD_LOCK_READ            The caller needs to read pixels from the dest
 193  *      SD_LOCK_WRITE           The caller needs to write pixels to the dest
 194  *      SD_LOCK_RD_WR           A combination of (SD_LOCK_READ | SD_LOCK_WRITE)
 195  *      SD_LOCK_LUT             The caller needs the colormap (Lut)
 196  *      SD_LOCK_INVCOLOR        The caller needs the inverse color table
 197  *      SD_LOCK_INVGRAY         The caller needs the inverse gray table
 198  *      SD_LOCK_FASTEST         The caller only wants direct pixel access
 199  * Note that the SD_LOCK_LUT, SD_LOCK_INVCOLOR, and SD_LOCK_INVGRAY flags
 200  * are only valid for destinations with IndexColorModels.
 201  * Also note that SD_LOCK_FASTEST will only succeed if the access to the
 202  * pixels will occur just as fast regardless of the size of the bounds.
 203  * This flag is used by the Text rendering routines to determine if it
 204  * matters whether or not they have calculated a tight bounding box for
 205  * the pixels they will be touching.
 206  *
 207  * Return value:
 208  *
 209  * If this function succeeds, it will return SD_SUCCESS (0).
 210  *
 211  * If this function is unable to honor the SD_LOCK_FASTEST flag,
 212  * it will return SD_SLOWLOCK.  The bounds parameter of the
 213  * SurfaceDataRasInfo object should be intersected with a tighter
 214  * bounding rectangle before calling the GetRasInfo function so
 215  * as to minimize the amount pixel copying or conversion.  Note
 216  * that the Lock function may have already intersected the
 217  * bounds with a tighter rectangle as it tried to honor the
 218  * SD_SLOWLOCK flag and so the caller should only use intersection
 219  * operations to further restrict the bounds.
 220  *
 221  * If this function fails for any reason that is not recoverable,
 222  * it will throw an appropriate Java exception and return SD_FAILED.
 223  *
 224  * Operation:
 225  *
 226  * This function will intersect the bounds specified in the rasInfo
 227  * parameter with the available raster data in the destination drawable
 228  * and modify the contents of the bounds field to represent the maximum
 229  * available raster data.
 230  *
 231  * If the available raster data in the destination drawable consists of
 232  * a non-rectangular region of pixels, this method may throw an InvalidPipe
 233  * exception (optionally the object may decide to provide a copy of the
 234  * destination pixel data with undefined data in the inaccessible portions).
 235  *
 236  * Further processing by the caller may discover that a smaller region of
 237  * data is actually needed and the call to GetRasData can be made with a
 238  * still smaller bounds.
 239  *
 240  * Note to callers:
 241  *      This function may use JNI methods so it is important that the
 242  *      caller not have any outstanding GetPrimitiveArrayCritical or
 243  *      GetStringCritical locks which have not been released.
 244  *
 245  * Note to implementers:
 246  *      The caller may also continue to use JNI methods after this method
 247  *      is called so it is important that implementations of SurfaceData
 248  *      not return from this function with any outstanding JNI Critical
 249  *      locks that have not been released.
 250  */
 251 typedef jint LockFunc(JNIEnv *env,
 252                       SurfaceDataOps *ops,
 253                       SurfaceDataRasInfo *rasInfo,
 254                       jint lockflags);
 255 
 256 /*
 257  * This function returns information about the raster data for the drawable.
 258  * The function will fill in or modify the contents of the SurfaceDataRasInfo
 259  * structure that is passed in with various pieces of information depending
 260  * on what was requested in the lockflags parameter that was handed into
 261  * the LockFunc.  For more information on which pieces of information are
 262  * returned based upon the lock flags see the documentation for the
 263  * RasInfo structure above.
 264  *
 265  * The env parameter should be the JNIEnv of the surrounding JNI context.
 266  *
 267  * The ops parameter should be a pointer to the ops object upon which
 268  * this function is being invoked.
 269  *
 270  * The pRasInfo parameter should be a pointer to the same structure of type
 271  * SurfaceDataRasInfo.  The bounds member of that structure should be
 272  * initialized to the bounding box of the raster data that is actually
 273  * needed for reading or writing before calling this function.  These
 274  * bounds must be a subset of the raster bounds that were given to the
 275  * LockFunc or the results will be undefined.
 276  *
 277  * If the surface was locked with the flag SD_LOCK_FASTEST then this
 278  * function may reevaluate the bounds in the RasInfo structure and
 279  * return a subset of what was requested.  Callers that use that flag
 280  * should be prepared to reevaluate their clipping after GetRasInfo
 281  * returns.  If the SD_LOCK_FASTEST flag was not specified, then this
 282  * function will return a buffer containing all of the pixels in the
 283  * requested bounds without reevaluating them.
 284  *
 285  * Any information that was requested in the lockflags of the LockFunc
 286  * will be returned and NULL pointers will be returned for all other
 287  * information.
 288  *
 289  * Note to callers:
 290  *      This function may use JNI Critical methods so it is important
 291  *      that the caller not call any other JNI methods after this function
 292  *      returns until the Release function is called.
 293  */
 294 typedef void GetRasInfoFunc(JNIEnv *env,
 295                             SurfaceDataOps *ops,
 296                             SurfaceDataRasInfo *pRasInfo);
 297 
 298 /*
 299  * This function releases all of the Critical data for the specified
 300  * drawable.
 301  *
 302  * This function vector is allowed to be NULL if a given SurfaceData
 303  * implementation does not require the use of JNI Critical array locks.
 304  * Callers should use the "SurfaceData_InvokeRelease(env, ops)" macro
 305  * to handle the conditional invocation of this function.
 306  *
 307  * In particular, this function will release any outstanding JNI Critical
 308  * locks that the SurfaceData implementation may have used so that it
 309  * will be safe for the caller to start using arbitrary JNI calls or
 310  * return from its calling JNI function.
 311  *
 312  * The env parameter should be the JNIEnv of the surrounding JNI context.
 313  *
 314  * The ops parameter should be a pointer to the ops object upon which
 315  * this function is being invoked.
 316  *
 317  * The pRasInfo parameter should be a pointer to the same structure of
 318  * type SurfaceDataRasInfo that was passed to the GetRasInfo function.
 319  * The bounds should be unchanged since that call.
 320  *
 321  * Note to callers:
 322  *      This function will release any outstanding JNI Critical locks so
 323  *      it will once again be safe to use arbitrary JNI calls or return
 324  *      to the enclosing JNI native context.
 325  *
 326  * Note to implementers:
 327  *      This function may not use any JNI methods other than to release
 328  *      outstanding JNI Critical array locks since there may be other
 329  *      nested SurfacData objects holding locks with their own outstanding
 330  *      JNI Critical locks.  This restriction includes the use of the
 331  *      JNI monitor calls so that all MonitorExit invocations must be
 332  *      done in the Unlock function.
 333  */
 334 typedef void ReleaseFunc(JNIEnv *env,
 335                          SurfaceDataOps *ops,
 336                          SurfaceDataRasInfo *pRasInfo);
 337 
 338 /*
 339  * This function unlocks the specified drawable.
 340  *
 341  * This function vector is allowed to be NULL if a given SurfaceData
 342  * implementation does not require any unlocking of the destination.
 343  * Callers should use the "SurfaceData_InvokeUnlock(env, ops)" macro
 344  * to handle the conditional invocation of this function.
 345  *
 346  * The env parameter should be the JNIEnv of the surrounding JNI context.
 347  *
 348  * The ops parameter should be a pointer to the ops object upon which
 349  * this function is being invoked.
 350  *
 351  * The pRasInfo parameter should be a pointer to the same structure of
 352  * type SurfaceDataRasInfo that was passed to the GetRasInfo function.
 353  * The bounds should be unchanged since that call.
 354  *
 355  * Note to callers:
 356  *      This function may use JNI methods so it is important that the
 357  *      caller not have any outstanding GetPrimitiveArrayCritical or
 358  *      GetStringCritical locks which have not been released.
 359  *
 360  * Note to implementers:
 361  *      This function may be used to release any JNI monitors used to
 362  *      prevent the destination from being modified.  It may also be
 363  *      used to perform operations which may require blocking (such as
 364  *      executing X11 operations which may need to flush data).
 365  */
 366 typedef void UnlockFunc(JNIEnv *env,
 367                         SurfaceDataOps *ops,
 368                         SurfaceDataRasInfo *pRasInfo);
 369 
 370 /*
 371  * This function sets up the specified drawable.  Some surfaces may
 372  * need to perform certain operations during Setup that cannot be
 373  * done after later operations such as Lock.  For example, on
 374  * win9x systems, when any surface is locked we cannot make a call to
 375  * the message-handling thread.
 376  *
 377  * This function vector is allowed to be NULL if a given SurfaceData
 378  * implementation does not require any setup.
 379  *
 380  * The env parameter should be the JNIEnv of the surrounding JNI context.
 381  *
 382  * The ops parameter should be a pointer to the ops object upon which
 383  * this function is being invoked.
 384  *
 385  * Note to callers:
 386  *      This function may use JNI methods so it is important that the
 387  *      caller not have any outstanding GetPrimitiveArrayCritical or
 388  *      GetStringCritical locks which have not been released.
 389  */
 390 typedef void SetupFunc(JNIEnv *env,
 391                        SurfaceDataOps *ops);
 392 
 393 /*
 394  * This function disposes the specified SurfaceDataOps structure
 395  * and associated native resources.
 396  * The implementation is SurfaceData-type specific.
 397  */
 398 typedef void DisposeFunc(JNIEnv *env,
 399                          SurfaceDataOps *ops);
 400 
 401 /*
 402  * Constants used for return values.  Constants less than 0 are
 403  * unrecoverable failures and indicate that a Java exception has
 404  * already been thrown.  Constants greater than 0 are conditional
 405  * successes which warn the caller that various optional features
 406  * were not available so that workarounds can be used.
 407  */
 408 #define SD_FAILURE              -1
 409 #define SD_SUCCESS              0
 410 #define SD_SLOWLOCK             1
 411 
 412 /*
 413  * Constants for the flags used in the Lock function.
 414  */
 415 #define SD_LOCK_READ            (1 << 0)
 416 #define SD_LOCK_WRITE           (1 << 1)
 417 #define SD_LOCK_RD_WR           (SD_LOCK_READ | SD_LOCK_WRITE)
 418 #define SD_LOCK_LUT             (1 << 2)
 419 #define SD_LOCK_INVCOLOR        (1 << 3)
 420 #define SD_LOCK_INVGRAY         (1 << 4)
 421 #define SD_LOCK_FASTEST         (1 << 5)
 422 #define SD_LOCK_PARTIAL         (1 << 6)
 423 #define SD_LOCK_PARTIAL_WRITE   (SD_LOCK_WRITE | SD_LOCK_PARTIAL)
 424 #define SD_LOCK_NEED_PIXELS     (SD_LOCK_READ | SD_LOCK_PARTIAL)
 425 
 426 /*
 427  * This structure provides the function vectors for manipulating
 428  * and retrieving information about the destination drawable.
 429  * There are also variables for the surface data object used by
 430  * native code to track the state of the surface.
 431  * The sdObject is a pointer to the Java SurfaceData object;
 432  * this is set in SurfaceData_InitOps() and used by any object
 433  * using the ops structure to refer to elements in the Java object
 434  * (such as fields that we need to set from native code).
 435  */
 436 struct _SurfaceDataOps {
 437     LockFunc            *Lock;
 438     GetRasInfoFunc      *GetRasInfo;
 439     ReleaseFunc         *Release;
 440     UnlockFunc          *Unlock;
 441     SetupFunc           *Setup;
 442     DisposeFunc         *Dispose;
 443     jobject             sdObject;
 444 };
 445 
 446 #define _ClrReduce(c)   (((unsigned char) c) >> 3)
 447 
 448 /*
 449  * This macro performs a lookup in an inverse color table given 3 8-bit
 450  * RGB primaries.  It automates the process of reducing the primaries
 451  * to 5-bits of precision and using them to index into the specified
 452  * inverse color lookup table.
 453  */
 454 #define SurfaceData_InvColorMap(invcolortbl, r, g, b) \
 455     (invcolortbl)[(_ClrReduce(r)<<10) + (_ClrReduce(g)<<5) + _ClrReduce(b)]
 456 
 457 /*
 458  * This macro invokes the SurfaceData Release function only if the
 459  * function vector is not NULL.
 460  */
 461 #define SurfaceData_InvokeRelease(env, ops, pRI)        \
 462     do {                                                \
 463         if ((ops)->Release != NULL) {                   \
 464             (ops)->Release(env, ops, pRI);              \
 465         }                                               \
 466     } while(0)
 467 
 468 /*
 469  * This macro invokes the SurfaceData Unlock function only if the
 470  * function vector is not NULL.
 471  */
 472 #define SurfaceData_InvokeUnlock(env, ops, pRI)         \
 473     do {                                                \
 474         if ((ops)->Unlock != NULL) {                    \
 475             (ops)->Unlock(env, ops, pRI);               \
 476         }                                               \
 477     } while(0)
 478 
 479 /*
 480  * This macro invokes both the SurfaceData Release and Unlock functions
 481  * only if the function vectors are not NULL.  It can be used in cases
 482  * where only one surface has been accessed and where no other JNI
 483  * Critical locks (which would need to be released after Release and
 484  * before Unlock) are held by the calling function.
 485  */
 486 #define SurfaceData_InvokeReleaseUnlock(env, ops, pRI)  \
 487     do {                                                \
 488         if ((ops)->Release != NULL) {                   \
 489             (ops)->Release(env, ops, pRI);              \
 490         }                                               \
 491         if ((ops)->Unlock != NULL) {                    \
 492             (ops)->Unlock(env, ops, pRI);               \
 493         }                                               \
 494     } while(0)
 495 
 496 /*
 497  * This macro invokes both the SurfaceData Release and Unlock functions
 498  * on two nested drawables only if the function vectors are not NULL.
 499  * It can be used in cases where two surfaces have been accessed and
 500  * where no other JNI Critical locks (which would need to be released
 501  * after Release and before Unlock) are held by the calling function.  The
 502  * two ops vectors should be specified in the same order that they were
 503  * locked.  Both surfaces will be released and then both unlocked.
 504  */
 505 #define SurfaceData_InvokeReleaseUnlock2(env, ops1, pRI1, ops2, pRI2)   \
 506     do {                                                        \
 507         if ((ops2)->Release != NULL) {                          \
 508             (ops2)->Release(env, ops2, pRI2);                   \
 509         }                                                       \
 510         if ((ops1)->Release != NULL) {                          \
 511             (ops1)->Release(env, ops1, pRI1);                   \
 512         }                                                       \
 513         if ((ops2)->Unlock != NULL) {                           \
 514             (ops2)->Unlock(env, ops2, pRI2);                    \
 515         }                                                       \
 516         if ((ops1)->Unlock != NULL) {                           \
 517             (ops1)->Unlock(env, ops1, pRI1);                    \
 518         }                                                       \
 519     } while(0)
 520 
 521 #define SurfaceData_InvokeDispose(env, ops)                     \
 522     do {                                                        \
 523         if ((ops)->Dispose != NULL) {                           \
 524             (ops)->Dispose(env, ops);                           \
 525         }                                                       \
 526     } while(0)
 527 
 528 #define SurfaceData_InvokeSetup(env, ops)                       \
 529     do {                                                        \
 530         if ((ops)->Setup != NULL) {                             \
 531             (ops)->Setup(env, ops);                             \
 532         }                                                       \
 533     } while(0)
 534 
 535 /*
 536  * This function returns a pointer to a native SurfaceDataOps
 537  * structure for accessing the indicated SurfaceData Java object.
 538  *
 539  * Note to callers:
 540  *      This function uses JNI methods so it is important that the
 541  *      caller not have any outstanding GetPrimitiveArrayCritical or
 542  *      GetStringCritical locks which have not been released.
 543  *
 544  *      The caller may continue to use JNI methods after this method
 545  *      is called since this function will not leave any outstanding
 546  *      JNI Critical locks unreleased.
 547  */
 548 JNIEXPORT SurfaceDataOps * JNICALL
 549 SurfaceData_GetOps(JNIEnv *env, jobject sData);
 550 
 551 /*
 552  * Does the same as the above, but doesn't call Setup function
 553  * even if it's set.
 554  */
 555 JNIEXPORT SurfaceDataOps * JNICALL
 556 SurfaceData_GetOpsNoSetup(JNIEnv *env, jobject sData);
 557 
 558 /*
 559  * This function stores a pointer to a native SurfaceDataOps
 560  * structure into the indicated Java SurfaceData object.
 561  *
 562  * Note to callers:
 563  *      This function uses JNI methods so it is important that the
 564  *      caller not have any outstanding GetPrimitiveArrayCritical or
 565  *      GetStringCritical locks which have not been released.
 566  *
 567  *      The caller may continue to use JNI methods after this method
 568  *      is called since this function will not leave any outstanding
 569  *      JNI Critical locks unreleased.
 570  */
 571 JNIEXPORT void JNICALL
 572 SurfaceData_SetOps(JNIEnv *env, jobject sData, SurfaceDataOps *ops);
 573 
 574 /*
 575  * This function throws an InvalidPipeException which will cause the
 576  * calling SunGraphics2D object to revalidate its pipelines and call
 577  * again.  This utility method should be called from the SurfaceData
 578  * native Lock routine when some attribute of the surface has changed
 579  * that requires pipeline revalidation, including:
 580  *
 581  *      The bit depth or pixel format of the surface.
 582  *      The surface (window) has been disposed.
 583  *      The device clip of the surface has been changed (resize, visibility, etc.)
 584  *
 585  * Note to callers:
 586  *      This function uses JNI methods so it is important that the
 587  *      caller not have any outstanding GetPrimitiveArrayCritical or
 588  *      GetStringCritical locks which have not been released.
 589  *
 590  *      The caller may continue to use JNI methods after this method
 591  *      is called since this function will not leave any outstanding
 592  *      JNI Critical locks unreleased.
 593  */
 594 JNIEXPORT void JNICALL
 595 SurfaceData_ThrowInvalidPipeException(JNIEnv *env, const char *msg);
 596 
 597 /*
 598  * This function intersects two bounds objects which exist in the same
 599  * coordinate space.  The contents of the first parameter (dst) are
 600  * modified to contain the intersection of the two bounds while the
 601  * contents of the second parameter (src) are untouched.
 602  */
 603 JNIEXPORT void JNICALL
 604 SurfaceData_IntersectBounds(SurfaceDataBounds *dst, SurfaceDataBounds *src);
 605 
 606 /*
 607  * This function intersects a bounds object with a rectangle specified
 608  * in lox, loy, hix, hiy format in the same coordinate space.  The
 609  * contents of the first parameter (bounds) are modified to contain
 610  * the intersection of the two rectangular regions.
 611  */
 612 JNIEXPORT void JNICALL
 613 SurfaceData_IntersectBoundsXYXY(SurfaceDataBounds *bounds,
 614                                 jint lox, jint loy, jint hix, jint hiy);
 615 
 616 /*
 617  * This function intersects a bounds object with a rectangle specified
 618  * in XYWH format in the same coordinate space.  The contents of the
 619  * first parameter (bounds) are modified to contain the intersection
 620  * of the two rectangular regions.
 621  */
 622 JNIEXPORT void JNICALL
 623 SurfaceData_IntersectBoundsXYWH(SurfaceDataBounds *bounds,
 624                                 jint x, jint y, jint w, jint h);
 625 
 626 /*
 627  * This function intersects two bounds objects which exist in different
 628  * coordinate spaces.  The coordinate spaces of the two objects are
 629  * related such that a given coordinate in the space of the A bounds
 630  * is related to the analogous coordinate in the space of the B bounds
 631  * by the formula: (AX + BXminusAX, AY + BYminusAY) == (BX, BY).
 632  * The contents of both bounds objects are modified to represent their
 633  * mutual intersection.
 634  */
 635 JNIEXPORT void JNICALL
 636 SurfaceData_IntersectBlitBounds(SurfaceDataBounds *Abounds,
 637                                 SurfaceDataBounds *Bbounds,
 638                                 jint BXminusAX, jint BYminusAY);
 639 
 640 
 641 /*
 642  * This function creates and initializes the ops structure.  The function
 643  * is called by "subclasses" of SurfaceData (e.g., BufImgSurfaceData)
 644  * which pass in the size of the structure to allocate (subclasses generally
 645  * need additional fields in the ops structure particular to their usage
 646  * of the structure).  The structure is allocated and initialized
 647  * and is stored in the SurfaceData java object for later retrieval.
 648  * Subclasses of SurfaceData should call this function instead of allocating
 649  * the memory directly.
 650  */
 651 SurfaceDataOps *SurfaceData_InitOps(JNIEnv *env, jobject sData, int opsSize);
 652 
 653 /*
 654  * This function invokes the ops-specific disposal function.
 655  * It is a part of the finalizers-free disposal mechanism.
 656  * (see Disposer and DefaultDisposerRecord classes for more information)
 657  * It also destroys the ops structure created in SurfaceData_InitOps.
 658  */
 659 void SurfaceData_DisposeOps(JNIEnv *env, jlong ops);
 660 
 661 #ifdef __cplusplus
 662 };
 663 #endif
 664 
 665 #endif