Clone of mesa.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

surface.c 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /**************************************************************************
  2. *
  3. * Copyright 2009 Younes Manton.
  4. * All Rights Reserved.
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a
  7. * copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sub license, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  21. * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
  22. * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. *
  26. **************************************************************************/
  27. #include <assert.h>
  28. #include <stdio.h>
  29. #include <X11/Xlibint.h>
  30. #include <pipe/p_video_decoder.h>
  31. #include <pipe/p_video_state.h>
  32. #include <pipe/p_state.h>
  33. #include <util/u_inlines.h>
  34. #include <util/u_memory.h>
  35. #include <util/u_math.h>
  36. #include <vl_winsys.h>
  37. #include "xvmc_private.h"
  38. static const unsigned const_empty_block_mask_420[3][2][2] = {
  39. { { 0x20, 0x10 }, { 0x08, 0x04 } },
  40. { { 0x02, 0x02 }, { 0x02, 0x02 } },
  41. { { 0x01, 0x01 }, { 0x01, 0x01 } }
  42. };
  43. static enum pipe_mpeg12_picture_type PictureToPipe(int xvmc_pic)
  44. {
  45. switch (xvmc_pic) {
  46. case XVMC_TOP_FIELD:
  47. return PIPE_MPEG12_PICTURE_TYPE_FIELD_TOP;
  48. case XVMC_BOTTOM_FIELD:
  49. return PIPE_MPEG12_PICTURE_TYPE_FIELD_BOTTOM;
  50. case XVMC_FRAME_PICTURE:
  51. return PIPE_MPEG12_PICTURE_TYPE_FRAME;
  52. default:
  53. assert(0);
  54. }
  55. XVMC_MSG(XVMC_ERR, "[XvMC] Unrecognized picture type 0x%08X.\n", xvmc_pic);
  56. return -1;
  57. }
  58. static inline void
  59. MacroBlockTypeToPipeWeights(const XvMCMacroBlock *xvmc_mb, unsigned weights[2])
  60. {
  61. assert(xvmc_mb);
  62. switch (xvmc_mb->macroblock_type & (XVMC_MB_TYPE_MOTION_FORWARD | XVMC_MB_TYPE_MOTION_BACKWARD)) {
  63. case XVMC_MB_TYPE_MOTION_FORWARD:
  64. weights[0] = PIPE_VIDEO_MV_WEIGHT_MAX;
  65. weights[1] = PIPE_VIDEO_MV_WEIGHT_MIN;
  66. break;
  67. case (XVMC_MB_TYPE_MOTION_FORWARD | XVMC_MB_TYPE_MOTION_BACKWARD):
  68. weights[0] = PIPE_VIDEO_MV_WEIGHT_HALF;
  69. weights[1] = PIPE_VIDEO_MV_WEIGHT_HALF;
  70. break;
  71. case XVMC_MB_TYPE_MOTION_BACKWARD:
  72. weights[0] = PIPE_VIDEO_MV_WEIGHT_MIN;
  73. weights[1] = PIPE_VIDEO_MV_WEIGHT_MAX;
  74. break;
  75. default:
  76. /* workaround for xines xxmc video out plugin */
  77. if (!(xvmc_mb->macroblock_type & ~XVMC_MB_TYPE_PATTERN)) {
  78. weights[0] = PIPE_VIDEO_MV_WEIGHT_MAX;
  79. weights[1] = PIPE_VIDEO_MV_WEIGHT_MIN;
  80. } else {
  81. weights[0] = PIPE_VIDEO_MV_WEIGHT_MIN;
  82. weights[1] = PIPE_VIDEO_MV_WEIGHT_MIN;
  83. }
  84. break;
  85. }
  86. }
  87. static inline struct pipe_motionvector
  88. MotionVectorToPipe(const XvMCMacroBlock *xvmc_mb, unsigned vector,
  89. unsigned field_select_mask, unsigned weight)
  90. {
  91. struct pipe_motionvector mv;
  92. assert(xvmc_mb);
  93. switch (xvmc_mb->motion_type) {
  94. case XVMC_PREDICTION_FRAME:
  95. mv.top.x = xvmc_mb->PMV[0][vector][0];
  96. mv.top.y = xvmc_mb->PMV[0][vector][1];
  97. mv.top.field_select = PIPE_VIDEO_FRAME;
  98. mv.top.weight = weight;
  99. mv.bottom.x = xvmc_mb->PMV[0][vector][0];
  100. mv.bottom.y = xvmc_mb->PMV[0][vector][1];
  101. mv.bottom.weight = weight;
  102. mv.bottom.field_select = PIPE_VIDEO_FRAME;
  103. break;
  104. case XVMC_PREDICTION_FIELD:
  105. mv.top.x = xvmc_mb->PMV[0][vector][0];
  106. mv.top.y = xvmc_mb->PMV[0][vector][1];
  107. mv.top.field_select = (xvmc_mb->motion_vertical_field_select & field_select_mask) ?
  108. PIPE_VIDEO_BOTTOM_FIELD : PIPE_VIDEO_TOP_FIELD;
  109. mv.top.weight = weight;
  110. mv.bottom.x = xvmc_mb->PMV[1][vector][0];
  111. mv.bottom.y = xvmc_mb->PMV[1][vector][1];
  112. mv.bottom.field_select = (xvmc_mb->motion_vertical_field_select & (field_select_mask << 2)) ?
  113. PIPE_VIDEO_BOTTOM_FIELD : PIPE_VIDEO_TOP_FIELD;
  114. mv.bottom.weight = weight;
  115. break;
  116. default: // TODO: Support DUALPRIME and 16x8
  117. break;
  118. }
  119. return mv;
  120. }
  121. static inline void
  122. UploadYcbcrBlocks(XvMCSurfacePrivate *surface,
  123. const XvMCMacroBlock *xvmc_mb,
  124. const XvMCBlockArray *xvmc_blocks)
  125. {
  126. enum pipe_mpeg12_dct_intra intra;
  127. enum pipe_mpeg12_dct_type coding;
  128. unsigned tb, x, y, luma_blocks;
  129. short *blocks;
  130. assert(surface);
  131. assert(xvmc_mb);
  132. if (!xvmc_mb->coded_block_pattern)
  133. return;
  134. intra = xvmc_mb->macroblock_type & XVMC_MB_TYPE_INTRA ?
  135. PIPE_MPEG12_DCT_INTRA : PIPE_MPEG12_DCT_DELTA;
  136. coding = xvmc_mb->dct_type == XVMC_DCT_TYPE_FIELD ?
  137. PIPE_MPEG12_DCT_TYPE_FIELD : PIPE_MPEG12_DCT_TYPE_FRAME;
  138. blocks = xvmc_blocks->blocks + xvmc_mb->index * BLOCK_SIZE_SAMPLES;
  139. for (y = 0, luma_blocks = 0; y < 2; ++y) {
  140. for (x = 0; x < 2; ++x, ++tb) {
  141. if (xvmc_mb->coded_block_pattern & const_empty_block_mask_420[0][y][x]) {
  142. struct pipe_ycbcr_block *stream = surface->ycbcr[0].stream;
  143. stream->x = xvmc_mb->x * 2 + x;
  144. stream->y = xvmc_mb->y * 2 + y;
  145. stream->intra = intra;
  146. stream->coding = coding;
  147. surface->ycbcr[0].num_blocks_added++;
  148. surface->ycbcr[0].stream++;
  149. luma_blocks++;
  150. }
  151. }
  152. }
  153. if (luma_blocks > 0) {
  154. memcpy(surface->ycbcr[0].buffer, blocks, BLOCK_SIZE_BYTES * luma_blocks);
  155. surface->ycbcr[0].buffer += BLOCK_SIZE_SAMPLES * luma_blocks;
  156. blocks += BLOCK_SIZE_SAMPLES * luma_blocks;
  157. }
  158. /* TODO: Implement 422, 444 */
  159. //assert(ctx->base.chroma_format == PIPE_VIDEO_CHROMA_FORMAT_420);
  160. for (tb = 1; tb < 3; ++tb) {
  161. if (xvmc_mb->coded_block_pattern & const_empty_block_mask_420[tb][0][0]) {
  162. struct pipe_ycbcr_block *stream = surface->ycbcr[tb].stream;
  163. stream->x = xvmc_mb->x;
  164. stream->y = xvmc_mb->y;
  165. stream->intra = intra;
  166. stream->coding = PIPE_MPEG12_DCT_TYPE_FRAME;
  167. memcpy(surface->ycbcr[tb].buffer, blocks, BLOCK_SIZE_BYTES);
  168. surface->ycbcr[tb].num_blocks_added++;
  169. surface->ycbcr[tb].stream++;
  170. surface->ycbcr[tb].buffer += BLOCK_SIZE_SAMPLES;
  171. blocks += BLOCK_SIZE_SAMPLES;
  172. }
  173. }
  174. }
  175. static void
  176. MacroBlocksToPipe(XvMCSurfacePrivate *surface,
  177. unsigned int xvmc_picture_structure,
  178. const XvMCMacroBlock *xvmc_mb,
  179. const XvMCBlockArray *xvmc_blocks,
  180. unsigned int num_macroblocks)
  181. {
  182. unsigned int i, j;
  183. assert(xvmc_mb);
  184. assert(xvmc_blocks);
  185. assert(num_macroblocks);
  186. for (i = 0; i < num_macroblocks; ++i) {
  187. unsigned mv_pos = xvmc_mb->x + surface->mv_stride * xvmc_mb->y;
  188. unsigned mv_weights[2];
  189. if (xvmc_mb->macroblock_type & (XVMC_MB_TYPE_PATTERN | XVMC_MB_TYPE_INTRA))
  190. UploadYcbcrBlocks(surface, xvmc_mb, xvmc_blocks);
  191. MacroBlockTypeToPipeWeights(xvmc_mb, mv_weights);
  192. for (j = 0; j < 2; ++j) {
  193. if (!surface->ref[j].mv) continue;
  194. surface->ref[j].mv[mv_pos] = MotionVectorToPipe
  195. (
  196. xvmc_mb, j,
  197. j ? XVMC_SELECT_FIRST_BACKWARD : XVMC_SELECT_FIRST_FORWARD,
  198. mv_weights[j]
  199. );
  200. }
  201. ++xvmc_mb;
  202. }
  203. }
  204. static void
  205. unmap_and_flush_surface(XvMCSurfacePrivate *surface)
  206. {
  207. struct pipe_video_buffer *ref_frames[2];
  208. XvMCContextPrivate *context_priv;
  209. unsigned i, num_ycbcr_blocks[3];
  210. assert(surface);
  211. context_priv = surface->context->privData;
  212. for ( i = 0; i < 2; ++i ) {
  213. if (surface->ref[i].surface) {
  214. XvMCSurfacePrivate *ref = surface->ref[i].surface->privData;
  215. assert(ref);
  216. unmap_and_flush_surface(ref);
  217. surface->ref[i].surface = NULL;
  218. ref_frames[i] = ref->video_buffer;
  219. } else {
  220. ref_frames[i] = NULL;
  221. }
  222. }
  223. if (surface->mapped) {
  224. surface->decode_buffer->end_frame(surface->decode_buffer);
  225. for (i = 0; i < 3; ++i)
  226. num_ycbcr_blocks[i] = surface->ycbcr[i].num_blocks_added;
  227. context_priv->decoder->flush_buffer(surface->decode_buffer,
  228. num_ycbcr_blocks,
  229. ref_frames,
  230. surface->video_buffer);
  231. surface->mapped = 0;
  232. }
  233. }
  234. PUBLIC
  235. Status XvMCCreateSurface(Display *dpy, XvMCContext *context, XvMCSurface *surface)
  236. {
  237. static const uint8_t dummy_quant[64] = {
  238. 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
  239. 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
  240. 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
  241. 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
  242. 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
  243. 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
  244. 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
  245. 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10
  246. };
  247. XvMCContextPrivate *context_priv;
  248. struct pipe_context *pipe;
  249. XvMCSurfacePrivate *surface_priv;
  250. XVMC_MSG(XVMC_TRACE, "[XvMC] Creating surface %p.\n", surface);
  251. assert(dpy);
  252. if (!context)
  253. return XvMCBadContext;
  254. if (!surface)
  255. return XvMCBadSurface;
  256. context_priv = context->privData;
  257. pipe = context_priv->vctx->pipe;
  258. surface_priv = CALLOC(1, sizeof(XvMCSurfacePrivate));
  259. if (!surface_priv)
  260. return BadAlloc;
  261. surface_priv->decode_buffer = context_priv->decoder->create_buffer(context_priv->decoder);
  262. surface_priv->decode_buffer->set_quant_matrix(surface_priv->decode_buffer, dummy_quant, dummy_quant);
  263. surface_priv->mv_stride = surface_priv->decode_buffer->get_mv_stream_stride(surface_priv->decode_buffer);
  264. surface_priv->video_buffer = pipe->create_video_buffer
  265. (
  266. pipe, PIPE_FORMAT_NV12, context_priv->decoder->chroma_format,
  267. context_priv->decoder->width, context_priv->decoder->height
  268. );
  269. surface_priv->context = context;
  270. surface->surface_id = XAllocID(dpy);
  271. surface->context_id = context->context_id;
  272. surface->surface_type_id = context->surface_type_id;
  273. surface->width = context->width;
  274. surface->height = context->height;
  275. surface->privData = surface_priv;
  276. SyncHandle();
  277. XVMC_MSG(XVMC_TRACE, "[XvMC] Surface %p created.\n", surface);
  278. return Success;
  279. }
  280. PUBLIC
  281. Status XvMCRenderSurface(Display *dpy, XvMCContext *context, unsigned int picture_structure,
  282. XvMCSurface *target_surface, XvMCSurface *past_surface, XvMCSurface *future_surface,
  283. unsigned int flags, unsigned int num_macroblocks, unsigned int first_macroblock,
  284. XvMCMacroBlockArray *macroblocks, XvMCBlockArray *blocks
  285. )
  286. {
  287. struct pipe_video_decode_buffer *t_buffer;
  288. XvMCSurfacePrivate *target_surface_priv;
  289. XvMCSurfacePrivate *past_surface_priv;
  290. XvMCSurfacePrivate *future_surface_priv;
  291. XvMCMacroBlock *xvmc_mb;
  292. unsigned i;
  293. XVMC_MSG(XVMC_TRACE, "[XvMC] Rendering to surface %p, with past %p and future %p\n",
  294. target_surface, past_surface, future_surface);
  295. assert(dpy);
  296. if (!context || !context->privData)
  297. return XvMCBadContext;
  298. if (!target_surface || !target_surface->privData)
  299. return XvMCBadSurface;
  300. if (picture_structure != XVMC_TOP_FIELD &&
  301. picture_structure != XVMC_BOTTOM_FIELD &&
  302. picture_structure != XVMC_FRAME_PICTURE)
  303. return BadValue;
  304. /* Bkwd pred equivalent to fwd (past && !future) */
  305. if (future_surface && !past_surface)
  306. return BadMatch;
  307. assert(context->context_id == target_surface->context_id);
  308. assert(!past_surface || context->context_id == past_surface->context_id);
  309. assert(!future_surface || context->context_id == future_surface->context_id);
  310. assert(macroblocks);
  311. assert(blocks);
  312. assert(macroblocks->context_id == context->context_id);
  313. assert(blocks->context_id == context->context_id);
  314. assert(flags == 0 || flags == XVMC_SECOND_FIELD);
  315. target_surface_priv = target_surface->privData;
  316. past_surface_priv = past_surface ? past_surface->privData : NULL;
  317. future_surface_priv = future_surface ? future_surface->privData : NULL;
  318. assert(target_surface_priv->context == context);
  319. assert(!past_surface || past_surface_priv->context == context);
  320. assert(!future_surface || future_surface_priv->context == context);
  321. t_buffer = target_surface_priv->decode_buffer;
  322. // enshure that all reference frames are flushed
  323. // not really nessasary, but speeds ups rendering
  324. if (past_surface)
  325. unmap_and_flush_surface(past_surface->privData);
  326. if (future_surface)
  327. unmap_and_flush_surface(future_surface->privData);
  328. xvmc_mb = macroblocks->macro_blocks + first_macroblock;
  329. /* If the surface we're rendering hasn't changed the ref frames shouldn't change. */
  330. if (target_surface_priv->mapped && (
  331. target_surface_priv->ref[0].surface != past_surface ||
  332. target_surface_priv->ref[1].surface != future_surface ||
  333. (xvmc_mb->x == 0 && xvmc_mb->y == 0))) {
  334. // If they change anyway we need to clear our surface
  335. unmap_and_flush_surface(target_surface_priv);
  336. }
  337. if (!target_surface_priv->mapped) {
  338. t_buffer->begin_frame(t_buffer);
  339. for (i = 0; i < 3; ++i) {
  340. target_surface_priv->ycbcr[i].num_blocks_added = 0;
  341. target_surface_priv->ycbcr[i].stream = t_buffer->get_ycbcr_stream(t_buffer, i);
  342. target_surface_priv->ycbcr[i].buffer = t_buffer->get_ycbcr_buffer(t_buffer, i);
  343. }
  344. for (i = 0; i < 2; ++i) {
  345. target_surface_priv->ref[i].surface = i == 0 ? past_surface : future_surface;
  346. if (target_surface_priv->ref[i].surface)
  347. target_surface_priv->ref[i].mv = t_buffer->get_mv_stream(t_buffer, i);
  348. else
  349. target_surface_priv->ref[i].mv = NULL;
  350. }
  351. target_surface_priv->mapped = 1;
  352. }
  353. MacroBlocksToPipe(target_surface_priv, picture_structure, xvmc_mb, blocks, num_macroblocks);
  354. XVMC_MSG(XVMC_TRACE, "[XvMC] Submitted surface %p for rendering.\n", target_surface);
  355. return Success;
  356. }
  357. PUBLIC
  358. Status XvMCFlushSurface(Display *dpy, XvMCSurface *surface)
  359. {
  360. assert(dpy);
  361. if (!surface)
  362. return XvMCBadSurface;
  363. // don't call flush here, because this is usually
  364. // called once for every slice instead of every frame
  365. XVMC_MSG(XVMC_TRACE, "[XvMC] Flushing surface %p\n", surface);
  366. return Success;
  367. }
  368. PUBLIC
  369. Status XvMCSyncSurface(Display *dpy, XvMCSurface *surface)
  370. {
  371. assert(dpy);
  372. if (!surface)
  373. return XvMCBadSurface;
  374. XVMC_MSG(XVMC_TRACE, "[XvMC] Syncing surface %p\n", surface);
  375. return Success;
  376. }
  377. PUBLIC
  378. Status XvMCPutSurface(Display *dpy, XvMCSurface *surface, Drawable drawable,
  379. short srcx, short srcy, unsigned short srcw, unsigned short srch,
  380. short destx, short desty, unsigned short destw, unsigned short desth,
  381. int flags)
  382. {
  383. static int dump_window = -1;
  384. struct pipe_context *pipe;
  385. struct vl_compositor *compositor;
  386. XvMCSurfacePrivate *surface_priv;
  387. XvMCContextPrivate *context_priv;
  388. XvMCSubpicturePrivate *subpicture_priv;
  389. XvMCContext *context;
  390. struct pipe_video_rect src_rect = {srcx, srcy, srcw, srch};
  391. struct pipe_video_rect dst_rect = {destx, desty, destw, desth};
  392. XVMC_MSG(XVMC_TRACE, "[XvMC] Displaying surface %p.\n", surface);
  393. assert(dpy);
  394. if (!surface || !surface->privData)
  395. return XvMCBadSurface;
  396. surface_priv = surface->privData;
  397. context = surface_priv->context;
  398. context_priv = context->privData;
  399. assert(flags == XVMC_TOP_FIELD || flags == XVMC_BOTTOM_FIELD || flags == XVMC_FRAME_PICTURE);
  400. assert(srcx + srcw - 1 < surface->width);
  401. assert(srcy + srch - 1 < surface->height);
  402. subpicture_priv = surface_priv->subpicture ? surface_priv->subpicture->privData : NULL;
  403. pipe = context_priv->vctx->pipe;
  404. compositor = &context_priv->compositor;
  405. if (!context_priv->drawable_surface ||
  406. context_priv->dst_rect.x != dst_rect.x || context_priv->dst_rect.y != dst_rect.y ||
  407. context_priv->dst_rect.w != dst_rect.w || context_priv->dst_rect.h != dst_rect.h) {
  408. pipe_surface_reference(&context_priv->drawable_surface, NULL);
  409. context_priv->drawable_surface = vl_drawable_surface_get(context_priv->vctx, drawable);
  410. context_priv->dst_rect = dst_rect;
  411. vl_compositor_reset_dirty_area(compositor);
  412. }
  413. if (!context_priv->drawable_surface)
  414. return BadDrawable;
  415. /*
  416. * Some apps (mplayer) hit these asserts because they call
  417. * this function after the window has been resized by the WM
  418. * but before they've handled the corresponding XEvent and
  419. * know about the new dimensions. The output should be clipped
  420. * until the app updates destw and desth.
  421. */
  422. /*
  423. assert(destx + destw - 1 < drawable_surface->width);
  424. assert(desty + desth - 1 < drawable_surface->height);
  425. */
  426. unmap_and_flush_surface(surface_priv);
  427. vl_compositor_clear_layers(compositor);
  428. vl_compositor_set_buffer_layer(compositor, 0, surface_priv->video_buffer, &src_rect, NULL);
  429. if (subpicture_priv) {
  430. XVMC_MSG(XVMC_TRACE, "[XvMC] Surface %p has subpicture %p.\n", surface, surface_priv->subpicture);
  431. assert(subpicture_priv->surface == surface);
  432. if (subpicture_priv->palette)
  433. vl_compositor_set_palette_layer(compositor, 1, subpicture_priv->sampler, subpicture_priv->palette,
  434. &subpicture_priv->src_rect, &subpicture_priv->dst_rect);
  435. else
  436. vl_compositor_set_rgba_layer(compositor, 1, subpicture_priv->sampler,
  437. &subpicture_priv->src_rect, &subpicture_priv->dst_rect);
  438. surface_priv->subpicture = NULL;
  439. subpicture_priv->surface = NULL;
  440. }
  441. // Workaround for r600g, there seems to be a bug in the fence refcounting code
  442. pipe->screen->fence_reference(pipe->screen, &surface_priv->fence, NULL);
  443. vl_compositor_render(compositor, PictureToPipe(flags), context_priv->drawable_surface, &dst_rect, &surface_priv->fence);
  444. XVMC_MSG(XVMC_TRACE, "[XvMC] Submitted surface %p for display. Pushing to front buffer.\n", surface);
  445. pipe->screen->flush_frontbuffer
  446. (
  447. pipe->screen,
  448. context_priv->drawable_surface->texture,
  449. 0, 0,
  450. vl_contextprivate_get(context_priv->vctx, context_priv->drawable_surface)
  451. );
  452. if(dump_window == -1) {
  453. dump_window = debug_get_num_option("XVMC_DUMP", 0);
  454. }
  455. if(dump_window) {
  456. static unsigned int framenum = 0;
  457. char cmd[256];
  458. sprintf(cmd, "xwd -id %d -out xvmc_frame_%08d.xwd", (int)drawable, ++framenum);
  459. if (system(cmd) != 0)
  460. XVMC_MSG(XVMC_ERR, "[XvMC] Dumping surface %p failed.\n", surface);
  461. }
  462. XVMC_MSG(XVMC_TRACE, "[XvMC] Pushed surface %p to front buffer.\n", surface);
  463. return Success;
  464. }
  465. PUBLIC
  466. Status XvMCGetSurfaceStatus(Display *dpy, XvMCSurface *surface, int *status)
  467. {
  468. struct pipe_context *pipe;
  469. XvMCSurfacePrivate *surface_priv;
  470. XvMCContextPrivate *context_priv;
  471. assert(dpy);
  472. if (!surface)
  473. return XvMCBadSurface;
  474. assert(status);
  475. surface_priv = surface->privData;
  476. context_priv = surface_priv->context->privData;
  477. pipe = context_priv->vctx->pipe;
  478. *status = 0;
  479. if (surface_priv->fence)
  480. if (!pipe->screen->fence_signalled(pipe->screen, surface_priv->fence))
  481. *status |= XVMC_RENDERING;
  482. return Success;
  483. }
  484. PUBLIC
  485. Status XvMCDestroySurface(Display *dpy, XvMCSurface *surface)
  486. {
  487. XvMCSurfacePrivate *surface_priv;
  488. XVMC_MSG(XVMC_TRACE, "[XvMC] Destroying surface %p.\n", surface);
  489. assert(dpy);
  490. if (!surface || !surface->privData)
  491. return XvMCBadSurface;
  492. surface_priv = surface->privData;
  493. if (surface_priv->mapped)
  494. surface_priv->decode_buffer->end_frame(surface_priv->decode_buffer);
  495. surface_priv->decode_buffer->destroy(surface_priv->decode_buffer);
  496. surface_priv->video_buffer->destroy(surface_priv->video_buffer);
  497. FREE(surface_priv);
  498. surface->privData = NULL;
  499. XVMC_MSG(XVMC_TRACE, "[XvMC] Surface %p destroyed.\n", surface);
  500. return Success;
  501. }
  502. PUBLIC
  503. Status XvMCHideSurface(Display *dpy, XvMCSurface *surface)
  504. {
  505. assert(dpy);
  506. if (!surface || !surface->privData)
  507. return XvMCBadSurface;
  508. /* No op, only for overlaid rendering */
  509. return Success;
  510. }