Clone of mesa.
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.

xm_api.c 35KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330
  1. /*
  2. * Mesa 3-D graphics library
  3. * Version: 7.1
  4. *
  5. * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a
  8. * copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation
  10. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  11. * and/or sell copies of the Software, and to permit persons to whom the
  12. * Software is furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included
  15. * 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. * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  21. * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  22. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. /**
  25. * \file xm_api.c
  26. *
  27. * All the XMesa* API functions.
  28. *
  29. *
  30. * NOTES:
  31. *
  32. * The window coordinate system origin (0,0) is in the lower-left corner
  33. * of the window. X11's window coordinate origin is in the upper-left
  34. * corner of the window. Therefore, most drawing functions in this
  35. * file have to flip Y coordinates.
  36. *
  37. *
  38. * Byte swapping: If the Mesa host and the X display use a different
  39. * byte order then there's some trickiness to be aware of when using
  40. * XImages. The byte ordering used for the XImage is that of the X
  41. * display, not the Mesa host.
  42. * The color-to-pixel encoding for True/DirectColor must be done
  43. * according to the display's visual red_mask, green_mask, and blue_mask.
  44. * If XPutPixel is used to put a pixel into an XImage then XPutPixel will
  45. * do byte swapping if needed. If one wants to directly "poke" the pixel
  46. * into the XImage's buffer then the pixel must be byte swapped first.
  47. *
  48. */
  49. #ifdef __CYGWIN__
  50. #undef WIN32
  51. #undef __WIN32__
  52. #endif
  53. #include "xm_api.h"
  54. #include "xm_st.h"
  55. #include "pipe/p_defines.h"
  56. #include "pipe/p_screen.h"
  57. #include "pipe/p_context.h"
  58. #include "util/u_atomic.h"
  59. #include "xm_public.h"
  60. #include <GL/glx.h>
  61. /* Driver interface routines, set up by xlib backend on library
  62. * _init(). These are global in the same way that function names are
  63. * global.
  64. */
  65. static struct xm_driver driver;
  66. static struct st_api *stapi;
  67. /* Default strict invalidate to false. This means we will not call
  68. * XGetGeometry after every swapbuffers, which allows swapbuffers to
  69. * remain asynchronous. For apps running at 100fps with synchronous
  70. * swapping, a 10% boost is typical. For gears, I see closer to 20%
  71. * speedup.
  72. *
  73. * Note that the work of copying data on swapbuffers doesn't disappear
  74. * - this change just allows the X server to execute the PutImage
  75. * asynchronously without us effectively blocked until its completion.
  76. *
  77. * This speeds up even llvmpipe's threaded rasterization as the
  78. * swapbuffers operation was a large part of the serial component of
  79. * an llvmpipe frame.
  80. *
  81. * The downside of this is correctness - applications which don't call
  82. * glViewport on window resizes will get incorrect rendering. A
  83. * better solution would be to have per-frame but asynchronous
  84. * invalidation. Xcb almost looks as if it could provide this, but
  85. * the API doesn't seem to quite be there.
  86. */
  87. boolean xmesa_strict_invalidate = FALSE;
  88. void xmesa_set_driver( const struct xm_driver *templ )
  89. {
  90. driver = *templ;
  91. stapi = driver.create_st_api();
  92. xmesa_strict_invalidate =
  93. debug_get_bool_option("XMESA_STRICT_INVALIDATE", FALSE);
  94. }
  95. /*
  96. * XXX replace this with a linked list, or better yet, try to attach the
  97. * gallium/mesa extra bits to the X Display object with XAddExtension().
  98. */
  99. #define MAX_DISPLAYS 10
  100. static struct xmesa_display Displays[MAX_DISPLAYS];
  101. static int NumDisplays = 0;
  102. static int
  103. xmesa_get_param(struct st_manager *smapi,
  104. enum st_manager_param param)
  105. {
  106. switch(param) {
  107. case ST_MANAGER_BROKEN_INVALIDATE:
  108. return !xmesa_strict_invalidate;
  109. default:
  110. return 0;
  111. }
  112. }
  113. static XMesaDisplay
  114. xmesa_init_display( Display *display )
  115. {
  116. pipe_static_mutex(init_mutex);
  117. XMesaDisplay xmdpy;
  118. int i;
  119. pipe_mutex_lock(init_mutex);
  120. /* Look for XMesaDisplay which corresponds to 'display' */
  121. for (i = 0; i < NumDisplays; i++) {
  122. if (Displays[i].display == display) {
  123. /* Found it */
  124. pipe_mutex_unlock(init_mutex);
  125. return &Displays[i];
  126. }
  127. }
  128. /* Create new XMesaDisplay */
  129. assert(NumDisplays < MAX_DISPLAYS);
  130. xmdpy = &Displays[NumDisplays];
  131. NumDisplays++;
  132. if (!xmdpy->display && display) {
  133. xmdpy->display = display;
  134. xmdpy->screen = driver.create_pipe_screen(display);
  135. xmdpy->smapi = CALLOC_STRUCT(st_manager);
  136. if (xmdpy->smapi) {
  137. xmdpy->smapi->screen = xmdpy->screen;
  138. xmdpy->smapi->get_param = xmesa_get_param;
  139. }
  140. if (xmdpy->screen && xmdpy->smapi) {
  141. pipe_mutex_init(xmdpy->mutex);
  142. }
  143. else {
  144. if (xmdpy->screen) {
  145. xmdpy->screen->destroy(xmdpy->screen);
  146. xmdpy->screen = NULL;
  147. }
  148. if (xmdpy->smapi) {
  149. FREE(xmdpy->smapi);
  150. xmdpy->smapi = NULL;
  151. }
  152. xmdpy->display = NULL;
  153. }
  154. }
  155. if (!xmdpy->display || xmdpy->display != display)
  156. xmdpy = NULL;
  157. pipe_mutex_unlock(init_mutex);
  158. return xmdpy;
  159. }
  160. /**********************************************************************/
  161. /***** X Utility Functions *****/
  162. /**********************************************************************/
  163. /**
  164. * Return the host's byte order as LSBFirst or MSBFirst ala X.
  165. */
  166. static int host_byte_order( void )
  167. {
  168. int i = 1;
  169. char *cptr = (char *) &i;
  170. return (*cptr==1) ? LSBFirst : MSBFirst;
  171. }
  172. /**
  173. * Return the true number of bits per pixel for XImages.
  174. * For example, if we request a 24-bit deep visual we may actually need/get
  175. * 32bpp XImages. This function returns the appropriate bpp.
  176. * Input: dpy - the X display
  177. * visinfo - desribes the visual to be used for XImages
  178. * Return: true number of bits per pixel for XImages
  179. */
  180. static int
  181. bits_per_pixel( XMesaVisual xmv )
  182. {
  183. Display *dpy = xmv->display;
  184. XVisualInfo * visinfo = xmv->visinfo;
  185. XImage *img;
  186. int bitsPerPixel;
  187. /* Create a temporary XImage */
  188. img = XCreateImage( dpy, visinfo->visual, visinfo->depth,
  189. ZPixmap, 0, /*format, offset*/
  190. (char*) MALLOC(8), /*data*/
  191. 1, 1, /*width, height*/
  192. 32, /*bitmap_pad*/
  193. 0 /*bytes_per_line*/
  194. );
  195. assert(img);
  196. /* grab the bits/pixel value */
  197. bitsPerPixel = img->bits_per_pixel;
  198. /* free the XImage */
  199. free( img->data );
  200. img->data = NULL;
  201. XDestroyImage( img );
  202. return bitsPerPixel;
  203. }
  204. /*
  205. * Determine if a given X window ID is valid (window exists).
  206. * Do this by calling XGetWindowAttributes() for the window and
  207. * checking if we catch an X error.
  208. * Input: dpy - the display
  209. * win - the window to check for existance
  210. * Return: GL_TRUE - window exists
  211. * GL_FALSE - window doesn't exist
  212. */
  213. static GLboolean WindowExistsFlag;
  214. static int window_exists_err_handler( Display* dpy, XErrorEvent* xerr )
  215. {
  216. (void) dpy;
  217. if (xerr->error_code == BadWindow) {
  218. WindowExistsFlag = GL_FALSE;
  219. }
  220. return 0;
  221. }
  222. static GLboolean window_exists( Display *dpy, Window win )
  223. {
  224. XWindowAttributes wa;
  225. int (*old_handler)( Display*, XErrorEvent* );
  226. WindowExistsFlag = GL_TRUE;
  227. old_handler = XSetErrorHandler(window_exists_err_handler);
  228. XGetWindowAttributes( dpy, win, &wa ); /* dummy request */
  229. XSetErrorHandler(old_handler);
  230. return WindowExistsFlag;
  231. }
  232. static Status
  233. get_drawable_size( Display *dpy, Drawable d, uint *width, uint *height )
  234. {
  235. Window root;
  236. Status stat;
  237. int xpos, ypos;
  238. unsigned int w, h, bw, depth;
  239. stat = XGetGeometry(dpy, d, &root, &xpos, &ypos, &w, &h, &bw, &depth);
  240. *width = w;
  241. *height = h;
  242. return stat;
  243. }
  244. /**
  245. * Return the size of the window (or pixmap) that corresponds to the
  246. * given XMesaBuffer.
  247. * \param width returns width in pixels
  248. * \param height returns height in pixels
  249. */
  250. void
  251. xmesa_get_window_size(Display *dpy, XMesaBuffer b,
  252. GLuint *width, GLuint *height)
  253. {
  254. XMesaDisplay xmdpy = xmesa_init_display(dpy);
  255. Status stat;
  256. pipe_mutex_lock(xmdpy->mutex);
  257. stat = get_drawable_size(dpy, b->ws.drawable, width, height);
  258. pipe_mutex_unlock(xmdpy->mutex);
  259. if (!stat) {
  260. /* probably querying a window that's recently been destroyed */
  261. _mesa_warning(NULL, "XGetGeometry failed!\n");
  262. *width = *height = 1;
  263. }
  264. }
  265. #define GET_REDMASK(__v) __v->mesa_visual.redMask
  266. #define GET_GREENMASK(__v) __v->mesa_visual.greenMask
  267. #define GET_BLUEMASK(__v) __v->mesa_visual.blueMask
  268. /**
  269. * Choose the pixel format for the given visual.
  270. * This will tell the gallium driver how to pack pixel data into
  271. * drawing surfaces.
  272. */
  273. static GLuint
  274. choose_pixel_format(XMesaVisual v)
  275. {
  276. boolean native_byte_order = (host_byte_order() ==
  277. ImageByteOrder(v->display));
  278. if ( GET_REDMASK(v) == 0x0000ff
  279. && GET_GREENMASK(v) == 0x00ff00
  280. && GET_BLUEMASK(v) == 0xff0000
  281. && v->BitsPerPixel == 32) {
  282. if (native_byte_order) {
  283. /* no byteswapping needed */
  284. return PIPE_FORMAT_R8G8B8A8_UNORM;
  285. }
  286. else {
  287. return PIPE_FORMAT_A8B8G8R8_UNORM;
  288. }
  289. }
  290. else if ( GET_REDMASK(v) == 0xff0000
  291. && GET_GREENMASK(v) == 0x00ff00
  292. && GET_BLUEMASK(v) == 0x0000ff
  293. && v->BitsPerPixel == 32) {
  294. if (native_byte_order) {
  295. /* no byteswapping needed */
  296. return PIPE_FORMAT_B8G8R8A8_UNORM;
  297. }
  298. else {
  299. return PIPE_FORMAT_A8R8G8B8_UNORM;
  300. }
  301. }
  302. else if ( GET_REDMASK(v) == 0x0000ff00
  303. && GET_GREENMASK(v) == 0x00ff0000
  304. && GET_BLUEMASK(v) == 0xff000000
  305. && v->BitsPerPixel == 32) {
  306. if (native_byte_order) {
  307. /* no byteswapping needed */
  308. return PIPE_FORMAT_A8R8G8B8_UNORM;
  309. }
  310. else {
  311. return PIPE_FORMAT_B8G8R8A8_UNORM;
  312. }
  313. }
  314. else if ( GET_REDMASK(v) == 0xf800
  315. && GET_GREENMASK(v) == 0x07e0
  316. && GET_BLUEMASK(v) == 0x001f
  317. && native_byte_order
  318. && v->BitsPerPixel == 16) {
  319. /* 5-6-5 RGB */
  320. return PIPE_FORMAT_B5G6R5_UNORM;
  321. }
  322. return PIPE_FORMAT_NONE;
  323. }
  324. /**
  325. * Choose a depth/stencil format that satisfies the given depth and
  326. * stencil sizes.
  327. */
  328. static enum pipe_format
  329. choose_depth_stencil_format(XMesaDisplay xmdpy, int depth, int stencil)
  330. {
  331. const enum pipe_texture_target target = PIPE_TEXTURE_2D;
  332. const unsigned tex_usage = PIPE_BIND_DEPTH_STENCIL;
  333. const unsigned sample_count = 0;
  334. enum pipe_format formats[8], fmt;
  335. int count, i;
  336. count = 0;
  337. if (depth <= 16 && stencil == 0) {
  338. formats[count++] = PIPE_FORMAT_Z16_UNORM;
  339. }
  340. if (depth <= 24 && stencil == 0) {
  341. formats[count++] = PIPE_FORMAT_X8Z24_UNORM;
  342. formats[count++] = PIPE_FORMAT_Z24X8_UNORM;
  343. }
  344. if (depth <= 24 && stencil <= 8) {
  345. formats[count++] = PIPE_FORMAT_S8_USCALED_Z24_UNORM;
  346. formats[count++] = PIPE_FORMAT_Z24_UNORM_S8_USCALED;
  347. }
  348. if (depth <= 32 && stencil == 0) {
  349. formats[count++] = PIPE_FORMAT_Z32_UNORM;
  350. }
  351. fmt = PIPE_FORMAT_NONE;
  352. for (i = 0; i < count; i++) {
  353. if (xmdpy->screen->is_format_supported(xmdpy->screen, formats[i],
  354. target, sample_count,
  355. tex_usage)) {
  356. fmt = formats[i];
  357. break;
  358. }
  359. }
  360. return fmt;
  361. }
  362. /**********************************************************************/
  363. /***** Linked list of XMesaBuffers *****/
  364. /**********************************************************************/
  365. static XMesaBuffer XMesaBufferList = NULL;
  366. /**
  367. * Allocate a new XMesaBuffer object which corresponds to the given drawable.
  368. * Note that XMesaBuffer is derived from struct gl_framebuffer.
  369. * The new XMesaBuffer will not have any size (Width=Height=0).
  370. *
  371. * \param d the corresponding X drawable (window or pixmap)
  372. * \param type either WINDOW, PIXMAP or PBUFFER, describing d
  373. * \param vis the buffer's visual
  374. * \param cmap the window's colormap, if known.
  375. * \return new XMesaBuffer or NULL if any problem
  376. */
  377. static XMesaBuffer
  378. create_xmesa_buffer(Drawable d, BufferType type,
  379. XMesaVisual vis, Colormap cmap)
  380. {
  381. XMesaDisplay xmdpy = xmesa_init_display(vis->display);
  382. XMesaBuffer b;
  383. uint width, height;
  384. ASSERT(type == WINDOW || type == PIXMAP || type == PBUFFER);
  385. if (!xmdpy)
  386. return NULL;
  387. b = (XMesaBuffer) CALLOC_STRUCT(xmesa_buffer);
  388. if (!b)
  389. return NULL;
  390. b->ws.drawable = d;
  391. b->ws.visual = vis->visinfo->visual;
  392. b->ws.depth = vis->visinfo->depth;
  393. b->xm_visual = vis;
  394. b->type = type;
  395. b->cmap = cmap;
  396. get_drawable_size(vis->display, d, &width, &height);
  397. /*
  398. * Create framebuffer, but we'll plug in our own renderbuffers below.
  399. */
  400. b->stfb = xmesa_create_st_framebuffer(xmdpy, b);
  401. /* GLX_EXT_texture_from_pixmap */
  402. b->TextureTarget = 0;
  403. b->TextureFormat = GLX_TEXTURE_FORMAT_NONE_EXT;
  404. b->TextureMipmap = 0;
  405. /* insert buffer into linked list */
  406. b->Next = XMesaBufferList;
  407. XMesaBufferList = b;
  408. return b;
  409. }
  410. /**
  411. * Find an XMesaBuffer by matching X display and colormap but NOT matching
  412. * the notThis buffer.
  413. */
  414. XMesaBuffer
  415. xmesa_find_buffer(Display *dpy, Colormap cmap, XMesaBuffer notThis)
  416. {
  417. XMesaBuffer b;
  418. for (b = XMesaBufferList; b; b = b->Next) {
  419. if (b->xm_visual->display == dpy &&
  420. b->cmap == cmap &&
  421. b != notThis) {
  422. return b;
  423. }
  424. }
  425. return NULL;
  426. }
  427. /**
  428. * Remove buffer from linked list, delete if no longer referenced.
  429. */
  430. static void
  431. xmesa_free_buffer(XMesaBuffer buffer)
  432. {
  433. XMesaBuffer prev = NULL, b;
  434. for (b = XMesaBufferList; b; b = b->Next) {
  435. if (b == buffer) {
  436. /* unlink buffer from list */
  437. if (prev)
  438. prev->Next = buffer->Next;
  439. else
  440. XMesaBufferList = buffer->Next;
  441. /* Since the X window for the XMesaBuffer is going away, we don't
  442. * want to dereference this pointer in the future.
  443. */
  444. b->ws.drawable = 0;
  445. /* XXX we should move the buffer to a delete-pending list and destroy
  446. * the buffer until it is no longer current.
  447. */
  448. xmesa_destroy_st_framebuffer(buffer->stfb);
  449. free(buffer);
  450. return;
  451. }
  452. /* continue search */
  453. prev = b;
  454. }
  455. /* buffer not found in XMesaBufferList */
  456. _mesa_problem(NULL,"xmesa_free_buffer() - buffer not found\n");
  457. }
  458. /**********************************************************************/
  459. /***** Misc Private Functions *****/
  460. /**********************************************************************/
  461. /**
  462. * When a context is bound for the first time, we can finally finish
  463. * initializing the context's visual and buffer information.
  464. * \param v the XMesaVisual to initialize
  465. * \param b the XMesaBuffer to initialize (may be NULL)
  466. * \param rgb_flag TRUE = RGBA mode, FALSE = color index mode
  467. * \param window the window/pixmap we're rendering into
  468. * \param cmap the colormap associated with the window/pixmap
  469. * \return GL_TRUE=success, GL_FALSE=failure
  470. */
  471. static GLboolean
  472. initialize_visual_and_buffer(XMesaVisual v, XMesaBuffer b,
  473. GLboolean rgb_flag, Drawable window,
  474. Colormap cmap)
  475. {
  476. ASSERT(!b || b->xm_visual == v);
  477. /* Save true bits/pixel */
  478. v->BitsPerPixel = bits_per_pixel(v);
  479. assert(v->BitsPerPixel > 0);
  480. if (rgb_flag == GL_FALSE) {
  481. /* COLOR-INDEXED WINDOW: not supported*/
  482. return GL_FALSE;
  483. }
  484. else {
  485. /* RGB WINDOW:
  486. * We support RGB rendering into almost any kind of visual.
  487. */
  488. const int xclass = v->visualType;
  489. if (xclass != GLX_TRUE_COLOR && xclass == !GLX_DIRECT_COLOR) {
  490. _mesa_warning(NULL,
  491. "XMesa: RGB mode rendering not supported in given visual.\n");
  492. return GL_FALSE;
  493. }
  494. v->mesa_visual.indexBits = 0;
  495. if (v->BitsPerPixel == 32) {
  496. /* We use XImages for all front/back buffers. If an X Window or
  497. * X Pixmap is 32bpp, there's no guarantee that the alpha channel
  498. * will be preserved. For XImages we're in luck.
  499. */
  500. v->mesa_visual.alphaBits = 8;
  501. }
  502. }
  503. /*
  504. * If MESA_INFO env var is set print out some debugging info
  505. * which can help Brian figure out what's going on when a user
  506. * reports bugs.
  507. */
  508. if (_mesa_getenv("MESA_INFO")) {
  509. printf("X/Mesa visual = %p\n", (void *) v);
  510. printf("X/Mesa level = %d\n", v->mesa_visual.level);
  511. printf("X/Mesa depth = %d\n", v->visinfo->depth);
  512. printf("X/Mesa bits per pixel = %d\n", v->BitsPerPixel);
  513. }
  514. return GL_TRUE;
  515. }
  516. #define NUM_VISUAL_TYPES 6
  517. /**
  518. * Convert an X visual type to a GLX visual type.
  519. *
  520. * \param visualType X visual type (i.e., \c TrueColor, \c StaticGray, etc.)
  521. * to be converted.
  522. * \return If \c visualType is a valid X visual type, a GLX visual type will
  523. * be returned. Otherwise \c GLX_NONE will be returned.
  524. *
  525. * \note
  526. * This code was lifted directly from lib/GL/glx/glcontextmodes.c in the
  527. * DRI CVS tree.
  528. */
  529. static GLint
  530. xmesa_convert_from_x_visual_type( int visualType )
  531. {
  532. static const int glx_visual_types[ NUM_VISUAL_TYPES ] = {
  533. GLX_STATIC_GRAY, GLX_GRAY_SCALE,
  534. GLX_STATIC_COLOR, GLX_PSEUDO_COLOR,
  535. GLX_TRUE_COLOR, GLX_DIRECT_COLOR
  536. };
  537. return ( (unsigned) visualType < NUM_VISUAL_TYPES )
  538. ? glx_visual_types[ visualType ] : GLX_NONE;
  539. }
  540. /**********************************************************************/
  541. /***** Public Functions *****/
  542. /**********************************************************************/
  543. /*
  544. * Create a new X/Mesa visual.
  545. * Input: display - X11 display
  546. * visinfo - an XVisualInfo pointer
  547. * rgb_flag - GL_TRUE = RGB mode,
  548. * GL_FALSE = color index mode
  549. * alpha_flag - alpha buffer requested?
  550. * db_flag - GL_TRUE = double-buffered,
  551. * GL_FALSE = single buffered
  552. * stereo_flag - stereo visual?
  553. * ximage_flag - GL_TRUE = use an XImage for back buffer,
  554. * GL_FALSE = use an off-screen pixmap for back buffer
  555. * depth_size - requested bits/depth values, or zero
  556. * stencil_size - requested bits/stencil values, or zero
  557. * accum_red_size - requested bits/red accum values, or zero
  558. * accum_green_size - requested bits/green accum values, or zero
  559. * accum_blue_size - requested bits/blue accum values, or zero
  560. * accum_alpha_size - requested bits/alpha accum values, or zero
  561. * num_samples - number of samples/pixel if multisampling, or zero
  562. * level - visual level, usually 0
  563. * visualCaveat - ala the GLX extension, usually GLX_NONE
  564. * Return; a new XMesaVisual or 0 if error.
  565. */
  566. PUBLIC
  567. XMesaVisual XMesaCreateVisual( Display *display,
  568. XVisualInfo * visinfo,
  569. GLboolean rgb_flag,
  570. GLboolean alpha_flag,
  571. GLboolean db_flag,
  572. GLboolean stereo_flag,
  573. GLboolean ximage_flag,
  574. GLint depth_size,
  575. GLint stencil_size,
  576. GLint accum_red_size,
  577. GLint accum_green_size,
  578. GLint accum_blue_size,
  579. GLint accum_alpha_size,
  580. GLint num_samples,
  581. GLint level,
  582. GLint visualCaveat )
  583. {
  584. XMesaDisplay xmdpy = xmesa_init_display(display);
  585. XMesaVisual v;
  586. GLint red_bits, green_bits, blue_bits, alpha_bits;
  587. if (!xmdpy)
  588. return NULL;
  589. /* For debugging only */
  590. if (_mesa_getenv("MESA_XSYNC")) {
  591. /* This makes debugging X easier.
  592. * In your debugger, set a breakpoint on _XError to stop when an
  593. * X protocol error is generated.
  594. */
  595. XSynchronize( display, 1 );
  596. }
  597. v = (XMesaVisual) CALLOC_STRUCT(xmesa_visual);
  598. if (!v) {
  599. return NULL;
  600. }
  601. v->display = display;
  602. /* Save a copy of the XVisualInfo struct because the user may Xfree()
  603. * the struct but we may need some of the information contained in it
  604. * at a later time.
  605. */
  606. v->visinfo = (XVisualInfo *) MALLOC(sizeof(*visinfo));
  607. if (!v->visinfo) {
  608. free(v);
  609. return NULL;
  610. }
  611. memcpy(v->visinfo, visinfo, sizeof(*visinfo));
  612. v->ximage_flag = ximage_flag;
  613. v->mesa_visual.redMask = visinfo->red_mask;
  614. v->mesa_visual.greenMask = visinfo->green_mask;
  615. v->mesa_visual.blueMask = visinfo->blue_mask;
  616. v->visualID = visinfo->visualid;
  617. v->screen = visinfo->screen;
  618. #if !(defined(__cplusplus) || defined(c_plusplus))
  619. v->visualType = xmesa_convert_from_x_visual_type(visinfo->class);
  620. #else
  621. v->visualType = xmesa_convert_from_x_visual_type(visinfo->c_class);
  622. #endif
  623. v->mesa_visual.visualRating = visualCaveat;
  624. if (alpha_flag)
  625. v->mesa_visual.alphaBits = 8;
  626. (void) initialize_visual_and_buffer( v, NULL, rgb_flag, 0, 0 );
  627. {
  628. const int xclass = v->visualType;
  629. if (xclass == GLX_TRUE_COLOR || xclass == GLX_DIRECT_COLOR) {
  630. red_bits = _mesa_bitcount(GET_REDMASK(v));
  631. green_bits = _mesa_bitcount(GET_GREENMASK(v));
  632. blue_bits = _mesa_bitcount(GET_BLUEMASK(v));
  633. }
  634. else {
  635. /* this is an approximation */
  636. int depth;
  637. depth = v->visinfo->depth;
  638. red_bits = depth / 3;
  639. depth -= red_bits;
  640. green_bits = depth / 2;
  641. depth -= green_bits;
  642. blue_bits = depth;
  643. alpha_bits = 0;
  644. assert( red_bits + green_bits + blue_bits == v->visinfo->depth );
  645. }
  646. alpha_bits = v->mesa_visual.alphaBits;
  647. }
  648. /* initialize visual */
  649. {
  650. struct gl_config *vis = &v->mesa_visual;
  651. vis->rgbMode = GL_TRUE;
  652. vis->doubleBufferMode = db_flag;
  653. vis->stereoMode = stereo_flag;
  654. vis->redBits = red_bits;
  655. vis->greenBits = green_bits;
  656. vis->blueBits = blue_bits;
  657. vis->alphaBits = alpha_bits;
  658. vis->rgbBits = red_bits + green_bits + blue_bits;
  659. vis->indexBits = 0;
  660. vis->depthBits = depth_size;
  661. vis->stencilBits = stencil_size;
  662. vis->accumRedBits = accum_red_size;
  663. vis->accumGreenBits = accum_green_size;
  664. vis->accumBlueBits = accum_blue_size;
  665. vis->accumAlphaBits = accum_alpha_size;
  666. vis->haveAccumBuffer = accum_red_size > 0;
  667. vis->haveDepthBuffer = depth_size > 0;
  668. vis->haveStencilBuffer = stencil_size > 0;
  669. vis->numAuxBuffers = 0;
  670. vis->level = 0;
  671. vis->sampleBuffers = 0;
  672. vis->samples = 0;
  673. }
  674. v->stvis.buffer_mask = ST_ATTACHMENT_FRONT_LEFT_MASK;
  675. if (db_flag)
  676. v->stvis.buffer_mask |= ST_ATTACHMENT_BACK_LEFT_MASK;
  677. if (stereo_flag) {
  678. v->stvis.buffer_mask |= ST_ATTACHMENT_FRONT_RIGHT_MASK;
  679. if (db_flag)
  680. v->stvis.buffer_mask |= ST_ATTACHMENT_BACK_RIGHT_MASK;
  681. }
  682. v->stvis.color_format = choose_pixel_format(v);
  683. if (v->stvis.color_format == PIPE_FORMAT_NONE) {
  684. FREE(v->visinfo);
  685. FREE(v);
  686. return NULL;
  687. }
  688. v->stvis.depth_stencil_format =
  689. choose_depth_stencil_format(xmdpy, depth_size, stencil_size);
  690. v->stvis.accum_format = (accum_red_size +
  691. accum_green_size + accum_blue_size + accum_alpha_size) ?
  692. PIPE_FORMAT_R16G16B16A16_SNORM : PIPE_FORMAT_NONE;
  693. v->stvis.samples = num_samples;
  694. v->stvis.render_buffer = ST_ATTACHMENT_INVALID;
  695. /* XXX minor hack */
  696. v->mesa_visual.level = level;
  697. return v;
  698. }
  699. PUBLIC
  700. void XMesaDestroyVisual( XMesaVisual v )
  701. {
  702. free(v->visinfo);
  703. free(v);
  704. }
  705. /**
  706. * Return the informative name.
  707. */
  708. const char *
  709. xmesa_get_name(void)
  710. {
  711. return stapi->name;
  712. }
  713. /**
  714. * Do per-display initializations.
  715. */
  716. void
  717. xmesa_init( Display *display )
  718. {
  719. xmesa_init_display(display);
  720. }
  721. /**
  722. * Create a new XMesaContext.
  723. * \param v the XMesaVisual
  724. * \param share_list another XMesaContext with which to share display
  725. * lists or NULL if no sharing is wanted.
  726. * \return an XMesaContext or NULL if error.
  727. */
  728. PUBLIC
  729. XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list,
  730. GLuint major, GLuint minor,
  731. GLuint profileMask, GLuint contextFlags)
  732. {
  733. XMesaDisplay xmdpy = xmesa_init_display(v->display);
  734. struct st_context_attribs attribs;
  735. XMesaContext c;
  736. if (!xmdpy)
  737. return NULL;
  738. /* Note: the XMesaContext contains a Mesa struct gl_context struct (inheritance) */
  739. c = (XMesaContext) CALLOC_STRUCT(xmesa_context);
  740. if (!c)
  741. return NULL;
  742. c->xm_visual = v;
  743. c->xm_buffer = NULL; /* set later by XMesaMakeCurrent */
  744. c->xm_read_buffer = NULL;
  745. memset(&attribs, 0, sizeof(attribs));
  746. attribs.profile = ST_PROFILE_DEFAULT;
  747. attribs.visual = v->stvis;
  748. attribs.major = major;
  749. attribs.minor = minor;
  750. if (contextFlags & GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB)
  751. attribs.flags |= ST_CONTEXT_FLAG_FORWARD_COMPATIBLE;
  752. if (contextFlags & GLX_CONTEXT_DEBUG_BIT_ARB)
  753. attribs.flags |= ST_CONTEXT_FLAG_DEBUG;
  754. if (contextFlags & GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB)
  755. attribs.flags |= ST_CONTEXT_FLAG_ROBUST_ACCESS;
  756. if (profileMask & GLX_CONTEXT_CORE_PROFILE_BIT_ARB)
  757. attribs.flags |= ST_CONTEXT_FLAG_CORE_PROFILE;
  758. if (profileMask & GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB)
  759. attribs.flags |= ST_CONTEXT_FLAG_COMPATIBLE_PROFILE;
  760. c->st = stapi->create_context(stapi, xmdpy->smapi,
  761. &attribs, (share_list) ? share_list->st : NULL);
  762. if (c->st == NULL)
  763. goto fail;
  764. c->st->st_manager_private = (void *) c;
  765. return c;
  766. fail:
  767. if (c->st)
  768. c->st->destroy(c->st);
  769. free(c);
  770. return NULL;
  771. }
  772. PUBLIC
  773. void XMesaDestroyContext( XMesaContext c )
  774. {
  775. c->st->destroy(c->st);
  776. /* FIXME: We should destroy the screen here, but if we do so, surfaces may
  777. * outlive it, causing segfaults
  778. struct pipe_screen *screen = c->st->pipe->screen;
  779. screen->destroy(screen);
  780. */
  781. free(c);
  782. }
  783. /**
  784. * Private function for creating an XMesaBuffer which corresponds to an
  785. * X window or pixmap.
  786. * \param v the window's XMesaVisual
  787. * \param w the window we're wrapping
  788. * \return new XMesaBuffer or NULL if error
  789. */
  790. PUBLIC XMesaBuffer
  791. XMesaCreateWindowBuffer(XMesaVisual v, Window w)
  792. {
  793. XWindowAttributes attr;
  794. XMesaBuffer b;
  795. Colormap cmap;
  796. int depth;
  797. assert(v);
  798. assert(w);
  799. /* Check that window depth matches visual depth */
  800. XGetWindowAttributes( v->display, w, &attr );
  801. depth = attr.depth;
  802. if (v->visinfo->depth != depth) {
  803. _mesa_warning(NULL, "XMesaCreateWindowBuffer: depth mismatch between visual (%d) and window (%d)!\n",
  804. v->visinfo->depth, depth);
  805. return NULL;
  806. }
  807. /* Find colormap */
  808. if (attr.colormap) {
  809. cmap = attr.colormap;
  810. }
  811. else {
  812. _mesa_warning(NULL, "Window %u has no colormap!\n", (unsigned int) w);
  813. /* this is weird, a window w/out a colormap!? */
  814. /* OK, let's just allocate a new one and hope for the best */
  815. cmap = XCreateColormap(v->display, w, attr.visual, AllocNone);
  816. }
  817. b = create_xmesa_buffer((Drawable) w, WINDOW, v, cmap);
  818. if (!b)
  819. return NULL;
  820. if (!initialize_visual_and_buffer( v, b, v->mesa_visual.rgbMode,
  821. (Drawable) w, cmap )) {
  822. xmesa_free_buffer(b);
  823. return NULL;
  824. }
  825. return b;
  826. }
  827. /**
  828. * Create a new XMesaBuffer from an X pixmap.
  829. *
  830. * \param v the XMesaVisual
  831. * \param p the pixmap
  832. * \param cmap the colormap, may be 0 if using a \c GLX_TRUE_COLOR or
  833. * \c GLX_DIRECT_COLOR visual for the pixmap
  834. * \returns new XMesaBuffer or NULL if error
  835. */
  836. PUBLIC XMesaBuffer
  837. XMesaCreatePixmapBuffer(XMesaVisual v, Pixmap p, Colormap cmap)
  838. {
  839. XMesaBuffer b;
  840. assert(v);
  841. b = create_xmesa_buffer((Drawable) p, PIXMAP, v, cmap);
  842. if (!b)
  843. return NULL;
  844. if (!initialize_visual_and_buffer(v, b, v->mesa_visual.rgbMode,
  845. (Drawable) p, cmap)) {
  846. xmesa_free_buffer(b);
  847. return NULL;
  848. }
  849. return b;
  850. }
  851. /**
  852. * For GLX_EXT_texture_from_pixmap
  853. */
  854. XMesaBuffer
  855. XMesaCreatePixmapTextureBuffer(XMesaVisual v, Pixmap p,
  856. Colormap cmap,
  857. int format, int target, int mipmap)
  858. {
  859. GET_CURRENT_CONTEXT(ctx);
  860. XMesaBuffer b;
  861. assert(v);
  862. b = create_xmesa_buffer((Drawable) p, PIXMAP, v, cmap);
  863. if (!b)
  864. return NULL;
  865. /* get pixmap size */
  866. xmesa_get_window_size(v->display, b, &b->width, &b->height);
  867. if (target == 0) {
  868. /* examine dims */
  869. if (ctx->Extensions.ARB_texture_non_power_of_two) {
  870. target = GLX_TEXTURE_2D_EXT;
  871. }
  872. else if ( _mesa_bitcount(b->width) == 1
  873. && _mesa_bitcount(b->height) == 1) {
  874. /* power of two size */
  875. if (b->height == 1) {
  876. target = GLX_TEXTURE_1D_EXT;
  877. }
  878. else {
  879. target = GLX_TEXTURE_2D_EXT;
  880. }
  881. }
  882. else if (ctx->Extensions.NV_texture_rectangle) {
  883. target = GLX_TEXTURE_RECTANGLE_EXT;
  884. }
  885. else {
  886. /* non power of two textures not supported */
  887. XMesaDestroyBuffer(b);
  888. return 0;
  889. }
  890. }
  891. b->TextureTarget = target;
  892. b->TextureFormat = format;
  893. b->TextureMipmap = mipmap;
  894. if (!initialize_visual_and_buffer(v, b, v->mesa_visual.rgbMode,
  895. (Drawable) p, cmap)) {
  896. xmesa_free_buffer(b);
  897. return NULL;
  898. }
  899. return b;
  900. }
  901. XMesaBuffer
  902. XMesaCreatePBuffer(XMesaVisual v, Colormap cmap,
  903. unsigned int width, unsigned int height)
  904. {
  905. Window root;
  906. Drawable drawable; /* X Pixmap Drawable */
  907. XMesaBuffer b;
  908. /* allocate pixmap for front buffer */
  909. root = RootWindow( v->display, v->visinfo->screen );
  910. drawable = XCreatePixmap(v->display, root, width, height,
  911. v->visinfo->depth);
  912. if (!drawable)
  913. return NULL;
  914. b = create_xmesa_buffer(drawable, PBUFFER, v, cmap);
  915. if (!b)
  916. return NULL;
  917. if (!initialize_visual_and_buffer(v, b, v->mesa_visual.rgbMode,
  918. drawable, cmap)) {
  919. xmesa_free_buffer(b);
  920. return NULL;
  921. }
  922. return b;
  923. }
  924. /*
  925. * Deallocate an XMesaBuffer structure and all related info.
  926. */
  927. PUBLIC void
  928. XMesaDestroyBuffer(XMesaBuffer b)
  929. {
  930. xmesa_free_buffer(b);
  931. }
  932. /**
  933. * Notify the binding context to validate the buffer.
  934. */
  935. void
  936. xmesa_notify_invalid_buffer(XMesaBuffer b)
  937. {
  938. p_atomic_inc(&b->stfb->stamp);
  939. }
  940. /**
  941. * Query the current drawable size and notify the binding context.
  942. */
  943. void
  944. xmesa_check_buffer_size(XMesaBuffer b)
  945. {
  946. GLuint old_width, old_height;
  947. if (b->type == PBUFFER)
  948. return;
  949. old_width = b->width;
  950. old_height = b->height;
  951. xmesa_get_window_size(b->xm_visual->display, b, &b->width, &b->height);
  952. if (b->width != old_width || b->height != old_height)
  953. xmesa_notify_invalid_buffer(b);
  954. }
  955. /*
  956. * Bind buffer b to context c and make c the current rendering context.
  957. */
  958. PUBLIC
  959. GLboolean XMesaMakeCurrent2( XMesaContext c, XMesaBuffer drawBuffer,
  960. XMesaBuffer readBuffer )
  961. {
  962. XMesaContext old_ctx = XMesaGetCurrentContext();
  963. if (old_ctx && old_ctx != c) {
  964. XMesaFlush(old_ctx);
  965. old_ctx->xm_buffer = NULL;
  966. old_ctx->xm_read_buffer = NULL;
  967. }
  968. if (c) {
  969. if (!drawBuffer || !readBuffer)
  970. return GL_FALSE; /* must specify buffers! */
  971. if (c == old_ctx &&
  972. c->xm_buffer == drawBuffer &&
  973. c->xm_read_buffer == readBuffer)
  974. return GL_TRUE;
  975. xmesa_check_buffer_size(drawBuffer);
  976. if (readBuffer != drawBuffer)
  977. xmesa_check_buffer_size(readBuffer);
  978. c->xm_buffer = drawBuffer;
  979. c->xm_read_buffer = readBuffer;
  980. stapi->make_current(stapi, c->st, drawBuffer->stfb, readBuffer->stfb);
  981. /* Solution to Stephane Rehel's problem with glXReleaseBuffersMESA(): */
  982. drawBuffer->wasCurrent = GL_TRUE;
  983. }
  984. else {
  985. /* Detach */
  986. stapi->make_current(stapi, NULL, NULL, NULL);
  987. }
  988. return GL_TRUE;
  989. }
  990. /*
  991. * Unbind the context c from its buffer.
  992. */
  993. GLboolean XMesaUnbindContext( XMesaContext c )
  994. {
  995. /* A no-op for XFree86 integration purposes */
  996. return GL_TRUE;
  997. }
  998. XMesaContext XMesaGetCurrentContext( void )
  999. {
  1000. struct st_context_iface *st = stapi->get_current(stapi);
  1001. return (XMesaContext) (st) ? st->st_manager_private : NULL;
  1002. }
  1003. /**
  1004. * Swap front and back color buffers and have winsys display front buffer.
  1005. * If there's no front color buffer no swap actually occurs.
  1006. */
  1007. PUBLIC
  1008. void XMesaSwapBuffers( XMesaBuffer b )
  1009. {
  1010. XMesaContext xmctx = XMesaGetCurrentContext();
  1011. if (xmctx && xmctx->xm_buffer == b) {
  1012. xmctx->st->flush( xmctx->st, ST_FLUSH_FRONT, NULL);
  1013. }
  1014. xmesa_swap_st_framebuffer(b->stfb);
  1015. }
  1016. /*
  1017. * Copy sub-region of back buffer to front buffer
  1018. */
  1019. void XMesaCopySubBuffer( XMesaBuffer b, int x, int y, int width, int height )
  1020. {
  1021. xmesa_copy_st_framebuffer(b->stfb,
  1022. ST_ATTACHMENT_BACK_LEFT, ST_ATTACHMENT_FRONT_LEFT,
  1023. x, y, width, height);
  1024. }
  1025. void XMesaFlush( XMesaContext c )
  1026. {
  1027. if (c && c->xm_visual->display) {
  1028. XMesaDisplay xmdpy = xmesa_init_display(c->xm_visual->display);
  1029. struct pipe_fence_handle *fence = NULL;
  1030. c->st->flush(c->st, ST_FLUSH_FRONT, &fence);
  1031. if (fence) {
  1032. xmdpy->screen->fence_finish(xmdpy->screen, fence,
  1033. PIPE_TIMEOUT_INFINITE);
  1034. xmdpy->screen->fence_reference(xmdpy->screen, &fence, NULL);
  1035. }
  1036. XFlush( c->xm_visual->display );
  1037. }
  1038. }
  1039. XMesaBuffer XMesaFindBuffer( Display *dpy, Drawable d )
  1040. {
  1041. XMesaBuffer b;
  1042. for (b = XMesaBufferList; b; b = b->Next) {
  1043. if (b->ws.drawable == d && b->xm_visual->display == dpy) {
  1044. return b;
  1045. }
  1046. }
  1047. return NULL;
  1048. }
  1049. /**
  1050. * Free/destroy all XMesaBuffers associated with given display.
  1051. */
  1052. void xmesa_destroy_buffers_on_display(Display *dpy)
  1053. {
  1054. XMesaBuffer b, next;
  1055. for (b = XMesaBufferList; b; b = next) {
  1056. next = b->Next;
  1057. if (b->xm_visual->display == dpy) {
  1058. xmesa_free_buffer(b);
  1059. /* delete head of list? */
  1060. if (XMesaBufferList == b) {
  1061. XMesaBufferList = next;
  1062. }
  1063. }
  1064. }
  1065. }
  1066. /*
  1067. * Look for XMesaBuffers whose X window has been destroyed.
  1068. * Deallocate any such XMesaBuffers.
  1069. */
  1070. void XMesaGarbageCollect( void )
  1071. {
  1072. XMesaBuffer b, next;
  1073. for (b=XMesaBufferList; b; b=next) {
  1074. next = b->Next;
  1075. if (b->xm_visual &&
  1076. b->xm_visual->display &&
  1077. b->ws.drawable &&
  1078. b->type == WINDOW) {
  1079. XSync(b->xm_visual->display, False);
  1080. if (!window_exists( b->xm_visual->display, b->ws.drawable )) {
  1081. /* found a dead window, free the ancillary info */
  1082. XMesaDestroyBuffer( b );
  1083. }
  1084. }
  1085. }
  1086. }
  1087. PUBLIC void
  1088. XMesaBindTexImage(Display *dpy, XMesaBuffer drawable, int buffer,
  1089. const int *attrib_list)
  1090. {
  1091. }
  1092. PUBLIC void
  1093. XMesaReleaseTexImage(Display *dpy, XMesaBuffer drawable, int buffer)
  1094. {
  1095. }
  1096. void
  1097. XMesaCopyContext(XMesaContext src, XMesaContext dst, unsigned long mask)
  1098. {
  1099. if (dst->st->copy)
  1100. dst->st->copy(dst->st, src->st, mask);
  1101. }