1 /****************************************************************************
3 * Copyright (C) 2005 - 2010 by Vivante Corp.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the license, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *****************************************************************************/
24 #ifndef __gc_hal_base_h_
25 #define __gc_hal_base_h_
27 #include "gc_hal_enum.h"
28 #include "gc_hal_types.h"
29 #include "gc_hal_dump.h"
35 /******************************************************************************\
36 ****************************** Object Declarations *****************************
37 \******************************************************************************/
39 typedef struct _gcoHAL * gcoHAL;
40 typedef struct _gcoOS * gcoOS;
41 typedef struct _gco2D * gco2D;
42 typedef struct _gcoVG * gcoVG;
43 typedef struct _gco3D * gco3D;
44 typedef struct _gcoSURF * gcoSURF;
45 typedef struct _gcsSURF_INFO * gcsSURF_INFO_PTR;
46 typedef struct _gcsSURF_NODE * gcsSURF_NODE_PTR;
47 typedef struct _gcsSURF_FORMAT_INFO * gcsSURF_FORMAT_INFO_PTR;
48 typedef struct _gcsPOINT * gcsPOINT_PTR;
49 typedef struct _gcsSIZE * gcsSIZE_PTR;
50 typedef struct _gcsRECT * gcsRECT_PTR;
51 typedef struct _gcsBOUNDARY * gcsBOUNDARY_PTR;
52 typedef struct _gcoDUMP * gcoDUMP;
53 typedef struct _gcoHARDWARE * gcoHARDWARE;
55 /******************************************************************************\
56 ********************************* Enumerations *********************************
57 \******************************************************************************/
59 /* Video memory pool type. */
65 gcvPOOL_LOCAL_INTERNAL,
66 gcvPOOL_LOCAL_EXTERNAL,
75 /* Blending functions. */
76 typedef enum _gceBLEND_FUNCTION
80 gcvBLEND_SOURCE_COLOR,
81 gcvBLEND_INV_SOURCE_COLOR,
82 gcvBLEND_SOURCE_ALPHA,
83 gcvBLEND_INV_SOURCE_ALPHA,
84 gcvBLEND_TARGET_COLOR,
85 gcvBLEND_INV_TARGET_COLOR,
86 gcvBLEND_TARGET_ALPHA,
87 gcvBLEND_INV_TARGET_ALPHA,
88 gcvBLEND_SOURCE_ALPHA_SATURATE,
90 gcvBLEND_INV_CONST_COLOR,
92 gcvBLEND_INV_CONST_ALPHA,
97 typedef enum _gceBLEND_MODE
101 gcvBLEND_REVERSE_SUBTRACT,
116 typedef enum _gceDEPTH_MODE
124 typedef enum _gceWHERE
134 gcvHOW_SEMAPHORE = 0x1,
136 gcvHOW_SEMAPHORE_STALL = 0x3,
140 /******************************************************************************\
141 ********************************* gcoHAL Object *********************************
142 \******************************************************************************/
144 /* Construct a new gcoHAL object. */
147 IN gctPOINTER Context,
152 /* Destroy an gcoHAL object. */
158 /* Get pointer to gco2D object. */
165 /* Get pointer to gcoVG object. */
172 /* Get pointer to gco3D object. */
179 /* Verify whether the specified feature is available in hardware. */
181 gcoHAL_IsFeatureAvailable(
183 IN gceFEATURE Feature
186 /* Query the identity of the hardware. */
188 gcoHAL_QueryChipIdentity(
190 OUT gceCHIPMODEL* ChipModel,
191 OUT gctUINT32* ChipRevision,
192 OUT gctUINT32* ChipFeatures,
193 OUT gctUINT32* ChipMinorFeatures
196 /* Query the amount of video memory. */
198 gcoHAL_QueryVideoMemory(
200 OUT gctPHYS_ADDR * InternalAddress,
201 OUT gctSIZE_T * InternalSize,
202 OUT gctPHYS_ADDR * ExternalAddress,
203 OUT gctSIZE_T * ExternalSize,
204 OUT gctPHYS_ADDR * ContiguousAddress,
205 OUT gctSIZE_T * ContiguousSize
208 /* Map video memory. */
212 IN gctPHYS_ADDR Physical,
213 IN gctSIZE_T NumberOfBytes,
214 OUT gctPOINTER * Logical
217 /* Unmap video memory. */
221 IN gctPHYS_ADDR Physical,
222 IN gctSIZE_T NumberOfBytes,
223 IN gctPOINTER Logical
226 /* Schedule an unmap of a buffer mapped through its physical address. */
228 gcoHAL_ScheduleUnmapMemory(
230 IN gctPHYS_ADDR Physical,
231 IN gctSIZE_T NumberOfBytes,
232 IN gctPOINTER Logical
235 /* Schedule an unmap of a user buffer using event mechanism. */
237 gcoHAL_ScheduleUnmapUserMemory(
241 IN gctUINT32 Address,
245 /* Commit the current command buffer. */
252 /* Query the tile capabilities. */
256 OUT gctINT32 * TileWidth2D,
257 OUT gctINT32 * TileHeight2D,
258 OUT gctINT32 * TileWidth3D,
259 OUT gctINT32 * TileHeight3D
275 IN gctCONST_STRING Title
278 /* Power Management */
280 gcoHAL_SetPowerManagementState(
282 IN gceCHIPPOWERSTATE State
286 gcoHAL_QueryPowerManagementState(
288 OUT gceCHIPPOWERSTATE *State
291 /* Set the filter type for filter blit. */
293 gcoHAL_SetFilterType(
295 IN gceFILTER_TYPE FilterType
304 /* Call the kernel HAL layer. */
308 IN OUT gcsHAL_INTERFACE_PTR Interface
311 /* Schedule an event. */
313 gcoHAL_ScheduleEvent(
315 IN OUT gcsHAL_INTERFACE_PTR Interface
318 /* Destroy a surface. */
320 gcoHAL_DestroySurface(
325 /******************************************************************************\
326 ********************************** gcoOS Object *********************************
327 \******************************************************************************/
329 /* Construct a new gcoOS object. */
332 IN gctPOINTER Context,
336 /* Destroy an gcoOS object. */
342 /* Get the base address for the physical memory. */
344 gcoOS_GetBaseAddress(
346 OUT gctUINT32_PTR BaseAddress
349 /* Allocate memory from the heap. */
354 OUT gctPOINTER * Memory
357 /* Free allocated memory. */
364 /* Allocate memory. */
366 gcoOS_AllocateMemory(
369 OUT gctPOINTER * Memory
379 /* Allocate contiguous memory. */
381 gcoOS_AllocateContiguous(
383 IN gctBOOL InUserSpace,
384 IN OUT gctSIZE_T * Bytes,
385 OUT gctPHYS_ADDR * Physical,
386 OUT gctPOINTER * Logical
389 /* Free contiguous memory. */
391 gcoOS_FreeContiguous(
393 IN gctPHYS_ADDR Physical,
394 IN gctPOINTER Logical,
398 /* Map user memory. */
402 IN gctPOINTER Memory,
404 OUT gctPOINTER * Info,
405 OUT gctUINT32_PTR Address
408 /* Unmap user memory. */
410 gcoOS_UnmapUserMemory(
412 IN gctPOINTER Memory,
418 /* Device I/O Control call to the kernel HAL layer. */
422 IN gctUINT32 IoControlCode,
423 IN gctPOINTER InputBuffer,
424 IN gctSIZE_T InputBufferSize,
425 IN gctPOINTER OutputBuffer,
426 IN gctSIZE_T OutputBufferSize
429 /* Allocate non paged memory. */
430 gceSTATUS gcoOS_AllocateNonPagedMemory(
432 IN gctBOOL InUserSpace,
433 IN OUT gctSIZE_T * Bytes,
434 OUT gctPHYS_ADDR * Physical,
435 OUT gctPOINTER * Logical
438 /* Free non paged memory. */
439 gceSTATUS gcoOS_FreeNonPagedMemory(
442 IN gctPHYS_ADDR Physical,
443 IN gctPOINTER Logical
446 typedef enum _gceFILE_MODE
461 IN gctCONST_STRING FileName,
462 IN gceFILE_MODE Mode,
473 /* Read data from a file. */
478 IN gctSIZE_T ByteCount,
480 OUT gctSIZE_T * ByteRead
483 /* Write data to a file. */
488 IN gctSIZE_T ByteCount,
489 IN gctCONST_POINTER Data
492 typedef enum _gceFILE_WHENCE
500 /* Set the current position of a file. */
506 IN gceFILE_WHENCE Whence
509 /* Set the current position of a file. */
514 IN gctUINT32 Position
517 /* Get the current position of a file. */
522 OUT gctUINT32 * Position
525 /* Perform a memory copy. */
528 IN gctPOINTER Destination,
529 IN gctCONST_POINTER Source,
533 /* Perform a memory fill. */
536 IN gctPOINTER Destination,
544 IN gctPOINTER Memory,
548 /* Find the last occurance of a character inside a string. */
550 gcoOS_StrFindReverse(
551 IN gctCONST_STRING String,
552 IN gctINT8 Character,
553 OUT gctSTRING * Output
558 IN gctCONST_STRING String,
559 OUT gctSIZE_T * Length
565 IN gctCONST_STRING String,
566 OUT gctSTRING * Target
572 IN gctSTRING Destination,
573 IN gctSIZE_T DestinationSize,
574 IN gctCONST_STRING Source
577 /* Append a string. */
580 IN gctSTRING Destination,
581 IN gctSIZE_T DestinationSize,
582 IN gctCONST_STRING Source
585 /* Compare two strings. */
588 IN gctCONST_STRING String1,
589 IN gctCONST_STRING String2
592 /* Compare characters of two strings. */
595 IN gctCONST_STRING String1,
596 IN gctCONST_STRING String2,
600 /* Convert string to float. */
603 IN gctCONST_STRING String,
607 /* Convert string to integer. */
610 IN gctCONST_STRING String,
616 IN gctCONST_POINTER Memory1,
617 IN gctCONST_POINTER Memory2,
623 OUT gctSTRING String,
624 IN gctSIZE_T StringSize,
625 IN OUT gctUINT * Offset,
626 IN gctCONST_STRING Format,
632 OUT gctSTRING String,
633 IN gctSIZE_T StringSize,
634 IN OUT gctUINT * Offset,
635 IN gctCONST_STRING Format,
636 IN gctPOINTER Arguments
642 IN gctCONST_STRING Library,
643 OUT gctHANDLE * Handle
653 gcoOS_GetProcAddress(
656 IN gctCONST_STRING Name,
657 OUT gctPOINTER * Function
673 IN gctCONST_STRING Title
677 gcoOS_SetProfileSetting(
680 IN gctCONST_STRING FileName
683 /* Query the video memory. */
685 gcoOS_QueryVideoMemory(
687 OUT gctPHYS_ADDR * InternalAddress,
688 OUT gctSIZE_T * InternalSize,
689 OUT gctPHYS_ADDR * ExternalAddress,
690 OUT gctSIZE_T * ExternalSize,
691 OUT gctPHYS_ADDR * ContiguousAddress,
692 OUT gctSIZE_T * ContiguousSize
695 /*----------------------------------------------------------------------------*/
696 /*----- Atoms ----------------------------------------------------------------*/
698 typedef struct gcsATOM * gcsATOM_PTR;
700 /* Construct an atom. */
704 OUT gcsATOM_PTR * Atom
707 /* Destroy an atom. */
714 /* Increment an atom. */
719 OUT gctINT32_PTR OldValue
722 /* Decrement an atom. */
727 OUT gctINT32_PTR OldValue
731 gcoOS_GetCurrentProcessID(
735 /*----------------------------------------------------------------------------*/
736 /*----- Time -----------------------------------------------------------------*/
738 /* Get the number of milliseconds since the system started. */
744 /* Get time in microseconds. */
750 /* Get CPU usage in microseconds. */
753 gctUINT64_PTR CPUTime
756 /* Get memory usage. */
758 gcoOS_GetMemoryUsage(
759 gctUINT32_PTR MaxRSS,
765 /* Delay a number of microseconds. */
772 /*----------------------------------------------------------------------------*/
773 /*----- Mutexes --------------------------------------------------------------*/
775 /* Create a new mutex. */
779 OUT gctPOINTER * Mutex
782 /* Delete a mutex. */
789 /* Acquire a mutex. */
797 /* Release a mutex. */
804 /*----------------------------------------------------------------------------*/
805 /*----- Signals --------------------------------------------------------------*/
807 /* Create a signal. */
811 IN gctBOOL ManualReset,
812 OUT gctSIGNAL * Signal
815 /* Destroy a signal. */
822 /* Signal a signal. */
830 /* Wait for a signal. */
838 /* Write a register. */
842 IN gctUINT32 Address,
846 /* Read a register. */
850 IN gctUINT32 Address,
857 IN gctPOINTER Logical,
862 gcoOS_CacheInvalidate(
864 IN gctPOINTER Logical,
868 /*******************************************************************************
872 #define gcdPI 3.14159265358979323846f
957 /******************************************************************************\
958 **************************** Coordinate Structures *****************************
959 \******************************************************************************/
961 typedef struct _gcsPOINT
968 typedef struct _gcsSIZE
975 typedef struct _gcsRECT
985 /******************************************************************************\
986 ********************************* gcoSURF Object ********************************
987 \******************************************************************************/
989 /*----------------------------------------------------------------------------*/
990 /*------------------------------- gcoSURF Common ------------------------------*/
992 /* Color format classes. */
993 typedef enum _gceFORMAT_CLASS
995 gcvFORMAT_CLASS_RGBA = 4500,
997 gcvFORMAT_CLASS_INDEX,
998 gcvFORMAT_CLASS_LUMINANCE,
999 gcvFORMAT_CLASS_BUMP,
1000 gcvFORMAT_CLASS_DEPTH,
1004 /* Special enums for width field in gcsFORMAT_COMPONENT. */
1005 typedef enum _gceCOMPONENT_CONTROL
1007 gcvCOMPONENT_NOTPRESENT = 0x00,
1008 gcvCOMPONENT_DONTCARE = 0x80,
1009 gcvCOMPONENT_WIDTHMASK = 0x7F,
1010 gcvCOMPONENT_ODD = 0x80
1012 gceCOMPONENT_CONTROL;
1014 /* Color format component parameters. */
1015 typedef struct _gcsFORMAT_COMPONENT
1020 gcsFORMAT_COMPONENT;
1022 /* RGBA color format class. */
1023 typedef struct _gcsFORMAT_CLASS_TYPE_RGBA
1025 gcsFORMAT_COMPONENT alpha;
1026 gcsFORMAT_COMPONENT red;
1027 gcsFORMAT_COMPONENT green;
1028 gcsFORMAT_COMPONENT blue;
1030 gcsFORMAT_CLASS_TYPE_RGBA;
1032 /* YUV color format class. */
1033 typedef struct _gcsFORMAT_CLASS_TYPE_YUV
1035 gcsFORMAT_COMPONENT y;
1036 gcsFORMAT_COMPONENT u;
1037 gcsFORMAT_COMPONENT v;
1039 gcsFORMAT_CLASS_TYPE_YUV;
1041 /* Index color format class. */
1042 typedef struct _gcsFORMAT_CLASS_TYPE_INDEX
1044 gcsFORMAT_COMPONENT value;
1046 gcsFORMAT_CLASS_TYPE_INDEX;
1048 /* Luminance color format class. */
1049 typedef struct _gcsFORMAT_CLASS_TYPE_LUMINANCE
1051 gcsFORMAT_COMPONENT alpha;
1052 gcsFORMAT_COMPONENT value;
1054 gcsFORMAT_CLASS_TYPE_LUMINANCE;
1056 /* Bump map color format class. */
1057 typedef struct _gcsFORMAT_CLASS_TYPE_BUMP
1059 gcsFORMAT_COMPONENT alpha;
1060 gcsFORMAT_COMPONENT l;
1061 gcsFORMAT_COMPONENT v;
1062 gcsFORMAT_COMPONENT u;
1063 gcsFORMAT_COMPONENT q;
1064 gcsFORMAT_COMPONENT w;
1066 gcsFORMAT_CLASS_TYPE_BUMP;
1068 /* Depth and stencil format class. */
1069 typedef struct _gcsFORMAT_CLASS_TYPE_DEPTH
1071 gcsFORMAT_COMPONENT depth;
1072 gcsFORMAT_COMPONENT stencil;
1074 gcsFORMAT_CLASS_TYPE_DEPTH;
1076 /* Format parameters. */
1077 typedef struct _gcsSURF_FORMAT_INFO
1079 /* Format code and class. */
1080 gceSURF_FORMAT format;
1081 gceFORMAT_CLASS fmtClass;
1083 /* The size of one pixel in bits. */
1084 gctUINT8 bitsPerPixel;
1086 /* Component swizzle. */
1087 gceSURF_SWIZZLE swizzle;
1089 /* Some formats have two neighbour pixels interleaved together. */
1090 /* To describe such format, set the flag to 1 and add another */
1091 /* like this one describing the odd pixel format. */
1092 gctUINT8 interleaved;
1094 /* Format components. */
1097 gcsFORMAT_CLASS_TYPE_BUMP bump;
1098 gcsFORMAT_CLASS_TYPE_RGBA rgba;
1099 gcsFORMAT_CLASS_TYPE_YUV yuv;
1100 gcsFORMAT_CLASS_TYPE_LUMINANCE lum;
1101 gcsFORMAT_CLASS_TYPE_INDEX index;
1102 gcsFORMAT_CLASS_TYPE_DEPTH depth;
1105 gcsSURF_FORMAT_INFO;
1107 /* Frame buffer information. */
1108 typedef struct _gcsSURF_FRAMEBUFFER
1111 gctUINT width, height;
1113 gceSURF_FORMAT format;
1115 gcsSURF_FRAMEBUFFER;
1117 /* Generic pixel component descriptors. */
1118 extern gcsFORMAT_COMPONENT gcvPIXEL_COMP_XXX8;
1119 extern gcsFORMAT_COMPONENT gcvPIXEL_COMP_XX8X;
1120 extern gcsFORMAT_COMPONENT gcvPIXEL_COMP_X8XX;
1121 extern gcsFORMAT_COMPONENT gcvPIXEL_COMP_8XXX;
1123 typedef enum _gceORIENTATION
1125 gcvORIENTATION_TOP_BOTTOM,
1126 gcvORIENTATION_BOTTOM_TOP,
1131 /* Construct a new gcoSURF object. */
1138 IN gceSURF_TYPE Type,
1139 IN gceSURF_FORMAT Format,
1141 OUT gcoSURF * Surface
1144 /* Destroy an gcoSURF object. */
1150 /* Map user-allocated surface. */
1152 gcoSURF_MapUserSurface(
1154 IN gctUINT Alignment,
1155 IN gctPOINTER Logical,
1156 IN gctUINT32 Physical
1159 /* Set the color type of the surface. */
1161 gcoSURF_SetColorType(
1163 IN gceSURF_COLOR_TYPE ColorType
1166 /* Get the color type of the surface. */
1168 gcoSURF_GetColorType(
1170 OUT gceSURF_COLOR_TYPE *ColorType
1173 /* Set the surface ration angle. */
1175 gcoSURF_SetRotation(
1177 IN gceSURF_ROTATION Rotation
1180 /* Verify and return the state of the tile status mechanism. */
1182 gcoSURF_IsTileStatusSupported(
1186 /* Enable tile status for the specified surface. */
1188 gcoSURF_EnableTileStatus(
1192 /* Disable tile status for the specified surface. */
1194 gcoSURF_DisableTileStatus(
1196 IN gctBOOL Decompress
1199 /* Get surface size. */
1203 OUT gctUINT * Width,
1204 OUT gctUINT * Height,
1208 /* Get surface aligned sizes. */
1210 gcoSURF_GetAlignedSize(
1212 OUT gctUINT * Width,
1213 OUT gctUINT * Height,
1217 /* Get surface type and format. */
1221 OUT gceSURF_TYPE * Type,
1222 OUT gceSURF_FORMAT * Format
1225 /* Lock the surface. */
1229 IN OUT gctUINT32 * Address,
1230 IN OUT gctPOINTER * Memory
1233 /* Unlock the surface. */
1237 IN gctPOINTER Memory
1240 /* Return pixel format parameters. */
1242 gcoSURF_QueryFormat(
1243 IN gceSURF_FORMAT Format,
1244 OUT gcsSURF_FORMAT_INFO_PTR * Info
1247 /* Compute the color pixel mask. */
1249 gcoSURF_ComputeColorMask(
1250 IN gcsSURF_FORMAT_INFO_PTR Format,
1251 OUT gctUINT32_PTR ColorMask
1254 /* Flush the surface. */
1260 /* Fill surface with a value. */
1264 IN gcsPOINT_PTR Origin,
1265 IN gcsSIZE_PTR Size,
1270 /* Alpha blend two surfaces together. */
1273 IN gcoSURF SrcSurface,
1274 IN gcoSURF DestSurface,
1275 IN gcsPOINT_PTR SrcOrig,
1276 IN gcsPOINT_PTR DestOrigin,
1277 IN gcsSIZE_PTR Size,
1278 IN gceSURF_BLEND_MODE Mode
1281 /* Create a new gcoSURF wrapper object. */
1283 gcoSURF_ConstructWrapper(
1285 OUT gcoSURF * Surface
1288 /* Set the underlying buffer for the surface wrapper. */
1292 IN gceSURF_TYPE Type,
1293 IN gceSURF_FORMAT Format,
1295 IN gctPOINTER Logical,
1296 IN gctUINT32 Physical
1299 /* Set the size of the surface in pixels and map the underlying buffer. */
1309 /* Increase reference count of the surface. */
1311 gcoSURF_ReferenceSurface(
1315 /* Get surface reference count. */
1317 gcoSURF_QueryReferenceCount(
1319 OUT gctINT32 * ReferenceCount
1322 /* Set surface orientation. */
1324 gcoSURF_SetOrientation(
1326 IN gceORIENTATION Orientation
1329 /* Query surface orientation. */
1331 gcoSURF_QueryOrientation(
1333 OUT gceORIENTATION * Orientation
1336 /******************************************************************************\
1337 ********************************* gcoDUMP Object ********************************
1338 \******************************************************************************/
1340 /* Construct a new gcoDUMP object. */
1348 /* Destroy a gcoDUMP object. */
1354 /* Enable/disable dumping. */
1358 IN gctSTRING FileName
1364 OUT gctBOOL * Enabled
1373 IN gceSURF_FORMAT PixelFormat,
1374 IN gctUINT32 Address,
1375 IN gctSIZE_T ByteCount
1378 /* Mark the beginning of a frame. */
1384 /* Mark the end of a frame. */
1394 IN gceDUMP_TAG Type,
1395 IN gctUINT32 Address,
1396 IN gctSIZE_T ByteCount,
1397 IN gctCONST_POINTER Data
1400 /* Delete an address. */
1404 IN gctUINT32 Address
1407 /******************************************************************************\
1408 ******************************* gcsRECT Structure ******************************
1409 \******************************************************************************/
1411 /* Initialize rectangle structure. */
1414 OUT gcsRECT_PTR Rect,
1421 /* Return the width of the rectangle. */
1424 IN gcsRECT_PTR Rect,
1425 OUT gctINT32 * Width
1428 /* Return the height of the rectangle. */
1431 IN gcsRECT_PTR Rect,
1432 OUT gctINT32 * Height
1435 /* Ensure that top left corner is to the left and above the right bottom. */
1438 IN OUT gcsRECT_PTR Rect
1441 /* Compare two rectangles. */
1444 IN gcsRECT_PTR Rect1,
1445 IN gcsRECT_PTR Rect2,
1449 /* Compare the sizes of two rectangles. */
1451 gcsRECT_IsOfEqualSize(
1452 IN gcsRECT_PTR Rect1,
1453 IN gcsRECT_PTR Rect2,
1454 OUT gctBOOL * EqualSize
1458 /******************************************************************************\
1459 **************************** gcsBOUNDARY Structure *****************************
1460 \******************************************************************************/
1462 typedef struct _gcsBOUNDARY
1471 /******************************************************************************\
1472 ********************************* gcoHEAP Object ********************************
1473 \******************************************************************************/
1475 typedef struct _gcoHEAP * gcoHEAP;
1477 /* Construct a new gcoHEAP object. */
1481 IN gctSIZE_T AllocationSize,
1485 /* Destroy an gcoHEAP object. */
1491 /* Allocate memory. */
1496 OUT gctPOINTER * Node
1506 /* Profile the heap. */
1508 gcoHEAP_ProfileStart(
1515 IN gctCONST_STRING Title
1518 #if defined gcdHAL_TEST
1522 IN gctSIZE_T Vectors,
1523 IN gctSIZE_T MaxSize
1527 /******************************************************************************\
1528 ******************************* Debugging Macros *******************************
1529 \******************************************************************************/
1532 gcoOS_SetDebugLevel(
1542 gcoOS_SetDebugLevelZone(
1548 gcoOS_SetDebugZones(
1555 IN gctCONST_STRING FileName
1558 /*******************************************************************************
1562 ** Print a message to the debugger and execute a break point.
1567 ** ... Optional arguments.
1572 IN gctCONST_STRING Message,
1578 IN gctCONST_STRING Message,
1583 # define gcmFATAL gcoOS_DebugFatal
1584 # define gcmkFATAL gckOS_DebugFatal
1585 #elif gcdHAS_ELLIPSES
1586 # define gcmFATAL(...)
1587 # define gcmkFATAL(...)
1589 gcmINLINE static void
1591 IN gctCONST_STRING Message,
1596 # define gcmFATAL __dummy_fatal
1597 # define gcmkFATAL __dummy_fatal
1600 #define gcmENUM2TEXT(e) case e: return #e
1602 /*******************************************************************************
1606 ** Print a message to the debugfer if the correct level has been set. In
1607 ** retail mode this macro does nothing.
1611 ** level Level of message.
1613 ** ... Optional arguments.
1615 #define gcvLEVEL_NONE -1
1616 #define gcvLEVEL_ERROR 0
1617 #define gcvLEVEL_WARNING 1
1618 #define gcvLEVEL_INFO 2
1619 #define gcvLEVEL_VERBOSE 3
1624 IN gctCONST_STRING Message,
1631 IN gctCONST_STRING Message,
1636 # define gcmTRACE gcoOS_DebugTrace
1637 # define gcmkTRACE gckOS_DebugTrace
1638 #elif gcdHAS_ELLIPSES
1639 # define gcmTRACE(...)
1640 # define gcmkTRACE(...)
1642 gcmINLINE static void
1645 IN gctCONST_STRING Message,
1650 # define gcmTRACE __dummy_trace
1651 # define gcmkTRACE __dummy_trace
1655 #define gcvZONE_OS (1 << 0)
1656 #define gcvZONE_HARDWARE (1 << 1)
1657 #define gcvZONE_HEAP (1 << 2)
1660 #define gcvZONE_KERNEL (1 << 3)
1661 #define gcvZONE_VIDMEM (1 << 4)
1662 #define gcvZONE_COMMAND (1 << 5)
1663 #define gcvZONE_DRIVER (1 << 6)
1664 #define gcvZONE_CMODEL (1 << 7)
1665 #define gcvZONE_MMU (1 << 8)
1666 #define gcvZONE_EVENT (1 << 9)
1667 #define gcvZONE_DEVICE (1 << 10)
1670 #define gcvZONE_HAL (1 << 3)
1671 #define gcvZONE_BUFFER (1 << 4)
1672 #define gcvZONE_CONTEXT (1 << 5)
1673 #define gcvZONE_SURFACE (1 << 6)
1674 #define gcvZONE_INDEX (1 << 7)
1675 #define gcvZONE_STREAM (1 << 8)
1676 #define gcvZONE_TEXTURE (1 << 9)
1677 #define gcvZONE_2D (1 << 10)
1678 #define gcvZONE_3D (1 << 11)
1679 #define gcvZONE_COMPILER (1 << 12)
1680 #define gcvZONE_MEMORY (1 << 13)
1681 #define gcvZONE_STATE (1 << 14)
1682 #define gcvZONE_AUX (1 << 15)
1684 /* API definitions. */
1685 #define gcvZONE_API_HAL (0 << 28)
1686 #define gcvZONE_API_EGL (1 << 28)
1687 #define gcvZONE_API_ES11 (2 << 28)
1688 #define gcvZONE_API_ES20 (3 << 28)
1689 #define gcvZONE_API_VG11 (4 << 28)
1690 #define gcvZONE_API_GL (5 << 28)
1691 #define gcvZONE_API_DFB (6 << 28)
1692 #define gcvZONE_API_GDI (7 << 28)
1693 #define gcvZONE_API_D3D (8 << 28)
1695 #define gcmZONE_GET_API(zone) ((zone) >> 28)
1696 #define gcdZONE_MASK 0x0FFFFFFF
1699 #define gcvZONE_NONE 0
1700 #define gcvZONE_ALL gcdZONE_MASK
1702 /*******************************************************************************
1706 ** Print a message to the debugger if the correct level and zone has been
1707 ** set. In retail mode this macro does nothing.
1711 ** Level Level of message.
1712 ** Zone Zone of message.
1714 ** ... Optional arguments.
1718 gckOS_DebugTraceZone(
1721 IN gctCONST_STRING Message,
1726 gcoOS_DebugTraceZone(
1729 IN gctCONST_STRING Message,
1734 # define gcmTRACE_ZONE gcoOS_DebugTraceZone
1735 # define gcmkTRACE_ZONE gckOS_DebugTraceZone
1736 #elif gcdHAS_ELLIPSES
1737 # define gcmTRACE_ZONE(...)
1738 # define gcmkTRACE_ZONE(...)
1740 gcmINLINE static void
1744 IN gctCONST_STRING Message,
1749 # define gcmTRACE_ZONE __dummy_trace_zone
1750 # define gcmkTRACE_ZONE __dummy_trace_zone
1753 /******************************************************************************\
1754 ******************************** Logging Macros ********************************
1755 \******************************************************************************/
1757 #define gcdHEADER_LEVEL gcvLEVEL_VERBOSE
1759 #define gcmHEADER() \
1760 gcmTRACE_ZONE(gcdHEADER_LEVEL, _GC_OBJ_ZONE, \
1761 "++%s(%d)", __FUNCTION__, __LINE__)
1764 # define gcmHEADER_ARG(Text, ...) \
1765 gcmTRACE_ZONE(gcdHEADER_LEVEL, _GC_OBJ_ZONE, \
1766 "++%s(%d): " Text, __FUNCTION__, __LINE__, __VA_ARGS__)
1768 gcmINLINE static void
1770 IN gctCONST_STRING Text,
1775 # define gcmHEADER_ARG __dummy_header_arg
1778 #define gcmFOOTER() \
1779 gcmTRACE_ZONE(gcdHEADER_LEVEL, _GC_OBJ_ZONE, \
1780 "--%s(%d): status=%d", \
1781 __FUNCTION__, __LINE__, status)
1783 #define gcmFOOTER_NO() \
1784 gcmTRACE_ZONE(gcdHEADER_LEVEL, _GC_OBJ_ZONE, \
1785 "--%s(%d)", __FUNCTION__, __LINE__)
1788 # define gcmFOOTER_ARG(Text, ...) \
1789 gcmTRACE_ZONE(gcdHEADER_LEVEL, _GC_OBJ_ZONE, \
1790 "--%s(%d): " Text, \
1791 __FUNCTION__, __LINE__, __VA_ARGS__)
1793 gcmINLINE static void
1795 IN gctCONST_STRING Text,
1800 # define gcmFOOTER_ARG __dummy_footer_arg
1803 #define gcmkHEADER() \
1804 gcmkTRACE_ZONE(gcdHEADER_LEVEL, _GC_OBJ_ZONE, \
1805 "++%s(%d)", __FUNCTION__, __LINE__)
1808 # define gcmkHEADER_ARG(Text, ...) \
1809 gcmkTRACE_ZONE(gcdHEADER_LEVEL, _GC_OBJ_ZONE, \
1810 "++%s(%d): " Text, __FUNCTION__, __LINE__, __VA_ARGS__)
1812 gcmINLINE static void
1813 __dummy_kheader_arg(
1814 IN gctCONST_STRING Text,
1819 # define gcmkHEADER_ARG __dummy_kheader_arg
1822 #define gcmkFOOTER() \
1823 gcmkTRACE_ZONE(gcdHEADER_LEVEL, _GC_OBJ_ZONE, \
1824 "--%s(%d): status=%d", \
1825 __FUNCTION__, __LINE__, status)
1827 #define gcmkFOOTER_NO() \
1828 gcmkTRACE_ZONE(gcdHEADER_LEVEL, _GC_OBJ_ZONE, \
1829 "--%s(%d)", __FUNCTION__, __LINE__)
1832 # define gcmkFOOTER_ARG(Text, ...) \
1833 gcmkTRACE_ZONE(gcdHEADER_LEVEL, _GC_OBJ_ZONE, \
1834 "--%s(%d): " Text, \
1835 __FUNCTION__, __LINE__, __VA_ARGS__)
1837 gcmINLINE static void
1838 __dummy_kfooter_arg(
1839 IN gctCONST_STRING Text,
1844 # define gcmkFOOTER_ARG __dummy_kfooter_arg
1847 #define gcmOPT_VALUE(ptr) (((ptr) == gcvNULL) ? 0 : *(ptr))
1848 #define gcmOPT_POINTER(ptr) (((ptr) == gcvNULL) ? gcvNULL : *(ptr))
1852 IN gctCONST_STRING Message,
1857 IN gctCONST_STRING Message,
1860 #define gcmPRINT gcoOS_Print
1861 #define gcmkPRINT gckOS_Print
1863 /*******************************************************************************
1867 ** Print a dump message.
1871 ** gctSTRING Message.
1873 ** ... Optional arguments.
1879 IN gctCONST_STRING String,
1882 # define gcmDUMP gcfDump
1883 #elif gcdHAS_ELLIPSES
1884 # define gcmDUMP(...)
1886 gcmINLINE static void
1889 IN gctCONST_STRING Message,
1894 # define gcmDUMP __dummy_dump
1897 /*******************************************************************************
1901 ** Add data to the dump.
1908 ** gctPOINTER Logical
1909 ** Logical address of buffer.
1920 IN gctPOINTER Logical,
1923 # define gcmDUMP_DATA gcfDumpData
1924 #elif gcdHAS_ELLIPSES
1925 # define gcmDUMP_DATA(...)
1927 gcmINLINE static void
1931 IN gctPOINTER Logical,
1936 # define gcmDUMP_DATA __dummy_dump_data
1939 /*******************************************************************************
1943 ** Print a buffer to the dump.
1950 ** gctUINT32 Physical
1951 ** Physical address of buffer.
1953 ** gctPOINTER Logical
1954 ** Logical address of buffer.
1957 ** Offset into buffer.
1968 IN gctUINT32 Physical,
1969 IN gctPOINTER Logical,
1970 IN gctUINT32 Offset,
1973 # define gcmDUMP_BUFFER gcfDumpBuffer
1974 #elif gcdHAS_ELLIPSES
1975 # define gcmDUMP_BUFFER(...)
1977 gcmINLINE static void
1978 __dummy_dump_buffer(
1981 IN gctUINT32 Physical,
1982 IN gctPOINTER Logical,
1983 IN gctUINT32 Offset,
1988 # define gcmDUMP_BUFFER __dummy_dump_buffer
1991 /*******************************************************************************
1995 ** Print a dump message for a high level API prefixed by the function name.
1999 ** gctSTRING Message.
2001 ** ... Optional arguments.
2006 IN gctCONST_STRING String,
2009 # define gcmDUMP_API gcfDumpApi
2010 #elif gcdHAS_ELLIPSES
2011 # define gcmDUMP_API(...)
2013 gcmINLINE static void
2015 IN gctCONST_STRING Message,
2020 # define gcmDUMP_API __dummy_dump_api
2023 /*******************************************************************************
2025 ** gcmDUMP_API_ARRAY
2027 ** Print an array of data.
2031 ** gctUINT32_PTR Pointer to array.
2037 IN gctCONST_POINTER Data,
2040 # define gcmDUMP_API_ARRAY gcfDumpArray
2041 #elif gcdHAS_ELLIPSES
2042 # define gcmDUMP_API_ARRAY(...)
2044 gcmINLINE static void
2045 __dummy_dump_api_array(
2046 IN gctCONST_POINTER Data,
2051 # define gcmDUMP_API_ARRAY __dummy_dump_api_array
2054 /*******************************************************************************
2056 ** gcmDUMP_API_ARRAY_TOKEN
2058 ** Print an array of data terminated by a token.
2062 ** gctUINT32_PTR Pointer to array.
2063 ** gctUINT32 Termination.
2068 IN gctCONST_POINTER Data,
2069 IN gctUINT32 Termination
2071 # define gcmDUMP_API_ARRAY_TOKEN gcfDumpArrayToken
2072 #elif gcdHAS_ELLIPSES
2073 # define gcmDUMP_API_ARRAY_TOKEN(...)
2075 gcmINLINE static void
2076 __dummy_dump_api_array_token(
2077 IN gctCONST_POINTER Data,
2078 IN gctUINT32 Termination
2082 # define gcmDUMP_API_ARRAY_TOKEN __dummy_dump_api_array_token
2085 /*******************************************************************************
2089 ** Print a message to the shader debugger.
2094 ** ... Optional arguments.
2097 #define gcmTRACE_RELEASE gcoOS_DebugShaderTrace
2100 gcoOS_DebugShaderTrace(
2101 IN gctCONST_STRING Message,
2106 gcoOS_SetDebugShaderFiles(
2107 IN gctCONST_STRING VSFileName,
2108 IN gctCONST_STRING FSFileName
2112 gcoOS_SetDebugShaderFileType(
2113 IN gctUINT32 ShaderType
2116 /*******************************************************************************
2120 ** Break into the debugger. In retail mode this macro does nothing.
2138 # define gcmBREAK gcoOS_DebugBreak
2139 # define gcmkBREAK gckOS_DebugBreak
2142 # define gcmkBREAK()
2145 /*******************************************************************************
2149 ** Evaluate an expression and break into the debugger if the expression
2150 ** evaluates to false. In retail mode this macro does nothing.
2154 ** exp Expression to evaluate.
2157 # define _gcmASSERT(prefix, exp) \
2162 prefix##TRACE(gcvLEVEL_ERROR, \
2163 #prefix "ASSERT at %s(%d) in " __FILE__, \
2164 __FUNCTION__, __LINE__); \
2165 prefix##TRACE(gcvLEVEL_ERROR, \
2171 # define gcmASSERT(exp) _gcmASSERT(gcm, exp)
2172 # define gcmkASSERT(exp) _gcmASSERT(gcmk, exp)
2174 # define gcmASSERT(exp)
2175 # define gcmkASSERT(exp)
2178 /*******************************************************************************
2182 ** Verify if an expression returns true. If the expression does not
2183 ** evaluates to true, an assertion will happen in debug mode.
2187 ** exp Expression to evaluate.
2190 # define gcmVERIFY(exp) gcmASSERT(exp)
2191 # define gcmkVERIFY(exp) gcmkASSERT(exp)
2193 # define gcmVERIFY(exp) exp
2194 # define gcmkVERIFY(exp) exp
2197 /*******************************************************************************
2201 ** Verify a fucntion returns gcvSTATUS_OK. If the function does not return
2202 ** gcvSTATUS_OK, an assertion will happen in debug mode.
2206 ** func Function to evaluate.
2220 # define gcmVERIFY_OK(func) \
2223 gceSTATUS verifyStatus = func; \
2224 gcoOS_Verify(verifyStatus); \
2225 gcmASSERT(verifyStatus == gcvSTATUS_OK); \
2228 # define gcmkVERIFY_OK(func) \
2231 gceSTATUS verifyStatus = func; \
2232 gckOS_Verify(verifyStatus); \
2233 gcmkASSERT(verifyStatus == gcvSTATUS_OK); \
2237 # define gcmVERIFY_OK(func) func
2238 # define gcmkVERIFY_OK(func) func
2241 /*******************************************************************************
2245 ** Executes a break statement on error.
2249 ** 'status' variable of gceSTATUS type must be defined.
2253 ** func Function to evaluate.
2255 #define _gcmERR_BREAK(prefix, func) \
2257 if (gcmIS_ERROR(status)) \
2259 prefix##TRACE(gcvLEVEL_ERROR, \
2260 #prefix "ERR_BREAK: status=%d @ %s(%d) in " __FILE__, \
2261 status, __FUNCTION__, __LINE__); \
2264 do { } while (gcvFALSE)
2265 #define gcmERR_BREAK(func) _gcmERR_BREAK(gcm, func)
2266 #define gcmkERR_BREAK(func) _gcmERR_BREAK(gcmk, func)
2268 /*******************************************************************************
2272 ** Executes a return on error.
2276 ** 'status' variable of gceSTATUS type must be defined.
2280 ** func Function to evaluate.
2282 #define _gcmERR_RETURN(prefix, func) \
2284 if (gcmIS_ERROR(status)) \
2286 prefix##TRACE(gcvLEVEL_ERROR, \
2287 #prefix "ERR_RETURN: status=%d @ %s(%d) in " __FILE__, \
2288 status, __FUNCTION__, __LINE__); \
2291 do { } while (gcvFALSE)
2292 #define gcmERR_RETURN(func) _gcmERR_RETURN(gcm, func)
2293 #define gcmkERR_RETURN(func) _gcmERR_RETURN(gcmk, func)
2295 /*******************************************************************************
2299 ** Jump to the error handler in case there is an error.
2303 ** 'status' variable of gceSTATUS type must be defined.
2307 ** func Function to evaluate.
2309 #define _gcmONERROR(prefix, func) \
2313 if (gcmIS_ERROR(status)) \
2315 prefix##TRACE(gcvLEVEL_ERROR, \
2316 #prefix "ONERROR: status=%d @ %s(%d) in " __FILE__, \
2317 status, __FUNCTION__, __LINE__); \
2322 #define gcmONERROR(func) _gcmONERROR(gcm, func)
2323 #define gcmkONERROR(func) _gcmONERROR(gcmk, func)
2325 /*******************************************************************************
2329 ** Verifies whether the surface is locked.
2333 ** surfaceInfo Pointer to the surface iniformational structure.
2335 #define gcmVERIFY_LOCK(surfaceInfo) \
2336 if (!surfaceInfo->node.valid) \
2338 status = gcvSTATUS_MEMORY_UNLOCKED; \
2341 do { } while (gcvFALSE)
2343 /*******************************************************************************
2345 ** gcmVERIFY_NODE_LOCK
2347 ** Verifies whether the surface node is locked.
2351 ** surfaceInfo Pointer to the surface iniformational structure.
2353 #define gcmVERIFY_NODE_LOCK(surfaceNode) \
2354 if (!surfaceNode->valid) \
2356 status = gcvSTATUS_MEMORY_UNLOCKED; \
2359 do { } while (gcvFALSE)
2361 /*******************************************************************************
2363 ** gcmBADOBJECT_BREAK
2365 ** Executes a break statement on bad object.
2369 ** obj Object to test.
2370 ** t Expected type of the object.
2372 #define gcmBADOBJECT_BREAK(obj, t) \
2373 if ((obj == gcvNULL) \
2374 || (((gcsOBJECT *)(obj))->type != t) \
2377 status = gcvSTATUS_INVALID_OBJECT; \
2380 do { } while (gcvFALSE)
2382 /*******************************************************************************
2386 ** Executes a break statement on error.
2390 ** 'status' variable of gceSTATUS type must be defined.
2394 ** func Function to evaluate.
2396 #define _gcmCHECK_STATUS(prefix, func) \
2400 if (gcmIS_ERROR(last)) \
2402 prefix##TRACE(gcvLEVEL_ERROR, \
2403 #prefix "CHECK_STATUS: status=%d @ %s(%d) in " __FILE__, \
2404 last, __FUNCTION__, __LINE__); \
2409 #define gcmCHECK_STATUS(func) _gcmCHECK_STATUS(gcm, func)
2410 #define gcmkCHECK_STATUS(func) _gcmCHECK_STATUS(gcmk, func)
2412 /*******************************************************************************
2414 ** gcmVERIFY_ARGUMENT
2416 ** Assert if an argument does not apply to the specified expression. If
2417 ** the argument evaluates to false, gcvSTATUS_INVALID_ARGUMENT will be
2418 ** returned from the current function. In retail mode this macro does
2423 ** arg Argument to evaluate.
2425 #ifndef EGL_API_ANDROID
2426 # define _gcmVERIFY_ARGUMENT(prefix, arg) \
2431 prefix##TRACE(gcvLEVEL_ERROR, #prefix "VERIFY_ARGUMENT failed:"); \
2432 prefix##ASSERT(arg); \
2433 prefix##FOOTER_ARG("status=%d", gcvSTATUS_INVALID_ARGUMENT); \
2434 return gcvSTATUS_INVALID_ARGUMENT; \
2438 # define gcmVERIFY_ARGUMENT(arg) _gcmVERIFY_ARGUMENT(gcm, arg)
2439 # define gcmkVERIFY_ARGUMENT(arg) _gcmVERIFY_ARGUMENT(gcmk, arg)
2441 # define gcmVERIFY_ARGUMENT(arg)
2442 # define gcmkVERIFY_ARGUMENT(arg)
2445 /*******************************************************************************
2447 ** gcmVERIFY_ARGUMENT_RETURN
2449 ** Assert if an argument does not apply to the specified expression. If
2450 ** the argument evaluates to false, gcvSTATUS_INVALID_ARGUMENT will be
2451 ** returned from the current function. In retail mode this macro does
2456 ** arg Argument to evaluate.
2458 #ifndef EGL_API_ANDROID
2459 # define _gcmVERIFY_ARGUMENT_RETURN(prefix, arg, value) \
2464 prefix##TRACE(gcvLEVEL_ERROR, \
2465 #prefix "gcmVERIFY_ARGUMENT_RETURN failed:"); \
2466 prefix##ASSERT(arg); \
2467 prefix##FOOTER_ARG("value=%d", value); \
2472 # define gcmVERIFY_ARGUMENT_RETURN(arg, value) \
2473 _gcmVERIFY_ARGUMENT_RETURN(gcm, arg, value)
2474 # define gcmkVERIFY_ARGUMENT_RETURN(arg, value) \
2475 _gcmVERIFY_ARGUMENT_RETURN(gcmk, arg, value)
2477 # define gcmVERIFY_ARGUMENT_RETURN(arg, value)
2478 # define gcmkVERIFY_ARGUMENT_RETURN(arg, value)
2484 #endif /* __gc_hal_base_h_ */