Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
3.9 KiB

  1. /******************************Module*Header*******************************\
  2. * Module Name: dlistfn.h
  3. *
  4. * Display list inline functions
  5. * Cannot be in dlist.h because they require full definitions of structures
  6. * defines in context.h
  7. *
  8. * Created: 23-Oct-1995 18:31:42
  9. * Author: Drew Bliss [drewb]
  10. *
  11. * Copyright (c) 1995-96 Microsoft Corporation
  12. *
  13. \**************************************************************************/
  14. #ifndef __DLISTFN_H__
  15. #define __DLISTFN_H__
  16. extern const GLubyte * FASTCALL __glle_Nop(__GLcontext *gc, const GLubyte *PC);
  17. // Allocate space in a display for a display list op and return
  18. // a pointer to the data space for the record
  19. // These functions are specially written to be small so that they
  20. // can be inlined to remove call overhead
  21. // Add an op which doesn't require QWORD alignment
  22. __inline
  23. void *__glDlistAddOpUnaligned(__GLcontext *gc,
  24. GLuint size,
  25. __GLlistExecFunc *fp)
  26. {
  27. __GLdlist *dlist;
  28. GLubyte *data;
  29. dlist = gc->dlist.listData;
  30. if (dlist->size-dlist->used < size)
  31. {
  32. if ((dlist = __glDlistGrow(size)) == NULL)
  33. {
  34. return NULL;
  35. }
  36. }
  37. data = dlist->head+dlist->used;
  38. dlist->used += size;
  39. *((__GLlistExecFunc * UNALIGNED64 *) data) = fp;
  40. return data+sizeof(__GLlistExecFunc *);
  41. }
  42. // Add an op which does require QWORD alignment
  43. __inline
  44. void *__glDlistAddOpAligned(__GLcontext *gc,
  45. GLuint size,
  46. __GLlistExecFunc *fp)
  47. {
  48. __GLdlist *dlist;
  49. GLubyte *data;
  50. GLboolean addPad;
  51. dlist = gc->dlist.listData;
  52. // dlist->head is always non-QWORD aligned, but make sure
  53. // We use this fact to simplify the alignment check below
  54. #ifndef _IA64_
  55. ASSERTOPENGL((((char *) (&dlist->head) - (char *) (dlist)) & 7) == 4,
  56. "bad dlist->head alignment\n");
  57. #endif
  58. // Add padding for aligned records
  59. // Since head is always non-QWORD aligned, dlist->head is guaranteed
  60. // to be at QWORD offset 4. Since we stick a dispatch pointer at
  61. // the head of every record, this gets bumped up to an even QWORD
  62. // boundary as long as the current record would begin at a half
  63. // QWORD boundary. That means as long as dlist->used is QWORD-even,
  64. // the record data will be QWORD aligned
  65. // Win95 note: LocalAlloc doesn't appear to return QWORD aligned
  66. // memory so we need to check the real pointer for alignment
  67. #ifndef _IA64_
  68. if (((ULONG_PTR)(dlist->head+dlist->used) & 7) == 0)
  69. {
  70. size += sizeof(__GLlistExecFunc **);
  71. addPad = GL_TRUE;
  72. }
  73. else
  74. #endif
  75. {
  76. addPad = GL_FALSE;
  77. }
  78. if (dlist->size-dlist->used < size)
  79. {
  80. // New dlist->head will be properly non-QWORD aligned - remove any
  81. // padding
  82. if( addPad ) {
  83. size -= sizeof(__GLlistExecFunc **);
  84. addPad = GL_FALSE;
  85. }
  86. if ((dlist = __glDlistGrow(size)) == NULL)
  87. {
  88. return NULL;
  89. }
  90. }
  91. data = dlist->head+dlist->used;
  92. dlist->used += size;
  93. if (addPad)
  94. {
  95. *((__GLlistExecFunc **) data) = __glle_Nop;
  96. data += sizeof(__GLlistExecFunc **);
  97. }
  98. *((__GLlistExecFunc * UNALIGNED64 *) data) = fp;
  99. return data+sizeof(__GLlistExecFunc *);
  100. }
  101. /*
  102. ** Append the given op to the currently under construction list.
  103. */
  104. __inline
  105. void __glDlistAppendOp(__GLcontext *gc, void *data,
  106. __GLlistExecFunc *fp)
  107. {
  108. if (gc->dlist.mode == GL_COMPILE_AND_EXECUTE)
  109. {
  110. fp(gc, (GLubyte *)data);
  111. }
  112. }
  113. // Resize the current op to a smaller size.
  114. __inline
  115. void __glDlistResizeCurrentOp(__GLcontext *gc, GLuint oldSize, GLuint newSize)
  116. {
  117. __GLdlist *dlist;
  118. ASSERTOPENGL(oldSize >= newSize, "new size > old size!\n");
  119. dlist = gc->dlist.listData;
  120. dlist->used -= oldSize - newSize;
  121. return;
  122. }
  123. #endif // __DLISTFN_H__