Leaked source code of windows server 2003
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.

287 lines
8.8 KiB

  1. /*
  2. ** Copyright 1991,1992, Silicon Graphics, Inc.
  3. ** All Rights Reserved.
  4. **
  5. ** This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6. ** the contents of this file may not be disclosed to third parties, copied or
  7. ** duplicated in any form, in whole or in part, without the prior written
  8. ** permission of Silicon Graphics, Inc.
  9. **
  10. ** RESTRICTED RIGHTS LEGEND:
  11. ** Use, duplication or disclosure by the Government is subject to restrictions
  12. ** as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13. ** and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14. ** successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15. ** rights reserved under the Copyright Laws of the United States.
  16. **
  17. */
  18. #include "precomp.h"
  19. #pragma hdrstop
  20. #include <namesint.h>
  21. void __glTexPriListRealize(__GLcontext *gc)
  22. {
  23. __GLtextureObject *high, *low;
  24. GLboolean tryUnload = GL_TRUE;
  25. MCDHANDLE loadKey;
  26. __GL_NAMES_ASSERT_LOCKED(gc->texture.shared->namesArray);
  27. // Attempt to load as many of the highest priority textures as
  28. // possible. If a lower priority texture is resident and a
  29. // higher priority texture is unable to load, kick it out
  30. // and try again
  31. high = gc->texture.shared->priorityListHighest;
  32. low = gc->texture.shared->priorityListLowest;
  33. while (high != NULL)
  34. {
  35. // We only want to load textures that have image data
  36. // Consider - Should check all mipmap levels?
  37. if (high->loadKey == 0 && high->texture.map.level[0].buffer != NULL)
  38. {
  39. for (;;)
  40. {
  41. // If high == low then there are no longer any
  42. // lower-priority textures to consider for unloading
  43. if (high == low)
  44. {
  45. tryUnload = GL_FALSE;
  46. }
  47. loadKey = __glGenLoadTexture(gc, &high->texture.map, 0);
  48. if (loadKey != 0)
  49. {
  50. high->resident = GL_TRUE;
  51. high->loadKey = loadKey;
  52. break;
  53. }
  54. if (tryUnload)
  55. {
  56. while (low->loadKey == 0 && low != high)
  57. {
  58. low = low->higherPriority;
  59. }
  60. if (low->loadKey != 0)
  61. {
  62. __glGenFreeTexture(gc, &low->texture.map, low->loadKey);
  63. low->loadKey = 0;
  64. low->resident = GL_FALSE;
  65. }
  66. }
  67. else
  68. {
  69. break;
  70. }
  71. }
  72. }
  73. high = high->lowerPriority;
  74. }
  75. }
  76. void __glTexPriListAddToList(__GLcontext *gc, __GLtextureObject *texobj)
  77. {
  78. __GLtextureObject *texobjLower;
  79. __GL_NAMES_ASSERT_LOCKED(gc->texture.shared->namesArray);
  80. // Walk the priority list to find a lower priority texture object
  81. texobjLower = gc->texture.shared->priorityListHighest;
  82. while (texobjLower != NULL &&
  83. texobjLower->texture.map.texobjs.priority >
  84. texobj->texture.map.texobjs.priority)
  85. {
  86. texobjLower = texobjLower->lowerPriority;
  87. }
  88. if (texobjLower == NULL)
  89. {
  90. // Place at end of list
  91. if (gc->texture.shared->priorityListLowest != NULL)
  92. {
  93. gc->texture.shared->priorityListLowest->lowerPriority = texobj;
  94. }
  95. else
  96. {
  97. gc->texture.shared->priorityListHighest = texobj;
  98. }
  99. texobj->higherPriority = gc->texture.shared->priorityListLowest;
  100. gc->texture.shared->priorityListLowest = texobj;
  101. }
  102. else
  103. {
  104. if (texobjLower->higherPriority != NULL)
  105. {
  106. texobjLower->higherPriority->lowerPriority = texobj;
  107. }
  108. else
  109. {
  110. gc->texture.shared->priorityListHighest = texobj;
  111. }
  112. texobj->higherPriority = texobjLower->higherPriority;
  113. texobjLower->higherPriority = texobj;
  114. }
  115. texobj->lowerPriority = texobjLower;
  116. }
  117. void __glTexPriListAdd(__GLcontext *gc, __GLtextureObject *texobj,
  118. GLboolean realize)
  119. {
  120. __glNamesLockArray(gc, gc->texture.shared->namesArray);
  121. __glTexPriListAddToList(gc, texobj);
  122. if (realize)
  123. {
  124. __glTexPriListRealize(gc);
  125. }
  126. __glNamesUnlockArray(gc, gc->texture.shared->namesArray);
  127. }
  128. void __glTexPriListRemoveFromList(__GLcontext *gc, __GLtextureObject *texobj)
  129. {
  130. __GL_NAMES_ASSERT_LOCKED(gc->texture.shared->namesArray);
  131. #if DBG
  132. {
  133. __GLtextureObject *t;
  134. for (t = gc->texture.shared->priorityListHighest;
  135. t != NULL; t = t->lowerPriority)
  136. {
  137. if (t == texobj)
  138. {
  139. break;
  140. }
  141. }
  142. ASSERTOPENGL(t != NULL, "Removing an unlisted texobj");
  143. }
  144. #endif
  145. if (texobj->higherPriority != NULL)
  146. {
  147. texobj->higherPriority->lowerPriority = texobj->lowerPriority;
  148. }
  149. else
  150. {
  151. gc->texture.shared->priorityListHighest = texobj->lowerPriority;
  152. }
  153. if (texobj->lowerPriority != NULL)
  154. {
  155. texobj->lowerPriority->higherPriority = texobj->higherPriority;
  156. }
  157. else
  158. {
  159. gc->texture.shared->priorityListLowest = texobj->higherPriority;
  160. }
  161. }
  162. void __glTexPriListRemove(__GLcontext *gc, __GLtextureObject *texobj,
  163. GLboolean realize)
  164. {
  165. __glNamesLockArray(gc, gc->texture.shared->namesArray);
  166. __glTexPriListRemoveFromList(gc, texobj);
  167. __glGenFreeTexture(gc, &texobj->texture.map, texobj->loadKey);
  168. texobj->loadKey = 0;
  169. texobj->resident = GL_FALSE;
  170. if (realize)
  171. {
  172. __glTexPriListRealize(gc);
  173. }
  174. __glNamesUnlockArray(gc, gc->texture.shared->namesArray);
  175. }
  176. void __glTexPriListChangePriority(__GLcontext *gc, __GLtextureObject *texobj,
  177. GLboolean realize)
  178. {
  179. __glNamesLockArray(gc, gc->texture.shared->namesArray);
  180. __glTexPriListRemoveFromList(gc, texobj);
  181. __glTexPriListAddToList(gc, texobj);
  182. // If we're re-realizing, don't bother calling the MCD texture-priority
  183. // function:
  184. if (realize) {
  185. __glTexPriListRealize(gc);
  186. } else if (((__GLGENcontext *)gc)->pMcdState && texobj->loadKey) {
  187. GenMcdUpdateTexturePriority((__GLGENcontext *)gc,
  188. &texobj->texture.map, texobj->loadKey);
  189. }
  190. __glNamesUnlockArray(gc, gc->texture.shared->namesArray);
  191. }
  192. void __glTexPriListLoadSubImage(__GLcontext *gc, GLenum target, GLint lod,
  193. GLint xoffset, GLint yoffset,
  194. GLsizei w, GLsizei h)
  195. {
  196. __GLtextureObject *pto;
  197. // Always mark things as resident:
  198. pto = __glLookUpTextureObject(gc, target);
  199. pto->resident = GL_TRUE;
  200. __glGenUpdateTexture(gc, &pto->texture.map, pto->loadKey);
  201. // For MCD, send down the full subimage command:
  202. if (((__GLGENcontext *)gc)->pMcdState && pto->loadKey) {
  203. GenMcdUpdateSubTexture((__GLGENcontext *)gc, &pto->texture.map,
  204. pto->loadKey, lod,
  205. xoffset, yoffset, w, h);
  206. }
  207. }
  208. void __glTexPriListLoadImage(__GLcontext *gc, GLenum target)
  209. {
  210. __GLtextureObject *pto;
  211. // If we're unaccelerated then always mark things as resident
  212. pto = __glLookUpTextureObject(gc, target);
  213. pto->resident = GL_TRUE;
  214. __glGenUpdateTexture(gc, &pto->texture.map, pto->loadKey);
  215. // For simplicity, we will assume that the texture size or format
  216. // has changed, so delete the texture and re-realize the list.
  217. //
  218. // !!! If this becomes a performance issue, we *could* be smart about
  219. // !!! detecting the cases where the texture size and format remains the
  220. // !!! same. However, modifying a texture should really be done through
  221. // !!! SubImage calls.
  222. if (((__GLGENcontext *)gc)->pMcdState) {
  223. if (pto->loadKey) {
  224. GenMcdDeleteTexture((__GLGENcontext *)gc, pto->loadKey);
  225. pto->loadKey = 0;
  226. }
  227. __glNamesLockArray(gc, gc->texture.shared->namesArray);
  228. __glTexPriListRealize(gc);
  229. __glNamesUnlockArray(gc, gc->texture.shared->namesArray);
  230. }
  231. }
  232. void __glTexPriListUnloadAll(__GLcontext *gc)
  233. {
  234. __GLtextureObject *texobj;
  235. __GL_NAMES_ASSERT_LOCKED(gc->texture.shared->namesArray);
  236. texobj = gc->texture.shared->priorityListHighest;
  237. while (texobj != NULL)
  238. {
  239. __glGenFreeTexture(gc, &texobj->texture.map, texobj->loadKey);
  240. texobj->loadKey = 0;
  241. texobj->resident = GL_FALSE;
  242. texobj = texobj->lowerPriority;
  243. }
  244. }