glamor_xf86_xv.c (5888B)
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 30 /** @file glamor_xf86_xv.c 31 * 32 * This implements the XF86 XV interface, and calls into glamor core 33 * for its support of the suspiciously similar XF86 and Kdrive 34 * device-dependent XV interfaces. 35 */ 36 37 #ifdef HAVE_DIX_CONFIG_H 38 #include <dix-config.h> 39 #endif 40 41 #define GLAMOR_FOR_XORG 42 #include "glamor_priv.h" 43 44 #include <X11/extensions/Xv.h> 45 #include "fourcc.h" 46 47 #define NUM_FORMATS 4 48 49 static XF86VideoFormatRec Formats[NUM_FORMATS] = { 50 {15, TrueColor}, {16, TrueColor}, {24, TrueColor}, {30, TrueColor} 51 }; 52 53 static void 54 glamor_xf86_xv_stop_video(ScrnInfoPtr pScrn, void *data, Bool cleanup) 55 { 56 if (!cleanup) 57 return; 58 59 glamor_xv_stop_video(data); 60 } 61 62 static int 63 glamor_xf86_xv_set_port_attribute(ScrnInfoPtr pScrn, 64 Atom attribute, INT32 value, void *data) 65 { 66 return glamor_xv_set_port_attribute(data, attribute, value); 67 } 68 69 static int 70 glamor_xf86_xv_get_port_attribute(ScrnInfoPtr pScrn, 71 Atom attribute, INT32 *value, void *data) 72 { 73 return glamor_xv_get_port_attribute(data, attribute, value); 74 } 75 76 static void 77 glamor_xf86_xv_query_best_size(ScrnInfoPtr pScrn, 78 Bool motion, 79 short vid_w, short vid_h, 80 short drw_w, short drw_h, 81 unsigned int *p_w, unsigned int *p_h, void *data) 82 { 83 *p_w = drw_w; 84 *p_h = drw_h; 85 } 86 87 static int 88 glamor_xf86_xv_query_image_attributes(ScrnInfoPtr pScrn, 89 int id, 90 unsigned short *w, unsigned short *h, 91 int *pitches, int *offsets) 92 { 93 return glamor_xv_query_image_attributes(id, w, h, pitches, offsets); 94 } 95 96 static int 97 glamor_xf86_xv_put_image(ScrnInfoPtr pScrn, 98 short src_x, short src_y, 99 short drw_x, short drw_y, 100 short src_w, short src_h, 101 short drw_w, short drw_h, 102 int id, 103 unsigned char *buf, 104 short width, 105 short height, 106 Bool sync, 107 RegionPtr clipBoxes, void *data, DrawablePtr pDrawable) 108 { 109 return glamor_xv_put_image(data, pDrawable, 110 src_x, src_y, 111 drw_x, drw_y, 112 src_w, src_h, 113 drw_w, drw_h, 114 id, buf, width, height, sync, clipBoxes); 115 } 116 117 static XF86VideoEncodingRec DummyEncodingGLAMOR[1] = { 118 { 119 0, 120 "XV_IMAGE", 121 8192, 8192, 122 {1, 1} 123 } 124 }; 125 126 XF86VideoAdaptorPtr 127 glamor_xv_init(ScreenPtr screen, int num_texture_ports) 128 { 129 glamor_port_private *port_priv; 130 XF86VideoAdaptorPtr adapt; 131 int i; 132 133 glamor_xv_core_init(screen); 134 135 adapt = calloc(1, sizeof(XF86VideoAdaptorRec) + num_texture_ports * 136 (sizeof(glamor_port_private) + sizeof(DevUnion))); 137 if (adapt == NULL) 138 return NULL; 139 140 adapt->type = XvWindowMask | XvInputMask | XvImageMask; 141 adapt->flags = 0; 142 adapt->name = "GLAMOR Textured Video"; 143 adapt->nEncodings = 1; 144 adapt->pEncodings = DummyEncodingGLAMOR; 145 146 adapt->nFormats = NUM_FORMATS; 147 adapt->pFormats = Formats; 148 adapt->nPorts = num_texture_ports; 149 adapt->pPortPrivates = (DevUnion *) (&adapt[1]); 150 151 adapt->pAttributes = glamor_xv_attributes; 152 adapt->nAttributes = glamor_xv_num_attributes; 153 154 port_priv = 155 (glamor_port_private *) (&adapt->pPortPrivates[num_texture_ports]); 156 adapt->pImages = glamor_xv_images; 157 adapt->nImages = glamor_xv_num_images; 158 adapt->PutVideo = NULL; 159 adapt->PutStill = NULL; 160 adapt->GetVideo = NULL; 161 adapt->GetStill = NULL; 162 adapt->StopVideo = glamor_xf86_xv_stop_video; 163 adapt->SetPortAttribute = glamor_xf86_xv_set_port_attribute; 164 adapt->GetPortAttribute = glamor_xf86_xv_get_port_attribute; 165 adapt->QueryBestSize = glamor_xf86_xv_query_best_size; 166 adapt->PutImage = glamor_xf86_xv_put_image; 167 adapt->ReputImage = NULL; 168 adapt->QueryImageAttributes = glamor_xf86_xv_query_image_attributes; 169 170 for (i = 0; i < num_texture_ports; i++) { 171 glamor_port_private *pPriv = &port_priv[i]; 172 173 pPriv->brightness = 0; 174 pPriv->contrast = 0; 175 pPriv->saturation = 0; 176 pPriv->hue = 0; 177 pPriv->gamma = 1000; 178 pPriv->transform_index = 0; 179 180 REGION_NULL(pScreen, &pPriv->clip); 181 182 adapt->pPortPrivates[i].ptr = (void *) (pPriv); 183 } 184 return adapt; 185 }