singlepix.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. /*
  2. * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
  3. * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice including the dates of first publication and
  13. * either this permission notice or a reference to
  14. * http://oss.sgi.com/projects/FreeB/
  15. * shall be included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  18. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  21. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
  22. * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23. * SOFTWARE.
  24. *
  25. * Except as contained in this notice, the name of Silicon Graphics, Inc.
  26. * shall not be used in advertising or otherwise to promote the sale, use or
  27. * other dealings in this Software without prior written authorization from
  28. * Silicon Graphics, Inc.
  29. */
  30. #ifdef HAVE_DIX_CONFIG_H
  31. #include <dix-config.h>
  32. #endif
  33. #include "glxserver.h"
  34. #include "glxext.h"
  35. #include "singlesize.h"
  36. #include "unpack.h"
  37. #include "indirect_size_get.h"
  38. #include "indirect_dispatch.h"
  39. int
  40. __glXDisp_ReadPixels(__GLXclientState * cl, GLbyte * pc)
  41. {
  42. GLsizei width, height;
  43. GLenum format, type;
  44. GLboolean swapBytes, lsbFirst;
  45. GLint compsize;
  46. __GLXcontext *cx;
  47. ClientPtr client = cl->client;
  48. int error;
  49. char *answer, answerBuffer[200];
  50. REQUEST_FIXED_SIZE(xGLXSingleReq, 28);
  51. cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
  52. if (!cx) {
  53. return error;
  54. }
  55. pc += __GLX_SINGLE_HDR_SIZE;
  56. width = *(GLsizei *) (pc + 8);
  57. height = *(GLsizei *) (pc + 12);
  58. format = *(GLenum *) (pc + 16);
  59. type = *(GLenum *) (pc + 20);
  60. swapBytes = *(GLboolean *) (pc + 24);
  61. lsbFirst = *(GLboolean *) (pc + 25);
  62. compsize = __glReadPixels_size(format, type, width, height);
  63. if (compsize < 0)
  64. return BadLength;
  65. glPixelStorei(GL_PACK_SWAP_BYTES, swapBytes);
  66. glPixelStorei(GL_PACK_LSB_FIRST, lsbFirst);
  67. __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1);
  68. __glXClearErrorOccured();
  69. glReadPixels(*(GLint *) (pc + 0), *(GLint *) (pc + 4),
  70. *(GLsizei *) (pc + 8), *(GLsizei *) (pc + 12),
  71. *(GLenum *) (pc + 16), *(GLenum *) (pc + 20), answer);
  72. if (__glXErrorOccured()) {
  73. __GLX_BEGIN_REPLY(0);
  74. __GLX_SEND_HEADER();
  75. }
  76. else {
  77. __GLX_BEGIN_REPLY(compsize);
  78. __GLX_SEND_HEADER();
  79. __GLX_SEND_VOID_ARRAY(compsize);
  80. }
  81. cx->hasUnflushedCommands = GL_FALSE;
  82. return Success;
  83. }
  84. int
  85. __glXDisp_GetTexImage(__GLXclientState * cl, GLbyte * pc)
  86. {
  87. GLint level, compsize;
  88. GLenum format, type, target;
  89. GLboolean swapBytes;
  90. __GLXcontext *cx;
  91. ClientPtr client = cl->client;
  92. int error;
  93. char *answer, answerBuffer[200];
  94. GLint width = 0, height = 0, depth = 1;
  95. REQUEST_FIXED_SIZE(xGLXSingleReq, 20);
  96. cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
  97. if (!cx) {
  98. return error;
  99. }
  100. pc += __GLX_SINGLE_HDR_SIZE;
  101. level = *(GLint *) (pc + 4);
  102. format = *(GLenum *) (pc + 8);
  103. type = *(GLenum *) (pc + 12);
  104. target = *(GLenum *) (pc + 0);
  105. swapBytes = *(GLboolean *) (pc + 16);
  106. glGetTexLevelParameteriv(target, level, GL_TEXTURE_WIDTH, &width);
  107. glGetTexLevelParameteriv(target, level, GL_TEXTURE_HEIGHT, &height);
  108. if (target == GL_TEXTURE_3D) {
  109. glGetTexLevelParameteriv(target, level, GL_TEXTURE_DEPTH, &depth);
  110. }
  111. /*
  112. * The three queries above might fail if we're in a state where queries
  113. * are illegal, but then width, height, and depth would still be zero anyway.
  114. */
  115. compsize =
  116. __glGetTexImage_size(target, level, format, type, width, height, depth);
  117. if (compsize < 0)
  118. return BadLength;
  119. glPixelStorei(GL_PACK_SWAP_BYTES, swapBytes);
  120. __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1);
  121. __glXClearErrorOccured();
  122. glGetTexImage(*(GLenum *) (pc + 0), *(GLint *) (pc + 4),
  123. *(GLenum *) (pc + 8), *(GLenum *) (pc + 12), answer);
  124. if (__glXErrorOccured()) {
  125. __GLX_BEGIN_REPLY(0);
  126. __GLX_SEND_HEADER();
  127. }
  128. else {
  129. __GLX_BEGIN_REPLY(compsize);
  130. ((xGLXGetTexImageReply *) &__glXReply)->width = width;
  131. ((xGLXGetTexImageReply *) &__glXReply)->height = height;
  132. ((xGLXGetTexImageReply *) &__glXReply)->depth = depth;
  133. __GLX_SEND_HEADER();
  134. __GLX_SEND_VOID_ARRAY(compsize);
  135. }
  136. return Success;
  137. }
  138. int
  139. __glXDisp_GetPolygonStipple(__GLXclientState * cl, GLbyte * pc)
  140. {
  141. GLboolean lsbFirst;
  142. __GLXcontext *cx;
  143. ClientPtr client = cl->client;
  144. int error;
  145. GLubyte answerBuffer[200];
  146. char *answer;
  147. REQUEST_FIXED_SIZE(xGLXSingleReq, 4);
  148. cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
  149. if (!cx) {
  150. return error;
  151. }
  152. pc += __GLX_SINGLE_HDR_SIZE;
  153. lsbFirst = *(GLboolean *) (pc + 0);
  154. glPixelStorei(GL_PACK_LSB_FIRST, lsbFirst);
  155. __GLX_GET_ANSWER_BUFFER(answer, cl, 128, 1);
  156. __glXClearErrorOccured();
  157. glGetPolygonStipple((GLubyte *) answer);
  158. if (__glXErrorOccured()) {
  159. __GLX_BEGIN_REPLY(0);
  160. __GLX_SEND_HEADER();
  161. }
  162. else {
  163. __GLX_BEGIN_REPLY(128);
  164. __GLX_SEND_HEADER();
  165. __GLX_SEND_BYTE_ARRAY(128);
  166. }
  167. return Success;
  168. }
  169. static int
  170. GetSeparableFilter(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
  171. {
  172. GLint compsize, compsize2;
  173. GLenum format, type, target;
  174. GLboolean swapBytes;
  175. __GLXcontext *cx;
  176. ClientPtr client = cl->client;
  177. int error;
  178. char *answer, answerBuffer[200];
  179. GLint width = 0, height = 0;
  180. cx = __glXForceCurrent(cl, tag, &error);
  181. if (!cx) {
  182. return error;
  183. }
  184. format = *(GLenum *) (pc + 4);
  185. type = *(GLenum *) (pc + 8);
  186. target = *(GLenum *) (pc + 0);
  187. swapBytes = *(GLboolean *) (pc + 12);
  188. /* target must be SEPARABLE_2D, however I guess we can let the GL
  189. barf on this one.... */
  190. glGetConvolutionParameteriv(target, GL_CONVOLUTION_WIDTH, &width);
  191. glGetConvolutionParameteriv(target, GL_CONVOLUTION_HEIGHT, &height);
  192. /*
  193. * The two queries above might fail if we're in a state where queries
  194. * are illegal, but then width and height would still be zero anyway.
  195. */
  196. compsize = __glGetTexImage_size(target, 1, format, type, width, 1, 1);
  197. compsize2 = __glGetTexImage_size(target, 1, format, type, height, 1, 1);
  198. if ((compsize = safe_pad(compsize)) < 0)
  199. return BadLength;
  200. if ((compsize2 = safe_pad(compsize2)) < 0)
  201. return BadLength;
  202. glPixelStorei(GL_PACK_SWAP_BYTES, swapBytes);
  203. __GLX_GET_ANSWER_BUFFER(answer, cl, safe_add(compsize, compsize2), 1);
  204. __glXClearErrorOccured();
  205. glGetSeparableFilter(*(GLenum *) (pc + 0), *(GLenum *) (pc + 4),
  206. *(GLenum *) (pc + 8), answer, answer + compsize, NULL);
  207. if (__glXErrorOccured()) {
  208. __GLX_BEGIN_REPLY(0);
  209. __GLX_SEND_HEADER();
  210. }
  211. else {
  212. __GLX_BEGIN_REPLY(compsize + compsize2);
  213. ((xGLXGetSeparableFilterReply *) &__glXReply)->width = width;
  214. ((xGLXGetSeparableFilterReply *) &__glXReply)->height = height;
  215. __GLX_SEND_HEADER();
  216. __GLX_SEND_VOID_ARRAY(compsize + compsize2);
  217. }
  218. return Success;
  219. }
  220. int
  221. __glXDisp_GetSeparableFilter(__GLXclientState * cl, GLbyte * pc)
  222. {
  223. const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
  224. ClientPtr client = cl->client;
  225. REQUEST_FIXED_SIZE(xGLXSingleReq, 16);
  226. return GetSeparableFilter(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
  227. }
  228. int
  229. __glXDisp_GetSeparableFilterEXT(__GLXclientState * cl, GLbyte * pc)
  230. {
  231. const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
  232. ClientPtr client = cl->client;
  233. REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 16);
  234. return GetSeparableFilter(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
  235. }
  236. static int
  237. GetConvolutionFilter(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
  238. {
  239. GLint compsize;
  240. GLenum format, type, target;
  241. GLboolean swapBytes;
  242. __GLXcontext *cx;
  243. ClientPtr client = cl->client;
  244. int error;
  245. char *answer, answerBuffer[200];
  246. GLint width = 0, height = 0;
  247. cx = __glXForceCurrent(cl, tag, &error);
  248. if (!cx) {
  249. return error;
  250. }
  251. format = *(GLenum *) (pc + 4);
  252. type = *(GLenum *) (pc + 8);
  253. target = *(GLenum *) (pc + 0);
  254. swapBytes = *(GLboolean *) (pc + 12);
  255. glGetConvolutionParameteriv(target, GL_CONVOLUTION_WIDTH, &width);
  256. if (target == GL_CONVOLUTION_1D) {
  257. height = 1;
  258. }
  259. else {
  260. glGetConvolutionParameteriv(target, GL_CONVOLUTION_HEIGHT, &height);
  261. }
  262. /*
  263. * The two queries above might fail if we're in a state where queries
  264. * are illegal, but then width and height would still be zero anyway.
  265. */
  266. compsize = __glGetTexImage_size(target, 1, format, type, width, height, 1);
  267. if (compsize < 0)
  268. return BadLength;
  269. glPixelStorei(GL_PACK_SWAP_BYTES, swapBytes);
  270. __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1);
  271. __glXClearErrorOccured();
  272. glGetConvolutionFilter(*(GLenum *) (pc + 0), *(GLenum *) (pc + 4),
  273. *(GLenum *) (pc + 8), answer);
  274. if (__glXErrorOccured()) {
  275. __GLX_BEGIN_REPLY(0);
  276. __GLX_SEND_HEADER();
  277. }
  278. else {
  279. __GLX_BEGIN_REPLY(compsize);
  280. ((xGLXGetConvolutionFilterReply *) &__glXReply)->width = width;
  281. ((xGLXGetConvolutionFilterReply *) &__glXReply)->height = height;
  282. __GLX_SEND_HEADER();
  283. __GLX_SEND_VOID_ARRAY(compsize);
  284. }
  285. return Success;
  286. }
  287. int
  288. __glXDisp_GetConvolutionFilter(__GLXclientState * cl, GLbyte * pc)
  289. {
  290. const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
  291. ClientPtr client = cl->client;
  292. REQUEST_FIXED_SIZE(xGLXSingleReq, 16);
  293. return GetConvolutionFilter(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
  294. }
  295. int
  296. __glXDisp_GetConvolutionFilterEXT(__GLXclientState * cl, GLbyte * pc)
  297. {
  298. const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
  299. ClientPtr client = cl->client;
  300. REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 16);
  301. return GetConvolutionFilter(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
  302. }
  303. static int
  304. GetHistogram(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
  305. {
  306. GLint compsize;
  307. GLenum format, type, target;
  308. GLboolean swapBytes, reset;
  309. __GLXcontext *cx;
  310. ClientPtr client = cl->client;
  311. int error;
  312. char *answer, answerBuffer[200];
  313. GLint width = 0;
  314. cx = __glXForceCurrent(cl, tag, &error);
  315. if (!cx) {
  316. return error;
  317. }
  318. format = *(GLenum *) (pc + 4);
  319. type = *(GLenum *) (pc + 8);
  320. target = *(GLenum *) (pc + 0);
  321. swapBytes = *(GLboolean *) (pc + 12);
  322. reset = *(GLboolean *) (pc + 13);
  323. glGetHistogramParameteriv(target, GL_HISTOGRAM_WIDTH, &width);
  324. /*
  325. * The one query above might fail if we're in a state where queries
  326. * are illegal, but then width would still be zero anyway.
  327. */
  328. compsize = __glGetTexImage_size(target, 1, format, type, width, 1, 1);
  329. if (compsize < 0)
  330. return BadLength;
  331. glPixelStorei(GL_PACK_SWAP_BYTES, swapBytes);
  332. __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1);
  333. __glXClearErrorOccured();
  334. glGetHistogram(target, reset, format, type, answer);
  335. if (__glXErrorOccured()) {
  336. __GLX_BEGIN_REPLY(0);
  337. __GLX_SEND_HEADER();
  338. }
  339. else {
  340. __GLX_BEGIN_REPLY(compsize);
  341. ((xGLXGetHistogramReply *) &__glXReply)->width = width;
  342. __GLX_SEND_HEADER();
  343. __GLX_SEND_VOID_ARRAY(compsize);
  344. }
  345. return Success;
  346. }
  347. int
  348. __glXDisp_GetHistogram(__GLXclientState * cl, GLbyte * pc)
  349. {
  350. const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
  351. ClientPtr client = cl->client;
  352. REQUEST_FIXED_SIZE(xGLXSingleReq, 16);
  353. return GetHistogram(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
  354. }
  355. int
  356. __glXDisp_GetHistogramEXT(__GLXclientState * cl, GLbyte * pc)
  357. {
  358. const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
  359. ClientPtr client = cl->client;
  360. REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 16);
  361. return GetHistogram(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
  362. }
  363. static int
  364. GetMinmax(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
  365. {
  366. GLint compsize;
  367. GLenum format, type, target;
  368. GLboolean swapBytes, reset;
  369. __GLXcontext *cx;
  370. ClientPtr client = cl->client;
  371. int error;
  372. char *answer, answerBuffer[200];
  373. cx = __glXForceCurrent(cl, tag, &error);
  374. if (!cx) {
  375. return error;
  376. }
  377. format = *(GLenum *) (pc + 4);
  378. type = *(GLenum *) (pc + 8);
  379. target = *(GLenum *) (pc + 0);
  380. swapBytes = *(GLboolean *) (pc + 12);
  381. reset = *(GLboolean *) (pc + 13);
  382. compsize = __glGetTexImage_size(target, 1, format, type, 2, 1, 1);
  383. if (compsize < 0)
  384. return BadLength;
  385. glPixelStorei(GL_PACK_SWAP_BYTES, swapBytes);
  386. __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1);
  387. __glXClearErrorOccured();
  388. glGetMinmax(target, reset, format, type, answer);
  389. if (__glXErrorOccured()) {
  390. __GLX_BEGIN_REPLY(0);
  391. __GLX_SEND_HEADER();
  392. }
  393. else {
  394. __GLX_BEGIN_REPLY(compsize);
  395. __GLX_SEND_HEADER();
  396. __GLX_SEND_VOID_ARRAY(compsize);
  397. }
  398. return Success;
  399. }
  400. int
  401. __glXDisp_GetMinmax(__GLXclientState * cl, GLbyte * pc)
  402. {
  403. const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
  404. ClientPtr client = cl->client;
  405. REQUEST_FIXED_SIZE(xGLXSingleReq, 16);
  406. return GetMinmax(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
  407. }
  408. int
  409. __glXDisp_GetMinmaxEXT(__GLXclientState * cl, GLbyte * pc)
  410. {
  411. const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
  412. ClientPtr client = cl->client;
  413. REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 16);
  414. return GetMinmax(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
  415. }
  416. static int
  417. GetColorTable(__GLXclientState * cl, GLbyte * pc, GLXContextTag tag)
  418. {
  419. GLint compsize;
  420. GLenum format, type, target;
  421. GLboolean swapBytes;
  422. __GLXcontext *cx;
  423. ClientPtr client = cl->client;
  424. int error;
  425. char *answer, answerBuffer[200];
  426. GLint width = 0;
  427. cx = __glXForceCurrent(cl, tag, &error);
  428. if (!cx) {
  429. return error;
  430. }
  431. target = *(GLenum *) (pc + 0);
  432. format = *(GLenum *) (pc + 4);
  433. type = *(GLenum *) (pc + 8);
  434. swapBytes = *(GLboolean *) (pc + 12);
  435. glGetColorTableParameteriv(target, GL_COLOR_TABLE_WIDTH, &width);
  436. /*
  437. * The one query above might fail if we're in a state where queries
  438. * are illegal, but then width would still be zero anyway.
  439. */
  440. compsize = __glGetTexImage_size(target, 1, format, type, width, 1, 1);
  441. if (compsize < 0)
  442. return BadLength;
  443. glPixelStorei(GL_PACK_SWAP_BYTES, swapBytes);
  444. __GLX_GET_ANSWER_BUFFER(answer, cl, compsize, 1);
  445. __glXClearErrorOccured();
  446. glGetColorTable(*(GLenum *) (pc + 0), *(GLenum *) (pc + 4),
  447. *(GLenum *) (pc + 8), answer);
  448. if (__glXErrorOccured()) {
  449. __GLX_BEGIN_REPLY(0);
  450. __GLX_SEND_HEADER();
  451. }
  452. else {
  453. __GLX_BEGIN_REPLY(compsize);
  454. ((xGLXGetColorTableReply *) &__glXReply)->width = width;
  455. __GLX_SEND_HEADER();
  456. __GLX_SEND_VOID_ARRAY(compsize);
  457. }
  458. return Success;
  459. }
  460. int
  461. __glXDisp_GetColorTable(__GLXclientState * cl, GLbyte * pc)
  462. {
  463. const GLXContextTag tag = __GLX_GET_SINGLE_CONTEXT_TAG(pc);
  464. ClientPtr client = cl->client;
  465. REQUEST_FIXED_SIZE(xGLXSingleReq, 16);
  466. return GetColorTable(cl, pc + __GLX_SINGLE_HDR_SIZE, tag);
  467. }
  468. int
  469. __glXDisp_GetColorTableSGI(__GLXclientState * cl, GLbyte * pc)
  470. {
  471. const GLXContextTag tag = __GLX_GET_VENDPRIV_CONTEXT_TAG(pc);
  472. ClientPtr client = cl->client;
  473. REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 16);
  474. return GetColorTable(cl, pc + __GLX_VENDPRIV_HDR_SIZE, tag);
  475. }