glamor_xv.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. /*
  2. * Copyright © 2013 Red Hat
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Dave Airlie <airlied@redhat.com>
  25. *
  26. * some code is derived from the xf86-video-ati radeon driver, mainly
  27. * the calculations.
  28. */
  29. /** @file glamor_xv.c
  30. *
  31. * Xv acceleration implementation
  32. */
  33. #ifdef HAVE_DIX_CONFIG_H
  34. #include <dix-config.h>
  35. #endif
  36. #include "xf86xv.h"
  37. #define GLAMOR_FOR_XORG
  38. #include "glamor_priv.h"
  39. #include <X11/extensions/Xv.h>
  40. #include "fourcc.h"
  41. /* Reference color space transform data */
  42. typedef struct tagREF_TRANSFORM {
  43. float RefLuma;
  44. float RefRCb;
  45. float RefRCr;
  46. float RefGCb;
  47. float RefGCr;
  48. float RefBCb;
  49. float RefBCr;
  50. } REF_TRANSFORM;
  51. #define RTFSaturation(a) (1.0 + ((a)*1.0)/1000.0)
  52. #define RTFBrightness(a) (((a)*1.0)/2000.0)
  53. #define RTFIntensity(a) (((a)*1.0)/2000.0)
  54. #define RTFContrast(a) (1.0 + ((a)*1.0)/1000.0)
  55. #define RTFHue(a) (((a)*3.1416)/1000.0)
  56. static const char *xv_vs = "attribute vec4 v_position;\n"
  57. "attribute vec4 v_texcoord0;\n"
  58. "varying vec2 tcs;\n"
  59. "void main()\n"
  60. "{\n"
  61. " gl_Position = v_position;\n"
  62. "tcs = v_texcoord0.xy;\n"
  63. "}\n";
  64. static const char *xv_ps = GLAMOR_DEFAULT_PRECISION
  65. "uniform sampler2D y_sampler;\n"
  66. "uniform sampler2D u_sampler;\n"
  67. "uniform sampler2D v_sampler;\n"
  68. "uniform vec4 offsetyco;\n"
  69. "uniform vec4 ucogamma;\n"
  70. "uniform vec4 vco;\n"
  71. "varying vec2 tcs;\n"
  72. "float sample;\n"
  73. "vec4 temp1;\n"
  74. "void main()\n"
  75. "{\n"
  76. "sample = texture2D(y_sampler, tcs).w;\n"
  77. "temp1.xyz = offsetyco.www * vec3(sample) + offsetyco.xyz;\n"
  78. "sample = texture2D(u_sampler, tcs).w;\n"
  79. "temp1.xyz = ucogamma.xyz * vec3(sample) + temp1.xyz;\n"
  80. "sample = texture2D(v_sampler, tcs).w;\n"
  81. "temp1.xyz = clamp(vco.xyz * vec3(sample) + temp1.xyz, 0.0, 1.0);\n"
  82. "temp1.w = 1.0;\n"
  83. "gl_FragColor = temp1;\n"
  84. "}\n";
  85. void
  86. glamor_init_xv_shader(ScreenPtr screen)
  87. {
  88. glamor_screen_private *glamor_priv;
  89. GLint fs_prog, vs_prog;
  90. glamor_priv = glamor_get_screen_private(screen);
  91. glamor_make_current(glamor_priv);
  92. glamor_priv->xv_prog = glCreateProgram();
  93. vs_prog = glamor_compile_glsl_prog(GL_VERTEX_SHADER, xv_vs);
  94. fs_prog = glamor_compile_glsl_prog(GL_FRAGMENT_SHADER, xv_ps);
  95. glAttachShader(glamor_priv->xv_prog, vs_prog);
  96. glAttachShader(glamor_priv->xv_prog, fs_prog);
  97. glBindAttribLocation(glamor_priv->xv_prog,
  98. GLAMOR_VERTEX_POS, "v_position");
  99. glBindAttribLocation(glamor_priv->xv_prog,
  100. GLAMOR_VERTEX_SOURCE, "v_texcoord0");
  101. glamor_link_glsl_prog(screen, glamor_priv->xv_prog, "xv");
  102. }
  103. #define ClipValue(v,min,max) ((v) < (min) ? (min) : (v) > (max) ? (max) : (v))
  104. #define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE)
  105. static Atom xvBrightness, xvContrast, xvSaturation, xvHue, xvColorspace,
  106. xvGamma;
  107. #define NUM_ATTRIBUTES 5
  108. static XF86AttributeRec Attributes_glamor[NUM_ATTRIBUTES + 1] = {
  109. {XvSettable | XvGettable, -1000, 1000, "XV_BRIGHTNESS"},
  110. {XvSettable | XvGettable, -1000, 1000, "XV_CONTRAST"},
  111. {XvSettable | XvGettable, -1000, 1000, "XV_SATURATION"},
  112. {XvSettable | XvGettable, -1000, 1000, "XV_HUE"},
  113. {XvSettable | XvGettable, 0, 1, "XV_COLORSPACE"},
  114. {0, 0, 0, NULL}
  115. };
  116. #define NUM_FORMATS 3
  117. static XF86VideoFormatRec Formats[NUM_FORMATS] = {
  118. {15, TrueColor}, {16, TrueColor}, {24, TrueColor}
  119. };
  120. #define NUM_IMAGES 2
  121. static XF86ImageRec Images[NUM_IMAGES] = {
  122. XVIMAGE_YV12,
  123. XVIMAGE_I420,
  124. };
  125. static void
  126. glamor_xv_stop_video(ScrnInfoPtr pScrn, void *data, Bool cleanup)
  127. {
  128. glamor_port_private *port_priv = (glamor_port_private *) data;
  129. int i;
  130. if (!cleanup)
  131. return;
  132. for (i = 0; i < 3; i++) {
  133. if (port_priv->src_pix[i]) {
  134. glamor_destroy_pixmap(port_priv->src_pix[i]);
  135. port_priv->src_pix[i] = NULL;
  136. }
  137. }
  138. }
  139. static int
  140. glamor_xv_set_port_attribute(ScrnInfoPtr pScrn,
  141. Atom attribute, INT32 value, void *data)
  142. {
  143. glamor_port_private *port_priv = (glamor_port_private *) data;
  144. if (attribute == xvBrightness)
  145. port_priv->brightness = ClipValue(value, -1000, 1000);
  146. else if (attribute == xvHue)
  147. port_priv->hue = ClipValue(value, -1000, 1000);
  148. else if (attribute == xvContrast)
  149. port_priv->contrast = ClipValue(value, -1000, 1000);
  150. else if (attribute == xvSaturation)
  151. port_priv->saturation = ClipValue(value, -1000, 1000);
  152. else if (attribute == xvGamma)
  153. port_priv->gamma = ClipValue(value, 100, 10000);
  154. else if (attribute == xvColorspace)
  155. port_priv->transform_index = ClipValue(value, 0, 1);
  156. else
  157. return BadMatch;
  158. return Success;
  159. }
  160. static int
  161. glamor_xv_get_port_attribute(ScrnInfoPtr pScrn,
  162. Atom attribute, INT32 *value, void *data)
  163. {
  164. glamor_port_private *port_priv = (glamor_port_private *) data;
  165. if (attribute == xvBrightness)
  166. *value = port_priv->brightness;
  167. else if (attribute == xvHue)
  168. *value = port_priv->hue;
  169. else if (attribute == xvContrast)
  170. *value = port_priv->contrast;
  171. else if (attribute == xvSaturation)
  172. *value = port_priv->saturation;
  173. else if (attribute == xvGamma)
  174. *value = port_priv->gamma;
  175. else if (attribute == xvColorspace)
  176. *value = port_priv->transform_index;
  177. else
  178. return BadMatch;
  179. return Success;
  180. }
  181. static void
  182. glamor_xv_query_best_size(ScrnInfoPtr pScrn,
  183. Bool motion,
  184. short vid_w, short vid_h,
  185. short drw_w, short drw_h,
  186. unsigned int *p_w, unsigned int *p_h, void *data)
  187. {
  188. *p_w = drw_w;
  189. *p_h = drw_h;
  190. }
  191. static int
  192. glamor_xv_query_image_attributes(ScrnInfoPtr pScrn,
  193. int id,
  194. unsigned short *w, unsigned short *h,
  195. int *pitches, int *offsets)
  196. {
  197. int size = 0, tmp;
  198. if (offsets)
  199. offsets[0] = 0;
  200. switch (id) {
  201. case FOURCC_YV12:
  202. case FOURCC_I420:
  203. *h = *h;
  204. *w = *w;
  205. size = *w;
  206. if (pitches)
  207. pitches[0] = size;
  208. size *= *h;
  209. if (offsets)
  210. offsets[1] = size;
  211. tmp = *w >> 1;
  212. if (pitches)
  213. pitches[1] = pitches[2] = tmp;
  214. tmp *= (*h >> 1);
  215. size += tmp;
  216. if (offsets)
  217. offsets[2] = size;
  218. size += tmp;
  219. break;
  220. }
  221. return size;
  222. }
  223. /* Parameters for ITU-R BT.601 and ITU-R BT.709 colour spaces
  224. note the difference to the parameters used in overlay are due
  225. to 10bit vs. float calcs */
  226. static REF_TRANSFORM trans[2] = {
  227. {1.1643, 0.0, 1.5960, -0.3918, -0.8129, 2.0172, 0.0}, /* BT.601 */
  228. {1.1643, 0.0, 1.7927, -0.2132, -0.5329, 2.1124, 0.0} /* BT.709 */
  229. };
  230. static void
  231. glamor_display_textured_video(glamor_port_private *port_priv)
  232. {
  233. ScreenPtr screen = port_priv->pPixmap->drawable.pScreen;
  234. glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
  235. glamor_pixmap_private *pixmap_priv =
  236. glamor_get_pixmap_private(port_priv->pPixmap);
  237. glamor_pixmap_private *src_pixmap_priv[3];
  238. float vertices[32], texcoords[8];
  239. BoxPtr box = REGION_RECTS(&port_priv->clip);
  240. int nBox = REGION_NUM_RECTS(&port_priv->clip);
  241. int dst_x_off, dst_y_off;
  242. GLfloat dst_xscale, dst_yscale;
  243. GLfloat src_xscale[3], src_yscale[3];
  244. int i;
  245. const float Loff = -0.0627;
  246. const float Coff = -0.502;
  247. float uvcosf, uvsinf;
  248. float yco;
  249. float uco[3], vco[3], off[3];
  250. float bright, cont, gamma;
  251. int ref = port_priv->transform_index;
  252. GLint uloc, sampler_loc;
  253. cont = RTFContrast(port_priv->contrast);
  254. bright = RTFBrightness(port_priv->brightness);
  255. gamma = (float) port_priv->gamma / 1000.0;
  256. uvcosf = RTFSaturation(port_priv->saturation) * cos(RTFHue(port_priv->hue));
  257. uvsinf = RTFSaturation(port_priv->saturation) * sin(RTFHue(port_priv->hue));
  258. /* overlay video also does pre-gamma contrast/sat adjust, should we? */
  259. yco = trans[ref].RefLuma * cont;
  260. uco[0] = -trans[ref].RefRCr * uvsinf;
  261. uco[1] = trans[ref].RefGCb * uvcosf - trans[ref].RefGCr * uvsinf;
  262. uco[2] = trans[ref].RefBCb * uvcosf;
  263. vco[0] = trans[ref].RefRCr * uvcosf;
  264. vco[1] = trans[ref].RefGCb * uvsinf + trans[ref].RefGCr * uvcosf;
  265. vco[2] = trans[ref].RefBCb * uvsinf;
  266. off[0] = Loff * yco + Coff * (uco[0] + vco[0]) + bright;
  267. off[1] = Loff * yco + Coff * (uco[1] + vco[1]) + bright;
  268. off[2] = Loff * yco + Coff * (uco[2] + vco[2]) + bright;
  269. gamma = 1.0;
  270. pixmap_priv_get_dest_scale(pixmap_priv, &dst_xscale, &dst_yscale);
  271. glamor_get_drawable_deltas(port_priv->pDraw, port_priv->pPixmap, &dst_x_off,
  272. &dst_y_off);
  273. glamor_set_destination_pixmap_priv_nc(pixmap_priv);
  274. for (i = 0; i < 3; i++) {
  275. if (port_priv->src_pix[i]) {
  276. src_pixmap_priv[i] =
  277. glamor_get_pixmap_private(port_priv->src_pix[i]);
  278. pixmap_priv_get_scale(src_pixmap_priv[i], &src_xscale[i],
  279. &src_yscale[i]);
  280. }
  281. }
  282. glamor_make_current(glamor_priv);
  283. glUseProgram(glamor_priv->xv_prog);
  284. uloc = glGetUniformLocation(glamor_priv->xv_prog, "offsetyco");
  285. glUniform4f(uloc, off[0], off[1], off[2], yco);
  286. uloc = glGetUniformLocation(glamor_priv->xv_prog, "ucogamma");
  287. glUniform4f(uloc, uco[0], uco[1], uco[2], gamma);
  288. uloc = glGetUniformLocation(glamor_priv->xv_prog, "vco");
  289. glUniform4f(uloc, vco[0], vco[1], vco[2], 0);
  290. glActiveTexture(GL_TEXTURE0);
  291. glBindTexture(GL_TEXTURE_2D, src_pixmap_priv[0]->base.fbo->tex);
  292. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  293. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  294. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  295. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  296. glActiveTexture(GL_TEXTURE1);
  297. glBindTexture(GL_TEXTURE_2D, src_pixmap_priv[1]->base.fbo->tex);
  298. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  299. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  300. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  301. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  302. glActiveTexture(GL_TEXTURE2);
  303. glBindTexture(GL_TEXTURE_2D, src_pixmap_priv[2]->base.fbo->tex);
  304. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  305. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  306. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  307. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  308. sampler_loc = glGetUniformLocation(glamor_priv->xv_prog, "y_sampler");
  309. glUniform1i(sampler_loc, 0);
  310. sampler_loc = glGetUniformLocation(glamor_priv->xv_prog, "u_sampler");
  311. glUniform1i(sampler_loc, 1);
  312. sampler_loc = glGetUniformLocation(glamor_priv->xv_prog, "v_sampler");
  313. glUniform1i(sampler_loc, 2);
  314. glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2,
  315. GL_FLOAT, GL_FALSE,
  316. 2 * sizeof(float), texcoords);
  317. glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
  318. glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT,
  319. GL_FALSE, 2 * sizeof(float), vertices);
  320. glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
  321. for (i = 0; i < nBox; i++) {
  322. float off_x = box[i].x1 - port_priv->drw_x;
  323. float off_y = box[i].y1 - port_priv->drw_y;
  324. float diff_x = (float) port_priv->src_w / (float) port_priv->dst_w;
  325. float diff_y = (float) port_priv->src_h / (float) port_priv->dst_h;
  326. float srcx, srcy, srcw, srch;
  327. int dstx, dsty, dstw, dsth;
  328. dstx = box[i].x1 + dst_x_off;
  329. dsty = box[i].y1 + dst_y_off;
  330. dstw = box[i].x2 - box[i].x1;
  331. dsth = box[i].y2 - box[i].y1;
  332. srcx = port_priv->src_x + off_x * diff_x;
  333. srcy = port_priv->src_y + off_y * diff_y;
  334. srcw = (port_priv->src_w * dstw) / (float) port_priv->dst_w;
  335. srch = (port_priv->src_h * dsth) / (float) port_priv->dst_h;
  336. glamor_set_normalize_vcoords(pixmap_priv,
  337. dst_xscale, dst_yscale,
  338. dstx,
  339. dsty,
  340. dstx + dstw,
  341. dsty + dsth,
  342. glamor_priv->yInverted, vertices);
  343. glamor_set_normalize_tcoords(src_pixmap_priv[0],
  344. src_xscale[0],
  345. src_yscale[0],
  346. srcx,
  347. srcy,
  348. srcx + srcw,
  349. srcy + srch,
  350. glamor_priv->yInverted, texcoords);
  351. glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
  352. }
  353. glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
  354. glDisableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
  355. DamageDamageRegion(port_priv->pDraw, &port_priv->clip);
  356. }
  357. static int
  358. glamor_xv_put_image(ScrnInfoPtr pScrn,
  359. short src_x, short src_y,
  360. short drw_x, short drw_y,
  361. short src_w, short src_h,
  362. short drw_w, short drw_h,
  363. int id,
  364. unsigned char *buf,
  365. short width,
  366. short height,
  367. Bool sync,
  368. RegionPtr clipBoxes, void *data, DrawablePtr pDrawable)
  369. {
  370. ScreenPtr screen = pDrawable->pScreen;
  371. glamor_port_private *port_priv = (glamor_port_private *) data;
  372. INT32 x1, x2, y1, y2;
  373. int srcPitch, srcPitch2;
  374. BoxRec dstBox;
  375. int top, nlines;
  376. int s2offset, s3offset, tmp;
  377. s2offset = s3offset = srcPitch2 = 0;
  378. /* Clip */
  379. x1 = src_x;
  380. x2 = src_x + src_w;
  381. y1 = src_y;
  382. y2 = src_y + src_h;
  383. dstBox.x1 = drw_x;
  384. dstBox.x2 = drw_x + drw_w;
  385. dstBox.y1 = drw_y;
  386. dstBox.y2 = drw_y + drw_h;
  387. if (!xf86XVClipVideoHelper
  388. (&dstBox, &x1, &x2, &y1, &y2, clipBoxes, width, height))
  389. return Success;
  390. if ((x1 >= x2) || (y1 >= y2))
  391. return Success;
  392. srcPitch = width;
  393. srcPitch2 = width >> 1;
  394. if (!port_priv->src_pix[0] ||
  395. (width != port_priv->src_pix_w || height != port_priv->src_pix_h)) {
  396. int i;
  397. for (i = 0; i < 3; i++)
  398. if (port_priv->src_pix[i])
  399. glamor_destroy_pixmap(port_priv->src_pix[i]);
  400. port_priv->src_pix[0] =
  401. glamor_create_pixmap(screen, width, height, 8, 0);
  402. port_priv->src_pix[1] =
  403. glamor_create_pixmap(screen, width >> 1, height >> 1, 8, 0);
  404. port_priv->src_pix[2] =
  405. glamor_create_pixmap(screen, width >> 1, height >> 1, 8, 0);
  406. port_priv->src_pix_w = width;
  407. port_priv->src_pix_h = height;
  408. if (!port_priv->src_pix[0] || !port_priv->src_pix[1] ||
  409. !port_priv->src_pix[2])
  410. return BadAlloc;
  411. }
  412. top = (y1 >> 16) & ~1;
  413. nlines = ((y2 + 0xffff) >> 16) - top;
  414. switch (id) {
  415. case FOURCC_YV12:
  416. case FOURCC_I420:
  417. s2offset = srcPitch * height;
  418. s3offset = s2offset + (srcPitch2 * ((height + 1) >> 1));
  419. s2offset += ((top >> 1) * srcPitch2);
  420. s3offset += ((top >> 1) * srcPitch2);
  421. if (id == FOURCC_YV12) {
  422. tmp = s2offset;
  423. s2offset = s3offset;
  424. s3offset = tmp;
  425. }
  426. glamor_upload_sub_pixmap_to_texture(port_priv->src_pix[0],
  427. 0, 0, srcPitch, nlines,
  428. port_priv->src_pix[0]->devKind,
  429. buf + (top * srcPitch), 0);
  430. glamor_upload_sub_pixmap_to_texture(port_priv->src_pix[1],
  431. 0, 0, srcPitch2, (nlines + 1) >> 1,
  432. port_priv->src_pix[1]->devKind,
  433. buf + s2offset, 0);
  434. glamor_upload_sub_pixmap_to_texture(port_priv->src_pix[2],
  435. 0, 0, srcPitch2, (nlines + 1) >> 1,
  436. port_priv->src_pix[2]->devKind,
  437. buf + s3offset, 0);
  438. break;
  439. default:
  440. return BadMatch;
  441. }
  442. if (pDrawable->type == DRAWABLE_WINDOW)
  443. port_priv->pPixmap = (*screen->GetWindowPixmap) ((WindowPtr) pDrawable);
  444. else
  445. port_priv->pPixmap = (PixmapPtr) pDrawable;
  446. if (!RegionEqual(&port_priv->clip, clipBoxes)) {
  447. RegionCopy(&port_priv->clip, clipBoxes);
  448. }
  449. port_priv->src_x = src_x;
  450. port_priv->src_y = src_y;
  451. port_priv->src_w = src_w;
  452. port_priv->src_h = src_h;
  453. port_priv->dst_w = drw_w;
  454. port_priv->dst_h = drw_h;
  455. port_priv->drw_x = drw_x;
  456. port_priv->drw_y = drw_y;
  457. port_priv->w = width;
  458. port_priv->h = height;
  459. port_priv->pDraw = pDrawable;
  460. glamor_display_textured_video(port_priv);
  461. return Success;
  462. }
  463. static XF86VideoEncodingRec DummyEncodingGLAMOR[1] = {
  464. {
  465. 0,
  466. "XV_IMAGE",
  467. 8192, 8192,
  468. {1, 1}
  469. }
  470. };
  471. XF86VideoAdaptorPtr
  472. glamor_xv_init(ScreenPtr screen, int num_texture_ports)
  473. {
  474. glamor_port_private *port_priv;
  475. XF86VideoAdaptorPtr adapt;
  476. int i;
  477. glamor_init_xv_shader(screen);
  478. adapt = calloc(1, sizeof(XF86VideoAdaptorRec) + num_texture_ports *
  479. (sizeof(glamor_port_private) + sizeof(DevUnion)));
  480. if (adapt == NULL)
  481. return NULL;
  482. xvBrightness = MAKE_ATOM("XV_BRIGHTNESS");
  483. xvContrast = MAKE_ATOM("XV_CONTRAST");
  484. xvSaturation = MAKE_ATOM("XV_SATURATION");
  485. xvHue = MAKE_ATOM("XV_HUE");
  486. xvGamma = MAKE_ATOM("XV_GAMMA");
  487. xvColorspace = MAKE_ATOM("XV_COLORSPACE");
  488. adapt->type = XvWindowMask | XvInputMask | XvImageMask;
  489. adapt->flags = 0;
  490. adapt->name = "GLAMOR Textured Video";
  491. adapt->nEncodings = 1;
  492. adapt->pEncodings = DummyEncodingGLAMOR;
  493. adapt->nFormats = NUM_FORMATS;
  494. adapt->pFormats = Formats;
  495. adapt->nPorts = num_texture_ports;
  496. adapt->pPortPrivates = (DevUnion *) (&adapt[1]);
  497. adapt->pAttributes = Attributes_glamor;
  498. adapt->nAttributes = NUM_ATTRIBUTES;
  499. port_priv =
  500. (glamor_port_private *) (&adapt->pPortPrivates[num_texture_ports]);
  501. adapt->pImages = Images;
  502. adapt->nImages = NUM_IMAGES;
  503. adapt->PutVideo = NULL;
  504. adapt->PutStill = NULL;
  505. adapt->GetVideo = NULL;
  506. adapt->GetStill = NULL;
  507. adapt->StopVideo = glamor_xv_stop_video;
  508. adapt->SetPortAttribute = glamor_xv_set_port_attribute;
  509. adapt->GetPortAttribute = glamor_xv_get_port_attribute;
  510. adapt->QueryBestSize = glamor_xv_query_best_size;
  511. adapt->PutImage = glamor_xv_put_image;
  512. adapt->ReputImage = NULL;
  513. adapt->QueryImageAttributes = glamor_xv_query_image_attributes;
  514. for (i = 0; i < num_texture_ports; i++) {
  515. glamor_port_private *pPriv = &port_priv[i];
  516. pPriv->brightness = 0;
  517. pPriv->contrast = 0;
  518. pPriv->saturation = 0;
  519. pPriv->hue = 0;
  520. pPriv->gamma = 1000;
  521. pPriv->transform_index = 0;
  522. REGION_NULL(pScreen, &pPriv->clip);
  523. adapt->pPortPrivates[i].ptr = (void *) (pPriv);
  524. }
  525. return adapt;
  526. }